| 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 "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 10 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 12 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
| 13 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
| 20 #include "chrome/test/base/test_switches.h" | 21 #include "chrome/test/base/test_switches.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"), | 233 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"), |
| 233 web_contents->GetTitle()); | 234 web_contents->GetTitle()); |
| 234 | 235 |
| 235 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 236 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
| 236 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); | 237 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 237 } | 238 } |
| 238 | 239 |
| 239 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, ContentSettingsBlockDataURLs) { | 240 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, ContentSettingsBlockDataURLs) { |
| 240 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>"); | 241 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>"); |
| 241 | 242 |
| 242 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 243 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 243 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 244 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 245 CONTENT_SETTING_BLOCK); |
| 244 | 246 |
| 245 ui_test_utils::NavigateToURL(browser(), url); | 247 ui_test_utils::NavigateToURL(browser(), url); |
| 246 | 248 |
| 247 content::WebContents* web_contents = | 249 content::WebContents* web_contents = |
| 248 browser()->tab_strip_model()->GetActiveWebContents(); | 250 browser()->tab_strip_model()->GetActiveWebContents(); |
| 249 ASSERT_EQ(base::UTF8ToUTF16("Data URL"), web_contents->GetTitle()); | 251 ASSERT_EQ(base::UTF8ToUTF16("Data URL"), web_contents->GetTitle()); |
| 250 | 252 |
| 251 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 253 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
| 252 IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 254 IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 253 } | 255 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 | 426 |
| 425 const char* const | 427 const char* const |
| 426 PepperContentSettingsSpecialCasesTest::kExternalClearKeyMimeType = | 428 PepperContentSettingsSpecialCasesTest::kExternalClearKeyMimeType = |
| 427 "application/x-ppapi-clearkey-cdm"; | 429 "application/x-ppapi-clearkey-cdm"; |
| 428 | 430 |
| 429 class PepperContentSettingsSpecialCasesPluginsBlockedTest | 431 class PepperContentSettingsSpecialCasesPluginsBlockedTest |
| 430 : public PepperContentSettingsSpecialCasesTest { | 432 : public PepperContentSettingsSpecialCasesTest { |
| 431 public: | 433 public: |
| 432 void SetUpOnMainThread() override { | 434 void SetUpOnMainThread() override { |
| 433 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); | 435 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); |
| 434 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 436 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 435 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 437 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 438 CONTENT_SETTING_BLOCK); |
| 436 } | 439 } |
| 437 }; | 440 }; |
| 438 | 441 |
| 439 class PepperContentSettingsSpecialCasesJavaScriptBlockedTest | 442 class PepperContentSettingsSpecialCasesJavaScriptBlockedTest |
| 440 : public PepperContentSettingsSpecialCasesTest { | 443 : public PepperContentSettingsSpecialCasesTest { |
| 441 public: | 444 public: |
| 442 void SetUpOnMainThread() override { | 445 void SetUpOnMainThread() override { |
| 443 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); | 446 PepperContentSettingsSpecialCasesTest::SetUpOnMainThread(); |
| 444 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 447 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 445 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); | 448 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 446 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 449 CONTENT_SETTING_ALLOW); |
| 447 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 450 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 451 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 452 CONTENT_SETTING_BLOCK); |
| 448 } | 453 } |
| 449 }; | 454 }; |
| 450 | 455 |
| 451 #if defined(ENABLE_PEPPER_CDMS) | 456 #if defined(ENABLE_PEPPER_CDMS) |
| 452 // A sanity check to verify that the plugin that is used as a baseline below | 457 // A sanity check to verify that the plugin that is used as a baseline below |
| 453 // can be loaded. | 458 // can be loaded. |
| 454 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { | 459 IN_PROC_BROWSER_TEST_F(PepperContentSettingsSpecialCasesTest, Baseline) { |
| 455 #if defined(OS_WIN) && defined(USE_ASH) | 460 #if defined(OS_WIN) && defined(USE_ASH) |
| 456 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 461 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 457 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 462 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 458 switches::kAshBrowserTests)) | 463 switches::kAshBrowserTests)) |
| 459 return; | 464 return; |
| 460 #endif | 465 #endif |
| 461 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 466 HostContentSettingsMapFactory::GetForProfile(browser()->profile()) |
| 462 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); | 467 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 468 CONTENT_SETTING_ALLOW); |
| 463 | 469 |
| 464 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true); | 470 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true); |
| 465 } | 471 } |
| 466 #endif // defined(ENABLE_PEPPER_CDMS) | 472 #endif // defined(ENABLE_PEPPER_CDMS) |
| 467 | 473 |
| 468 // The following tests verify that Pepper plugins that use JavaScript settings | 474 // The following tests verify that Pepper plugins that use JavaScript settings |
| 469 // instead of Plugins settings still work when Plugins are blocked. | 475 // instead of Plugins settings still work when Plugins are blocked. |
| 470 | 476 |
| 471 #if defined(ENABLE_PEPPER_CDMS) | 477 #if defined(ENABLE_PEPPER_CDMS) |
| 472 // The plugin successfully loaded above is blocked. | 478 // The plugin successfully loaded above is blocked. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 551 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 546 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 552 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 547 switches::kAshBrowserTests)) | 553 switches::kAshBrowserTests)) |
| 548 return; | 554 return; |
| 549 #endif | 555 #endif |
| 550 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 556 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
| 551 } | 557 } |
| 552 #endif // !defined(DISABLE_NACL) | 558 #endif // !defined(DISABLE_NACL) |
| 553 | 559 |
| 554 #endif // defined(ENABLE_PLUGINS) | 560 #endif // defined(ENABLE_PLUGINS) |
| OLD | NEW |