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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/test/scoped_feature_list.h" |
9 #include "build/build_config.h" | 10 #include "build/build_config.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 12 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
14 #include "chrome/browser/net/url_request_mock_util.h" | 15 #include "chrome/browser/net/url_request_mock_util.h" |
15 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 16 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_commands.h" | 19 #include "chrome/browser/ui/browser_commands.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/common/chrome_features.h" |
20 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/test_launcher_utils.h" | 24 #include "chrome/test/base/test_launcher_utils.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
24 #include "components/content_settings/core/browser/cookie_settings.h" | 26 #include "components/content_settings/core/browser/cookie_settings.h" |
25 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/navigation_handle.h" | 29 #include "content/public/browser/navigation_handle.h" |
28 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
29 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/plugin_service.h" | 32 #include "content/public/browser/plugin_service.h" |
31 #include "content/public/browser/render_frame_host.h" | 33 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 35 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/common/content_constants.h" |
35 #include "content/public/common/content_switches.h" | 38 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/mhtml_generation_params.h" | 39 #include "content/public/common/mhtml_generation_params.h" |
37 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 41 #include "content/public/test/ppapi_test_utils.h" |
38 #include "content/public/test/test_utils.h" | 42 #include "content/public/test/test_utils.h" |
39 #include "media/cdm/cdm_paths.h" | 43 #include "media/cdm/cdm_paths.h" |
40 #include "net/dns/mock_host_resolver.h" | 44 #include "net/dns/mock_host_resolver.h" |
41 #include "net/test/embedded_test_server/embedded_test_server.h" | 45 #include "net/test/embedded_test_server/embedded_test_server.h" |
42 #include "net/test/url_request/url_request_mock_http_job.h" | 46 #include "net/test/url_request/url_request_mock_http_job.h" |
| 47 #include "ppapi/shared_impl/ppapi_switches.h" |
43 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
44 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 49 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
45 | 50 |
46 #if defined(OS_MACOSX) | 51 #if defined(OS_MACOSX) |
47 #include "base/mac/scoped_nsautorelease_pool.h" | 52 #include "base/mac/scoped_nsautorelease_pool.h" |
48 #endif | 53 #endif |
49 | 54 |
50 #if defined(ENABLE_PEPPER_CDMS) | |
51 #include "chrome/browser/media/pepper_cdm_test_constants.h" | |
52 #include "chrome/browser/media/pepper_cdm_test_helper.h" | |
53 #endif | |
54 | |
55 using content::BrowserThread; | 55 using content::BrowserThread; |
56 using net::URLRequestMockHTTPJob; | 56 using net::URLRequestMockHTTPJob; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer( | 60 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer( |
61 Browser* browser) { | 61 Browser* browser) { |
62 TabSpecificContentSettings* settings = | 62 TabSpecificContentSettings* settings = |
63 TabSpecificContentSettings::FromWebContents( | 63 TabSpecificContentSettings::FromWebContents( |
64 browser->tab_strip_model()->GetWebContentsAt(0)); | 64 browser->tab_strip_model()->GetWebContentsAt(0)); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 content::WebContents* web_contents = | 335 content::WebContents* web_contents = |
336 browser()->tab_strip_model()->GetActiveWebContents(); | 336 browser()->tab_strip_model()->GetActiveWebContents(); |
337 | 337 |
338 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 338 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
339 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); | 339 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
340 } | 340 } |
341 | 341 |
342 #if defined(ENABLE_PLUGINS) | 342 #if defined(ENABLE_PLUGINS) |
343 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { | 343 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { |
344 protected: | 344 protected: |
345 // Registers any CDM plugins not registered by default. | |
346 void SetUpCommandLine(base::CommandLine* command_line) override { | 345 void SetUpCommandLine(base::CommandLine* command_line) override { |
347 #if defined(ENABLE_PEPPER_CDMS) | 346 ASSERT_TRUE(ppapi::RegisterFlashTestPlugin(command_line)); |
348 // Append the switch to register the External Clear Key CDM. | |
349 base::FilePath::StringType pepper_plugins = BuildPepperCdmRegistration( | |
350 kClearKeyCdmBaseDirectory, kClearKeyCdmAdapterFileName, | |
351 kClearKeyCdmDisplayName, kClearKeyCdmPepperMimeType); | |
352 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | |
353 pepper_plugins); | |
354 #endif // defined(ENABLE_PEPPER_CDMS) | |
355 | 347 |
356 #if !defined(DISABLE_NACL) | 348 #if !defined(DISABLE_NACL) |
357 // Ensure NaCl can run. | 349 // Ensure NaCl can run. |
358 command_line->AppendSwitch(switches::kEnableNaCl); | 350 command_line->AppendSwitch(switches::kEnableNaCl); |
359 #endif | 351 #endif |
360 } | 352 } |
361 | 353 |
362 #if defined(ENABLE_PEPPER_CDMS) | |
363 void SetUpDefaultCommandLine(base::CommandLine* command_line) override { | 354 void SetUpDefaultCommandLine(base::CommandLine* command_line) override { |
364 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); | 355 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); |
365 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); | 356 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); |
366 test_launcher_utils::RemoveCommandLineSwitch( | 357 test_launcher_utils::RemoveCommandLineSwitch( |
367 default_command_line, switches::kDisableComponentUpdate, command_line); | 358 default_command_line, switches::kDisableComponentUpdate, command_line); |
368 } | 359 } |
369 #endif // defined(ENABLE_PEPPER_CDMS) | 360 |
| 361 void SetUpInProcessBrowserTestFixture() override { |
| 362 ContentSettingsTest::SetUpInProcessBrowserTestFixture(); |
| 363 |
| 364 // Disable the HTML by Default feature so we can test blocked plugins. |
| 365 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins); |
| 366 } |
370 | 367 |
371 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { | 368 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { |
372 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; | 369 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; |
373 content::WebContents* web_contents = | 370 content::WebContents* web_contents = |
374 browser()->tab_strip_model()->GetActiveWebContents(); | 371 browser()->tab_strip_model()->GetActiveWebContents(); |
375 | 372 |
376 base::string16 expected_title(base::ASCIIToUTF16(expected_result)); | 373 base::string16 expected_title(base::ASCIIToUTF16(expected_result)); |
377 content::TitleWatcher title_watcher(web_contents, expected_title); | 374 content::TitleWatcher title_watcher(web_contents, expected_title); |
378 | 375 |
379 // GetTestUrl assumes paths, so we must append query parameters to result. | 376 // GetTestUrl assumes paths, so we must append query parameters to result. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 // false, javascript_content_blocked_observer would never succeed. | 432 // false, javascript_content_blocked_observer would never succeed. |
436 // There is no way to ensure blocked content would not have been reported | 433 // There is no way to ensure blocked content would not have been reported |
437 // after the check below. For coverage of this scenario, we must rely on | 434 // after the check below. For coverage of this scenario, we must rely on |
438 // the TitleWatcher adding sufficient delay most of the time. | 435 // the TitleWatcher adding sufficient delay most of the time. |
439 } | 436 } |
440 | 437 |
441 EXPECT_EQ(expect_is_javascript_content_blocked, | 438 EXPECT_EQ(expect_is_javascript_content_blocked, |
442 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 439 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
443 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); | 440 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
444 } | 441 } |
| 442 |
| 443 private: |
| 444 base::test::ScopedFeatureList feature_list; |
445 }; | 445 }; |
446 | 446 |
447 class PepperContentSettingsSpecialCasesPluginsBlockedTest | 447 class PepperContentSettingsSpecialCasesPluginsBlockedTest |
448 : public PepperContentSettingsSpecialCasesTest { | 448 : public PepperContentSettingsSpecialCasesTest { |
449 public: | 449 public: |
450 void SetUpOnMainThread() override { | 450 void SetUpOnMainThread() override { |
451 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); | 451 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); |
452 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 452 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
453 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 453 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
454 CONTENT_SETTING_BLOCK); | 454 CONTENT_SETTING_BLOCK); |
455 } | 455 } |
456 }; | 456 }; |
457 | 457 |
458 class PepperContentSettingsSpecialCasesJavaScriptBlockedTest | 458 class PepperContentSettingsSpecialCasesJavaScriptBlockedTest |
459 : public PepperContentSettingsSpecialCasesTest { | 459 : public PepperContentSettingsSpecialCasesTest { |
460 public: | 460 public: |
461 void SetUpOnMainThread() override { | 461 void SetUpOnMainThread() override { |
462 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); | 462 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); |
463 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 463 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
464 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 464 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
465 CONTENT_SETTING_ALLOW); | 465 CONTENT_SETTING_ALLOW); |
466 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 466 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
468 CONTENT_SETTING_BLOCK); | 468 CONTENT_SETTING_BLOCK); |
469 } | 469 } |
470 }; | 470 }; |
471 | 471 |
472 #if defined(ENABLE_PEPPER_CDMS) | |
473 // A sanity check to verify that the plugin that is used as a baseline below | 472 // A sanity check to verify that the plugin that is used as a baseline below |
474 // can be loaded. | 473 // can be loaded. |
475 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { | 474 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Flash) { |
476 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 475 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
477 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 476 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
478 CONTENT_SETTING_ALLOW); | 477 CONTENT_SETTING_ALLOW); |
479 | 478 |
480 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, true); | 479 RunLoadPepperPluginTest(content::kFlashPluginSwfMimeType, true); |
481 } | 480 } |
482 #endif // defined(ENABLE_PEPPER_CDMS) | |
483 | 481 |
484 // The following tests verify that Pepper plugins that use JavaScript settings | 482 // The following tests verify that Pepper plugins that use JavaScript settings |
485 // instead of Plugins settings still work when Plugins are blocked. | 483 // instead of Plugins settings still work when Plugins are blocked. |
486 | 484 |
487 #if defined(ENABLE_PEPPER_CDMS) | |
488 // The plugin successfully loaded above is blocked. | 485 // The plugin successfully loaded above is blocked. |
489 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, | 486 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, |
490 Normal) { | 487 BlockedFlash) { |
491 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, false); | 488 RunLoadPepperPluginTest(content::kFlashPluginSwfMimeType, false); |
492 } | 489 } |
493 | 490 |
494 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) | 491 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) |
495 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, | 492 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, |
496 WidevineCdm) { | 493 WidevineCdm) { |
497 // Check that Widevine CDM is available and registered. | 494 // Check that Widevine CDM is available and registered. |
498 base::FilePath adapter_path = | 495 base::FilePath adapter_path = |
499 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); | 496 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); |
500 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); | 497 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); |
501 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); | 498 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); |
502 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); | 499 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); |
503 } | 500 } |
504 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) | 501 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) |
505 #endif // defined(ENABLE_PEPPER_CDMS) | |
506 | 502 |
507 #if !defined(DISABLE_NACL) | 503 #if !defined(DISABLE_NACL) |
508 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, | 504 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, |
509 NaCl) { | 505 NaCl) { |
510 RunLoadPepperPluginTest("application/x-nacl", true); | 506 RunLoadPepperPluginTest("application/x-nacl", true); |
511 } | 507 } |
512 #endif // !defined(DISABLE_NACL) | 508 #endif // !defined(DISABLE_NACL) |
513 | 509 |
514 // The following tests verify that those same Pepper plugins do not work when | 510 // The following tests verify that those same Pepper plugins do not work when |
515 // JavaScript is blocked. | 511 // JavaScript is blocked. |
516 | 512 |
517 #if defined(ENABLE_PEPPER_CDMS) | |
518 // A plugin with no special behavior is not blocked when JavaScript is blocked. | 513 // A plugin with no special behavior is not blocked when JavaScript is blocked. |
519 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, | 514 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, |
520 Normal) { | 515 Flash) { |
521 RunJavaScriptBlockedTest("load_clearkey_no_js.html", false); | 516 RunJavaScriptBlockedTest("load_flash_no_js.html", false); |
522 } | 517 } |
523 | 518 |
524 #if defined(WIDEVINE_CDM_AVAILABLE) | 519 #if defined(ENABLE_PEPPER_CDMS) && defined(WIDEVINE_CDM_AVAILABLE) |
525 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, | 520 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, |
526 WidevineCdm) { | 521 WidevineCdm) { |
527 // Check that Widevine CDM is available and registered. | 522 // Check that Widevine CDM is available and registered. |
528 base::FilePath adapter_path = | 523 base::FilePath adapter_path = |
529 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); | 524 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); |
530 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); | 525 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); |
531 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); | 526 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); |
532 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); | 527 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); |
533 } | 528 } |
534 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 529 #endif // defined(ENABLE_PEPPER_CDMS) && defined(WIDEVINE_CDM_AVAILABLE) |
535 #endif // defined(ENABLE_PEPPER_CDMS) | |
536 | 530 |
537 #if !defined(DISABLE_NACL) | 531 #if !defined(DISABLE_NACL) |
538 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, | 532 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, |
539 NaCl) { | 533 NaCl) { |
540 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 534 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
541 } | 535 } |
542 #endif // !defined(DISABLE_NACL) | 536 #endif // !defined(DISABLE_NACL) |
543 | 537 |
544 #endif // defined(ENABLE_PLUGINS) | 538 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |