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

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

Issue 1983563002: media: Add helper function to register pepper CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup 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
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"
11 #include "chrome/browser/content_settings/cookie_settings_factory.h" 11 #include "chrome/browser/content_settings/cookie_settings_factory.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/media/pepper_cdm_test_helper.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"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/content_settings/core/browser/cookie_settings.h" 24 #include "components/content_settings/core/browser/cookie_settings.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 content::WebContents* web_contents = 311 content::WebContents* web_contents =
311 browser()->tab_strip_model()->GetActiveWebContents(); 312 browser()->tab_strip_model()->GetActiveWebContents();
312 313
313 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> 314 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
314 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); 315 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
315 } 316 }
316 317
317 #if defined(ENABLE_PLUGINS) 318 #if defined(ENABLE_PLUGINS)
318 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { 319 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest {
319 protected: 320 protected:
320 static const char kExternalClearKeyMimeType[];
321
322 // Registers any CDM plugins not registered by default. 321 // Registers any CDM plugins not registered by default.
323 void SetUpCommandLine(base::CommandLine* command_line) override { 322 void SetUpCommandLine(base::CommandLine* command_line) override {
324 #if defined(ENABLE_PEPPER_CDMS) 323 #if defined(ENABLE_PEPPER_CDMS)
325 // Base path for Clear Key CDM (relative to the chrome executable).
326 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm";
327
328 // Platform-specific filename relative to kClearKeyCdmBaseDirectory.
329 #if defined(OS_WIN)
330 const char kClearKeyCdmAdapterFileName[] = "clearkeycdmadapter.dll";
331 #else // !defined(OS_WIN)
332 #if defined(OS_MACOSX)
333 const char kClearKeyCdmAdapterFileName[] = "clearkeycdmadapter.plugin";
334 #elif defined(OS_POSIX)
335 const char kClearKeyCdmAdapterFileName[] = "libclearkeycdmadapter.so";
336 #endif // defined(OS_MACOSX)
337 #endif // defined(OS_WIN)
338
339 // Append the switch to register the External Clear Key CDM. 324 // Append the switch to register the External Clear Key CDM.
340 base::FilePath::StringType pepper_plugins = BuildPepperPluginRegistration( 325 base::FilePath::StringType pepper_plugins = BuildPepperCdmRegistration(
341 kClearKeyCdmBaseDirectory, kClearKeyCdmAdapterFileName, "Clear Key CDM", 326 kClearKeyCdmBaseDirectory, kClearKeyCdmAdapterFileName,
342 kExternalClearKeyMimeType); 327 kClearKeyCdmPluginMimeType);
343 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 328 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
344 // The CDM must be registered when it is a component. 329 // The CDM must be registered when it is a component.
345 pepper_plugins.append(FILE_PATH_LITERAL(",")); 330 pepper_plugins.append(FILE_PATH_LITERAL(","));
346 pepper_plugins.append(BuildPepperPluginRegistration( 331 pepper_plugins.append(BuildPepperCdmRegistration(
347 kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName, 332 kWidevineCdmBaseDirectory, kWidevineCdmAdapterFileName,
348 kWidevineCdmDisplayName, kWidevineCdmPluginMimeType)); 333 kWidevineCdmPluginMimeType));
349 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) 334 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
350 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins, 335 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
351 pepper_plugins); 336 pepper_plugins);
352 #endif // defined(ENABLE_PEPPER_CDMS) 337 #endif // defined(ENABLE_PEPPER_CDMS)
353 338
354 #if !defined(DISABLE_NACL) 339 #if !defined(DISABLE_NACL)
355 // Ensure NaCl can run. 340 // Ensure NaCl can run.
356 command_line->AppendSwitch(switches::kEnableNaCl); 341 command_line->AppendSwitch(switches::kEnableNaCl);
357 #endif 342 #endif
358 } 343 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // false, javascript_content_blocked_observer would never succeed. 409 // false, javascript_content_blocked_observer would never succeed.
425 // There is no way to ensure blocked content would not have been reported 410 // There is no way to ensure blocked content would not have been reported
426 // after the check below. For coverage of this scenario, we must rely on 411 // after the check below. For coverage of this scenario, we must rely on
427 // the TitleWatcher adding sufficient delay most of the time. 412 // the TitleWatcher adding sufficient delay most of the time.
428 } 413 }
429 414
430 EXPECT_EQ(expect_is_javascript_content_blocked, 415 EXPECT_EQ(expect_is_javascript_content_blocked,
431 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); 416 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT));
432 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); 417 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS));
433 } 418 }
434
435 private:
436 // Builds the string to pass to kRegisterPepperPlugins for a single
437 // plugin using the provided parameters and a dummy version.
438 // Multiple results may be passed to kRegisterPepperPlugins, separated by ",".
439 base::FilePath::StringType BuildPepperPluginRegistration(
440 const char* library_path,
441 const char* library_name,
442 const char* display_name,
443 const char* mime_type) {
444 base::FilePath plugin_dir;
445 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
446 plugin_dir = plugin_dir.AppendASCII(library_path);
447
448 base::FilePath plugin_lib = plugin_dir.AppendASCII(library_name);
449 EXPECT_TRUE(base::PathExists(plugin_lib));
450
451 base::FilePath::StringType pepper_plugin = plugin_lib.value();
452 std::string string_to_append = "#";
453 string_to_append.append(display_name);
454 string_to_append.append("#A CDM#0.1.0.0;");
455 string_to_append.append(mime_type);
456
457 #if defined(OS_WIN)
458 pepper_plugin.append(base::ASCIIToUTF16(string_to_append));
459 #else
460 pepper_plugin.append(string_to_append);
461 #endif
462
463 return pepper_plugin;
464 }
465 }; 419 };
466 420
467 const char
468 PepperContentSettingsSpecialCasesTest::kExternalClearKeyMimeType[] =
469 "application/x-ppapi-clearkey-cdm";
470
471 class PepperContentSettingsSpecialCasesPluginsBlockedTest 421 class PepperContentSettingsSpecialCasesPluginsBlockedTest
472 : public PepperContentSettingsSpecialCasesTest { 422 : public PepperContentSettingsSpecialCasesTest {
473 public: 423 public:
474 void SetUpOnMainThread() override { 424 void SetUpOnMainThread() override {
475 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); 425 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread();
476 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 426 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
477 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 427 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
478 CONTENT_SETTING_BLOCK); 428 CONTENT_SETTING_BLOCK);
479 } 429 }
480 }; 430 };
(...skipping 13 matching lines...) Expand all
494 }; 444 };
495 445
496 #if defined(ENABLE_PEPPER_CDMS) 446 #if defined(ENABLE_PEPPER_CDMS)
497 // A sanity check to verify that the plugin that is used as a baseline below 447 // A sanity check to verify that the plugin that is used as a baseline below
498 // can be loaded. 448 // can be loaded.
499 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { 449 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) {
500 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) 450 HostContentSettingsMapFactory::GetForProfile(browser()->profile())
501 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, 451 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
502 CONTENT_SETTING_ALLOW); 452 CONTENT_SETTING_ALLOW);
503 453
504 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true); 454 RunLoadPepperPluginTest(kClearKeyCdmPluginMimeType, true);
505 } 455 }
506 #endif // defined(ENABLE_PEPPER_CDMS) 456 #endif // defined(ENABLE_PEPPER_CDMS)
507 457
508 // The following tests verify that Pepper plugins that use JavaScript settings 458 // The following tests verify that Pepper plugins that use JavaScript settings
509 // instead of Plugins settings still work when Plugins are blocked. 459 // instead of Plugins settings still work when Plugins are blocked.
510 460
511 #if defined(ENABLE_PEPPER_CDMS) 461 #if defined(ENABLE_PEPPER_CDMS)
512 // The plugin successfully loaded above is blocked. 462 // The plugin successfully loaded above is blocked.
513 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 463 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
514 Normal) { 464 Normal) {
515 RunLoadPepperPluginTest(kExternalClearKeyMimeType, false); 465 RunLoadPepperPluginTest(kClearKeyCdmPluginMimeType, false);
516 } 466 }
517 467
518 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 468 #if defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
519 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest, 469 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesPluginsBlockedTest,
520 WidevineCdm) { 470 WidevineCdm) {
521 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true); 471 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true);
522 } 472 }
523 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS) 473 #endif // defined(WIDEVINE_CDM_AVAILABLE) && !defined(OS_CHROMEOS)
524 #endif // defined(ENABLE_PEPPER_CDMS) 474 #endif // defined(ENABLE_PEPPER_CDMS)
525 475
(...skipping 23 matching lines...) Expand all
549 #endif // defined(ENABLE_PEPPER_CDMS) 499 #endif // defined(ENABLE_PEPPER_CDMS)
550 500
551 #if !defined(DISABLE_NACL) 501 #if !defined(DISABLE_NACL)
552 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest, 502 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesJavaScriptBlockedTest,
553 NaCl) { 503 NaCl) {
554 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); 504 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
555 } 505 }
556 #endif // !defined(DISABLE_NACL) 506 #endif // !defined(DISABLE_NACL)
557 507
558 #endif // defined(ENABLE_PLUGINS) 508 #endif // defined(ENABLE_PLUGINS)
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/encrypted_media_browsertest.cc » ('j') | chrome/browser/media/pepper_cdm_test_helper.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698