Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: chrome/browser/content_settings/content_settings_browsertest.cc

Issue 2356053002: [HBD] Only use Plugin Content Settings for Flash. (Closed)
Patch Set: fix prerender tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // This plugin is treated like Flash by Content Settings.
348 // Append the switch to register the External Clear Key CDM. 347 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line));
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 348
356 #if !defined(DISABLE_NACL) 349 #if !defined(DISABLE_NACL)
357 // Ensure NaCl can run. 350 // Ensure NaCl can run.
358 command_line->AppendSwitch(switches::kEnableNaCl); 351 command_line->AppendSwitch(switches::kEnableNaCl);
359 #endif 352 #endif
360 } 353 }
361 354
362 #if defined(ENABLE_PEPPER_CDMS)
363 void SetUpDefaultCommandLine(base::CommandLine* command_line) override { 355 void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
364 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); 356 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM);
365 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); 357 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line);
366 test_launcher_utils::RemoveCommandLineSwitch( 358 test_launcher_utils::RemoveCommandLineSwitch(
367 default_command_line, switches::kDisableComponentUpdate, command_line); 359 default_command_line, switches::kDisableComponentUpdate, command_line);
xhwang 2016/09/26 23:44:50 The test related to the CDM is special that the CD
tommycli 2016/09/27 18:51:07 We should probably still test the CDM, since users
368 } 360 }
369 #endif // defined(ENABLE_PEPPER_CDMS)
370 361
371 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { 362 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) {
372 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; 363 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded";
373 content::WebContents* web_contents = 364 content::WebContents* web_contents =
374 browser()->tab_strip_model()->GetActiveWebContents(); 365 browser()->tab_strip_model()->GetActiveWebContents();
375 366
376 base::string16 expected_title(base::ASCIIToUTF16(expected_result)); 367 base::string16 expected_title(base::ASCIIToUTF16(expected_result));
377 content::TitleWatcher title_watcher(web_contents, expected_title); 368 content::TitleWatcher title_watcher(web_contents, expected_title);
378 369
379 // GetTestUrl assumes paths, so we must append query parameters to result. 370 // GetTestUrl assumes paths, so we must append query parameters to result.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); 453 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread();
463 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 454 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
464 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 455 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
465 CONTENT_SETTING_ALLOW); 456 CONTENT_SETTING_ALLOW);
466 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 457 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, 458 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
468 CONTENT_SETTING_BLOCK); 459 CONTENT_SETTING_BLOCK);
469 } 460 }
470 }; 461 };
471 462
472 #if defined(ENABLE_PEPPER_CDMS)
473 // A sanity check to verify that the plugin that is used as a baseline below 463 // A sanity check to verify that the plugin that is used as a baseline below
474 // can be loaded. 464 // can be loaded.
475 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { 465 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) {
476 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 466 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
477 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
478 CONTENT_SETTING_ALLOW); 468 CONTENT_SETTING_ALLOW);
479 469
480 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, true); 470 RunLoadPepperPluginTest(content::kTestPluginMimeType, true);
481 } 471 }
482 #endif // defined(ENABLE_PEPPER_CDMS)
483 472
484 // The following tests verify that Pepper plugins that use JavaScript settings 473 // The following tests verify that Pepper plugins that use JavaScript settings
485 // instead of Plugins settings still work when Plugins are blocked. 474 // instead of Plugins settings still work when Plugins are blocked.
486 475
487 #if defined(ENABLE_PEPPER_CDMS)
488 // The plugin successfully loaded above is blocked. 476 // The plugin successfully loaded above is blocked.
489 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 477 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
490 Normal) { 478 BlockedPlugin) {
491 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, false); 479 // Disable the HTML by Default feature so we can test blocked plugins.
480 base::test::ScopedFeatureList feature_list;
481 feature_list.InitAndDisableFeature(features::kPreferHtmlOverPlugins);
482
483 RunLoadPepperPluginTest(content::kTestPluginMimeType, false);
492 } 484 }
493 485
494 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 486 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
495 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 487 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
496 WidevineCdm) { 488 WidevineCdm) {
497 // Check that Widevine CDM is available and registered. 489 // Check that Widevine CDM is available and registered.
498 base::FilePath adapter_path = 490 base::FilePath adapter_path =
499 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); 491 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName);
500 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); 492 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII();
501 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); 493 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType));
502 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); 494 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true);
503 } 495 }
504 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 496 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
505 #endif // defined(ENABLE_PEPPER_CDMS)
506 497
507 #if !defined(DISABLE_NACL) 498 #if !defined(DISABLE_NACL)
508 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 499 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
509 NaCl) { 500 NaCl) {
510 RunLoadPepperPluginTest("application/x-nacl", true); 501 RunLoadPepperPluginTest("application/x-nacl", true);
511 } 502 }
512 #endif // !defined(DISABLE_NACL) 503 #endif // !defined(DISABLE_NACL)
513 504
514 // The following tests verify that those same Pepper plugins do not work when 505 // The following tests verify that those same Pepper plugins do not work when
515 // JavaScript is blocked. 506 // JavaScript is blocked.
516 507
517 #if defined(ENABLE_PEPPER_CDMS)
518 // A plugin with no special behavior is not blocked when JavaScript is blocked. 508 // A plugin with no special behavior is not blocked when JavaScript is blocked.
519 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 509 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
520 Normal) { 510 Normal) {
521 RunJavaScriptBlockedTest("load_clearkey_no_js.html", false); 511 RunJavaScriptBlockedTest("load_test_plugin_no_js.html", false);
522 } 512 }
523 513
524 #if defined(WIDEVINE_CDM_AVAILABLE) 514 #if defined(WIDEVINE_CDM_AVAILABLE)
525 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 515 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
526 WidevineCdm) { 516 WidevineCdm) {
527 // Check that Widevine CDM is available and registered. 517 // Check that Widevine CDM is available and registered.
528 base::FilePath adapter_path = 518 base::FilePath adapter_path =
529 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); 519 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName);
530 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); 520 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII();
531 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); 521 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType));
532 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); 522 RunJavaScriptBlockedTest("load_widevine_no_js.html", true);
533 } 523 }
534 #endif // defined(WIDEVINE_CDM_AVAILABLE) 524 #endif // defined(WIDEVINE_CDM_AVAILABLE)
xhwang 2016/09/26 23:44:50 This should still be guarded by defined(ENABLE_PEP
xhwang 2016/09/27 20:35:26 This is not addressed.
tommycli 2016/09/27 20:45:38 Done. Thanks! I missed that one.
535 #endif // defined(ENABLE_PEPPER_CDMS)
536 525
537 #if !defined(DISABLE_NACL) 526 #if !defined(DISABLE_NACL)
538 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 527 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
539 NaCl) { 528 NaCl) {
540 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 529 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
541 } 530 }
542 #endif // !defined(DISABLE_NACL) 531 #endif // !defined(DISABLE_NACL)
543 532
544 #endif // defined(ENABLE_PLUGINS) 533 #endif // defined(ENABLE_PLUGINS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698