| 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 // Tests for the top plugins to catch regressions in our plugin host code, as | 5 // Tests for the top plugins to catch regressions in our plugin host code, as |
| 6 // well as in the out of process code. Currently this tests: | 6 // well as in the out of process code. Currently this tests: |
| 7 // Flash | 7 // Flash |
| 8 // Real | 8 // Real |
| 9 // QuickTime | 9 // QuickTime |
| 10 // Windows Media Player | 10 // Windows Media Player |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include <string.h> | 25 #include <string.h> |
| 26 #include <memory.h> | 26 #include <memory.h> |
| 27 | 27 |
| 28 #include <string> | 28 #include <string> |
| 29 | 29 |
| 30 #include "base/file_path.h" | 30 #include "base/file_path.h" |
| 31 #include "base/file_util.h" | 31 #include "base/file_util.h" |
| 32 #include "base/message_loop.h" | 32 #include "base/message_loop.h" |
| 33 #include "base/path_service.h" | 33 #include "base/path_service.h" |
| 34 #include "base/test/test_timeouts.h" | 34 #include "base/test/test_timeouts.h" |
| 35 #include "chrome/browser/plugin_download_helper.h" |
| 35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/test/automation/automation_proxy.h" | 38 #include "chrome/test/automation/automation_proxy.h" |
| 38 #include "chrome/test/automation/tab_proxy.h" | 39 #include "chrome/test/automation/tab_proxy.h" |
| 39 #include "chrome/test/base/ui_test_utils.h" | 40 #include "chrome/test/base/ui_test_utils.h" |
| 40 #include "chrome/test/ui/ui_test.h" | 41 #include "chrome/test/ui/ui_test.h" |
| 42 #include "content/browser/browser_thread_impl.h" |
| 41 #include "content/browser/net/url_request_mock_http_job.h" | 43 #include "content/browser/net/url_request_mock_http_job.h" |
| 42 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 43 #include "net/url_request/url_request_context_getter.h" | 45 #include "net/url_request/url_request_context_getter.h" |
| 44 #include "net/url_request/url_request_test_util.h" | 46 #include "net/url_request/url_request_test_util.h" |
| 45 #include "third_party/npapi/bindings/npapi.h" | 47 #include "third_party/npapi/bindings/npapi.h" |
| 46 #include "webkit/plugins/npapi/plugin_constants_win.h" | 48 #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 47 #include "webkit/plugins/npapi/plugin_list.h" | 49 #include "webkit/plugins/npapi/plugin_list.h" |
| 48 #include "webkit/plugins/plugin_switches.h" | 50 #include "webkit/plugins/plugin_switches.h" |
| 49 | 51 |
| 50 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 51 #include "base/win/registry.h" | 53 #include "base/win/registry.h" |
| 52 #include "chrome/browser/plugin_download_helper.h" | |
| 53 #endif | 54 #endif |
| 54 | 55 |
| 55 class PluginTest : public UITest { | 56 class PluginTest : public UITest { |
| 56 public: | 57 public: |
| 57 // Generate the URL for testing a particular test. | 58 // Generate the URL for testing a particular test. |
| 58 // HTML for the tests is all located in test_directory\plugin\<testcase> | 59 // HTML for the tests is all located in test_directory\plugin\<testcase> |
| 59 // Set |mock_http| to true to use mock HTTP server. | 60 // Set |mock_http| to true to use mock HTTP server. |
| 60 static GURL GetTestUrl(const std::string& test_case, | 61 static GURL GetTestUrl(const std::string& test_case, |
| 61 const std::string& query, | 62 const std::string& query, |
| 62 bool mock_http) { | 63 bool mock_http) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 245 |
| 245 // http://crbug.com/8690 | 246 // http://crbug.com/8690 |
| 246 TEST_F(PluginTest, DISABLED_Java) { | 247 TEST_F(PluginTest, DISABLED_Java) { |
| 247 TestPlugin("Java.html", "", TestTimeouts::action_max_timeout_ms(), false); | 248 TestPlugin("Java.html", "", TestTimeouts::action_max_timeout_ms(), false); |
| 248 } | 249 } |
| 249 | 250 |
| 250 TEST_F(PluginTest, Silverlight) { | 251 TEST_F(PluginTest, Silverlight) { |
| 251 TestPlugin("silverlight.html", "", | 252 TestPlugin("silverlight.html", "", |
| 252 TestTimeouts::action_max_timeout_ms(), false); | 253 TestTimeouts::action_max_timeout_ms(), false); |
| 253 } | 254 } |
| 255 #endif // defined(OS_WIN) |
| 254 | 256 |
| 257 #if !defined(OS_CHROMEOS) |
| 255 namespace { | 258 namespace { |
| 256 | 259 |
| 257 class TestURLRequestContextGetter : public net::URLRequestContextGetter { | 260 class TestURLRequestContextGetter : public net::URLRequestContextGetter { |
| 258 public: | 261 public: |
| 259 explicit TestURLRequestContextGetter() { | 262 explicit TestURLRequestContextGetter() { |
| 260 io_message_loop_proxy_ = base::MessageLoopProxy::current(); | 263 io_message_loop_proxy_ = base::MessageLoopProxy::current(); |
| 261 } | 264 } |
| 262 virtual net::URLRequestContext* GetURLRequestContext() { | 265 virtual net::URLRequestContext* GetURLRequestContext() { |
| 263 if (!context_) | 266 if (!context_) |
| 264 context_ = new TestURLRequestContext(); | 267 context_ = new TestURLRequestContext(); |
| 265 return context_; | 268 return context_; |
| 266 } | 269 } |
| 267 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { | 270 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const { |
| 268 return io_message_loop_proxy_; | 271 return io_message_loop_proxy_; |
| 269 } | 272 } |
| 270 | 273 |
| 271 protected: | 274 protected: |
| 272 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | 275 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 273 | 276 |
| 274 private: | 277 private: |
| 275 virtual ~TestURLRequestContextGetter() {} | 278 virtual ~TestURLRequestContextGetter() {} |
| 276 | 279 |
| 277 scoped_refptr<net::URLRequestContext> context_; | 280 scoped_refptr<net::URLRequestContext> context_; |
| 278 }; | 281 }; |
| 279 | 282 |
| 280 } // namespace | 283 } // namespace |
| 284 |
| 281 // This class provides functionality to test the plugin installer download | 285 // This class provides functionality to test the plugin installer download |
| 282 // file functionality. | 286 // file functionality. |
| 283 class PluginInstallerDownloadTest | 287 class PluginInstallerDownloadTest : public testing::Test { |
| 284 : public PluginDownloadUrlHelper::DownloadDelegate, | |
| 285 public testing::Test { | |
| 286 public: | 288 public: |
| 287 PluginInstallerDownloadTest() | 289 PluginInstallerDownloadTest() |
| 288 : success_(false), | 290 : message_loop_(MessageLoop::TYPE_IO), |
| 289 download_helper_(NULL) {} | 291 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 292 download_helper_(NULL), |
| 293 success_(false) {} |
| 290 ~PluginInstallerDownloadTest() {} | 294 ~PluginInstallerDownloadTest() {} |
| 291 | 295 |
| 292 void Start() { | 296 void Start() { |
| 293 initial_download_path_ = PluginTest::GetTestUrl("flash.html", "", false); | 297 initial_download_path_ = PluginTest::GetTestUrl("flash.html", "", false); |
| 294 download_helper_ = new PluginDownloadUrlHelper( | 298 download_helper_ = new PluginDownloadUrlHelper(); |
| 295 initial_download_path_.spec(), NULL, | |
| 296 static_cast<PluginDownloadUrlHelper::DownloadDelegate*>(this)); | |
| 297 TestURLRequestContextGetter* context_getter = | 299 TestURLRequestContextGetter* context_getter = |
| 298 new TestURLRequestContextGetter; | 300 new TestURLRequestContextGetter; |
| 299 download_helper_->InitiateDownload(context_getter, | 301 download_helper_->InitiateDownload( |
| 300 context_getter->GetIOMessageLoopProxy()); | 302 initial_download_path_, |
| 303 context_getter, |
| 304 base::Bind(&PluginInstallerDownloadTest::OnDownloadCompleted, |
| 305 base::Unretained(this))); |
| 301 | 306 |
| 302 MessageLoop::current()->PostDelayedTask( | 307 message_loop_.PostDelayedTask( |
| 303 FROM_HERE, new MessageLoop::QuitTask, | 308 FROM_HERE, new MessageLoop::QuitTask, |
| 304 TestTimeouts::action_max_timeout_ms()); | 309 TestTimeouts::action_max_timeout_ms()); |
| 305 } | 310 } |
| 306 | 311 |
| 307 virtual void OnDownloadCompleted(const FilePath& download_path, | 312 void OnDownloadCompleted(const FilePath& download_path) { |
| 308 bool success) { | 313 success_ = true; |
| 309 success_ = success; | |
| 310 final_download_path_ = download_path; | 314 final_download_path_ = download_path; |
| 311 MessageLoop::current()->Quit(); | 315 message_loop_.Quit(); |
| 312 download_helper_ = NULL; | 316 download_helper_ = NULL; |
| 313 } | 317 } |
| 314 | 318 |
| 315 FilePath final_download_path() const { | 319 FilePath final_download_path() const { |
| 316 return final_download_path_; | 320 return final_download_path_; |
| 317 } | 321 } |
| 318 | 322 |
| 319 FilePath initial_download_path() const { | 323 FilePath initial_download_path() const { |
| 320 return final_download_path_; | 324 return final_download_path_; |
| 321 } | 325 } |
| 322 | 326 |
| 323 bool success() const { | 327 bool success() const { |
| 324 return success_; | 328 return success_; |
| 325 } | 329 } |
| 326 | 330 |
| 327 private: | 331 private: |
| 332 MessageLoop message_loop_; |
| 333 content::BrowserThreadImpl file_thread_; |
| 328 FilePath final_download_path_; | 334 FilePath final_download_path_; |
| 329 PluginDownloadUrlHelper* download_helper_; | 335 PluginDownloadUrlHelper* download_helper_; |
| 330 bool success_; | 336 bool success_; |
| 331 GURL initial_download_path_; | 337 GURL initial_download_path_; |
| 332 }; | 338 }; |
| 333 | 339 |
| 334 // This test validates that the plugin downloader downloads the specified file | 340 // This test validates that the plugin downloader downloads the specified file |
| 335 // to a temporary path with the same file name. | 341 // to a temporary path with the same file name. |
| 336 TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) { | 342 TEST_F(PluginInstallerDownloadTest, PluginInstallerDownloadPathTest) { |
| 337 MessageLoop loop(MessageLoop::TYPE_IO); | |
| 338 Start(); | 343 Start(); |
| 339 loop.Run(); | 344 MessageLoop::current()->Run(); |
| 340 | 345 |
| 341 EXPECT_TRUE(success()); | 346 EXPECT_TRUE(success()); |
| 342 EXPECT_TRUE(initial_download_path().BaseName().value() == | 347 EXPECT_TRUE(initial_download_path().BaseName().value() == |
| 343 final_download_path().BaseName().value()); | 348 final_download_path().BaseName().value()); |
| 344 } | 349 } |
| 345 #endif // defined(OS_WIN) | 350 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |