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

Side by Side Diff: chrome/browser/ui/location_bar/location_bar_browsertest.cc

Issue 540483002: Fix regression in showing bookmark star when an extension should override it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
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:
45 LocationBarBrowserTest() {}
42 virtual ~LocationBarBrowserTest() {} 46 virtual ~LocationBarBrowserTest() {}
43 47
44 protected: 48 protected:
49 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
50
45 // Load an extension with a PageAction that sends a message when clicked. 51 // Load an extension with a PageAction that sends a message when clicked.
46 const extensions::Extension* LoadPageActionExtension( 52 const extensions::Extension* LoadPageActionExtension(
47 extensions::TestExtensionDir* dir); 53 extensions::TestExtensionDir* dir);
54
55 private:
56 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_override_;
57
58 DISALLOW_COPY_AND_ASSIGN(LocationBarBrowserTest);
48 }; 59 };
49 60
61 void LocationBarBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
62 // In order to let a vanilla extension override the bookmark star, we have to
63 // enable the switch.
64 enable_override_.reset(new extensions::FeatureSwitch::ScopedOverride(
65 extensions::FeatureSwitch::enable_override_bookmarks_ui(), true));
66 ExtensionBrowserTest::SetUpCommandLine(command_line);
67 }
68
50 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension( 69 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension(
51 extensions::TestExtensionDir* dir) { 70 extensions::TestExtensionDir* dir) {
52 DCHECK(dir); 71 DCHECK(dir);
53 72
54 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1")); 73 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1"));
55 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource); 74 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource);
56 75
57 ExtensionTestMessageListener registered_listener("registered", false); 76 ExtensionTestMessageListener registered_listener("registered", false);
58 const extensions::Extension* extension = LoadExtension(dir->unpacked_path()); 77 const extensions::Extension* extension = LoadExtension(dir->unpacked_path());
59 registered_listener.WaitUntilSatisfied(); 78 registered_listener.WaitUntilSatisfied();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); 128 EXPECT_EQ(1, location_bar->PageActionVisibleCount());
110 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u)); 129 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u));
111 130
112 // Trigger the visible page action, and ensure it executes. 131 // Trigger the visible page action, and ensure it executes.
113 ExtensionTestMessageListener clicked_listener("clicked", false); 132 ExtensionTestMessageListener clicked_listener("clicked", false);
114 clicked_listener.set_extension_id(page_action1->id()); 133 clicked_listener.set_extension_id(page_action1->id());
115 location_bar->TestPageActionPressed(0u); 134 location_bar->TestPageActionPressed(0u);
116 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied()); 135 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied());
117 } 136 }
118 137
138 // Test that installing an extension that overrides the bookmark star
139 // successfully hides the star.
140 IN_PROC_BROWSER_TEST_F(LocationBarBrowserTest,
141 ExtensionCanOverrideBookmarkStar) {
142 LocationBarTesting* location_bar =
143 browser()->window()->GetLocationBar()->GetLocationBarForTesting();
144 // By default, we should show the star.
145 EXPECT_TRUE(location_bar->GetBookmarkStarVisibility());
146
147 // Create and install an extension that overrides the bookmark star.
148 extensions::DictionaryBuilder chrome_ui_overrides;
149 chrome_ui_overrides.Set(
150 "bookmarks_ui",
151 extensions::DictionaryBuilder().SetBoolean("remove_button", true));
152 scoped_refptr<const extensions::Extension> extension =
153 extensions::ExtensionBuilder().
154 SetManifest(extensions::DictionaryBuilder().
155 Set("name", "overrides star").
156 Set("manifest_version", 2).
157 Set("version", "0.1").
158 Set("description", "override the star").
159 Set("chrome_ui_overrides",
160 chrome_ui_overrides.Pass())).Build();
161 extension_service()->AddExtension(extension.get());
162
163 // The star should now be hidden.
164 EXPECT_FALSE(location_bar->GetBookmarkStarVisibility());
165 }
166
119 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest { 167 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest {
168 public:
169 LocationBarBrowserTestWithRedesign() {}
170 virtual ~LocationBarBrowserTestWithRedesign() {}
171
120 private: 172 private:
121 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; 173 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
122 174
123 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; 175 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
176
177 DISALLOW_COPY_AND_ASSIGN(LocationBarBrowserTestWithRedesign);
124 }; 178 };
125 179
126 void LocationBarBrowserTestWithRedesign::SetUpCommandLine( 180 void LocationBarBrowserTestWithRedesign::SetUpCommandLine(
127 base::CommandLine* command_line) { 181 base::CommandLine* command_line) {
128 LocationBarBrowserTest::SetUpCommandLine(command_line); 182 LocationBarBrowserTest::SetUpCommandLine(command_line);
129 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( 183 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
130 extensions::FeatureSwitch::extension_action_redesign(), true)); 184 extensions::FeatureSwitch::extension_action_redesign(), true));
131 } 185 }
132 186
133 // Test that page actions are not displayed in the location bar if the 187 // Test that page actions are not displayed in the location bar if the
(...skipping 22 matching lines...) Expand all
156 browser()->tab_strip_model()->GetActiveWebContents(); 210 browser()->tab_strip_model()->GetActiveWebContents();
157 int tab_id = SessionTabHelper::IdForTab(tab); 211 int tab_id = SessionTabHelper::IdForTab(tab);
158 action->SetIsVisible(tab_id, true); 212 action->SetIsVisible(tab_id, true);
159 extensions::ExtensionActionAPI::Get(profile())->NotifyChange( 213 extensions::ExtensionActionAPI::Get(profile())->NotifyChange(
160 action, tab, profile()); 214 action, tab, profile());
161 215
162 // We should still have no page actions. 216 // We should still have no page actions.
163 EXPECT_EQ(0, location_bar->PageActionCount()); 217 EXPECT_EQ(0, location_bar->PageActionCount());
164 EXPECT_EQ(0, location_bar->PageActionVisibleCount()); 218 EXPECT_EQ(0, location_bar->PageActionVisibleCount());
165 } 219 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/location_bar/location_bar.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698