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

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

Issue 143493005: Allow extensions to remove and override the bookmark shortcut key (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mac test fix Created 6 years, 10 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 | Annotate | Revision Log
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 "chrome/browser/extensions/active_tab_permission_granter.h" 6 #include "chrome/browser/extensions/active_tab_permission_granter.h"
6 #include "chrome/browser/extensions/browser_action_test_util.h" 7 #include "chrome/browser/extensions/browser_action_test_util.h"
7 #include "chrome/browser/extensions/extension_action.h" 8 #include "chrome/browser/extensions/extension_action.h"
8 #include "chrome/browser/extensions/extension_action_manager.h" 9 #include "chrome/browser/extensions/extension_action_manager.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/tab_helper.h" 11 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/sessions/session_tab_helper.h" 12 #include "chrome/browser/sessions/session_tab_helper.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/interactive_test_utils.h" 15 #include "chrome/test/base/interactive_test_utils.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 182 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
182 183
183 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; 184 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_;
184 185
185 ui_test_utils::NavigateToURL(browser(), 186 ui_test_utils::NavigateToURL(browser(),
186 test_server()->GetURL("files/extensions/test_file.txt")); 187 test_server()->GetURL("files/extensions/test_file.txt"));
187 188
188 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 189 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
189 ASSERT_TRUE(tab); 190 ASSERT_TRUE(tab);
190 191
191 // Activate the shortcut (Alt+Shift+F) to make page blue. 192 // Activate the shortcut (Alt+Shift+F) to make the page blue.
192 { 193 {
193 ResultCatcher catcher; 194 ResultCatcher catcher;
194 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 195 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
195 browser(), ui::VKEY_F, false, true, true, false)); 196 browser(), ui::VKEY_F, false, true, true, false));
196 ASSERT_TRUE(catcher.GetNextResult()); 197 ASSERT_TRUE(catcher.GetNextResult());
197 } 198 }
198 199
199 bool result = false; 200 bool result = false;
200 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 201 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
201 tab, 202 tab,
202 "setInterval(function() {" 203 "setInterval(function() {"
203 " if (document.body.bgColor == 'blue') {" 204 " if (document.body.bgColor == 'blue') {"
204 " window.domAutomationController.send(true)}}, 100)", 205 " window.domAutomationController.send(true)}}, 100)",
205 &result)); 206 &result));
206 ASSERT_TRUE(result); 207 ASSERT_TRUE(result);
207 208
208 // Activate the shortcut (Ctrl+F) to make page red (should not work). 209 // Activate the bookmark shortcut (Ctrl+D) to make the page green (should not
210 // work without requesting via chrome_settings_overrides).
211 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
212 browser(), ui::VKEY_D, true, false, false, false));
Finnur 2014/02/14 10:53:41 This also needs the if-def, otherwise this negativ
Mike Wittman 2014/02/14 17:03:53 Done.
213
214 // The page should still be blue.
215 result = false;
216 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
217 tab,
218 "setInterval(function() {"
219 " if (document.body.bgColor == 'blue') {"
220 " window.domAutomationController.send(true)}}, 100)",
221 &result));
222 ASSERT_TRUE(result);
223
224 // Activate the shortcut (Ctrl+F) to make the page red (should not work).
209 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 225 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
210 browser(), ui::VKEY_F, true, false, false, false)); 226 browser(), ui::VKEY_F, true, false, false, false));
211 227
212 // The page should still be blue. 228 // The page should still be blue.
213 result = false; 229 result = false;
214 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 230 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
215 tab, 231 tab,
216 "setInterval(function() {" 232 "setInterval(function() {"
217 " if (document.body.bgColor == 'blue') {" 233 " if (document.body.bgColor == 'blue') {"
218 " window.domAutomationController.send(true)}}, 100)", 234 " window.domAutomationController.send(true)}}, 100)",
219 &result)); 235 &result));
220 ASSERT_TRUE(result); 236 ASSERT_TRUE(result);
221 } 237 }
222 238
239 // This test validates that an extension can override the Chrome bookmark
240 // shortcut if it has requested to do so.
241 IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) {
242 ASSERT_TRUE(test_server()->Start());
243
244 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
245
246 // This functionality requires a feature flag.
247 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
248 "--enable-override-bookmarks-ui",
249 "1");
250
251 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut"))
252 << message_;
253
254 ui_test_utils::NavigateToURL(browser(),
255 test_server()->GetURL("files/extensions/test_file.txt"));
256
257 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
258 ASSERT_TRUE(tab);
259
260 // Activate the shortcut (Ctrl+D) to make the page green.
261 {
262 ResultCatcher catcher;
263 #if defined(OS_MACOSX)
264 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
265 browser(), ui::VKEY_D, false, false, false, true));
266 #else
267 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
268 browser(), ui::VKEY_D, true, false, false, false));
269 #endif
270 ASSERT_TRUE(catcher.GetNextResult());
271 }
272
273 bool result = false;
274 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
275 tab,
276 "setInterval(function() {"
277 " if (document.body.bgColor == 'green') {"
278 " window.domAutomationController.send(true)}}, 100)",
279 &result));
280 ASSERT_TRUE(result);
281 }
282
223 #if defined(OS_WIN) 283 #if defined(OS_WIN)
224 // Currently this feature is implemented on Windows only. 284 // Currently this feature is implemented on Windows only.
225 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys 285 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys
226 #else 286 #else
227 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys 287 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys
228 #endif 288 #endif
229 289
230 // Test that media keys go to all extensions that register for them. 290 // Test that media keys go to all extensions that register for them.
231 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { 291 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) {
232 ResultCatcher catcher; 292 ResultCatcher catcher;
233 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0")) 293 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0"))
234 << message_; 294 << message_;
235 ASSERT_TRUE(catcher.GetNextResult()); 295 ASSERT_TRUE(catcher.GetNextResult());
236 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1")) 296 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1"))
237 << message_; 297 << message_;
238 ASSERT_TRUE(catcher.GetNextResult()); 298 ASSERT_TRUE(catcher.GetNextResult());
239 299
240 // Activate the Media Stop key. 300 // Activate the Media Stop key.
241 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 301 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
242 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false)); 302 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false));
243 303
244 // We should get two success result. 304 // We should get two success result.
245 ASSERT_TRUE(catcher.GetNextResult()); 305 ASSERT_TRUE(catcher.GetNextResult());
246 ASSERT_TRUE(catcher.GetNextResult()); 306 ASSERT_TRUE(catcher.GetNextResult());
247 } 307 }
248 308
249 } // namespace extensions 309 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/commands/command_service.cc ('k') | chrome/browser/ui/accelerator_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698