| 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 #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 "content/browser/mock_resource_context.h" | 16 #include "content/browser/mock_resource_context.h" |
| 17 #include "content/browser/renderer_host/dummy_resource_handler.h" | |
| 18 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | |
| 19 #include "content/public/browser/plugin_service.h" | 17 #include "content/public/browser/plugin_service.h" |
| 18 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
| 21 #include "ipc/ipc_message.h" | |
| 22 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
| 23 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_job.h" | 22 #include "net/url_request/url_request_job.h" |
| 25 #include "net/url_request/url_request_job_factory.h" | 23 #include "net/url_request/url_request_job_factory.h" |
| 26 #include "net/url_request/url_request_test_job.h" | 24 #include "net/url_request/url_request_test_job.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "webkit/plugins/npapi/mock_plugin_list.h" | 27 #include "webkit/plugins/npapi/mock_plugin_list.h" |
| 30 | 28 |
| 31 using content::BrowserThread; | 29 using content::BrowserThread; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(&prefs_); | 102 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(&prefs_); |
| 105 plugin_prefs_ = new PluginPrefs(); | 103 plugin_prefs_ = new PluginPrefs(); |
| 106 plugin_prefs_->SetPrefs(&prefs_); | 104 plugin_prefs_->SetPrefs(&prefs_); |
| 107 ChromePluginServiceFilter* filter = | 105 ChromePluginServiceFilter* filter = |
| 108 ChromePluginServiceFilter::GetInstance(); | 106 ChromePluginServiceFilter::GetInstance(); |
| 109 filter->RegisterResourceContext(plugin_prefs_, &resource_context_); | 107 filter->RegisterResourceContext(plugin_prefs_, &resource_context_); |
| 110 PluginService::GetInstance()->SetFilter(filter); | 108 PluginService::GetInstance()->SetFilter(filter); |
| 111 | 109 |
| 112 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); | 110 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path_)); |
| 113 | 111 |
| 114 handler_ = new content::DummyResourceHandler(); | |
| 115 | |
| 116 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list_); | 112 PluginService::GetInstance()->SetPluginListForTesting(&plugin_list_); |
| 117 PluginService::GetInstance()->Init(); | 113 PluginService::GetInstance()->Init(); |
| 118 } | 114 } |
| 119 | 115 |
| 120 virtual void TearDown() { | 116 virtual void TearDown() { |
| 121 plugin_prefs_->ShutdownOnUIThread(); | 117 plugin_prefs_->ShutdownOnUIThread(); |
| 122 net::URLRequestContext* request_context = | 118 net::URLRequestContext* request_context = |
| 123 resource_context_.GetRequestContext(); | 119 resource_context_.GetRequestContext(); |
| 124 request_context->set_job_factory(old_factory_); | 120 request_context->set_job_factory(old_factory_); |
| 125 ChromePluginServiceFilter* filter = | 121 ChromePluginServiceFilter* filter = |
| (...skipping 25 matching lines...) Expand all Loading... |
| 151 // system - which is OK since we don't actually use it, just | 147 // system - which is OK since we don't actually use it, just |
| 152 // need it to be "enabled" for the test. | 148 // need it to be "enabled" for the test. |
| 153 RegisterPDFPlugin(); | 149 RegisterPDFPlugin(); |
| 154 is_loaded = PluginService::GetInstance()->GetPluginInfoByPath( | 150 is_loaded = PluginService::GetInstance()->GetPluginInfoByPath( |
| 155 pdf_path_, &info); | 151 pdf_path_, &info); |
| 156 } | 152 } |
| 157 EXPECT_EQ(want_loaded, is_loaded); | 153 EXPECT_EQ(want_loaded, is_loaded); |
| 158 } | 154 } |
| 159 | 155 |
| 160 void SetupRequest(net::URLRequest* request) { | 156 void SetupRequest(net::URLRequest* request) { |
| 161 ResourceDispatcherHostRequestInfo* info = | 157 request->SetUserData( |
| 162 new ResourceDispatcherHostRequestInfo( | 158 NULL, |
| 163 handler_, | 159 content::ResourceRequestInfo::CreateForTesting(&resource_context_)); |
| 164 content::PROCESS_TYPE_RENDERER, | |
| 165 -1, // child_id | |
| 166 MSG_ROUTING_NONE, | |
| 167 0, // origin_pid | |
| 168 request->identifier(), | |
| 169 false, // is_main_frame | |
| 170 -1, // frame_id | |
| 171 false, // parent_is_main_frame | |
| 172 -1, // parent_frame_id | |
| 173 ResourceType::MAIN_FRAME, | |
| 174 content::PAGE_TRANSITION_LINK, | |
| 175 0, // upload_size | |
| 176 false, // is_download | |
| 177 true, // allow_download | |
| 178 false, // has_user_gesture | |
| 179 WebKit::WebReferrerPolicyDefault, | |
| 180 &resource_context_); | |
| 181 request->SetUserData(NULL, info); | |
| 182 request->set_context(resource_context_.GetRequestContext()); | 160 request->set_context(resource_context_.GetRequestContext()); |
| 183 } | 161 } |
| 184 | 162 |
| 185 protected: | 163 protected: |
| 186 base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService. | 164 base::ShadowingAtExitManager at_exit_manager_; // Deletes PluginService. |
| 187 MessageLoopForIO message_loop_; | 165 MessageLoopForIO message_loop_; |
| 188 content::TestBrowserThread ui_thread_; | 166 content::TestBrowserThread ui_thread_; |
| 189 content::TestBrowserThread file_thread_; | 167 content::TestBrowserThread file_thread_; |
| 190 content::TestBrowserThread io_thread_; | 168 content::TestBrowserThread io_thread_; |
| 191 webkit::npapi::MockPluginList plugin_list_; | 169 webkit::npapi::MockPluginList plugin_list_; |
| 192 TestingPrefService prefs_; | 170 TestingPrefService prefs_; |
| 193 scoped_refptr<PluginPrefs> plugin_prefs_; | 171 scoped_refptr<PluginPrefs> plugin_prefs_; |
| 194 net::URLRequestJobFactory job_factory_; | 172 net::URLRequestJobFactory job_factory_; |
| 195 const net::URLRequestJobFactory* old_factory_; | 173 const net::URLRequestJobFactory* old_factory_; |
| 196 scoped_refptr<ResourceHandler> handler_; | |
| 197 TestDelegate test_delegate_; | 174 TestDelegate test_delegate_; |
| 198 FilePath pdf_path_; | 175 FilePath pdf_path_; |
| 199 content::MockResourceContext resource_context_; | 176 content::MockResourceContext resource_context_; |
| 200 }; | 177 }; |
| 201 | 178 |
| 202 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { | 179 TEST_F(GViewRequestInterceptorTest, DoNotInterceptHtml) { |
| 203 net::URLRequest request(GURL(kHtmlUrl), &test_delegate_); | 180 net::URLRequest request(GURL(kHtmlUrl), &test_delegate_); |
| 204 SetupRequest(&request); | 181 SetupRequest(&request); |
| 205 request.Start(); | 182 request.Start(); |
| 206 MessageLoop::current()->Run(); | 183 MessageLoop::current()->Run(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 SetupRequest(&request); | 263 SetupRequest(&request); |
| 287 request.Start(); | 264 request.Start(); |
| 288 MessageLoop::current()->Run(); | 265 MessageLoop::current()->Run(); |
| 289 EXPECT_EQ(0, test_delegate_.received_redirect_count()); | 266 EXPECT_EQ(0, test_delegate_.received_redirect_count()); |
| 290 EXPECT_EQ(GURL(kPdfBlob), request.url()); | 267 EXPECT_EQ(GURL(kPdfBlob), request.url()); |
| 291 } | 268 } |
| 292 | 269 |
| 293 } // namespace | 270 } // namespace |
| 294 | 271 |
| 295 } // namespace chromeos | 272 } // namespace chromeos |
| OLD | NEW |