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

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

Issue 788053008: [Extensions] Re-enable test CommandsApiTest.PageAction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finnur's Created 5 years, 11 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/keybinding/page_action/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/app/chrome_command_ids.h" 6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/extensions/active_tab_permission_granter.h" 7 #include "chrome/browser/extensions/active_tab_permission_granter.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h" 9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_action.h" 10 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/tab_helper.h" 13 #include "chrome/browser/extensions/tab_helper.h"
14 #include "chrome/browser/sessions/session_tab_helper.h" 14 #include "chrome/browser/sessions/session_tab_helper.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_command_controller.h" 16 #include "chrome/browser/ui/browser_command_controller.h"
17 #include "chrome/browser/ui/browser_commands.h" 17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/test/base/interactive_test_utils.h" 19 #include "chrome/test/base/interactive_test_utils.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h" 23 #include "content/public/test/browser_test_utils.h"
24 #include "extensions/browser/extension_registry.h" 24 #include "extensions/browser/extension_registry.h"
25 #include "extensions/common/extension.h" 25 #include "extensions/common/extension.h"
26 #include "extensions/common/feature_switch.h" 26 #include "extensions/common/feature_switch.h"
27 #include "extensions/common/manifest_constants.h" 27 #include "extensions/common/manifest_constants.h"
28 #include "extensions/common/permissions/permissions_data.h" 28 #include "extensions/common/permissions/permissions_data.h"
29 #include "extensions/test/extension_test_message_listener.h"
29 #include "extensions/test/result_catcher.h" 30 #include "extensions/test/result_catcher.h"
30 31
31 using content::WebContents; 32 using content::WebContents;
32 33
33 namespace extensions { 34 namespace extensions {
34 35
35 namespace { 36 namespace {
36 // This extension ID is used for tests require a stable ID over multiple 37 // This extension ID is used for tests require a stable ID over multiple
37 // extension installs. 38 // extension installs.
38 const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp"; 39 const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp";
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 result = false; 163 result = false;
163 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 164 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
164 tab, 165 tab,
165 "setInterval(function(){" 166 "setInterval(function(){"
166 " if(document.body.bgColor == 'blue'){" 167 " if(document.body.bgColor == 'blue'){"
167 " window.domAutomationController.send(true)}}, 100)", 168 " window.domAutomationController.send(true)}}, 100)",
168 &result)); 169 &result));
169 ASSERT_TRUE(result); 170 ASSERT_TRUE(result);
170 } 171 }
171 172
172 // Flaky on linux and chromeos, http://crbug.com/165825 173 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) {
173 #if defined(OS_MACOSX) || defined(OS_WIN)
174 #define MAYBE_PageAction PageAction
175 #else
176 #define MAYBE_PageAction DISABLED_PageAction
177 #endif
178 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_PageAction) {
179 ASSERT_TRUE(test_server()->Start()); 174 ASSERT_TRUE(test_server()->Start());
180 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; 175 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_;
181 const Extension* extension = GetSingleLoadedExtension(); 176 const Extension* extension = GetSingleLoadedExtension();
182 ASSERT_TRUE(extension) << message_; 177 ASSERT_TRUE(extension) << message_;
183 178
184 { 179 {
185 // Load a page, the extension will detect the navigation and request to show 180 // Load a page, the extension will detect the navigation and request to show
186 // the page action icon. 181 // the page action icon.
187 ResultCatcher catcher; 182 ResultCatcher catcher;
188 ui_test_utils::NavigateToURL( 183 ui_test_utils::NavigateToURL(
189 browser(), test_server()->GetURL("files/extensions/test_file.txt")); 184 browser(), test_server()->GetURL("files/extensions/test_file.txt"));
190 ASSERT_TRUE(catcher.GetNextResult()); 185 ASSERT_TRUE(catcher.GetNextResult());
191 } 186 }
192 187
193 // Make sure it appears and is the right one. 188 // Make sure it appears and is the right one.
194 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); 189 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1));
195 int tab_id = SessionTabHelper::FromWebContents( 190 int tab_id = SessionTabHelper::FromWebContents(
196 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); 191 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id();
197 ExtensionAction* action = 192 ExtensionAction* action =
198 ExtensionActionManager::Get(browser()->profile())-> 193 ExtensionActionManager::Get(browser()->profile())->
199 GetPageAction(*extension); 194 GetPageAction(*extension);
200 ASSERT_TRUE(action); 195 ASSERT_TRUE(action);
201 EXPECT_EQ("Make this page red", action->GetTitle(tab_id)); 196 EXPECT_EQ("Send message", action->GetTitle(tab_id));
197
198 ExtensionTestMessageListener test_listener(false); // Won't reply.
199 test_listener.set_extension_id(extension->id());
202 200
203 // Activate the shortcut (Alt+Shift+F). 201 // Activate the shortcut (Alt+Shift+F).
204 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 202 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
205 browser(), ui::VKEY_F, false, true, true, false)); 203 browser(), ui::VKEY_F, false, true, true, false));
206 204
207 // Verify the command worked (the page action turns the page red). 205 test_listener.WaitUntilSatisfied();
208 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 206 EXPECT_EQ("clicked", test_listener.message());
209 bool result = false;
210 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
211 tab,
212 "setInterval(function(){"
213 " if(document.body.bgColor == 'red'){"
214 " window.domAutomationController.send(true)}}, 100)",
215 &result));
216 ASSERT_TRUE(result);
217 } 207 }
218 208
219 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionKeyUpdated) { 209 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionKeyUpdated) {
220 ASSERT_TRUE(test_server()->Start()); 210 ASSERT_TRUE(test_server()->Start());
221 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; 211 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_;
222 const Extension* extension = GetSingleLoadedExtension(); 212 const Extension* extension = GetSingleLoadedExtension();
223 ASSERT_TRUE(extension) << message_; 213 ASSERT_TRUE(extension) << message_;
224 214
225 CommandService* command_service = CommandService::Get(browser()->profile()); 215 CommandService* command_service = CommandService::Get(browser()->profile());
226 // Simulate the user setting the keybinding to Alt+Shift+G. 216 // Simulate the user setting the keybinding to Alt+Shift+G.
227 command_service->UpdateKeybindingPrefs( 217 command_service->UpdateKeybindingPrefs(
228 extension->id(), manifest_values::kPageActionCommandEvent, kAltShiftG); 218 extension->id(), manifest_values::kPageActionCommandEvent, kAltShiftG);
229 219
230 { 220 {
231 // Load a page. The extension will detect the navigation and request to show 221 // Load a page. The extension will detect the navigation and request to show
232 // the page action icon. 222 // the page action icon.
233 ResultCatcher catcher; 223 ResultCatcher catcher;
234 ui_test_utils::NavigateToURL( 224 ui_test_utils::NavigateToURL(
235 browser(), test_server()->GetURL("files/extensions/test_file.txt")); 225 browser(), test_server()->GetURL("files/extensions/test_file.txt"));
236 ASSERT_TRUE(catcher.GetNextResult()); 226 ASSERT_TRUE(catcher.GetNextResult());
237 } 227 }
238 228
239 // Activate the shortcut to make the page red. 229 ExtensionTestMessageListener test_listener(false); // Won't reply.
230 test_listener.set_extension_id(extension->id());
231
232 // Activate the shortcut.
240 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 233 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
241 browser(), ui::VKEY_G, false, true, true, false)); 234 browser(), ui::VKEY_G, false, true, true, false));
242 235
243 // Verify the command worked (the page action turns the page red). 236 test_listener.WaitUntilSatisfied();
244 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 237 EXPECT_EQ("clicked", test_listener.message());
245 bool result = false;
246 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
247 tab,
248 std::string("setInterval(function() {") +
249 " if (document.body.bgColor == 'red') {" +
250 " window.domAutomationController.send(true)}}, 100)",
251 &result));
252 ASSERT_TRUE(result);
253 } 238 }
254 239
255 // This test validates that the getAll query API function returns registered 240 // This test validates that the getAll query API function returns registered
256 // commands as well as synthesized ones and that inactive commands (like the 241 // commands as well as synthesized ones and that inactive commands (like the
257 // synthesized ones are in nature) have no shortcuts. 242 // synthesized ones are in nature) have no shortcuts.
258 IN_PROC_BROWSER_TEST_F(CommandsApiTest, SynthesizedCommand) { 243 IN_PROC_BROWSER_TEST_F(CommandsApiTest, SynthesizedCommand) {
259 ASSERT_TRUE(test_server()->Start()); 244 ASSERT_TRUE(test_server()->Start());
260 ASSERT_TRUE(RunExtensionTest("keybinding/synthesized")) << message_; 245 ASSERT_TRUE(RunExtensionTest("keybinding/synthesized")) << message_;
261 } 246 }
262 247
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 #define MAYBE_ChromeOSConversions DISABLED_ChromeOSConversions 942 #define MAYBE_ChromeOSConversions DISABLED_ChromeOSConversions
958 #else 943 #else
959 #define MAYBE_ChromeOSConversions ChromeOSConversions 944 #define MAYBE_ChromeOSConversions ChromeOSConversions
960 #endif 945 #endif
961 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) { 946 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) {
962 RunChromeOSConversionTest("keybinding/chromeos_conversions"); 947 RunChromeOSConversionTest("keybinding/chromeos_conversions");
963 } 948 }
964 #endif // OS_CHROMEOS 949 #endif // OS_CHROMEOS
965 950
966 } // namespace extensions 951 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/keybinding/page_action/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698