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.h" | 10 #include "chrome/browser/content_settings/cookie_settings.h" |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 ui_test_utils::NavigateToURL(browser(), test_url); | 285 ui_test_utils::NavigateToURL(browser(), test_url); |
286 | 286 |
287 content::WebContents* web_contents = | 287 content::WebContents* web_contents = |
288 browser()->tab_strip_model()->GetActiveWebContents(); | 288 browser()->tab_strip_model()->GetActiveWebContents(); |
289 | 289 |
290 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> | 290 EXPECT_TRUE(TabSpecificContentSettings::FromWebContents(web_contents)-> |
291 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); | 291 IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
292 } | 292 } |
293 | 293 |
294 // On Aura NPAPI only works on Windows. | |
295 #if !defined(USE_AURA) || defined(OS_WIN) | |
296 | |
297 class LoadPluginTest : public ContentSettingsTest { | |
298 protected: | |
299 void PerformTest(bool expect_loaded) { | |
300 GURL url = ui_test_utils::GetTestUrl( | |
301 base::FilePath(), | |
302 base::FilePath().AppendASCII("load_npapi_plugin.html")); | |
303 ui_test_utils::NavigateToURL(browser(), url); | |
304 | |
305 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; | |
306 const char* unexpected_result = expect_loaded ? "Not Loaded" : "Loaded"; | |
307 | |
308 base::string16 expected_title(base::ASCIIToUTF16(expected_result)); | |
309 base::string16 unexpected_title(base::ASCIIToUTF16(unexpected_result)); | |
310 | |
311 content::TitleWatcher title_watcher( | |
312 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
313 title_watcher.AlsoWaitForTitle(unexpected_title); | |
314 | |
315 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
316 } | |
317 | |
318 void SetUpCommandLineInternal(base::CommandLine* command_line, | |
319 bool expect_loaded) { | |
320 #if defined(OS_MACOSX) | |
321 base::FilePath plugin_dir; | |
322 PathService::Get(base::DIR_MODULE, &plugin_dir); | |
323 plugin_dir = plugin_dir.AppendASCII("plugins"); | |
324 // The plugins directory isn't read by default on the Mac, so it needs to be | |
325 // explicitly registered. | |
326 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir); | |
327 #endif | |
328 command_line->AppendSwitch(switches::kAlwaysAuthorizePlugins); | |
329 if (expect_loaded) | |
330 command_line->AppendSwitch(switches::kEnableNpapiForTesting); | |
331 } | |
332 }; | |
333 | |
334 class DisabledPluginTest : public LoadPluginTest { | |
335 public: | |
336 DisabledPluginTest() {} | |
337 | |
338 void SetUpCommandLine(base::CommandLine* command_line) override { | |
339 SetUpCommandLineInternal(command_line, false); | |
340 } | |
341 }; | |
342 | |
343 IN_PROC_BROWSER_TEST_F(DisabledPluginTest, Load) { | |
344 PerformTest(false); | |
345 } | |
346 | |
347 class EnabledPluginTest : public LoadPluginTest { | |
348 public: | |
349 EnabledPluginTest() {} | |
350 | |
351 void SetUpCommandLine(base::CommandLine* command_line) override { | |
352 SetUpCommandLineInternal(command_line, true); | |
353 } | |
354 }; | |
355 | |
356 IN_PROC_BROWSER_TEST_F(EnabledPluginTest, Load) { | |
357 PerformTest(true); | |
358 } | |
359 | |
360 class ClickToPlayPluginTest : public ContentSettingsTest { | |
361 public: | |
362 ClickToPlayPluginTest() {} | |
363 | |
364 void SetUpCommandLine(base::CommandLine* command_line) override { | |
365 #if defined(OS_MACOSX) | |
366 base::FilePath plugin_dir; | |
367 PathService::Get(base::DIR_MODULE, &plugin_dir); | |
368 plugin_dir = plugin_dir.AppendASCII("plugins"); | |
369 // The plugins directory isn't read by default on the Mac, so it needs to be | |
370 // explicitly registered. | |
371 command_line->AppendSwitchPath(switches::kExtraPluginDir, plugin_dir); | |
372 #endif | |
373 command_line->AppendSwitch(switches::kEnableNpapiForTesting); | |
374 } | |
375 }; | |
376 | |
377 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { | |
378 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
379 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | |
380 | |
381 GURL url = ui_test_utils::GetTestUrl( | |
382 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | |
383 ui_test_utils::NavigateToURL(browser(), url); | |
384 | |
385 base::string16 expected_title(base::ASCIIToUTF16("OK")); | |
386 content::TitleWatcher title_watcher( | |
387 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
388 | |
389 content::WebContents* web_contents = | |
390 browser()->tab_strip_model()->GetActiveWebContents(); | |
391 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); | |
392 int process_id = web_contents->GetMainFrame()->GetProcess()->GetID(); | |
393 base::FilePath path(FILE_PATH_LITERAL("blah")); | |
394 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path)); | |
395 filter->AuthorizeAllPlugins(web_contents, true, std::string()); | |
396 EXPECT_TRUE(filter->CanLoadPlugin(process_id, path)); | |
397 | |
398 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
399 } | |
400 | |
401 // Verify that plugins can be allowed on a domain by adding an exception | |
402 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, AllowException) { | |
403 GURL url = ui_test_utils::GetTestUrl( | |
404 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | |
405 | |
406 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
407 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | |
408 browser()->profile()->GetHostContentSettingsMap() | |
409 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | |
410 ContentSettingsPattern::Wildcard(), | |
411 CONTENT_SETTINGS_TYPE_PLUGINS, | |
412 std::string(), | |
413 CONTENT_SETTING_ALLOW); | |
414 | |
415 base::string16 expected_title(base::ASCIIToUTF16("OK")); | |
416 content::TitleWatcher title_watcher( | |
417 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
418 ui_test_utils::NavigateToURL(browser(), url); | |
419 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
420 } | |
421 | |
422 // Verify that plugins can be blocked on a domain by adding an exception. | |
423 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, BlockException) { | |
424 GURL url = ui_test_utils::GetTestUrl( | |
425 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | |
426 | |
427 browser()->profile()->GetHostContentSettingsMap() | |
428 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | |
429 ContentSettingsPattern::Wildcard(), | |
430 CONTENT_SETTINGS_TYPE_PLUGINS, | |
431 std::string(), | |
432 CONTENT_SETTING_BLOCK); | |
433 | |
434 base::string16 expected_title(base::ASCIIToUTF16("Click To Play")); | |
435 content::TitleWatcher title_watcher( | |
436 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
437 ui_test_utils::NavigateToURL(browser(), url); | |
438 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
439 } | |
440 | |
441 // Crashes on Mac Asan. http://crbug.com/239169 | |
442 #if defined(OS_MACOSX) | |
443 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins | |
444 // TODO(jschuh): Flaky plugin tests. crbug.com/244653 | |
445 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
446 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins | |
447 #else | |
448 #define MAYBE_LoadAllBlockedPlugins LoadAllBlockedPlugins | |
449 #endif | |
450 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, MAYBE_LoadAllBlockedPlugins) { | |
451 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
452 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | |
453 | |
454 GURL url = ui_test_utils::GetTestUrl( | |
455 base::FilePath(), | |
456 base::FilePath().AppendASCII("load_all_blocked_plugins.html")); | |
457 ui_test_utils::NavigateToURL(browser(), url); | |
458 | |
459 base::string16 expected_title1(base::ASCIIToUTF16("1")); | |
460 content::TitleWatcher title_watcher1( | |
461 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); | |
462 | |
463 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | |
464 browser()->tab_strip_model()->GetActiveWebContents(), true, | |
465 std::string()); | |
466 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); | |
467 | |
468 base::string16 expected_title2(base::ASCIIToUTF16("2")); | |
469 content::TitleWatcher title_watcher2( | |
470 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2); | |
471 | |
472 ASSERT_TRUE(content::ExecuteScript( | |
473 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()")); | |
474 | |
475 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); | |
476 } | |
477 | |
478 // If this flakes, use http://crbug.com/113057. | |
479 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 | |
480 #if !defined(OS_WIN) && !defined(ARCH_CPU_X86_64) | |
481 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { | |
482 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
483 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | |
484 | |
485 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); | |
486 ui_test_utils::NavigateToURL(browser(), url); | |
487 | |
488 std::string script("CallOnStartup = function() { "); | |
489 script.append("document.documentElement.appendChild"); | |
490 script.append("(document.createElement(\"head\")); "); | |
491 script.append("document.title = \"OK\"; }"); | |
492 | |
493 // Inject the callback function into the HTML page generated by the browser. | |
494 ASSERT_TRUE(content::ExecuteScript( | |
495 browser()->tab_strip_model()->GetActiveWebContents(), script)); | |
496 | |
497 base::string16 expected_title(base::ASCIIToUTF16("OK")); | |
498 content::TitleWatcher title_watcher( | |
499 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
500 | |
501 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | |
502 browser()->tab_strip_model()->GetActiveWebContents(), true, | |
503 std::string()); | |
504 | |
505 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
506 } | |
507 #endif | |
508 | |
509 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) { | |
510 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | |
511 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | |
512 | |
513 GURL url = ui_test_utils::GetTestUrl( | |
514 base::FilePath(), | |
515 base::FilePath().AppendASCII("plugin_delete_self_at_load.html")); | |
516 ui_test_utils::NavigateToURL(browser(), url); | |
517 | |
518 base::string16 expected_title(base::ASCIIToUTF16("OK")); | |
519 content::TitleWatcher title_watcher( | |
520 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
521 | |
522 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | |
523 browser()->tab_strip_model()->GetActiveWebContents(), true, | |
524 std::string()); | |
525 | |
526 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | |
527 } | |
528 | |
529 #endif // !defined(USE_AURA) || defined(OS_WIN) | |
530 | |
531 #if defined(ENABLE_PLUGINS) | 294 #if defined(ENABLE_PLUGINS) |
532 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { | 295 class PepperContentSettingsSpecialCasesTest : public ContentSettingsTest { |
533 protected: | 296 protected: |
534 static const char* const kExternalClearKeyMimeType; | 297 static const char* const kExternalClearKeyMimeType; |
535 | 298 |
536 // Registers any CDM plugins not registered by default. | 299 // Registers any CDM plugins not registered by default. |
537 void SetUpCommandLine(base::CommandLine* command_line) override { | 300 void SetUpCommandLine(base::CommandLine* command_line) override { |
538 #if defined(ENABLE_PEPPER_CDMS) | 301 #if defined(ENABLE_PEPPER_CDMS) |
539 // Platform-specific filename relative to the chrome executable. | 302 // Platform-specific filename relative to the chrome executable. |
540 #if defined(OS_WIN) | 303 #if defined(OS_WIN) |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 559 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
797 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 560 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
798 switches::kAshBrowserTests)) | 561 switches::kAshBrowserTests)) |
799 return; | 562 return; |
800 #endif | 563 #endif |
801 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 564 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
802 } | 565 } |
803 #endif // !defined(DISABLE_NACL) | 566 #endif // !defined(DISABLE_NACL) |
804 | 567 |
805 #endif // defined(ENABLE_PLUGINS) | 568 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |