OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/chrome_plugin_service_filter.h" | 10 #include "chrome/browser/chrome_plugin_service_filter.h" |
11 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 11 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
12 #include "chrome/browser/plugin_prefs.h" | 12 #include "chrome/browser/plugin_prefs.h" |
13 #include "chrome/browser/plugin_prefs_factory.h" | 13 #include "chrome/browser/plugin_prefs_factory.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/test/base/testing_pref_service.h" | 15 #include "chrome/test/base/testing_pref_service.h" |
| 16 #include "chrome/test/base/testing_profile.h" |
16 #include "content/public/browser/plugin_service.h" | 17 #include "content/public/browser/plugin_service.h" |
17 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
18 #include "content/public/test/mock_resource_context.h" | 19 #include "content/public/test/mock_resource_context.h" |
19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
20 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_job.h" | 23 #include "net/url_request/url_request_job.h" |
23 #include "net/url_request/url_request_job_factory.h" | 24 #include "net/url_request/url_request_job_factory.h" |
24 #include "net/url_request/url_request_job_factory_impl.h" | 25 #include "net/url_request/url_request_job_factory_impl.h" |
25 #include "net/url_request/url_request_test_job.h" | 26 #include "net/url_request/url_request_test_job.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 io_thread_(BrowserThread::IO, &message_loop_), | 96 io_thread_(BrowserThread::IO, &message_loop_), |
96 plugin_list_(NULL, 0) {} | 97 plugin_list_(NULL, 0) {} |
97 | 98 |
98 virtual void SetUp() { | 99 virtual void SetUp() { |
99 net::URLRequestContext* request_context = | 100 net::URLRequestContext* request_context = |
100 resource_context_.GetRequestContext(); | 101 resource_context_.GetRequestContext(); |
101 old_factory_ = request_context->job_factory(); | 102 old_factory_ = request_context->job_factory(); |
102 job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory); | 103 job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory); |
103 job_factory_.AddInterceptor(new GViewRequestInterceptor); | 104 job_factory_.AddInterceptor(new GViewRequestInterceptor); |
104 request_context->set_job_factory(&job_factory_); | 105 request_context->set_job_factory(&job_factory_); |
105 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(&prefs_); | 106 plugin_prefs_ = PluginPrefs::GetForTestingProfile(&profile_); |
106 plugin_prefs_ = new PluginPrefs(); | 107 PluginPrefsFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
107 plugin_prefs_->SetPrefs(&prefs_); | |
108 ChromePluginServiceFilter* filter = | 108 ChromePluginServiceFilter* filter = |
109 ChromePluginServiceFilter::GetInstance(); | 109 ChromePluginServiceFilter::GetInstance(); |
110 filter->RegisterResourceContext(plugin_prefs_, &resource_context_); | 110 filter->RegisterResourceContext(plugin_prefs_, &resource_context_); |
111 PluginService::GetInstance()->SetFilter(filter); | 111 PluginService::GetInstance()->SetFilter(filter); |
112 | 112 |
113 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); | 113 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); |
114 | 114 |
115 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list_); | 115 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list_); |
116 PluginService::GetInstance()->Init(); | 116 PluginService::GetInstance()->Init(); |
117 } | 117 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 -1); | 167 -1); |
168 } | 168 } |
169 | 169 |
170 protected: | 170 protected: |
171 base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService. | 171 base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService. |
172 MessageLoopForIO message_loop_; | 172 MessageLoopForIO message_loop_; |
173 content::TestBrowserThread ui_thread_; | 173 content::TestBrowserThread ui_thread_; |
174 content::TestBrowserThread file_thread_; | 174 content::TestBrowserThread file_thread_; |
175 content::TestBrowserThread io_thread_; | 175 content::TestBrowserThread io_thread_; |
176 webkit::npapi::MockPluginList plugin_list_; | 176 webkit::npapi::MockPluginList plugin_list_; |
177 TestingPrefService prefs_; | 177 TestingProfile profile_; |
178 scoped_refptr<PluginPrefs> plugin_prefs_; | 178 scoped_refptr<PluginPrefs> plugin_prefs_; |
179 net::URLRequestJobFactoryImpl job_factory_; | 179 net::URLRequestJobFactoryImpl job_factory_; |
180 const net::URLRequestJobFactory* old_factory_; | 180 const net::URLRequestJobFactory* old_factory_; |
181 TestDelegate test_delegate_; | 181 TestDelegate test_delegate_; |
182 FilePath pdf_path_; | 182 FilePath pdf_path_; |
183 content::MockResourceContext resource_context_; | 183 content::MockResourceContext resource_context_; |
184 }; | 184 }; |
185 | 185 |
186 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { | 186 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { |
187 net::URLRequest request( | 187 net::URLRequest request( |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 SetupRequest(&request); | 280 SetupRequest(&request); |
281 request.Start(); | 281 request.Start(); |
282 MessageLoop::current()->Run(); | 282 MessageLoop::current()->Run(); |
283 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 283 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
284 EXPECT_EQ(GURL(kPdfBlob), request.url()); | 284 EXPECT_EQ(GURL(kPdfBlob), request.url()); |
285 } | 285 } |
286 | 286 |
287 } // namespace | 287 } // namespace |
288 | 288 |
289 } // namespace chromeos | 289 } // namespace chromeos |
OLD | NEW |