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

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: update test 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 ASSERT_TRUE(RunExtensionTest("keybinding/basics"))
352 << message_;
353
354 CommandService* command_service = CommandService::Get(browser()->profile());
355
356 const Extension* extension = GetSingleLoadedExtension();
357 // Simulate the user setting the keybinding to Ctrl+D.
358 command_service->UpdateKeybindingPrefs(
359 extension->id(), manifest_values::kBrowserActionCommandEvent, "Ctrl+D");
360
361 ui_test_utils::NavigateToURL(browser(),
362 test_server()->GetURL(
363 "files/extensions/test_file_with_ctrl-d_keybinding.html"));
364
365 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
366 ASSERT_TRUE(tab);
367
368 // Activate the shortcut (Ctrl+D) which should be handled by the extension and
369 // make the background color red.
370 #if defined(OS_MACOSX)
371 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
372 browser(), ui::VKEY_D, false, false, false, true));
373 #else
374 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
375 browser(), ui::VKEY_D, true, false, false, false));
376 #endif
377
378 bool result = false;
379 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
380 tab,
381 "setInterval(function() {"
382 " if (document.body.bgColor == 'red') {"
383 " window.domAutomationController.send(true)}}, 100)",
384 &result));
385 ASSERT_TRUE(result);
386 }
387
285 #if defined(OS_WIN) 388 #if defined(OS_WIN)
286 // Currently this feature is implemented on Windows only. 389 // Currently this feature is implemented on Windows only.
287 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys 390 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys
288 #else 391 #else
289 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys 392 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys
290 #endif 393 #endif
291 394
292 // Test that media keys go to all extensions that register for them. 395 // Test that media keys go to all extensions that register for them.
293 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { 396 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) {
294 ResultCatcher catcher; 397 ResultCatcher catcher;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // Verify the keybinding is still set. 699 // Verify the keybinding is still set.
597 accelerator = command_service->FindCommandByName( 700 accelerator = command_service->FindCommandByName(
598 kId, manifest_values::kBrowserActionCommandEvent).accelerator(); 701 kId, manifest_values::kBrowserActionCommandEvent).accelerator();
599 EXPECT_EQ(ui::VKEY_G, accelerator.key_code()); 702 EXPECT_EQ(ui::VKEY_G, accelerator.key_code());
600 EXPECT_FALSE(accelerator.IsCtrlDown()); 703 EXPECT_FALSE(accelerator.IsCtrlDown());
601 EXPECT_TRUE(accelerator.IsShiftDown()); 704 EXPECT_TRUE(accelerator.IsShiftDown());
602 EXPECT_TRUE(accelerator.IsAltDown()); 705 EXPECT_TRUE(accelerator.IsAltDown());
603 } 706 }
604 707
605 } // namespace extensions 708 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698