Chromium Code Reviews| Index: chrome/browser/extensions/active_script_controller_browsertest.cc |
| diff --git a/chrome/browser/extensions/active_script_controller_browsertest.cc b/chrome/browser/extensions/active_script_controller_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ea29c2844cac1c200702ce182045aaf7baf6ac6d |
| --- /dev/null |
| +++ b/chrome/browser/extensions/active_script_controller_browsertest.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/active_script_controller.h" |
| +#include "chrome/browser/extensions/extension_action.h" |
| +#include "chrome/browser/extensions/extension_browsertest.h" |
| +#include "chrome/browser/extensions/extension_test_message_listener.h" |
| +#include "chrome/browser/extensions/location_bar_controller.h" |
| +#include "chrome/browser/extensions/tab_helper.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "extensions/common/feature_switch.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace extensions { |
| + |
| +class ActiveScriptControllerBrowserTest : public ExtensionBrowserTest { |
| + public: |
| + ActiveScriptControllerBrowserTest() |
| + : feature_override_(FeatureSwitch::scripts_require_action(), |
| + FeatureSwitch::OVERRIDE_ENABLED) {} |
| + private: |
| + FeatureSwitch::ScopedOverride feature_override_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest, |
| + ActiveScriptsAreDisplayed) { |
| + base::FilePath active_script_path = |
| + test_data_dir_.AppendASCII("active_script"); |
| + |
| + // First, we load up three extensions: |
| + // - An extension with a content script that runs on all hosts, |
| + // - An extension that injects scripts into all hosts, |
| + // - An extension with a content script that runs on explicit hosts. |
| + const Extension* content_scripts_all_hosts = LoadExtension( |
| + active_script_path.AppendASCII("content_scripts_all_hosts")); |
| + ASSERT_TRUE(content_scripts_all_hosts); |
| + const Extension* inject_scripts_all_hosts = LoadExtension( |
| + active_script_path.AppendASCII("inject_scripts_all_hosts")); |
| + ASSERT_TRUE(inject_scripts_all_hosts); |
| + const Extension* content_scripts_explicit_hosts = LoadExtension( |
| + active_script_path.AppendASCII("content_scripts_explicit_hosts")); |
| + ASSERT_TRUE(content_scripts_explicit_hosts); |
| + |
| + // All of these extensions should inject a script (either through content |
| + // scripts or through chrome.tabs.executeScript()) that sends a message with |
| + // their names (for verification). |
| + // Be prepared to wait for each extension to inject the script. |
| + ExtensionTestMessageListener content_scripts_all_hosts_listener( |
| + "content_scripts_all_hosts", false /* won't reply */); |
| + ExtensionTestMessageListener inject_scripts_all_hosts_listener( |
| + "inject_scripts_all_hosts", false /* won't reply */); |
| + ExtensionTestMessageListener content_scripts_explicit_hosts_listener( |
| + "content_scripts_explicit_hosts", false /* won't reply */); |
| + |
| + // Navigate to an URL (which matches the explicit host specified in the |
| + // extension content_scripts_explicit_hosts). All three extensions should |
| + // inject the script. |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| + ui_test_utils::NavigateToURL( |
| + browser(), |
| + embedded_test_server()->GetURL("/extensions/test_file.html")); |
| + |
| + // Wait for them all to complete. |
| + content_scripts_all_hosts_listener.WaitUntilSatisfied(); |
| + content_scripts_explicit_hosts_listener.WaitUntilSatisfied(); |
| + inject_scripts_all_hosts_listener.WaitUntilSatisfied(); |
| + |
| + // Retrieve the ActiveScriptController for that tab. |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_TRUE(web_contents); |
| + TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); |
| + ASSERT_TRUE(tab_helper); |
| + ActiveScriptController* controller = |
| + tab_helper->location_bar_controller()->active_script_controller(); |
| + ASSERT_TRUE(controller); |
| + |
| + // Verify the shown ExtensionActions. Each of the extensions with "all hosts" |
| + // should be displayed, but the extension that specified explicit hosts |
| + // should not. |
| + EXPECT_TRUE(controller->GetActionForExtension(content_scripts_all_hosts)); |
| + EXPECT_TRUE(controller->GetActionForExtension(inject_scripts_all_hosts)); |
| + EXPECT_FALSE( |
| + controller->GetActionForExtension(content_scripts_explicit_hosts)); |
|
not at google - send to devlin
2014/05/08 20:47:09
A lot of repeated code here. how about defining a
Devlin
2014/05/08 23:01:00
Definitely not as pretty as it was when you wrote
|
| +} |
| + |
| +} // namespace extensions |