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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 }; | 308 }; |
309 | 309 |
310 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { | 310 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, Basic) { |
311 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 311 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
312 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 312 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
313 | 313 |
314 GURL url = ui_test_utils::GetTestUrl( | 314 GURL url = ui_test_utils::GetTestUrl( |
315 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | 315 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); |
316 ui_test_utils::NavigateToURL(browser(), url); | 316 ui_test_utils::NavigateToURL(browser(), url); |
317 | 317 |
318 string16 expected_title(ASCIIToUTF16("OK")); | 318 base::string16 expected_title(ASCIIToUTF16("OK")); |
319 content::TitleWatcher title_watcher( | 319 content::TitleWatcher title_watcher( |
320 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 320 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
321 | 321 |
322 content::RenderViewHost* host = | 322 content::RenderViewHost* host = |
323 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 323 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
324 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); | 324 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); |
325 int process_id = host->GetProcess()->GetID(); | 325 int process_id = host->GetProcess()->GetID(); |
326 base::FilePath path(FILE_PATH_LITERAL("blah")); | 326 base::FilePath path(FILE_PATH_LITERAL("blah")); |
327 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path)); | 327 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path)); |
328 filter->AuthorizeAllPlugins(process_id); | 328 filter->AuthorizeAllPlugins(process_id); |
(...skipping 11 matching lines...) Expand all Loading... |
340 | 340 |
341 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 341 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
342 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 342 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
343 browser()->profile()->GetHostContentSettingsMap() | 343 browser()->profile()->GetHostContentSettingsMap() |
344 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | 344 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
345 ContentSettingsPattern::Wildcard(), | 345 ContentSettingsPattern::Wildcard(), |
346 CONTENT_SETTINGS_TYPE_PLUGINS, | 346 CONTENT_SETTINGS_TYPE_PLUGINS, |
347 std::string(), | 347 std::string(), |
348 CONTENT_SETTING_ALLOW); | 348 CONTENT_SETTING_ALLOW); |
349 | 349 |
350 string16 expected_title(ASCIIToUTF16("OK")); | 350 base::string16 expected_title(ASCIIToUTF16("OK")); |
351 content::TitleWatcher title_watcher( | 351 content::TitleWatcher title_watcher( |
352 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 352 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
353 ui_test_utils::NavigateToURL(browser(), url); | 353 ui_test_utils::NavigateToURL(browser(), url); |
354 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 354 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
355 } | 355 } |
356 | 356 |
357 // Verify that plugins can be blocked on a domain by adding an exception. | 357 // Verify that plugins can be blocked on a domain by adding an exception. |
358 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, BlockException) { | 358 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, BlockException) { |
359 GURL url = ui_test_utils::GetTestUrl( | 359 GURL url = ui_test_utils::GetTestUrl( |
360 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | 360 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); |
361 | 361 |
362 browser()->profile()->GetHostContentSettingsMap() | 362 browser()->profile()->GetHostContentSettingsMap() |
363 ->SetContentSetting(ContentSettingsPattern::FromURL(url), | 363 ->SetContentSetting(ContentSettingsPattern::FromURL(url), |
364 ContentSettingsPattern::Wildcard(), | 364 ContentSettingsPattern::Wildcard(), |
365 CONTENT_SETTINGS_TYPE_PLUGINS, | 365 CONTENT_SETTINGS_TYPE_PLUGINS, |
366 std::string(), | 366 std::string(), |
367 CONTENT_SETTING_BLOCK); | 367 CONTENT_SETTING_BLOCK); |
368 | 368 |
369 string16 expected_title(ASCIIToUTF16("Click To Play")); | 369 base::string16 expected_title(ASCIIToUTF16("Click To Play")); |
370 content::TitleWatcher title_watcher( | 370 content::TitleWatcher title_watcher( |
371 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 371 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
372 ui_test_utils::NavigateToURL(browser(), url); | 372 ui_test_utils::NavigateToURL(browser(), url); |
373 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 373 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
374 } | 374 } |
375 | 375 |
376 // Crashes on Mac Asan. http://crbug.com/239169 | 376 // Crashes on Mac Asan. http://crbug.com/239169 |
377 #if defined(OS_MACOSX) | 377 #if defined(OS_MACOSX) |
378 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins | 378 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins |
379 // TODO(jschuh): Flaky plugin tests. crbug.com/244653 | 379 // TODO(jschuh): Flaky plugin tests. crbug.com/244653 |
380 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64) | 380 #elif defined(OS_WIN) && defined(ARCH_CPU_X86_64) |
381 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins | 381 #define MAYBE_LoadAllBlockedPlugins DISABLED_LoadAllBlockedPlugins |
382 #else | 382 #else |
383 #define MAYBE_LoadAllBlockedPlugins LoadAllBlockedPlugins | 383 #define MAYBE_LoadAllBlockedPlugins LoadAllBlockedPlugins |
384 #endif | 384 #endif |
385 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, MAYBE_LoadAllBlockedPlugins) { | 385 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, MAYBE_LoadAllBlockedPlugins) { |
386 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 386 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
387 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 387 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
388 | 388 |
389 GURL url = ui_test_utils::GetTestUrl( | 389 GURL url = ui_test_utils::GetTestUrl( |
390 base::FilePath(), | 390 base::FilePath(), |
391 base::FilePath().AppendASCII("load_all_blocked_plugins.html")); | 391 base::FilePath().AppendASCII("load_all_blocked_plugins.html")); |
392 ui_test_utils::NavigateToURL(browser(), url); | 392 ui_test_utils::NavigateToURL(browser(), url); |
393 | 393 |
394 string16 expected_title1(ASCIIToUTF16("1")); | 394 base::string16 expected_title1(ASCIIToUTF16("1")); |
395 content::TitleWatcher title_watcher1( | 395 content::TitleWatcher title_watcher1( |
396 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); | 396 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); |
397 | 397 |
398 content::RenderViewHost* host = | 398 content::RenderViewHost* host = |
399 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 399 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
400 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 400 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
401 host->GetProcess()->GetID()); | 401 host->GetProcess()->GetID()); |
402 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 402 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
403 host->GetRoutingID(), std::string())); | 403 host->GetRoutingID(), std::string())); |
404 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); | 404 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); |
405 | 405 |
406 string16 expected_title2(ASCIIToUTF16("2")); | 406 base::string16 expected_title2(ASCIIToUTF16("2")); |
407 content::TitleWatcher title_watcher2( | 407 content::TitleWatcher title_watcher2( |
408 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2); | 408 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2); |
409 | 409 |
410 ASSERT_TRUE(content::ExecuteScript( | 410 ASSERT_TRUE(content::ExecuteScript( |
411 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()")); | 411 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()")); |
412 | 412 |
413 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); | 413 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); |
414 } | 414 } |
415 | 415 |
416 // If this flakes, use http://crbug.com/113057. | 416 // If this flakes, use http://crbug.com/113057. |
417 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 | 417 // TODO(jschuh): Hanging plugin tests. crbug.com/244653 |
418 #if !defined(OS_WIN) && !defined(ARCH_CPU_X86_64) | 418 #if !defined(OS_WIN) && !defined(ARCH_CPU_X86_64) |
419 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { | 419 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, NoCallbackAtLoad) { |
420 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 420 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
421 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 421 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
422 | 422 |
423 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); | 423 GURL url("data:application/vnd.npapi-test,CallOnStartup();"); |
424 ui_test_utils::NavigateToURL(browser(), url); | 424 ui_test_utils::NavigateToURL(browser(), url); |
425 | 425 |
426 // Inject the callback function into the HTML page generated by the browser. | 426 // Inject the callback function into the HTML page generated by the browser. |
427 ASSERT_TRUE(content::ExecuteScript( | 427 ASSERT_TRUE(content::ExecuteScript( |
428 browser()->tab_strip_model()->GetActiveWebContents(), | 428 browser()->tab_strip_model()->GetActiveWebContents(), |
429 "CallOnStartup = function() { document.title = \"OK\"; }")); | 429 "CallOnStartup = function() { document.title = \"OK\"; }")); |
430 | 430 |
431 string16 expected_title(ASCIIToUTF16("OK")); | 431 base::string16 expected_title(ASCIIToUTF16("OK")); |
432 content::TitleWatcher title_watcher( | 432 content::TitleWatcher title_watcher( |
433 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 433 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
434 | 434 |
435 content::RenderViewHost* host = | 435 content::RenderViewHost* host = |
436 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 436 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
437 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 437 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
438 host->GetProcess()->GetID()); | 438 host->GetProcess()->GetID()); |
439 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 439 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
440 host->GetRoutingID(), std::string())); | 440 host->GetRoutingID(), std::string())); |
441 | 441 |
442 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 442 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
443 } | 443 } |
444 #endif | 444 #endif |
445 | 445 |
446 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) { | 446 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) { |
447 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 447 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
448 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 448 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
449 | 449 |
450 GURL url = ui_test_utils::GetTestUrl( | 450 GURL url = ui_test_utils::GetTestUrl( |
451 base::FilePath(), | 451 base::FilePath(), |
452 base::FilePath().AppendASCII("plugin_delete_self_at_load.html")); | 452 base::FilePath().AppendASCII("plugin_delete_self_at_load.html")); |
453 ui_test_utils::NavigateToURL(browser(), url); | 453 ui_test_utils::NavigateToURL(browser(), url); |
454 | 454 |
455 string16 expected_title(ASCIIToUTF16("OK")); | 455 base::string16 expected_title(ASCIIToUTF16("OK")); |
456 content::TitleWatcher title_watcher( | 456 content::TitleWatcher title_watcher( |
457 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 457 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
458 | 458 |
459 content::RenderViewHost* host = | 459 content::RenderViewHost* host = |
460 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 460 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); |
461 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 461 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
462 host->GetProcess()->GetID()); | 462 host->GetProcess()->GetID()); |
463 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 463 host->Send(new ChromeViewMsg_LoadBlockedPlugins( |
464 host->GetRoutingID(), std::string())); | 464 host->GetRoutingID(), std::string())); |
465 | 465 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 // Ensure NaCl can run. | 511 // Ensure NaCl can run. |
512 command_line->AppendSwitch(switches::kEnableNaCl); | 512 command_line->AppendSwitch(switches::kEnableNaCl); |
513 #endif | 513 #endif |
514 } | 514 } |
515 | 515 |
516 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { | 516 void RunLoadPepperPluginTest(const char* mime_type, bool expect_loaded) { |
517 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; | 517 const char* expected_result = expect_loaded ? "Loaded" : "Not Loaded"; |
518 content::WebContents* web_contents = | 518 content::WebContents* web_contents = |
519 browser()->tab_strip_model()->GetActiveWebContents(); | 519 browser()->tab_strip_model()->GetActiveWebContents(); |
520 | 520 |
521 string16 expected_title(ASCIIToUTF16(expected_result)); | 521 base::string16 expected_title(ASCIIToUTF16(expected_result)); |
522 content::TitleWatcher title_watcher(web_contents, expected_title); | 522 content::TitleWatcher title_watcher(web_contents, expected_title); |
523 | 523 |
524 // GetTestUrl assumes paths, so we must append query parameters to result. | 524 // GetTestUrl assumes paths, so we must append query parameters to result. |
525 GURL file_url = ui_test_utils::GetTestUrl( | 525 GURL file_url = ui_test_utils::GetTestUrl( |
526 base::FilePath(), | 526 base::FilePath(), |
527 base::FilePath().AppendASCII("load_pepper_plugin.html")); | 527 base::FilePath().AppendASCII("load_pepper_plugin.html")); |
528 GURL url(file_url.spec() + | 528 GURL url(file_url.spec() + |
529 base::StringPrintf("?mimetype=%s", mime_type)); | 529 base::StringPrintf("?mimetype=%s", mime_type)); |
530 ui_test_utils::NavigateToURL(browser(), url); | 530 ui_test_utils::NavigateToURL(browser(), url); |
531 | 531 |
532 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 532 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
533 EXPECT_EQ(!expect_loaded, | 533 EXPECT_EQ(!expect_loaded, |
534 TabSpecificContentSettings::FromWebContents(web_contents)-> | 534 TabSpecificContentSettings::FromWebContents(web_contents)-> |
535 IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); | 535 IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
536 } | 536 } |
537 | 537 |
538 void RunJavaScriptBlockedTest(const char* html_file, | 538 void RunJavaScriptBlockedTest(const char* html_file, |
539 bool expect_is_javascript_content_blocked) { | 539 bool expect_is_javascript_content_blocked) { |
540 // Because JavaScript is disabled, <title> will be the only title set. | 540 // Because JavaScript is disabled, <title> will be the only title set. |
541 // Checking for it ensures that the page loaded. | 541 // Checking for it ensures that the page loaded. |
542 const char* const kExpectedTitle = "Initial Title"; | 542 const char* const kExpectedTitle = "Initial Title"; |
543 content::WebContents* web_contents = | 543 content::WebContents* web_contents = |
544 browser()->tab_strip_model()->GetActiveWebContents(); | 544 browser()->tab_strip_model()->GetActiveWebContents(); |
545 TabSpecificContentSettings* tab_settings = | 545 TabSpecificContentSettings* tab_settings = |
546 TabSpecificContentSettings::FromWebContents(web_contents); | 546 TabSpecificContentSettings::FromWebContents(web_contents); |
547 string16 expected_title(ASCIIToUTF16(kExpectedTitle)); | 547 base::string16 expected_title(ASCIIToUTF16(kExpectedTitle)); |
548 content::TitleWatcher title_watcher(web_contents, expected_title); | 548 content::TitleWatcher title_watcher(web_contents, expected_title); |
549 | 549 |
550 GURL url = ui_test_utils::GetTestUrl( | 550 GURL url = ui_test_utils::GetTestUrl( |
551 base::FilePath(), base::FilePath().AppendASCII(html_file)); | 551 base::FilePath(), base::FilePath().AppendASCII(html_file)); |
552 ui_test_utils::NavigateToURL(browser(), url); | 552 ui_test_utils::NavigateToURL(browser(), url); |
553 | 553 |
554 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 554 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
555 | 555 |
556 EXPECT_EQ(expect_is_javascript_content_blocked, | 556 EXPECT_EQ(expect_is_javascript_content_blocked, |
557 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 557 tab_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); | 612 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); |
613 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 613 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
614 #endif // defined(ENABLE_PEPPER_CDMS) | 614 #endif // defined(ENABLE_PEPPER_CDMS) |
615 | 615 |
616 #if !defined(DISABLE_NACL) | 616 #if !defined(DISABLE_NACL) |
617 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 617 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
618 #endif // !defined(DISABLE_NACL) | 618 #endif // !defined(DISABLE_NACL) |
619 } | 619 } |
620 | 620 |
621 #endif // defined(ENABLE_PLUGINS) | 621 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |