OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "chrome/browser/chrome_plugin_service_filter.h" | 8 #include "chrome/browser/chrome_plugin_service_filter.h" |
9 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 9 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
10 #include "chrome/browser/plugin_prefs.h" | 10 #include "chrome/browser/plugin_prefs.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | 65 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { |
66 return new GViewURLRequestTestJob(request); | 66 return new GViewURLRequestTestJob(request); |
67 } | 67 } |
68 }; | 68 }; |
69 | 69 |
70 class GViewRequestInterceptorTest : public testing::Test { | 70 class GViewRequestInterceptorTest : public testing::Test { |
71 public: | 71 public: |
72 GViewRequestInterceptorTest() | 72 GViewRequestInterceptorTest() |
73 : ui_thread_(BrowserThread::UI, &message_loop_), | 73 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 74 file_thread_(BrowserThread::FILE, &message_loop_), |
74 io_thread_(BrowserThread::IO, &message_loop_) {} | 75 io_thread_(BrowserThread::IO, &message_loop_) {} |
75 | 76 |
76 virtual void SetUp() { | 77 virtual void SetUp() { |
77 content::ResourceContext* resource_context = | 78 content::ResourceContext* resource_context = |
78 content::MockResourceContext::GetInstance(); | 79 content::MockResourceContext::GetInstance(); |
79 net::URLRequestContext* request_context = | 80 net::URLRequestContext* request_context = |
80 resource_context->request_context(); | 81 resource_context->request_context(); |
81 old_factory_ = request_context->job_factory(); | 82 old_factory_ = request_context->job_factory(); |
82 job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory); | 83 job_factory_.SetProtocolHandler("http", new GViewRequestProtocolFactory); |
83 job_factory_.AddInterceptor(new GViewRequestInterceptor); | 84 job_factory_.AddInterceptor(new GViewRequestInterceptor); |
84 request_context->set_job_factory(&job_factory_); | 85 request_context->set_job_factory(&job_factory_); |
85 PluginPrefs::RegisterPrefs(&prefs_); | 86 PluginPrefs::RegisterPrefs(&prefs_); |
86 plugin_prefs_ = new PluginPrefs(); | 87 plugin_prefs_ = new PluginPrefs(); |
87 plugin_prefs_->SetPrefs(&prefs_); | 88 plugin_prefs_->SetPrefs(&prefs_); |
88 ChromePluginServiceFilter* filter = | 89 ChromePluginServiceFilter* filter = |
89 ChromePluginServiceFilter::GetInstance(); | 90 ChromePluginServiceFilter::GetInstance(); |
90 filter->RegisterResourceContext(plugin_prefs_, resource_context); | 91 filter->RegisterResourceContext(plugin_prefs_, resource_context); |
91 PluginService::GetInstance()->set_filter(filter); | 92 PluginService::GetInstance()->set_filter(filter); |
92 | 93 |
93 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); | 94 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); |
94 | 95 |
95 handler_ = new content::DummyResourceHandler(); | 96 handler_ = new content::DummyResourceHandler(); |
96 } | 97 } |
97 | 98 |
98 virtual void TearDown() { | 99 virtual void TearDown() { |
| 100 plugin_prefs_->ShutdownOnUIThread(); |
99 content::ResourceContext* resource_context = | 101 content::ResourceContext* resource_context = |
100 content::MockResourceContext::GetInstance(); | 102 content::MockResourceContext::GetInstance(); |
101 net::URLRequestContext* request_context = | 103 net::URLRequestContext* request_context = |
102 resource_context->request_context(); | 104 resource_context->request_context(); |
103 request_context->set_job_factory(old_factory_); | 105 request_context->set_job_factory(old_factory_); |
104 ChromePluginServiceFilter* filter = | 106 ChromePluginServiceFilter* filter = |
105 ChromePluginServiceFilter::GetInstance(); | 107 ChromePluginServiceFilter::GetInstance(); |
106 filter->UnregisterResourceContext(resource_context); | 108 filter->UnregisterResourceContext(resource_context); |
107 PluginService::GetInstance()->set_filter(NULL); | 109 PluginService::GetInstance()->set_filter(NULL); |
108 } | 110 } |
109 | 111 |
110 void RegisterPDFPlugin() { | 112 void RegisterPDFPlugin() { |
111 webkit::WebPluginInfo info; | 113 webkit::WebPluginInfo info; |
112 info.path = pdf_path_; | 114 info.path = pdf_path_; |
113 info.enabled = webkit::WebPluginInfo::USER_ENABLED_POLICY_UNMANAGED; | |
114 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); | 115 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
115 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 116 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
116 } | 117 } |
117 | 118 |
118 void UnregisterPDFPlugin() { | 119 void UnregisterPDFPlugin() { |
119 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); | 120 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); |
120 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 121 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
121 } | 122 } |
122 | 123 |
123 void SetPDFPluginLoadedState(bool want_loaded) { | 124 void SetPDFPluginLoadedState(bool want_loaded) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 true, // allow_download | 160 true, // allow_download |
160 false, // has_user_gesture | 161 false, // has_user_gesture |
161 context); | 162 context); |
162 request->SetUserData(NULL, info); | 163 request->SetUserData(NULL, info); |
163 request->set_context(context->request_context()); | 164 request->set_context(context->request_context()); |
164 } | 165 } |
165 | 166 |
166 protected: | 167 protected: |
167 MessageLoopForIO message_loop_; | 168 MessageLoopForIO message_loop_; |
168 BrowserThread ui_thread_; | 169 BrowserThread ui_thread_; |
| 170 BrowserThread file_thread_; |
169 BrowserThread io_thread_; | 171 BrowserThread io_thread_; |
170 TestingPrefService prefs_; | 172 TestingPrefService prefs_; |
171 scoped_refptr<PluginPrefs> plugin_prefs_; | 173 scoped_refptr<PluginPrefs> plugin_prefs_; |
172 net::URLRequestJobFactory job_factory_; | 174 net::URLRequestJobFactory job_factory_; |
173 const net::URLRequestJobFactory* old_factory_; | 175 const net::URLRequestJobFactory* old_factory_; |
174 scoped_refptr<ResourceHandler> handler_; | 176 scoped_refptr<ResourceHandler> handler_; |
175 TestDelegate test_delegate_; | 177 TestDelegate test_delegate_; |
176 FilePath pdf_path_; | 178 FilePath pdf_path_; |
177 }; | 179 }; |
178 | 180 |
(...skipping 11 matching lines...) Expand all Loading... |
190 SetupRequest(&request); | 192 SetupRequest(&request); |
191 request.set_load_flags(net::LOAD_IS_DOWNLOAD); | 193 request.set_load_flags(net::LOAD_IS_DOWNLOAD); |
192 request.Start(); | 194 request.Start(); |
193 MessageLoop::current()->Run(); | 195 MessageLoop::current()->Run(); |
194 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 196 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
195 EXPECT_EQ(GURL("http://foo.com/file.pdf"), request.url()); | 197 EXPECT_EQ(GURL("http://foo.com/file.pdf"), request.url()); |
196 } | 198 } |
197 | 199 |
198 TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { | 200 TEST_F(GViewRequestInterceptorTest, DoNotInterceptPdfWhenEnabled) { |
199 SetPDFPluginLoadedState(true); | 201 SetPDFPluginLoadedState(true); |
200 webkit::npapi::PluginList::Singleton()->EnablePlugin(pdf_path_); | 202 plugin_prefs_->EnablePlugin(true, pdf_path_); |
201 | 203 |
202 net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); | 204 net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); |
203 SetupRequest(&request); | 205 SetupRequest(&request); |
204 request.Start(); | 206 request.Start(); |
205 MessageLoop::current()->Run(); | 207 MessageLoop::current()->Run(); |
206 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 208 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
207 EXPECT_EQ(GURL("http://foo.com/file.pdf"), request.url()); | 209 EXPECT_EQ(GURL("http://foo.com/file.pdf"), request.url()); |
208 } | 210 } |
209 | 211 |
210 TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { | 212 TEST_F(GViewRequestInterceptorTest, InterceptPdfWhenDisabled) { |
211 SetPDFPluginLoadedState(true); | 213 SetPDFPluginLoadedState(true); |
212 webkit::npapi::PluginList::Singleton()->DisablePlugin(pdf_path_); | 214 plugin_prefs_->EnablePlugin(false, pdf_path_); |
213 | 215 |
214 net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); | 216 net::URLRequest request(GURL("http://foo.com/file.pdf"), &test_delegate_); |
215 SetupRequest(&request); | 217 SetupRequest(&request); |
216 request.Start(); | 218 request.Start(); |
217 MessageLoop::current()->Run(); | 219 MessageLoop::current()->Run(); |
218 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 220 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
219 EXPECT_EQ( | 221 EXPECT_EQ( |
220 GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.pdf"), | 222 GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.pdf"), |
221 request.url()); | 223 request.url()); |
222 } | 224 } |
(...skipping 16 matching lines...) Expand all Loading... |
239 request.Start(); | 241 request.Start(); |
240 MessageLoop::current()->Run(); | 242 MessageLoop::current()->Run(); |
241 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 243 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
242 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), | 244 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), |
243 request.url()); | 245 request.url()); |
244 } | 246 } |
245 | 247 |
246 } // namespace | 248 } // namespace |
247 | 249 |
248 } // namespace chromeos | 250 } // namespace chromeos |
OLD | NEW |