Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/extensions/active_script_controller_browsertest.cc

Issue 270153004: Introduce ActiveScriptController; track active extension scripts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kalman's Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/active_script_controller.h"
6 #include "chrome/browser/extensions/extension_action.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/extensions/location_bar_controller.h"
10 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "extensions/common/feature_switch.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace extensions {
19
20 class ActiveScriptControllerBrowserTest : public ExtensionBrowserTest {
21 public:
22 ActiveScriptControllerBrowserTest()
23 : feature_override_(FeatureSwitch::scripts_require_action(),
24 FeatureSwitch::OVERRIDE_ENABLED) {}
25 private:
26 FeatureSwitch::ScopedOverride feature_override_;
27 };
28
29 IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest,
30 ActiveScriptsAreDisplayed) {
31 base::FilePath active_script_path =
32 test_data_dir_.AppendASCII("active_script");
33
34 // First, we load up three extensions:
35 // - An extension with a content script that runs on all hosts,
36 // - An extension that injects scripts into all hosts,
37 // - An extension with a content script that runs on explicit hosts.
38 const Extension* content_scripts_all_hosts = LoadExtension(
39 active_script_path.AppendASCII("content_scripts_all_hosts"));
40 ASSERT_TRUE(content_scripts_all_hosts);
41 const Extension* inject_scripts_all_hosts = LoadExtension(
42 active_script_path.AppendASCII("inject_scripts_all_hosts"));
43 ASSERT_TRUE(inject_scripts_all_hosts);
44 const Extension* content_scripts_explicit_hosts = LoadExtension(
45 active_script_path.AppendASCII("content_scripts_explicit_hosts"));
46 ASSERT_TRUE(content_scripts_explicit_hosts);
47
48 // All of these extensions should inject a script (either through content
49 // scripts or through chrome.tabs.executeScript()) that sends a message with
50 // their names (for verification).
51 // Be prepared to wait for each extension to inject the script.
52 ExtensionTestMessageListener content_scripts_all_hosts_listener(
53 "content_scripts_all_hosts", false /* won't reply */);
54 ExtensionTestMessageListener inject_scripts_all_hosts_listener(
55 "inject_scripts_all_hosts", false /* won't reply */);
56 ExtensionTestMessageListener content_scripts_explicit_hosts_listener(
57 "content_scripts_explicit_hosts", false /* won't reply */);
58
59 // Navigate to an URL (which matches the explicit host specified in the
60 // extension content_scripts_explicit_hosts). All three extensions should
61 // inject the script.
62 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
63 ui_test_utils::NavigateToURL(
64 browser(),
65 embedded_test_server()->GetURL("/extensions/test_file.html"));
66
67 // Wait for them all to complete.
68 content_scripts_all_hosts_listener.WaitUntilSatisfied();
69 content_scripts_explicit_hosts_listener.WaitUntilSatisfied();
70 inject_scripts_all_hosts_listener.WaitUntilSatisfied();
71
72 // Retrieve the ActiveScriptController for that tab.
73 content::WebContents* web_contents =
74 browser()->tab_strip_model()->GetActiveWebContents();
75 ASSERT_TRUE(web_contents);
76 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents);
77 ASSERT_TRUE(tab_helper);
78 ActiveScriptController* controller =
79 tab_helper->location_bar_controller()->active_script_controller();
80 ASSERT_TRUE(controller);
81
82 // Verify the shown ExtensionActions. Each of the extensions with "all hosts"
83 // should be displayed, but the extension that specified explicit hosts
84 // should not.
85 EXPECT_TRUE(controller->GetActionForExtension(content_scripts_all_hosts));
86 EXPECT_TRUE(controller->GetActionForExtension(inject_scripts_all_hosts));
87 EXPECT_FALSE(
88 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
89 }
90
91 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698