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

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 Created 4 years, 3 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 "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 14 matching lines...) Expand all
25 #include "components/content_settings/core/browser/host_content_settings_map.h" 25 #include "components/content_settings/core/browser/host_content_settings_map.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/navigation_handle.h" 27 #include "content/public/browser/navigation_handle.h"
28 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "content/public/browser/plugin_service.h" 30 #include "content/public/browser/plugin_service.h"
31 #include "content/public/browser/render_frame_host.h" 31 #include "content/public/browser/render_frame_host.h"
32 #include "content/public/browser/render_process_host.h" 32 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_view_host.h" 33 #include "content/public/browser/render_view_host.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/common/content_constants.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "content/public/common/mhtml_generation_params.h" 37 #include "content/public/common/mhtml_generation_params.h"
37 #include "content/public/test/browser_test_utils.h" 38 #include "content/public/test/browser_test_utils.h"
39 #include "content/public/test/ppapi_test_utils.h"
38 #include "content/public/test/test_utils.h" 40 #include "content/public/test/test_utils.h"
39 #include "media/cdm/cdm_paths.h" 41 #include "media/cdm/cdm_paths.h"
40 #include "net/dns/mock_host_resolver.h" 42 #include "net/dns/mock_host_resolver.h"
41 #include "net/test/embedded_test_server/embedded_test_server.h" 43 #include "net/test/embedded_test_server/embedded_test_server.h"
42 #include "net/test/url_request/url_request_mock_http_job.h" 44 #include "net/test/url_request/url_request_mock_http_job.h"
45 #include "ppapi/shared_impl/ppapi_switches.h"
43 #include "testing/gmock/include/gmock/gmock.h" 46 #include "testing/gmock/include/gmock/gmock.h"
44 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. 47 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
45 48
46 #if defined(OS_MACOSX) 49 #if defined(OS_MACOSX)
47 #include "base/mac/scoped_nsautorelease_pool.h" 50 #include "base/mac/scoped_nsautorelease_pool.h"
48 #endif 51 #endif
49 52
50 #if defined(ENABLE_PEPPER_CDMS)
raymes 2016/09/26 08:18:29 I'm not sure if this was specifically testing some
tommycli 2016/09/26 16:29:44 xhwang, can you verify that changing this to test
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; 53 using content::BrowserThread;
56 using net::URLRequestMockHTTPJob; 54 using net::URLRequestMockHTTPJob;
57 55
58 namespace { 56 namespace {
59 57
60 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer( 58 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer(
61 Browser* browser) { 59 Browser* browser) {
62 TabSpecificContentSettings* settings = 60 TabSpecificContentSettings* settings =
63 TabSpecificContentSettings::FromWebContents( 61 TabSpecificContentSettings::FromWebContents(
64 browser->tab_strip_model()->GetWebContentsAt(0)); 62 browser->tab_strip_model()->GetWebContentsAt(0));
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 content::WebContents* web_contents = 333 content::WebContents* web_contents =
336 browser()->tab_strip_model()->GetActiveWebContents(); 334 browser()->tab_strip_model()->GetActiveWebContents();
337 335
338 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> 336 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
339 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); 337 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
340 } 338 }
341 339
342 #if defined(ENABLE_PLUGINS) 340 #if defined(ENABLE_PLUGINS)
343 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { 341 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest {
344 protected: 342 protected:
345 // Registers any CDM plugins not registered by default.
346 void SetUpCommandLine(base::CommandLine* command_line) override { 343 void SetUpCommandLine(base::CommandLine* command_line) override {
347 #if defined(ENABLE_PEPPER_CDMS) 344 // This plugin is treated like Flash by Content Settings.
348 // Append the switch to register the External Clear Key CDM. 345 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 346
356 #if !defined(DISABLE_NACL) 347 #if !defined(DISABLE_NACL)
357 // Ensure NaCl can run. 348 // Ensure NaCl can run.
358 command_line->AppendSwitch(switches::kEnableNaCl); 349 command_line->AppendSwitch(switches::kEnableNaCl);
359 #endif 350 #endif
360 } 351 }
361 352
362 #if defined(ENABLE_PEPPER_CDMS)
363 void SetUpDefaultCommandLine(base::CommandLine* command_line) override { 353 void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
364 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM); 354 base::CommandLine default_command_line(base::CommandLine::NO_PROGRAM);
365 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line); 355 InProcessBrowserTest::SetUpDefaultCommandLine(&default_command_line);
366 test_launcher_utils::RemoveCommandLineSwitch( 356 test_launcher_utils::RemoveCommandLineSwitch(
367 default_command_line, switches::kDisableComponentUpdate, command_line); 357 default_command_line, switches::kDisableComponentUpdate, command_line);
368 } 358 }
369 #endif // defined(ENABLE_PEPPER_CDMS)
370 359
371 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { 360 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) {
372 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; 361 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded";
373 content::WebContents* web_contents = 362 content::WebContents* web_contents =
374 browser()->tab_strip_model()->GetActiveWebContents(); 363 browser()->tab_strip_model()->GetActiveWebContents();
375 364
376 base::string16 expected_title(base::ASCIIToUTF16(expected_result)); 365 base::string16 expected_title(base::ASCIIToUTF16(expected_result));
377 content::TitleWatcher title_watcher(web_contents, expected_title); 366 content::TitleWatcher title_watcher(web_contents, expected_title);
378 367
379 // GetTestUrl assumes paths, so we must append query parameters to result. 368 // 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(); 451 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread();
463 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 452 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
464 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 453 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
465 CONTENT_SETTING_ALLOW); 454 CONTENT_SETTING_ALLOW);
466 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 455 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, 456 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT,
468 CONTENT_SETTING_BLOCK); 457 CONTENT_SETTING_BLOCK);
469 } 458 }
470 }; 459 };
471 460
472 #if defined(ENABLE_PEPPER_CDMS)
473 // A sanity check to verify that the plugin that is used as a baseline below 461 // A sanity check to verify that the plugin that is used as a baseline below
474 // can be loaded. 462 // can be loaded.
475 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { 463 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) {
476 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 464 RunLoadPepperPluginTest(content::kTestPluginMimeType, true);
477 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
478 CONTENT_SETTING_ALLOW);
479
480 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, true);
481 } 465 }
482 #endif // defined(ENABLE_PEPPER_CDMS)
483 466
484 // The following tests verify that Pepper plugins that use JavaScript settings 467 // The following tests verify that Pepper plugins that use JavaScript settings
485 // instead of Plugins settings still work when Plugins are blocked. 468 // instead of Plugins settings still work when Plugins are blocked.
486 469
487 #if defined(ENABLE_PEPPER_CDMS)
488 // The plugin successfully loaded above is blocked. 470 // The plugin successfully loaded above is blocked.
489 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 471 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
490 Normal) { 472 Normal) {
491 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, false); 473 RunLoadPepperPluginTest(content::kTestPluginMimeType, false);
492 } 474 }
493 475
494 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 476 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
495 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 477 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
496 WidevineCdm) { 478 WidevineCdm) {
497 // Check that Widevine CDM is available and registered. 479 // Check that Widevine CDM is available and registered.
498 base::FilePath adapter_path = 480 base::FilePath adapter_path =
499 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); 481 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName);
500 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); 482 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII();
501 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); 483 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType));
502 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); 484 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true);
503 } 485 }
504 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 486 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
505 #endif // defined(ENABLE_PEPPER_CDMS)
506 487
507 #if !defined(DISABLE_NACL) 488 #if !defined(DISABLE_NACL)
508 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 489 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
509 NaCl) { 490 NaCl) {
510 RunLoadPepperPluginTest("application/x-nacl", true); 491 RunLoadPepperPluginTest("application/x-nacl", true);
511 } 492 }
512 #endif // !defined(DISABLE_NACL) 493 #endif // !defined(DISABLE_NACL)
513 494
514 // The following tests verify that those same Pepper plugins do not work when 495 // The following tests verify that those same Pepper plugins do not work when
515 // JavaScript is blocked. 496 // JavaScript is blocked.
516 497
517 #if defined(ENABLE_PEPPER_CDMS)
518 // A plugin with no special behavior is not blocked when JavaScript is blocked. 498 // A plugin with no special behavior is not blocked when JavaScript is blocked.
519 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 499 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
520 Normal) { 500 Normal) {
521 RunJavaScriptBlockedTest("load_clearkey_no_js.html", false); 501 RunJavaScriptBlockedTest("load_test_plugin_no_js.html", false);
522 } 502 }
523 503
524 #if defined(WIDEVINE_CDM_AVAILABLE) 504 #if defined(WIDEVINE_CDM_AVAILABLE)
525 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 505 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
526 WidevineCdm) { 506 WidevineCdm) {
527 // Check that Widevine CDM is available and registered. 507 // Check that Widevine CDM is available and registered.
528 base::FilePath adapter_path = 508 base::FilePath adapter_path =
529 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName); 509 GetPepperCdmPath(kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName);
530 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII(); 510 EXPECT_TRUE(base::PathExists(adapter_path)) << adapter_path.MaybeAsASCII();
531 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType)); 511 EXPECT_TRUE(IsPepperCdmRegistered(kWidevineCdmPluginMimeType));
532 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); 512 RunJavaScriptBlockedTest("load_widevine_no_js.html", true);
533 } 513 }
534 #endif // defined(WIDEVINE_CDM_AVAILABLE) 514 #endif // defined(WIDEVINE_CDM_AVAILABLE)
535 #endif // defined(ENABLE_PEPPER_CDMS)
536 515
537 #if !defined(DISABLE_NACL) 516 #if !defined(DISABLE_NACL)
538 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 517 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
539 NaCl) { 518 NaCl) {
540 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 519 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
541 } 520 }
542 #endif // !defined(DISABLE_NACL) 521 #endif // !defined(DISABLE_NACL)
543 522
544 #endif // defined(ENABLE_PLUGINS) 523 #endif // defined(ENABLE_PLUGINS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698