| 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/bind.h" |
| 7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 8 #include "chrome/browser/chrome_plugin_service_filter.h" | 9 #include "chrome/browser/chrome_plugin_service_filter.h" |
| 9 #include "chrome/browser/chromeos/gview_request_interceptor.h" | 10 #include "chrome/browser/chromeos/gview_request_interceptor.h" |
| 10 #include "chrome/browser/plugin_prefs.h" | 11 #include "chrome/browser/plugin_prefs.h" |
| 11 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 12 #include "chrome/test/base/testing_pref_service.h" | 13 #include "chrome/test/base/testing_pref_service.h" |
| 13 #include "content/browser/mock_resource_context.h" | 14 #include "content/browser/mock_resource_context.h" |
| 14 #include "content/browser/plugin_service.h" | 15 #include "content/browser/plugin_service.h" |
| 15 #include "content/browser/renderer_host/dummy_resource_handler.h" | 16 #include "content/browser/renderer_host/dummy_resource_handler.h" |
| 16 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 17 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 : public net::URLRequestJobFactory::ProtocolHandler { | 61 : public net::URLRequestJobFactory::ProtocolHandler { |
| 61 public: | 62 public: |
| 62 GViewRequestProtocolFactory() {} | 63 GViewRequestProtocolFactory() {} |
| 63 virtual ~GViewRequestProtocolFactory() {} | 64 virtual ~GViewRequestProtocolFactory() {} |
| 64 | 65 |
| 65 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { | 66 virtual net::URLRequestJob* MaybeCreateJob(net::URLRequest* request) const { |
| 66 return new GViewURLRequestTestJob(request); | 67 return new GViewURLRequestTestJob(request); |
| 67 } | 68 } |
| 68 }; | 69 }; |
| 69 | 70 |
| 71 void QuitMessageLoop(const std::vector<webkit::WebPluginInfo>&) { |
| 72 MessageLoop::current()->Quit(); |
| 73 } |
| 74 |
| 70 class GViewRequestInterceptorTest : public testing::Test { | 75 class GViewRequestInterceptorTest : public testing::Test { |
| 71 public: | 76 public: |
| 72 GViewRequestInterceptorTest() | 77 GViewRequestInterceptorTest() |
| 73 : ui_thread_(BrowserThread::UI, &message_loop_), | 78 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 74 file_thread_(BrowserThread::FILE, &message_loop_), | 79 file_thread_(BrowserThread::FILE, &message_loop_), |
| 75 io_thread_(BrowserThread::IO, &message_loop_) {} | 80 io_thread_(BrowserThread::IO, &message_loop_) {} |
| 76 | 81 |
| 77 virtual void SetUp() { | 82 virtual void SetUp() { |
| 78 content::ResourceContext* resource_context = | 83 content::ResourceContext* resource_context = |
| 79 content::MockResourceContext::GetInstance(); | 84 content::MockResourceContext::GetInstance(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 102 content::MockResourceContext::GetInstance(); | 107 content::MockResourceContext::GetInstance(); |
| 103 net::URLRequestContext* request_context = | 108 net::URLRequestContext* request_context = |
| 104 resource_context->request_context(); | 109 resource_context->request_context(); |
| 105 request_context->set_job_factory(old_factory_); | 110 request_context->set_job_factory(old_factory_); |
| 106 ChromePluginServiceFilter* filter = | 111 ChromePluginServiceFilter* filter = |
| 107 ChromePluginServiceFilter::GetInstance(); | 112 ChromePluginServiceFilter::GetInstance(); |
| 108 filter->UnregisterResourceContext(resource_context); | 113 filter->UnregisterResourceContext(resource_context); |
| 109 PluginService::GetInstance()->set_filter(NULL); | 114 PluginService::GetInstance()->set_filter(NULL); |
| 110 } | 115 } |
| 111 | 116 |
| 117 // GetPluginInfoByPath() will only use stale information. Because plugin |
| 118 // refresh is asynchronous, spin a MessageLoop until the callback is run, |
| 119 // after which, the test will continue. |
| 112 void RegisterPDFPlugin() { | 120 void RegisterPDFPlugin() { |
| 113 webkit::WebPluginInfo info; | 121 webkit::WebPluginInfo info; |
| 114 info.path = pdf_path_; | 122 info.path = pdf_path_; |
| 115 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); | 123 webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 116 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 124 |
| 125 PluginService::GetInstance()->RefreshPluginList(); |
| 126 PluginService::GetInstance()->GetPlugins(base::Bind(&QuitMessageLoop)); |
| 127 MessageLoop::current()->Run(); |
| 117 } | 128 } |
| 118 | 129 |
| 119 void UnregisterPDFPlugin() { | 130 void UnregisterPDFPlugin() { |
| 120 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); | 131 webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(pdf_path_); |
| 121 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 132 |
| 133 PluginService::GetInstance()->RefreshPluginList(); |
| 134 PluginService::GetInstance()->GetPlugins(base::Bind(&QuitMessageLoop)); |
| 135 MessageLoop::current()->Run(); |
| 122 } | 136 } |
| 123 | 137 |
| 124 void SetPDFPluginLoadedState(bool want_loaded) { | 138 void SetPDFPluginLoadedState(bool want_loaded) { |
| 125 webkit::WebPluginInfo info; | 139 webkit::WebPluginInfo info; |
| 126 bool is_loaded = | 140 bool is_loaded = PluginService::GetInstance()->GetPluginInfoByPath( |
| 127 webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 141 pdf_path_, &info); |
| 128 pdf_path_, &info); | |
| 129 if (is_loaded && !want_loaded) { | 142 if (is_loaded && !want_loaded) { |
| 130 UnregisterPDFPlugin(); | 143 UnregisterPDFPlugin(); |
| 131 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 144 is_loaded = PluginService::GetInstance()->GetPluginInfoByPath( |
| 132 pdf_path_, &info); | 145 pdf_path_, &info); |
| 133 } else if (!is_loaded && want_loaded) { | 146 } else if (!is_loaded && want_loaded) { |
| 134 // This "loads" the plug-in even if it's not present on the | 147 // This "loads" the plug-in even if it's not present on the |
| 135 // system - which is OK since we don't actually use it, just | 148 // system - which is OK since we don't actually use it, just |
| 136 // need it to be "enabled" for the test. | 149 // need it to be "enabled" for the test. |
| 137 RegisterPDFPlugin(); | 150 RegisterPDFPlugin(); |
| 138 is_loaded = webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( | 151 is_loaded = PluginService::GetInstance()->GetPluginInfoByPath( |
| 139 pdf_path_, &info); | 152 pdf_path_, &info); |
| 140 } | 153 } |
| 141 EXPECT_EQ(want_loaded, is_loaded); | 154 EXPECT_EQ(want_loaded, is_loaded); |
| 142 } | 155 } |
| 143 | 156 |
| 144 void SetupRequest(net::URLRequest* request) { | 157 void SetupRequest(net::URLRequest* request) { |
| 145 content::ResourceContext* context = | 158 content::ResourceContext* context = |
| 146 content::MockResourceContext::GetInstance(); | 159 content::MockResourceContext::GetInstance(); |
| 147 ResourceDispatcherHostRequestInfo* info = | 160 ResourceDispatcherHostRequestInfo* info = |
| 148 new ResourceDispatcherHostRequestInfo(handler_, | 161 new ResourceDispatcherHostRequestInfo(handler_, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 request.Start(); | 254 request.Start(); |
| 242 MessageLoop::current()->Run(); | 255 MessageLoop::current()->Run(); |
| 243 EXPECT_EQ(1, test_delegate_.received_redirect_count()); | 256 EXPECT_EQ(1, test_delegate_.received_redirect_count()); |
| 244 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), | 257 EXPECT_EQ(GURL("http://docs.google.com/gview?url=http%3A//foo.com/file.ppt"), |
| 245 request.url()); | 258 request.url()); |
| 246 } | 259 } |
| 247 | 260 |
| 248 } // namespace | 261 } // namespace |
| 249 | 262 |
| 250 } // namespace chromeos | 263 } // namespace chromeos |
| OLD | NEW |