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

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:
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_;
48 }; 56 };
Peter Kasting 2014/09/03 23:13:08 Nit: While here: DISALLOW_COPY_AND_ASSIGN
Devlin 2014/09/03 23:23:21 Ah, good catch. Done.
49 57
58 void LocationBarBrowserTest::SetUpCommandLine(base::CommandLine* command_line) {
59 // In order to let a vanilla extension override the bookmark star, we have to
60 // enable the switch.
61 enable_override_.reset(new extensions::FeatureSwitch::ScopedOverride(
62 extensions::FeatureSwitch::enable_override_bookmarks_ui(), true));
63 ExtensionBrowserTest::SetUpCommandLine(command_line);
64 }
65
50 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension( 66 const extensions::Extension* LocationBarBrowserTest::LoadPageActionExtension(
51 extensions::TestExtensionDir* dir) { 67 extensions::TestExtensionDir* dir) {
52 DCHECK(dir); 68 DCHECK(dir);
53 69
54 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1")); 70 dir->WriteManifest(base::StringPrintf(kManifestSource, "page_action1"));
55 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource); 71 dir->WriteFile(FILE_PATH_LITERAL("background.js"), kBackgroundScriptSource);
56 72
57 ExtensionTestMessageListener registered_listener("registered", false); 73 ExtensionTestMessageListener registered_listener("registered", false);
58 const extensions::Extension* extension = LoadExtension(dir->unpacked_path()); 74 const extensions::Extension* extension = LoadExtension(dir->unpacked_path());
59 registered_listener.WaitUntilSatisfied(); 75 registered_listener.WaitUntilSatisfied();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_EQ(1, location_bar->PageActionVisibleCount()); 119 EXPECT_EQ(1, location_bar->PageActionVisibleCount());
104 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u)); 120 EXPECT_EQ(action, location_bar->GetVisiblePageAction(0u));
105 121
106 // Trigger the visible page action, and ensure it executes. 122 // Trigger the visible page action, and ensure it executes.
107 ExtensionTestMessageListener clicked_listener("clicked", false); 123 ExtensionTestMessageListener clicked_listener("clicked", false);
108 clicked_listener.set_extension_id(page_action1->id()); 124 clicked_listener.set_extension_id(page_action1->id());
109 location_bar->TestPageActionPressed(0u); 125 location_bar->TestPageActionPressed(0u);
110 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied()); 126 EXPECT_TRUE(clicked_listener.WaitUntilSatisfied());
111 } 127 }
112 128
129 // Test that installing an extension that overrides the bookmark star works.
Peter Kasting 2014/09/03 23:13:09 Nit: works -> successfully hides the star
Devlin 2014/09/03 23:23:20 Done.
130 IN_PROC_BROWSER_TEST_F(LocationBarBrowserTest,
131 ExtensionCanOverrideBookmarkStar) {
132 LocationBarTesting* location_bar =
133 browser()->window()->GetLocationBar()->GetLocationBarForTesting();
134 // By default, we should show the star.
135 EXPECT_TRUE(location_bar->GetBookmarkStarVisibility());
136
137 // Create and install an extension that overrides the bookmark star.
138 extensions::DictionaryBuilder chrome_ui_overrides;
139 chrome_ui_overrides.Set(
140 "bookmarks_ui",
141 extensions::DictionaryBuilder().
142 SetBoolean("remove_button", true).
143 SetBoolean("remove_bookmark_shortcut", true));
144 scoped_refptr<const extensions::Extension> extension =
145 extensions::ExtensionBuilder().
146 SetManifest(extensions::DictionaryBuilder().
147 Set("name", "overrides star").
148 Set("manifest_version", 2).
149 Set("version", "0.1").
150 Set("description", "override the star").
151 Set("chrome_ui_overrides",
152 chrome_ui_overrides.Pass())).Build();
153 extension_service()->AddExtension(extension);
154
155 // The star should now be hidden.
156 EXPECT_FALSE(location_bar->GetBookmarkStarVisibility());
157 }
158
113 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest { 159 class LocationBarBrowserTestWithRedesign : public LocationBarBrowserTest {
114 private: 160 private:
115 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE; 161 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
116 162
117 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; 163 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
118 }; 164 };
119 165
120 void LocationBarBrowserTestWithRedesign::SetUpCommandLine( 166 void LocationBarBrowserTestWithRedesign::SetUpCommandLine(
121 base::CommandLine* command_line) { 167 base::CommandLine* command_line) {
122 LocationBarBrowserTest::SetUpCommandLine(command_line); 168 LocationBarBrowserTest::SetUpCommandLine(command_line);
(...skipping 27 matching lines...) Expand all
150 browser()->tab_strip_model()->GetActiveWebContents(); 196 browser()->tab_strip_model()->GetActiveWebContents();
151 int tab_id = SessionTabHelper::IdForTab(tab); 197 int tab_id = SessionTabHelper::IdForTab(tab);
152 action->SetIsVisible(tab_id, true); 198 action->SetIsVisible(tab_id, true);
153 extensions::ExtensionActionAPI::Get(profile())->NotifyChange( 199 extensions::ExtensionActionAPI::Get(profile())->NotifyChange(
154 action, tab, profile()); 200 action, tab, profile());
155 201
156 // We should still have no page actions. 202 // We should still have no page actions.
157 EXPECT_EQ(0, location_bar->PageActionCount()); 203 EXPECT_EQ(0, location_bar->PageActionCount());
158 EXPECT_EQ(0, location_bar->PageActionVisibleCount()); 204 EXPECT_EQ(0, location_bar->PageActionVisibleCount());
159 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698