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" |
11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 12 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
13 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 14 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/test_switches.h" | 22 #include "chrome/test/base/test_switches.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/plugin_service.h" | 25 #include "content/public/browser/plugin_service.h" |
| 26 #include "content/public/browser/render_frame_host.h" |
26 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
30 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
31 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
32 #include "content/test/net/url_request_mock_http_job.h" | 33 #include "content/test/net/url_request_mock_http_job.h" |
33 #include "net/test/spawned_test_server/spawned_test_server.h" | 34 #include "net/test/spawned_test_server/spawned_test_server.h" |
34 | 35 |
35 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 36 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 313 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
313 | 314 |
314 GURL url = ui_test_utils::GetTestUrl( | 315 GURL url = ui_test_utils::GetTestUrl( |
315 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | 316 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); |
316 ui_test_utils::NavigateToURL(browser(), url); | 317 ui_test_utils::NavigateToURL(browser(), url); |
317 | 318 |
318 base::string16 expected_title(ASCIIToUTF16("OK")); | 319 base::string16 expected_title(ASCIIToUTF16("OK")); |
319 content::TitleWatcher title_watcher( | 320 content::TitleWatcher title_watcher( |
320 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 321 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
321 | 322 |
322 content::RenderViewHost* host = | 323 content::WebContents* web_contents = |
323 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | 324 browser()->tab_strip_model()->GetActiveWebContents(); |
324 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); | 325 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance(); |
325 int process_id = host->GetProcess()->GetID(); | 326 int process_id = web_contents->GetMainFrame()->GetProcess()->GetID(); |
326 base::FilePath path(FILE_PATH_LITERAL("blah")); | 327 base::FilePath path(FILE_PATH_LITERAL("blah")); |
327 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path)); | 328 EXPECT_FALSE(filter->CanLoadPlugin(process_id, path)); |
328 filter->AuthorizeAllPlugins(process_id); | 329 filter->AuthorizeAllPlugins(web_contents, true, std::string()); |
329 EXPECT_TRUE(filter->CanLoadPlugin(process_id, path)); | 330 EXPECT_TRUE(filter->CanLoadPlugin(process_id, path)); |
330 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | |
331 host->GetRoutingID(), std::string())); | |
332 | 331 |
333 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 332 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
334 } | 333 } |
335 | 334 |
336 // Verify that plugins can be allowed on a domain by adding an exception | 335 // Verify that plugins can be allowed on a domain by adding an exception |
337 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, AllowException) { | 336 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, AllowException) { |
338 GURL url = ui_test_utils::GetTestUrl( | 337 GURL url = ui_test_utils::GetTestUrl( |
339 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); | 338 base::FilePath(), base::FilePath().AppendASCII("clicktoplay.html")); |
340 | 339 |
341 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 340 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 387 |
389 GURL url = ui_test_utils::GetTestUrl( | 388 GURL url = ui_test_utils::GetTestUrl( |
390 base::FilePath(), | 389 base::FilePath(), |
391 base::FilePath().AppendASCII("load_all_blocked_plugins.html")); | 390 base::FilePath().AppendASCII("load_all_blocked_plugins.html")); |
392 ui_test_utils::NavigateToURL(browser(), url); | 391 ui_test_utils::NavigateToURL(browser(), url); |
393 | 392 |
394 base::string16 expected_title1(ASCIIToUTF16("1")); | 393 base::string16 expected_title1(ASCIIToUTF16("1")); |
395 content::TitleWatcher title_watcher1( | 394 content::TitleWatcher title_watcher1( |
396 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); | 395 browser()->tab_strip_model()->GetActiveWebContents(), expected_title1); |
397 | 396 |
398 content::RenderViewHost* host = | |
399 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | |
400 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 397 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
401 host->GetProcess()->GetID()); | 398 browser()->tab_strip_model()->GetActiveWebContents(), true, |
402 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 399 std::string()); |
403 host->GetRoutingID(), std::string())); | |
404 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); | 400 EXPECT_EQ(expected_title1, title_watcher1.WaitAndGetTitle()); |
405 | 401 |
406 base::string16 expected_title2(ASCIIToUTF16("2")); | 402 base::string16 expected_title2(ASCIIToUTF16("2")); |
407 content::TitleWatcher title_watcher2( | 403 content::TitleWatcher title_watcher2( |
408 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2); | 404 browser()->tab_strip_model()->GetActiveWebContents(), expected_title2); |
409 | 405 |
410 ASSERT_TRUE(content::ExecuteScript( | 406 ASSERT_TRUE(content::ExecuteScript( |
411 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()")); | 407 browser()->tab_strip_model()->GetActiveWebContents(), "window.inject()")); |
412 | 408 |
413 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); | 409 EXPECT_EQ(expected_title2, title_watcher2.WaitAndGetTitle()); |
(...skipping 11 matching lines...) Expand all Loading... |
425 | 421 |
426 // Inject the callback function into the HTML page generated by the browser. | 422 // Inject the callback function into the HTML page generated by the browser. |
427 ASSERT_TRUE(content::ExecuteScript( | 423 ASSERT_TRUE(content::ExecuteScript( |
428 browser()->tab_strip_model()->GetActiveWebContents(), | 424 browser()->tab_strip_model()->GetActiveWebContents(), |
429 "CallOnStartup = function() { document.title = \"OK\"; }")); | 425 "CallOnStartup = function() { document.title = \"OK\"; }")); |
430 | 426 |
431 base::string16 expected_title(ASCIIToUTF16("OK")); | 427 base::string16 expected_title(ASCIIToUTF16("OK")); |
432 content::TitleWatcher title_watcher( | 428 content::TitleWatcher title_watcher( |
433 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 429 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
434 | 430 |
435 content::RenderViewHost* host = | |
436 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | |
437 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 431 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
438 host->GetProcess()->GetID()); | 432 browser()->tab_strip_model()->GetActiveWebContents(), true, |
439 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 433 std::string()); |
440 host->GetRoutingID(), std::string())); | |
441 | 434 |
442 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 435 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
443 } | 436 } |
444 #endif | 437 #endif |
445 | 438 |
446 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) { | 439 IN_PROC_BROWSER_TEST_F(ClickToPlayPluginTest, DeleteSelfAtLoad) { |
447 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 440 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
448 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 441 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
449 | 442 |
450 GURL url = ui_test_utils::GetTestUrl( | 443 GURL url = ui_test_utils::GetTestUrl( |
451 base::FilePath(), | 444 base::FilePath(), |
452 base::FilePath().AppendASCII("plugin_delete_self_at_load.html")); | 445 base::FilePath().AppendASCII("plugin_delete_self_at_load.html")); |
453 ui_test_utils::NavigateToURL(browser(), url); | 446 ui_test_utils::NavigateToURL(browser(), url); |
454 | 447 |
455 base::string16 expected_title(ASCIIToUTF16("OK")); | 448 base::string16 expected_title(ASCIIToUTF16("OK")); |
456 content::TitleWatcher title_watcher( | 449 content::TitleWatcher title_watcher( |
457 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 450 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
458 | 451 |
459 content::RenderViewHost* host = | |
460 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); | |
461 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 452 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
462 host->GetProcess()->GetID()); | 453 browser()->tab_strip_model()->GetActiveWebContents(), true, |
463 host->Send(new ChromeViewMsg_LoadBlockedPlugins( | 454 std::string()); |
464 host->GetRoutingID(), std::string())); | |
465 | 455 |
466 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 456 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
467 } | 457 } |
468 | 458 |
469 #endif // !defined(USE_AURA) || defined(OS_WIN) | 459 #endif // !defined(USE_AURA) || defined(OS_WIN) |
470 | 460 |
471 #if defined(ENABLE_PLUGINS) | 461 #if defined(ENABLE_PLUGINS) |
472 | 462 |
473 class PepperContentSettingsTest : public ContentSettingsTest { | 463 class PepperContentSettingsTest : public ContentSettingsTest { |
474 public: | 464 public: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); | 602 RunJavaScriptBlockedTest("load_widevine_no_js.html", true); |
613 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 603 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
614 #endif // defined(ENABLE_PEPPER_CDMS) | 604 #endif // defined(ENABLE_PEPPER_CDMS) |
615 | 605 |
616 #if !defined(DISABLE_NACL) | 606 #if !defined(DISABLE_NACL) |
617 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); | 607 RunJavaScriptBlockedTest("load_nacl_no_js.html", true); |
618 #endif // !defined(DISABLE_NACL) | 608 #endif // !defined(DISABLE_NACL) |
619 } | 609 } |
620 | 610 |
621 #endif // defined(ENABLE_PLUGINS) | 611 #endif // defined(ENABLE_PLUGINS) |
OLD | NEW |