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

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

Issue 360423002: Allow WebContents key handling to supplant extension overrides of the bookmark shortcut (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: address comments Created 6 years, 5 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/extensions/active_tab_permission_granter.h" 6 #include "chrome/browser/extensions/active_tab_permission_granter.h"
7 #include "chrome/browser/extensions/api/commands/command_service.h" 7 #include "chrome/browser/extensions/api/commands/command_service.h"
8 #include "chrome/browser/extensions/browser_action_test_util.h" 8 #include "chrome/browser/extensions/browser_action_test_util.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"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 bool result = false; 275 bool result = false;
276 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 276 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
277 tab, 277 tab,
278 "setInterval(function() {" 278 "setInterval(function() {"
279 " if (document.body.bgColor == 'green') {" 279 " if (document.body.bgColor == 'green') {"
280 " window.domAutomationController.send(true)}}, 100)", 280 " window.domAutomationController.send(true)}}, 100)",
281 &result)); 281 &result));
282 ASSERT_TRUE(result); 282 ASSERT_TRUE(result);
283 } 283 }
284 284
285 // Behavior to be implemented on Mac. See http://crbug.com/389340.
286 #if defined(OS_MACOSX)
287 #define MAYBE_OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding DISABLED_Ove rwriteBookmarkShortcutDoesNotOverrideWebKeybinding
288 #else
289 #define MAYBE_OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding OverwriteBoo kmarkShortcutDoesNotOverrideWebKeybinding
290 #endif
291 // This test validates that an extension override of the Chrome bookmark
292 // shortcut does not supersede the same keybinding by web pages.
293 IN_PROC_BROWSER_TEST_F(
294 CommandsApiTest,
295 MAYBE_OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding) {
296 ASSERT_TRUE(test_server()->Start());
297
298 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
299
300 // This functionality requires a feature flag.
301 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
302 "--enable-override-bookmarks-ui",
303 "1");
304
305 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut"))
306 << message_;
307
308 ui_test_utils::NavigateToURL(browser(),
309 test_server()->GetURL(
310 "files/extensions/test_file_with_ctrl-d_keybinding.html"));
311
312 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
313 ASSERT_TRUE(tab);
314
315 // Activate the shortcut (Ctrl+D) which should be handled by the page and make
316 // the background color magenta.
317 #if defined(OS_MACOSX)
318 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
319 browser(), ui::VKEY_D, false, false, false, true));
320 #else
321 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
322 browser(), ui::VKEY_D, true, false, false, false));
323 #endif
324
325 bool result = false;
326 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
327 tab,
328 "setInterval(function() {"
329 " if (document.body.bgColor == 'magenta') {"
330 " window.domAutomationController.send(true)}}, 100)",
331 &result));
332 ASSERT_TRUE(result);
333 }
334
335 // Behavior to be implemented on Mac. See http://crbug.com/389340.
336 #if defined(OS_MACOSX)
337 #define MAYBE_OverwriteBookmarkShortcutByUserOverridesWebKeybinding DISABLED_Ove rwriteBookmarkShortcutByUserOverridesWebKeybinding
338 #else
339 #define MAYBE_OverwriteBookmarkShortcutByUserOverridesWebKeybinding OverwriteBoo kmarkShortcutByUserOverridesWebKeybinding
340 #endif
341 // This test validates that user-set override of the Chrome bookmark shortcut in
342 // an extension that does not request it does supersede the same keybinding by
343 // web pages.
344 IN_PROC_BROWSER_TEST_F(
345 CommandsApiTest,
346 MAYBE_OverwriteBookmarkShortcutByUserOverridesWebKeybinding) {
347 ASSERT_TRUE(test_server()->Start());
348
349 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
350
351 // This functionality requires a feature flag.
352 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
353 "--enable-override-bookmarks-ui",
354 "1");
355
356 ASSERT_TRUE(RunExtensionTest("keybinding/basics"))
357 << message_;
358
359 CommandService* command_service = CommandService::Get(browser()->profile());
360
361 const Extension* extension = GetSingleLoadedExtension();
362 // Simulate the user setting the keybinding to Ctrl+D.
363 command_service->UpdateKeybindingPrefs(
364 extension->id(), manifest_values::kBrowserActionCommandEvent, "Ctrl+D");
365
366 ui_test_utils::NavigateToURL(browser(),
367 test_server()->GetURL(
368 "files/extensions/test_file_with_ctrl-d_keybinding.html"));
369
370 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
371 ASSERT_TRUE(tab);
372
373 // Activate the shortcut (Ctrl+D) which should be handled by the extension and
374 // make the background color red.
375 #if defined(OS_MACOSX)
376 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
377 browser(), ui::VKEY_D, false, false, false, true));
378 #else
379 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
380 browser(), ui::VKEY_D, true, false, false, false));
381 #endif
382
383 bool result = false;
384 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
385 tab,
386 "setInterval(function() {"
387 " if (document.body.bgColor == 'red') {"
388 " window.domAutomationController.send(true)}}, 100)",
389 &result));
390 ASSERT_TRUE(result);
391 }
392
285 #if defined(OS_WIN) 393 #if defined(OS_WIN)
286 // Currently this feature is implemented on Windows only. 394 // Currently this feature is implemented on Windows only.
287 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys 395 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys
288 #else 396 #else
289 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys 397 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys
290 #endif 398 #endif
291 399
292 // Test that media keys go to all extensions that register for them. 400 // Test that media keys go to all extensions that register for them.
293 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { 401 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) {
294 ResultCatcher catcher; 402 ResultCatcher catcher;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // Verify the keybinding is still set. 704 // Verify the keybinding is still set.
597 accelerator = command_service->FindCommandByName( 705 accelerator = command_service->FindCommandByName(
598 kId, manifest_values::kBrowserActionCommandEvent).accelerator(); 706 kId, manifest_values::kBrowserActionCommandEvent).accelerator();
599 EXPECT_EQ(ui::VKEY_G, accelerator.key_code()); 707 EXPECT_EQ(ui::VKEY_G, accelerator.key_code());
600 EXPECT_FALSE(accelerator.IsCtrlDown()); 708 EXPECT_FALSE(accelerator.IsCtrlDown());
601 EXPECT_TRUE(accelerator.IsShiftDown()); 709 EXPECT_TRUE(accelerator.IsShiftDown());
602 EXPECT_TRUE(accelerator.IsAltDown()); 710 EXPECT_TRUE(accelerator.IsAltDown());
603 } 711 }
604 712
605 } // namespace extensions 713 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698