Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_browsertest.cc
blobc0d0018c9daba41caacc2b8be73b19345353d9e1
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/path_service.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/cookie_settings.h"
11 #include "chrome/browser/content_settings/host_content_settings_map.h"
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
13 #include "chrome/browser/net/url_request_mock_util.h"
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/render_messages.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/test_switches.h"
23 #include "chrome/test/base/ui_test_utils.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/plugin_service.h"
26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/render_view_host.h"
29 #include "content/public/browser/web_contents.h"
30 #include "content/public/common/content_switches.h"
31 #include "content/public/test/browser_test_utils.h"
32 #include "content/public/test/test_utils.h"
33 #include "content/test/net/url_request_mock_http_job.h"
34 #include "net/test/spawned_test_server/spawned_test_server.h"
36 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
38 #if defined(OS_MACOSX)
39 #include "base/mac/scoped_nsautorelease_pool.h"
40 #endif
42 using content::BrowserThread;
43 using content::URLRequestMockHTTPJob;
45 class ContentSettingsTest : public InProcessBrowserTest {
46 public:
47 ContentSettingsTest()
48 : https_server_(net::SpawnedTestServer::TYPE_HTTPS,
49 net::SpawnedTestServer::SSLOptions(
50 net::SpawnedTestServer::SSLOptions::CERT_OK),
51 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
54 virtual void SetUpOnMainThread() OVERRIDE {
55 BrowserThread::PostTask(
56 BrowserThread::IO, FROM_HERE,
57 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
60 // Check the cookie for the given URL in an incognito window.
61 void CookieCheckIncognitoWindow(const GURL& url, bool cookies_enabled) {
62 ASSERT_TRUE(content::GetCookies(browser()->profile(), url).empty());
64 Browser* incognito = CreateIncognitoBrowser();
65 ASSERT_TRUE(content::GetCookies(incognito->profile(), url).empty());
66 ui_test_utils::NavigateToURL(incognito, url);
67 ASSERT_EQ(cookies_enabled,
68 !content::GetCookies(incognito->profile(), url).empty());
70 // Ensure incognito cookies don't leak to regular profile.
71 ASSERT_TRUE(content::GetCookies(browser()->profile(), url).empty());
73 // Ensure cookies get wiped after last incognito window closes.
74 content::WindowedNotificationObserver signal(
75 chrome::NOTIFICATION_BROWSER_CLOSED,
76 content::Source<Browser>(incognito));
78 chrome::CloseWindow(incognito);
80 #if defined(OS_MACOSX)
81 // BrowserWindowController depends on the auto release pool being recycled
82 // in the message loop to delete itself, which frees the Browser object
83 // which fires this event.
84 AutoreleasePool()->Recycle();
85 #endif
87 signal.Wait();
89 incognito = CreateIncognitoBrowser();
90 ASSERT_TRUE(content::GetCookies(incognito->profile(), url).empty());
91 chrome::CloseWindow(incognito);
94 void PreBasic(const GURL& url) {
95 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
97 CookieCheckIncognitoWindow(url, true);
99 ui_test_utils::NavigateToURL(browser(), url);
100 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty());
103 void Basic(const GURL& url) {
104 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty());
107 net::SpawnedTestServer https_server_;
110 // Sanity check on cookies before we do other tests. While these can be written
111 // in content_browsertests, we want to verify Chrome's cookie storage and how it
112 // handles incognito windows.
113 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookies) {
114 ASSERT_TRUE(test_server()->Start());
115 GURL http_url = test_server()->GetURL("files/setcookie.html");
116 PreBasic(http_url);
119 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookies) {
120 ASSERT_TRUE(test_server()->Start());
121 GURL http_url = test_server()->GetURL("files/setcookie.html");
122 Basic(http_url);
125 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BasicCookiesHttps) {
126 ASSERT_TRUE(https_server_.Start());
127 GURL https_url = https_server_.GetURL("files/setcookie.html");
128 PreBasic(https_url);
131 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BasicCookiesHttps) {
132 ASSERT_TRUE(https_server_.Start());
133 GURL https_url = https_server_.GetURL("files/setcookie.html");
134 Basic(https_url);
137 // Verify that cookies are being blocked.
138 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, PRE_BlockCookies) {
139 ASSERT_TRUE(test_server()->Start());
140 CookieSettings::Factory::GetForProfile(browser()->profile())->
141 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
142 GURL url = test_server()->GetURL("files/setcookie.html");
143 ui_test_utils::NavigateToURL(browser(), url);
144 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
145 CookieCheckIncognitoWindow(url, false);
148 // Ensure that the setting persists.
149 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookies) {
150 ASSERT_EQ(
151 CONTENT_SETTING_BLOCK,
152 CookieSettings::Factory::GetForProfile(browser()->profile())->
153 GetDefaultCookieSetting(NULL));
156 // Verify that cookies can be allowed and set using exceptions for particular
157 // website(s) when all others are blocked.
158 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, AllowCookiesUsingExceptions) {
159 ASSERT_TRUE(test_server()->Start());
160 GURL url = test_server()->GetURL("files/setcookie.html");
161 CookieSettings* settings =
162 CookieSettings::Factory::GetForProfile(browser()->profile()).get();
163 settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
165 ui_test_utils::NavigateToURL(browser(), url);
166 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
168 settings->SetCookieSetting(
169 ContentSettingsPattern::FromURL(url),
170 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_ALLOW);
172 ui_test_utils::NavigateToURL(browser(), url);
173 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty());
176 // Verify that cookies can be blocked for a specific website using exceptions.
177 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, BlockCookiesUsingExceptions) {
178 ASSERT_TRUE(test_server()->Start());
179 GURL url = test_server()->GetURL("files/setcookie.html");
180 CookieSettings* settings =
181 CookieSettings::Factory::GetForProfile(browser()->profile()).get();
182 settings->SetCookieSetting(ContentSettingsPattern::FromURL(url),
183 ContentSettingsPattern::Wildcard(),
184 CONTENT_SETTING_BLOCK);
186 ui_test_utils::NavigateToURL(browser(), url);
187 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
189 ASSERT_TRUE(https_server_.Start());
190 GURL unblocked_url = https_server_.GetURL("files/cookie1.html");
192 ui_test_utils::NavigateToURL(browser(), unblocked_url);
193 ASSERT_FALSE(GetCookies(browser()->profile(), unblocked_url).empty());
196 // This fails on ChromeOS because kRestoreOnStartup is ignored and the startup
197 // preference is always "continue where I left off.
198 #if !defined(OS_CHROMEOS)
200 // Verify that cookies can be allowed and set using exceptions for particular
201 // website(s) only for a session when all others are blocked.
202 IN_PROC_BROWSER_TEST_F(ContentSettingsTest,
203 PRE_AllowCookiesForASessionUsingExceptions) {
204 // NOTE: don't use test_server here, since we need the port to be the same
205 // across the restart.
206 GURL url = URLRequestMockHTTPJob::GetMockUrl(
207 base::FilePath(FILE_PATH_LITERAL("setcookie.html")));
208 CookieSettings* settings =
209 CookieSettings::Factory::GetForProfile(browser()->profile()).get();
210 settings->SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
212 ui_test_utils::NavigateToURL(browser(), url);
213 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
215 settings->SetCookieSetting(
216 ContentSettingsPattern::FromURL(url),
217 ContentSettingsPattern::Wildcard(), CONTENT_SETTING_SESSION_ONLY);
218 ui_test_utils::NavigateToURL(browser(), url);
219 ASSERT_FALSE(GetCookies(browser()->profile(), url).empty());
222 IN_PROC_BROWSER_TEST_F(ContentSettingsTest,
223 AllowCookiesForASessionUsingExceptions) {
224 GURL url = URLRequestMockHTTPJob::GetMockUrl(
225 base::FilePath(FILE_PATH_LITERAL("setcookie.html")));
226 ASSERT_TRUE(GetCookies(browser()->profile(), url).empty());
229 #endif // !CHROME_OS
231 // Regression test for http://crbug.com/63649.
232 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectLoopCookies) {
233 ASSERT_TRUE(test_server()->Start());
235 GURL test_url = test_server()->GetURL("files/redirect-loop.html");
237 CookieSettings::Factory::GetForProfile(browser()->profile())->
238 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
240 ui_test_utils::NavigateToURL(browser(), test_url);
242 content::WebContents* web_contents =
243 browser()->tab_strip_model()->GetActiveWebContents();
244 ASSERT_EQ(base::UTF8ToUTF16(test_url.spec() + " failed to load"),
245 web_contents->GetTitle());
247 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
248 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
251 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, ContentSettingsBlockDataURLs) {
252 GURL url("data:text/html,<title>Data URL</title><script>alert(1)</script>");
254 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
255 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
257 ui_test_utils::NavigateToURL(browser(), url);
259 content::WebContents* web_contents =
260 browser()->tab_strip_model()->GetActiveWebContents();
261 ASSERT_EQ(base::UTF8ToUTF16("Data URL"), web_contents->GetTitle());
263 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
264 IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT));
267 // Tests that if redirect across origins occurs, the new process still gets the
268 // content settings before the resource headers.
269 IN_PROC_BROWSER_TEST_F(ContentSettingsTest, RedirectCrossOrigin) {
270 ASSERT_TRUE(test_server()->Start());
272 net::HostPortPair host_port = test_server()->host_port_pair();
273 DCHECK_EQ(host_port.host(), std::string("127.0.0.1"));
275 std::string redirect(base::StringPrintf(
276 "http://localhost:%d/files/redirect-cross-origin.html",
277 host_port.port()));
278 GURL test_url = test_server()->GetURL("server-redirect?" + redirect);
280 CookieSettings::Factory::GetForProfile(browser()->profile())->
281 SetDefaultCookieSetting(CONTENT_SETTING_BLOCK);
283 ui_test_utils::NavigateToURL(browser(), test_url);
285 content::WebContents* web_contents =
286 browser()->tab_strip_model()->GetActiveWebContents();
288 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)->
289 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES));
292 // On Aura NPAPI only works on Windows.
293 #if !defined(USE_AURA) || defined(OS_WIN)
295 class ClickToPlayPluginTest : public ContentSettingsTest {
296 public:
297 ClickToPlayPluginTest() {}
299 #if defined(OS_MACOSX)
300 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
301 base::FilePath plugin_dir;
302 PathService::Get(base::DIR_MODULE, &plugin_dir);
303 plugin_dir = plugin_dir.AppendASCII("plugins");
304 // The plugins directory isn't read by default on the Mac, so it needs to be
305 // explicitly registered.
306 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir);
308 #endif
311 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) {
312 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
313 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
315 GURL url = ui_test_utils::GetTestUrl(
316 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html"));
317 ui_test_utils::NavigateToURL(browser(), url);
319 base::string16 expected_title(base::ASCIIToUTF16("OK"));
320 content::TitleWatcher title_watcher(
321 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
323 content::WebContents* web_contents =
324 browser()->tab_strip_model()->GetActiveWebContents();
325 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance();
326 int process_id = web_contents->GetMainFrame()->GetProcess()->GetID();
327 base::FilePath path(FILE_PATH_LITERAL("blah"));
328 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path));
329 filter->AuthorizeAllPlugins(web_contents, true, std::string());
330 EXPECT_TRUE(filter->CanLoadPlugin(process_id, path));
332 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
335 // Verify that plugins can be allowed on a domain by adding an exception
336 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, AllowException) {
337 GURL url = ui_test_utils::GetTestUrl(
338 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html"));
340 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
341 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
342 browser()->profile()->GetHostContentSettingsMap()
343 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
344 ContentSettingsPattern::Wildcard(),
345 CONTENT_SETTINGS_TYPE_PLUGINS,
346 std::string(),
347 CONTENT_SETTING_ALLOW);
349 base::string16 expected_title(base::ASCIIToUTF16("OK"));
350 content::TitleWatcher title_watcher(
351 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
352 ui_test_utils::NavigateToURL(browser(), url);
353 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
356 // Verify that plugins can be blocked on a domain by adding an exception.
357 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, BlockException) {
358 GURL url = ui_test_utils::GetTestUrl(
359 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html"));
361 browser()->profile()->GetHostContentSettingsMap()
362 ->SetContentSetting(ContentSettingsPattern::FromURL(url),
363 ContentSettingsPattern::Wildcard(),
364 CONTENT_SETTINGS_TYPE_PLUGINS,
365 std::string(),
366 CONTENT_SETTING_BLOCK);
368 base::string16 expected_title(base::ASCIIToUTF16("Click To Play"));
369 content::TitleWatcher title_watcher(
370 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
371 ui_test_utils::NavigateToURL(browser(), url);
372 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
375 // Crashes on Mac Asan. http://crbug.com/239169
376 #if defined(OS_MACOSX)
377 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins
378 // TODO(jschuh): Flaky plugin tests. crbug.com/244653
379 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64)
380 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins
381 #else
382 #define MAYBE_LoadAllBlockedPlugins LoadAllBlockedPlugins
383 #endif
384 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, MAYBE_LoadAllBlockedPlugins) {
385 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
386 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
388 GURL url = ui_test_utils::GetTestUrl(
389 base::FilePath(),
390 base::FilePath().AppendASCII("load_all_blocked_plugins.html"));
391 ui_test_utils::NavigateToURL(browser(), url);
393 base::string16 expected_title1(base::ASCIIToUTF16("1"));
394 content::TitleWatcher title_watcher1(
395 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1);
397 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
398 browser()->tab_strip_model()->GetActiveWebContents(), true,
399 std::string());
400 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle());
402 base::string16 expected_title2(base::ASCIIToUTF16("2"));
403 content::TitleWatcher title_watcher2(
404 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2);
406 ASSERT_TRUE(content::ExecuteScript(
407 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()"));
409 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle());
412 // If this flakes, use http://crbug.com/113057.
413 // TODO(jschuh): Hanging plugin tests. crbug.com/244653
414 #if !defined(OS_WIN) && !defined(ARCH_CPU_X86_64)
415 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) {
416 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
417 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
419 GURL url("data:application/vnd.npapi-test,CallOnStartup();");
420 ui_test_utils::NavigateToURL(browser(), url);
422 // Inject the callback function into the HTML page generated by the browser.
423 ASSERT_TRUE(content::ExecuteScript(
424 browser()->tab_strip_model()->GetActiveWebContents(),
425 "CallOnStartup = function() { document.title = \"OK\"; }"));
427 base::string16 expected_title(base::ASCIIToUTF16("OK"));
428 content::TitleWatcher title_watcher(
429 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
431 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
432 browser()->tab_strip_model()->GetActiveWebContents(), true,
433 std::string());
435 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
437 #endif
439 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) {
440 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
441 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
443 GURL url = ui_test_utils::GetTestUrl(
444 base::FilePath(),
445 base::FilePath().AppendASCII("plugin_delete_self_at_load.html"));
446 ui_test_utils::NavigateToURL(browser(), url);
448 base::string16 expected_title(base::ASCIIToUTF16("OK"));
449 content::TitleWatcher title_watcher(
450 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
452 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
453 browser()->tab_strip_model()->GetActiveWebContents(), true,
454 std::string());
456 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
459 #endif // !defined(USE_AURA) || defined(OS_WIN)
461 #if defined(ENABLE_PLUGINS)
463 class PepperContentSettingsTest : public ContentSettingsTest {
464 public:
465 PepperContentSettingsTest() {}
467 protected:
468 static const char* const kExternalClearKeyMimeType;
470 // Registers any CDM plugins not registered by default.
471 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
472 #if defined(ENABLE_PEPPER_CDMS)
473 // Platform-specific filename relative to the chrome executable.
474 #if defined(OS_WIN)
475 const std::wstring external_clear_key_mime_type =
476 base::ASCIIToWide(kExternalClearKeyMimeType);
477 const char kLibraryName[] = "clearkeycdmadapter.dll";
478 #else // !defined(OS_WIN)
479 const char* external_clear_key_mime_type = kExternalClearKeyMimeType;
480 #if defined(OS_MACOSX)
481 const char kLibraryName[] = "clearkeycdmadapter.plugin";
482 #elif defined(OS_POSIX)
483 const char kLibraryName[] = "libclearkeycdmadapter.so";
484 #endif // defined(OS_MACOSX)
485 #endif // defined(OS_WIN)
487 // Append the switch to register the External Clear Key CDM.
488 base::FilePath plugin_dir;
489 EXPECT_TRUE(PathService::Get(base::DIR_MODULE, &plugin_dir));
490 base::FilePath plugin_lib = plugin_dir.AppendASCII(kLibraryName);
491 EXPECT_TRUE(base::PathExists(plugin_lib));
492 base::FilePath::StringType pepper_plugin = plugin_lib.value();
493 pepper_plugin.append(FILE_PATH_LITERAL(
494 "#Clear Key CDM#Clear Key CDM 0.1.0.0#0.1.0.0;"));
495 pepper_plugin.append(external_clear_key_mime_type);
496 command_line->AppendSwitchNative(switches::kRegisterPepperPlugins,
497 pepper_plugin);
498 #endif // defined(ENABLE_PEPPER_CDMS)
500 #if !defined(DISABLE_NACL)
501 // Ensure NaCl can run.
502 command_line->AppendSwitch(switches::kEnableNaCl);
503 #endif
506 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) {
507 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded";
508 content::WebContents* web_contents =
509 browser()->tab_strip_model()->GetActiveWebContents();
511 base::string16 expected_title(base::ASCIIToUTF16(expected_result));
512 content::TitleWatcher title_watcher(web_contents, expected_title);
514 // GetTestUrl assumes paths, so we must append query parameters to result.
515 GURL file_url = ui_test_utils::GetTestUrl(
516 base::FilePath(),
517 base::FilePath().AppendASCII("load_pepper_plugin.html"));
518 GURL url(file_url.spec() +
519 base::StringPrintf("?mimetype=%s", mime_type));
520 ui_test_utils::NavigateToURL(browser(), url);
522 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
523 EXPECT_EQ(!expect_loaded,
524 TabSpecificContentSettings::FromWebContents(web_contents)->
525 IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS));
528 void RunJavaScriptBlockedTest(const char* html_file,
529 bool expect_is_javascript_content_blocked) {
530 // Because JavaScript is disabled, <title> will be the only title set.
531 // Checking for it ensures that the page loaded.
532 const char* const kExpectedTitle = "Initial Title";
533 content::WebContents* web_contents =
534 browser()->tab_strip_model()->GetActiveWebContents();
535 TabSpecificContentSettings* tab_settings =
536 TabSpecificContentSettings::FromWebContents(web_contents);
537 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
538 content::TitleWatcher title_watcher(web_contents, expected_title);
540 GURL url = ui_test_utils::GetTestUrl(
541 base::FilePath(), base::FilePath().AppendASCII(html_file));
542 ui_test_utils::NavigateToURL(browser(), url);
544 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
546 EXPECT_EQ(expect_is_javascript_content_blocked,
547 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT));
548 EXPECT_FALSE(tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS));
552 const char* const PepperContentSettingsTest::kExternalClearKeyMimeType =
553 "application/x-ppapi-clearkey-cdm";
555 // Tests Pepper plugins that use JavaScript instead of Plug-ins settings.
556 IN_PROC_BROWSER_TEST_F(PepperContentSettingsTest, DISABLED_PluginSpecialCases) {
557 #if defined(OS_WIN) && defined(USE_ASH)
558 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
559 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
560 return;
561 #endif
563 HostContentSettingsMap* content_settings =
564 browser()->profile()->GetHostContentSettingsMap();
566 // First, verify that this plugin can be loaded.
567 content_settings->SetDefaultContentSetting(
568 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW);
570 #if defined(ENABLE_PEPPER_CDMS)
571 RunLoadPepperPluginTest(kExternalClearKeyMimeType, true);
572 #endif // defined(ENABLE_PEPPER_CDMS)
574 // Next, test behavior when plug-ins are blocked.
575 content_settings->SetDefaultContentSetting(
576 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
578 #if defined(ENABLE_PEPPER_CDMS)
579 // The plugin we loaded above does not load now.
580 RunLoadPepperPluginTest(kExternalClearKeyMimeType, false);
582 #if defined(WIDEVINE_CDM_AVAILABLE)
583 RunLoadPepperPluginTest(kWidevineCdmPluginMimeType, true);
584 #endif // defined(WIDEVINE_CDM_AVAILABLE)
585 #endif // defined(ENABLE_PEPPER_CDMS)
587 #if !defined(DISABLE_NACL)
588 RunLoadPepperPluginTest("application/x-nacl", true);
589 #endif // !defined(DISABLE_NACL)
591 // Finally, test behavior when (just) JavaScript is blocked.
592 content_settings->SetDefaultContentSetting(
593 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW);
594 content_settings->SetDefaultContentSetting(
595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
597 #if defined(ENABLE_PEPPER_CDMS)
598 // This plugin has no special behavior and does not require JavaScript.
599 RunJavaScriptBlockedTest("load_clearkey_no_js.html", false);
601 #if defined(WIDEVINE_CDM_AVAILABLE)
602 RunJavaScriptBlockedTest("load_widevine_no_js.html", true);
603 #endif // defined(WIDEVINE_CDM_AVAILABLE)
604 #endif // defined(ENABLE_PEPPER_CDMS)
606 #if !defined(DISABLE_NACL)
607 RunJavaScriptBlockedTest("load_nacl_no_js.html", true);
608 #endif // !defined(DISABLE_NACL)
611 #endif // defined(ENABLE_PLUGINS)