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

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

Issue 1991963002: (reland) madia: Add helper function to register pepper CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/media/encrypted_media_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
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
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, kClearKeyCdmDisplayName,
330 kClearKeyCdmPepperMimeType);
339 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 331 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
340 // The CDM must be registered when it is a component. 332 // The CDM must be registered when it is a component.
341 pepper_plugins.append(FILE_PATH_LITERAL(",")); 333 pepper_plugins.append(FILE_PATH_LITERAL(","));
342 pepper_plugins.append( 334 pepper_plugins.append(BuildPepperCdmRegistration(
343 BuildPepperPluginRegistration(kWidevineCdmAdapterFileName, 335 kWidevineCdmAdapterFileName, kWidevineCdmDisplayName,
344 kWidevineCdmDisplayName, 336 kWidevineCdmPluginMimeType));
345 kWidevineCdmPluginMimeType));
346 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 337 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
347 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 338 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
348 pepper_plugins); 339 pepper_plugins);
349 #endif // defined(ENABLE_PEPPER_CDMS) 340 #endif // defined(ENABLE_PEPPER_CDMS)
350 341
351 #if !defined(DISABLE_NACL) 342 #if !defined(DISABLE_NACL)
352 // Ensure NaCl can run. 343 // Ensure NaCl can run.
353 command_line->AppendSwitch(switches::kEnableNaCl); 344 command_line->AppendSwitch(switches::kEnableNaCl);
354 #endif 345 #endif
355 } 346 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // false, javascript_content_blocked_observer would never succeed. 412 // false, javascript_content_blocked_observer would never succeed.
422 // There is no way to ensure blocked content would not have been reported 413 // 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 414 // after the check below. For coverage of this scenario, we must rely on
424 // the TitleWatcher adding sufficient delay most of the time. 415 // the TitleWatcher adding sufficient delay most of the time.
425 } 416 }
426 417
427 EXPECT_EQ(expect_is_javascript_content_blocked, 418 EXPECT_EQ(expect_is_javascript_content_blocked,
428 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); 419 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT));
429 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); 420 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS));
430 } 421 }
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 }; 422 };
461 423
462 const char
463 PepperContentSettingsSpecialCasesTest::kExternalClearKeyMimeType[] =
464 "application/x-ppapi-clearkey-cdm";
465
466 class PepperContentSettingsSpecialCasesPluginsBlockedTest 424 class PepperContentSettingsSpecialCasesPluginsBlockedTest
467 : public PepperContentSettingsSpecialCasesTest { 425 : public PepperContentSettingsSpecialCasesTest {
468 public: 426 public:
469 void SetUpOnMainThread() override { 427 void SetUpOnMainThread() override {
470 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); 428 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread();
471 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 429 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
472 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 430 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
473 CONTENT_SETTING_BLOCK); 431 CONTENT_SETTING_BLOCK);
474 } 432 }
475 }; 433 };
(...skipping 13 matching lines...) Expand all
489 }; 447 };
490 448
491 #if defined(ENABLE_PEPPER_CDMS) 449 #if defined(ENABLE_PEPPER_CDMS)
492 // A sanity check to verify that the plugin that is used as a baseline below 450 // A sanity check to verify that the plugin that is used as a baseline below
493 // can be loaded. 451 // can be loaded.
494 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { 452 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) {
495 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 453 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
496 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 454 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
497 CONTENT_SETTING_ALLOW); 455 CONTENT_SETTING_ALLOW);
498 456
499 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true); 457 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, true);
500 } 458 }
501 #endif // defined(ENABLE_PEPPER_CDMS) 459 #endif // defined(ENABLE_PEPPER_CDMS)
502 460
503 // The following tests verify that Pepper plugins that use JavaScript settings 461 // The following tests verify that Pepper plugins that use JavaScript settings
504 // instead of Plugins settings still work when Plugins are blocked. 462 // instead of Plugins settings still work when Plugins are blocked.
505 463
506 #if defined(ENABLE_PEPPER_CDMS) 464 #if defined(ENABLE_PEPPER_CDMS)
507 // The plugin successfully loaded above is blocked. 465 // The plugin successfully loaded above is blocked.
508 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 466 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
509 Normal) { 467 Normal) {
510 RunLoadPepperPluginTest(kExternalClearKeyMimeType, false); 468 RunLoadPepperPluginTest(kClearKeyCdmPepperMimeType, false);
511 } 469 }
512 470
513 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 471 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
514 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 472 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
515 WidevineCdm) { 473 WidevineCdm) {
516 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); 474 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true);
517 } 475 }
518 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 476 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
519 #endif // defined(ENABLE_PEPPER_CDMS) 477 #endif // defined(ENABLE_PEPPER_CDMS)
520 478
(...skipping 23 matching lines...) Expand all
544 #endif // defined(ENABLE_PEPPER_CDMS) 502 #endif // defined(ENABLE_PEPPER_CDMS)
545 503
546 #if !defined(DISABLE_NACL) 504 #if !defined(DISABLE_NACL)
547 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 505 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
548 NaCl) { 506 NaCl) {
549 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 507 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
550 } 508 }
551 #endif // !defined(DISABLE_NACL) 509 #endif // !defined(DISABLE_NACL)
552 510
553 #endif // defined(ENABLE_PLUGINS) 511 #endif // defined(ENABLE_PLUGINS)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/encrypted_media_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698