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

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

Issue 1804123003: [Extensions] Refactor extension action execution (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #if defined OS_CHROMEOS 62 #if defined OS_CHROMEOS
63 test_user_manager_.reset(); 63 test_user_manager_.reset();
64 #endif 64 #endif
65 ChromeRenderViewHostTestHarness::TearDown(); 65 ChromeRenderViewHostTestHarness::TearDown();
66 } 66 }
67 67
68 int tab_id() { 68 int tab_id() {
69 return SessionTabHelper::IdForTab(web_contents()); 69 return SessionTabHelper::IdForTab(web_contents());
70 } 70 }
71 71
72 bool PageActionWantsToRun(const Extension* extension) {
73 ExtensionAction* page_action =
74 ExtensionActionManager::Get(profile())->GetPageAction(*extension);
75 return page_action && page_action->GetIsVisible(tab_id());
76 }
77
72 const Extension* AddExtension(bool has_page_actions, 78 const Extension* AddExtension(bool has_page_actions,
73 const std::string& name) { 79 const std::string& name) {
74 DictionaryBuilder manifest; 80 DictionaryBuilder manifest;
75 manifest.Set("name", name) 81 manifest.Set("name", name)
76 .Set("version", "1.0.0") 82 .Set("version", "1.0.0")
77 .Set("manifest_version", 2) 83 .Set("manifest_version", 2)
78 .Set("permissions", ListBuilder().Append("tabs").Build()); 84 .Set("permissions", ListBuilder().Append("tabs").Build());
79 if (has_page_actions) { 85 if (has_page_actions) {
80 manifest.Set("page_action", 86 manifest.Set("page_action",
81 DictionaryBuilder().Set("default_title", "Hello").Build()); 87 DictionaryBuilder().Set("default_title", "Hello").Build());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 TEST_F(LocationBarControllerUnitTest, NavigationClearsState) { 167 TEST_F(LocationBarControllerUnitTest, NavigationClearsState) {
162 const Extension* extension = AddExtension(true, "page_actions"); 168 const Extension* extension = AddExtension(true, "page_actions");
163 169
164 NavigateAndCommit(GURL("http://www.google.com")); 170 NavigateAndCommit(GURL("http://www.google.com"));
165 171
166 ExtensionAction& page_action = 172 ExtensionAction& page_action =
167 *ExtensionActionManager::Get(profile())->GetPageAction(*extension); 173 *ExtensionActionManager::Get(profile())->GetPageAction(*extension);
168 page_action.SetTitle(tab_id(), "Goodbye"); 174 page_action.SetTitle(tab_id(), "Goodbye");
169 page_action.SetPopupUrl(tab_id(), extension->GetResourceURL("popup.html")); 175 page_action.SetPopupUrl(tab_id(), extension->GetResourceURL("popup.html"));
170 176
171 ExtensionActionAPI* extension_action_api =
172 ExtensionActionAPI::Get(profile());
173 // By default, extensions shouldn't want to act on a page. 177 // By default, extensions shouldn't want to act on a page.
174 EXPECT_FALSE( 178 EXPECT_FALSE(PageActionWantsToRun(extension));
175 extension_action_api->PageActionWantsToRun(extension, web_contents()));
176 // Showing the page action should indicate that an extension *does* want to 179 // Showing the page action should indicate that an extension *does* want to
177 // run on the page. 180 // run on the page.
178 page_action.SetIsVisible(tab_id(), true); 181 page_action.SetIsVisible(tab_id(), true);
179 EXPECT_TRUE( 182 EXPECT_TRUE(PageActionWantsToRun(extension));
180 extension_action_api->PageActionWantsToRun(extension, web_contents()));
181 183
182 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); 184 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id()));
183 EXPECT_EQ(extension->GetResourceURL("popup.html"), 185 EXPECT_EQ(extension->GetResourceURL("popup.html"),
184 page_action.GetPopupUrl(tab_id())); 186 page_action.GetPopupUrl(tab_id()));
185 187
186 // Within-page navigation should keep the settings. 188 // Within-page navigation should keep the settings.
187 NavigateAndCommit(GURL("http://www.google.com/#hash")); 189 NavigateAndCommit(GURL("http://www.google.com/#hash"));
188 190
189 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id())); 191 EXPECT_EQ("Goodbye", page_action.GetTitle(tab_id()));
190 EXPECT_EQ(extension->GetResourceURL("popup.html"), 192 EXPECT_EQ(extension->GetResourceURL("popup.html"),
191 page_action.GetPopupUrl(tab_id())); 193 page_action.GetPopupUrl(tab_id()));
192 EXPECT_TRUE( 194 EXPECT_TRUE(PageActionWantsToRun(extension));
193 extension_action_api->PageActionWantsToRun(extension, web_contents()));
194 195
195 // Should discard the settings, and go back to the defaults. 196 // Should discard the settings, and go back to the defaults.
196 NavigateAndCommit(GURL("http://www.yahoo.com")); 197 NavigateAndCommit(GURL("http://www.yahoo.com"));
197 198
198 EXPECT_EQ("Hello", page_action.GetTitle(tab_id())); 199 EXPECT_EQ("Hello", page_action.GetTitle(tab_id()));
199 EXPECT_EQ(GURL(), page_action.GetPopupUrl(tab_id())); 200 EXPECT_EQ(GURL(), page_action.GetPopupUrl(tab_id()));
200 EXPECT_FALSE( 201 EXPECT_FALSE(PageActionWantsToRun(extension));
201 extension_action_api->PageActionWantsToRun(extension, web_contents()));
202 } 202 }
203 203
204 } // namespace 204 } // namespace
205 } // namespace extensions 205 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698