OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
9 #include "chrome/browser/extensions/extension_action.h" | 9 #include "chrome/browser/extensions/extension_action.h" |
10 #include "chrome/browser/extensions/extension_action_manager.h" | 10 #include "chrome/browser/extensions/extension_action_manager.h" |
11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
13 #include "chrome/browser/extensions/test_extension_dir.h" | 14 #include "chrome/browser/extensions/test_extension_dir.h" |
14 #include "chrome/browser/sessions/session_tab_helper.h" | 15 #include "chrome/browser/sessions/session_tab_helper.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/location_bar/location_bar.h" | 18 #include "chrome/browser/ui/location_bar/location_bar.h" |
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
21 #include "extensions/common/extension_builder.h" | |
20 #include "extensions/common/feature_switch.h" | 22 #include "extensions/common/feature_switch.h" |
23 #include "extensions/common/value_builder.h" | |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 const char kBackgroundScriptSource[] = | 27 const char kBackgroundScriptSource[] = |
25 "chrome.pageAction.onClicked.addListener(function() {\n" | 28 "chrome.pageAction.onClicked.addListener(function() {\n" |
26 " chrome.test.sendMessage('clicked');\n" | 29 " chrome.test.sendMessage('clicked');\n" |
27 "});\n" | 30 "});\n" |
28 "chrome.test.sendMessage('registered');\n"; | 31 "chrome.test.sendMessage('registered');\n"; |
29 const char kManifestSource[] = | 32 const char kManifestSource[] = |
30 "{" | 33 "{" |
31 " \"name\": \"%s\"," | 34 " \"name\": \"%s\"," |
32 " \"version\": \"1.0\"," | 35 " \"version\": \"1.0\"," |
33 " \"manifest_version\": 2," | 36 " \"manifest_version\": 2," |
34 " \"background\": { \"scripts\": [\"background.js\"] }," | 37 " \"background\": { \"scripts\": [\"background.js\"] }," |
35 " \"page_action\": { }" | 38 " \"page_action\": { }" |
36 "}"; | 39 "}"; |
37 | 40 |
38 } // namespace | 41 } // namespace |
39 | 42 |
40 class LocationBarBrowserTest : public ExtensionBrowserTest { | 43 class LocationBarBrowserTest : public ExtensionBrowserTest { |
41 public: | 44 public: |
42 virtual ~LocationBarBrowserTest() {} | 45 virtual ~LocationBarBrowserTest() {} |
43 | 46 |
44 protected: | 47 protected: |
48 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; | |
49 | |
45 // Load an extension with a PageAction that sends a message when clicked. | 50 // Load an extension with a PageAction that sends a message when clicked. |
46 const extensions::Extension* LoadPageActionExtension( | 51 const extensions::Extension* LoadPageActionExtension( |
47 extensions::TestExtensionDir* dir); | 52 extensions::TestExtensionDir* dir); |
53 | |
54 private: | |
55 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_override_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(LocationBarBrowserTest); | |
48 }; | 58 }; |
49 | 59 |
60 void LocationBarBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | |
61 // In order to let a vanilla extension override the bookmark star, we have to | |
62 // enable the switch. | |
63 enable_override_.reset(new extensions::FeatureSwitch::ScopedOverride( | |
64 extensions::FeatureSwitch::enable_override_bookmarks_ui(), true)); | |
65 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
66 } | |
67 | |
50 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension( | 68 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension( |
51 extensions::TestExtensionDir* dir) { | 69 extensions::TestExtensionDir* dir) { |
52 DCHECK(dir); | 70 DCHECK(dir); |
53 | 71 |
54 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1")); | 72 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1")); |
55 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource); | 73 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource); |
56 | 74 |
57 ExtensionTestMessageListener registered_listener("registered", false); | 75 ExtensionTestMessageListener registered_listener("registered", false); |
58 const extensions::Extension* extension = LoadExtension(dir->unpacked_path()); | 76 const extensions::Extension* extension = LoadExtension(dir->unpacked_path()); |
59 registered_listener.WaitUntilSatisfied(); | 77 registered_listener.WaitUntilSatisfied(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); | 121 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); |
104 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u)); | 122 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u)); |
105 | 123 |
106 // Trigger the visible page action, and ensure it executes. | 124 // Trigger the visible page action, and ensure it executes. |
107 ExtensionTestMessageListener clicked_listener("clicked", false); | 125 ExtensionTestMessageListener clicked_listener("clicked", false); |
108 clicked_listener.set_extension_id(page_action1->id()); | 126 clicked_listener.set_extension_id(page_action1->id()); |
109 location_bar->TestPageActionPressed(0u); | 127 location_bar->TestPageActionPressed(0u); |
110 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied()); | 128 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied()); |
111 } | 129 } |
112 | 130 |
131 // Test that installing an extension that overrides the bookmark star | |
132 // successfully hides the star. | |
133 IN_PROC_BROWSER_TEST_F(LocationBarBrowserTest, | |
134 ExtensionCanOverrideBookmarkStar) { | |
135 LocationBarTesting* location_bar = | |
136 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | |
137 // By default, we should show the star. | |
138 EXPECT_TRUE(location_bar->GetBookmarkStarVisibility()); | |
139 | |
140 // Create and install an extension that overrides the bookmark star. | |
141 extensions::DictionaryBuilder chrome_ui_overrides; | |
142 chrome_ui_overrides.Set( | |
143 "bookmarks_ui", | |
144 extensions::DictionaryBuilder(). | |
145 SetBoolean("remove_button", true). | |
146 SetBoolean("remove_bookmark_shortcut", true)); | |
Mike Wittman
2014/09/03 23:57:44
nit: this property shouldn't be necessary
Devlin
2014/09/05 20:15:16
True enough. Removed.
| |
147 scoped_refptr<const extensions::Extension> extension = | |
148 extensions::ExtensionBuilder(). | |
149 SetManifest(extensions::DictionaryBuilder(). | |
150 Set("name", "overrides star"). | |
151 Set("manifest_version", 2). | |
152 Set("version", "0.1"). | |
153 Set("description", "override the star"). | |
154 Set("chrome_ui_overrides", | |
155 chrome_ui_overrides.Pass())).Build(); | |
156 extension_service()->AddExtension(extension); | |
157 | |
158 // The star should now be hidden. | |
159 EXPECT_FALSE(location_bar->GetBookmarkStarVisibility()); | |
160 } | |
161 | |
113 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest { | 162 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest { |
114 private: | 163 private: |
115 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; | 164 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; |
116 | 165 |
117 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; | 166 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; |
167 | |
168 DISALLOW_COPY_AND_ASSIGN(LocationBarBrowserTestWithRedesign); | |
118 }; | 169 }; |
119 | 170 |
120 void LocationBarBrowserTestWithRedesign::SetUpCommandLine( | 171 void LocationBarBrowserTestWithRedesign::SetUpCommandLine( |
121 base::CommandLine* command_line) { | 172 base::CommandLine* command_line) { |
122 LocationBarBrowserTest::SetUpCommandLine(command_line); | 173 LocationBarBrowserTest::SetUpCommandLine(command_line); |
123 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 174 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( |
124 extensions::FeatureSwitch::extension_action_redesign(), true)); | 175 extensions::FeatureSwitch::extension_action_redesign(), true)); |
125 } | 176 } |
126 | 177 |
127 // Test that page actions are not displayed in the location bar if the | 178 // Test that page actions are not displayed in the location bar if the |
(...skipping 22 matching lines...) Expand all Loading... | |
150 browser()->tab_strip_model()->GetActiveWebContents(); | 201 browser()->tab_strip_model()->GetActiveWebContents(); |
151 int tab_id = SessionTabHelper::IdForTab(tab); | 202 int tab_id = SessionTabHelper::IdForTab(tab); |
152 action->SetIsVisible(tab_id, true); | 203 action->SetIsVisible(tab_id, true); |
153 extensions::ExtensionActionAPI::Get(profile())->NotifyChange( | 204 extensions::ExtensionActionAPI::Get(profile())->NotifyChange( |
154 action, tab, profile()); | 205 action, tab, profile()); |
155 | 206 |
156 // We should still have no page actions. | 207 // We should still have no page actions. |
157 EXPECT_EQ(0, location_bar->PageActionCount()); | 208 EXPECT_EQ(0, location_bar->PageActionCount()); |
158 EXPECT_EQ(0, location_bar->PageActionVisibleCount()); | 209 EXPECT_EQ(0, location_bar->PageActionVisibleCount()); |
159 } | 210 } |
OLD | NEW |