Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 15 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 16 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
| 17 #include "chrome/browser/extensions/extension_management_test_util.h" | 17 #include "chrome/browser/extensions/extension_management_test_util.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_with_management_policy_apitest.h" | 19 #include "chrome/browser/extensions/extension_with_management_policy_apitest.h" |
| 20 #include "chrome/browser/extensions/test_extension_dir.h" | 20 #include "chrome/browser/extensions/test_extension_dir.h" |
| 21 #include "chrome/browser/search/search.h" | |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" | 23 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "content/public/browser/javascript_dialog_manager.h" | 27 #include "content/public/browser/javascript_dialog_manager.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_delegate.h" | 30 #include "content/public/browser/web_contents_delegate.h" |
| 30 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 base::FilePath data_dir = test_data_dir_.AppendASCII("content_scripts"); | 616 base::FilePath data_dir = test_data_dir_.AppendASCII("content_scripts"); |
| 616 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); | 617 ExtensionTestMessageListener iframe_loaded_listener("iframe loaded", false); |
| 617 ExtensionTestMessageListener content_script_listener("script injected", | 618 ExtensionTestMessageListener content_script_listener("script injected", |
| 618 false); | 619 false); |
| 619 LoadExtension(data_dir.AppendASCII("script_a_com")); | 620 LoadExtension(data_dir.AppendASCII("script_a_com")); |
| 620 LoadExtension(data_dir.AppendASCII("background_page_iframe")); | 621 LoadExtension(data_dir.AppendASCII("background_page_iframe")); |
| 621 iframe_loaded_listener.WaitUntilSatisfied(); | 622 iframe_loaded_listener.WaitUntilSatisfied(); |
| 622 EXPECT_FALSE(content_script_listener.was_satisfied()); | 623 EXPECT_FALSE(content_script_listener.was_satisfied()); |
| 623 } | 624 } |
| 624 | 625 |
| 626 IN_PROC_BROWSER_TEST_P(ContentScriptApiTest, CannotScriptTheNewTabPage) { | |
| 627 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 628 | |
| 629 ExtensionTestMessageListener test_listener("ready", true); | |
| 630 LoadExtension(test_data_dir_.AppendASCII("content_scripts/ntp")); | |
| 631 ASSERT_TRUE(test_listener.WaitUntilSatisfied()); | |
| 632 | |
| 633 auto did_script_inject = [](content::WebContents* web_contents) { | |
| 634 bool did_inject = false; | |
| 635 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 636 web_contents, | |
| 637 "domAutomationController.send(window.didInject != undefined);", | |
| 638 &did_inject)); | |
| 639 return did_inject; | |
| 640 }; | |
| 641 | |
| 642 // First, test the executeScript() method. | |
| 643 ResultCatcher catcher; | |
| 644 test_listener.Reply(std::string()); | |
| 645 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
| 646 EXPECT_FALSE( | |
|
karandeepb
2017/07/18 19:26:59
nit: Also verify that the active web contents url
Devlin
2017/07/18 20:53:46
Done.
| |
| 647 did_script_inject(browser()->tab_strip_model()->GetActiveWebContents())); | |
| 648 | |
| 649 // Next, check content script injection. | |
|
karandeepb
2017/07/18 19:27:00
Also check injection on a normal page first, to ve
Devlin
2017/07/18 20:53:46
Done. Good suggestion; this helped flush out a bu
| |
| 650 ui_test_utils::NavigateToURL(browser(), search::GetNewTabPageURL(profile())); | |
| 651 EXPECT_FALSE( | |
| 652 did_script_inject(browser()->tab_strip_model()->GetActiveWebContents())); | |
| 653 } | |
| 654 | |
| 625 INSTANTIATE_TEST_CASE_P( | 655 INSTANTIATE_TEST_CASE_P( |
| 626 ContentScriptApiTests, | 656 ContentScriptApiTests, |
| 627 ContentScriptApiTest, | 657 ContentScriptApiTest, |
| 628 testing::Values(TestConfig::kDefault, | 658 testing::Values(TestConfig::kDefault, |
| 629 TestConfig::kYieldBetweenContentScriptRunsEnabled)); | 659 TestConfig::kYieldBetweenContentScriptRunsEnabled)); |
| 630 | 660 |
| 631 } // namespace extensions | 661 } // namespace extensions |
| OLD | NEW |