| 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 "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 25 matching lines...) Expand all Loading... |
| 36 #include "net/dns/mock_host_resolver.h" | 36 #include "net/dns/mock_host_resolver.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 37 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 #include "net/test/url_request/url_request_mock_http_job.h" | 38 #include "net/test/url_request/url_request_mock_http_job.h" |
| 39 | 39 |
| 40 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 40 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
| 41 | 41 |
| 42 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
| 43 #include "base/mac/scoped_nsautorelease_pool.h" | 43 #include "base/mac/scoped_nsautorelease_pool.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 #if defined(ENABLE_PEPPER_CDMS) |
| 47 #include "chrome/browser/media/pepper_cdm_test_helper.h" |
| 48 #endif |
| 49 |
| 46 using content::BrowserThread; | 50 using content::BrowserThread; |
| 47 using net::URLRequestMockHTTPJob; | 51 using net::URLRequestMockHTTPJob; |
| 48 | 52 |
| 49 namespace { | 53 namespace { |
| 50 | 54 |
| 51 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer( | 55 const LocalSharedObjectsContainer* GetSiteSettingsCookieContainer( |
| 52 Browser* browser) { | 56 Browser* browser) { |
| 53 TabSpecificContentSettings* settings = | 57 TabSpecificContentSettings* settings = |
| 54 TabSpecificContentSettings::FromWebContents( | 58 TabSpecificContentSettings::FromWebContents( |
| 55 browser->tab_strip_model()->GetWebContentsAt(0)); | 59 browser->tab_strip_model()->GetWebContentsAt(0)); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 content::WebContents* web_contents = | 314 content::WebContents* web_contents = |
| 311 browser()->tab_strip_model()->GetActiveWebContents(); | 315 browser()->tab_strip_model()->GetActiveWebContents(); |
| 312 | 316 |
| 313 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 317 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
| 314 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); | 318 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 315 } | 319 } |
| 316 | 320 |
| 317 #if defined(ENABLE_PLUGINS) | 321 #if defined(ENABLE_PLUGINS) |
| 318 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { | 322 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { |
| 319 protected: | 323 protected: |
| 320 static const char kExternalClearKeyMimeType[]; | |
| 321 | |
| 322 // Registers any CDM plugins not registered by default. | 324 // Registers any CDM plugins not registered by default. |
| 323 void SetUpCommandLine(base::CommandLine* command_line) override { | 325 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 324 #if defined(ENABLE_PEPPER_CDMS) | 326 #if defined(ENABLE_PEPPER_CDMS) |
| 325 // Platform-specific filename relative to the chrome executable. | |
| 326 #if defined(OS_WIN) | |
| 327 const char kLibraryName[] = "clearkeycdmadapter.dll"; | |
| 328 #else // !defined(OS_WIN) | |
| 329 #if defined(OS_MACOSX) | |
| 330 const char kLibraryName[] = "clearkeycdmadapter.plugin"; | |
| 331 #elif defined(OS_POSIX) | |
| 332 const char kLibraryName[] = "libclearkeycdmadapter.so"; | |
| 333 #endif // defined(OS_MACOSX) | |
| 334 #endif // defined(OS_WIN) | |
| 335 | |
| 336 // Append the switch to register the External Clear Key CDM. | 327 // Append the switch to register the External Clear Key CDM. |
| 337 base::FilePath::StringType pepper_plugins = BuildPepperPluginRegistration( | 328 base::FilePath::StringType pepper_plugins = BuildPepperCdmRegistration( |
| 338 kLibraryName, "Clear Key CDM", kExternalClearKeyMimeType); | 329 kClearKeyCdmAdapterFileName, kClearKeyCdmPepperMimeType); |
| 339 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 330 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 340 // The CDM must be registered when it is a component. | 331 // The CDM must be registered when it is a component. |
| 341 pepper_plugins.append(FILE_PATH_LITERAL(",")); | 332 pepper_plugins.append(FILE_PATH_LITERAL(",")); |
| 342 pepper_plugins.append( | 333 pepper_plugins.append(BuildPepperCdmRegistration( |
| 343 BuildPepperPluginRegistration(kWidevineCdmAdapterFileName, | 334 kWidevineCdmAdapterFileName, kWidevineCdmPluginMimeType)); |
| 344 kWidevineCdmDisplayName, | |
| 345 kWidevineCdmPluginMimeType)); | |
| 346 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | 335 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) |
| 347 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, | 336 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, |
| 348 pepper_plugins); | 337 pepper_plugins); |
| 349 #endif // defined(ENABLE_PEPPER_CDMS) | 338 #endif // defined(ENABLE_PEPPER_CDMS) |
| 350 | 339 |
| 351 #if !defined(DISABLE_NACL) | 340 #if !defined(DISABLE_NACL) |
| 352 // Ensure NaCl can run. | 341 // Ensure NaCl can run. |
| 353 command_line->AppendSwitch(switches::kEnableNaCl); | 342 command_line->AppendSwitch(switches::kEnableNaCl); |
| 354 #endif | 343 #endif |
| 355 } | 344 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 // false, javascript_content_blocked_observer would never succeed. | 410 // false, javascript_content_blocked_observer would never succeed. |
| 422 // There is no way to ensure blocked content would not have been reported | 411 // There is no way to ensure blocked content would not have been reported |
| 423 // after the check below. For coverage of this scenario, we must rely on | 412 // after the check below. For coverage of this scenario, we must rely on |
| 424 // the TitleWatcher adding sufficient delay most of the time. | 413 // the TitleWatcher adding sufficient delay most of the time. |
| 425 } | 414 } |
| 426 | 415 |
| 427 EXPECT_EQ(expect_is_javascript_content_blocked, | 416 EXPECT_EQ(expect_is_javascript_content_blocked, |
| 428 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 417 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 429 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); | 418 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 430 } | 419 } |
| 431 | |
| 432 private: | |
| 433 // Builds the string to pass to kRegisterPepperPlugins for a single | |
| 434 // plugin using the provided parameters and a dummy version. | |
| 435 // Multiple results may be passed to kRegisterPepperPlugins, separated by ",". | |
| 436 base::FilePath::StringType BuildPepperPluginRegistration( | |
| 437 const char* library_name, | |
| 438 const char* display_name, | |
| 439 const char* mime_type) { | |
| 440 base::FilePath plugin_dir; | |
| 441 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir)); | |
| 442 | |
| 443 base::FilePath plugin_lib = plugin_dir.AppendASCII(library_name); | |
| 444 EXPECT_TRUE(base::PathExists(plugin_lib)); | |
| 445 | |
| 446 base::FilePath::StringType pepper_plugin = plugin_lib.value(); | |
| 447 std::string string_to_append = "#"; | |
| 448 string_to_append.append(display_name); | |
| 449 string_to_append.append("#A CDM#0.1.0.0;"); | |
| 450 string_to_append.append(mime_type); | |
| 451 | |
| 452 #if defined(OS_WIN) | |
| 453 pepper_plugin.append(base::ASCIIToUTF16(string_to_append)); | |
| 454 #else | |
| 455 pepper_plugin.append(string_to_append); | |
| 456 #endif | |
| 457 | |
| 458 return pepper_plugin; | |
| 459 } | |
| 460 }; | 420 }; |
| 461 | 421 |
| 462 const char | |
| 463 PepperContentSettingsSpecialCasesTest::kExternalClearKeyMimeType[] = | |
| 464 "application/x-ppapi-clearkey-cdm"; | |
| 465 | |
| 466 class PepperContentSettingsSpecialCasesPluginsBlockedTest | 422 class PepperContentSettingsSpecialCasesPluginsBlockedTest |
| 467 : public PepperContentSettingsSpecialCasesTest { | 423 : public PepperContentSettingsSpecialCasesTest { |
| 468 public: | 424 public: |
| 469 void SetUpOnMainThread() override { | 425 void SetUpOnMainThread() override { |
| 470 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); | 426 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); |
| 471 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 427 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 472 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 428 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 473 CONTENT_SETTING_BLOCK); | 429 CONTENT_SETTING_BLOCK); |
| 474 } | 430 } |
| 475 }; | 431 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 489 }; | 445 }; |
| 490 | 446 |
| 491 #if defined(ENABLE_PEPPER_CDMS) | 447 #if defined(ENABLE_PEPPER_CDMS) |
| 492 // A sanity check to verify that the plugin that is used as a baseline below | 448 // A sanity check to verify that the plugin that is used as a baseline below |
| 493 // can be loaded. | 449 // can be loaded. |
| 494 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { | 450 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { |
| 495 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) | 451 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 496 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, | 452 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 497 CONTENT_SETTING_ALLOW); | 453 CONTENT_SETTING_ALLOW); |
| 498 | 454 |
| 499 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true); | 455 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, true); |
| 500 } | 456 } |
| 501 #endif // defined(ENABLE_PEPPER_CDMS) | 457 #endif // defined(ENABLE_PEPPER_CDMS) |
| 502 | 458 |
| 503 // The following tests verify that Pepper plugins that use JavaScript settings | 459 // The following tests verify that Pepper plugins that use JavaScript settings |
| 504 // instead of Plugins settings still work when Plugins are blocked. | 460 // instead of Plugins settings still work when Plugins are blocked. |
| 505 | 461 |
| 506 #if defined(ENABLE_PEPPER_CDMS) | 462 #if defined(ENABLE_PEPPER_CDMS) |
| 507 // The plugin successfully loaded above is blocked. | 463 // The plugin successfully loaded above is blocked. |
| 508 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, | 464 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, |
| 509 Normal) { | 465 Normal) { |
| 510 RunLoadPepperPluginTest(kExternalClearKeyMimeType, false); | 466 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, false); |
| 511 } | 467 } |
| 512 | 468 |
| 513 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) | 469 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) |
| 514 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, | 470 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, |
| 515 WidevineCdm) { | 471 WidevineCdm) { |
| 516 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); | 472 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); |
| 517 } | 473 } |
| 518 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) | 474 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) |
| 519 #endif // defined(ENABLE_PEPPER_CDMS) | 475 #endif // defined(ENABLE_PEPPER_CDMS) |
| 520 | 476 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 544 #endif // defined(ENABLE_PEPPER_CDMS) | 500 #endif // defined(ENABLE_PEPPER_CDMS) |
| 545 | 501 |
| 546 #if !defined(DISABLE_NACL) | 502 #if !defined(DISABLE_NACL) |
| 547 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, | 503 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, |
| 548 NaCl) { | 504 NaCl) { |
| 549 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 505 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
| 550 } | 506 } |
| 551 #endif // !defined(DISABLE_NACL) | 507 #endif // !defined(DISABLE_NACL) |
| 552 | 508 |
| 553 #endif // defined(ENABLE_PLUGINS) | 509 #endif // defined(ENABLE_PLUGINS) |
| OLD | NEW |