| OLD | NEW |
| 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 Loading... |
| 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 | 285 // This test validates that an extension override of the Chrome bookmark |
| 292 // shortcut does not supersede the same keybinding by web pages. | 286 // shortcut does not supersede the same keybinding by web pages. |
| 293 IN_PROC_BROWSER_TEST_F( | 287 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
| 294 CommandsApiTest, | 288 OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding) { |
| 295 MAYBE_OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding) { | |
| 296 ASSERT_TRUE(test_server()->Start()); | 289 ASSERT_TRUE(test_server()->Start()); |
| 297 | 290 |
| 298 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 291 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 299 | 292 |
| 300 // This functionality requires a feature flag. | 293 // This functionality requires a feature flag. |
| 301 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 294 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 302 "--enable-override-bookmarks-ui", | 295 "--enable-override-bookmarks-ui", |
| 303 "1"); | 296 "1"); |
| 304 | 297 |
| 305 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 298 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 325 bool result = false; | 318 bool result = false; |
| 326 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 319 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 327 tab, | 320 tab, |
| 328 "setInterval(function() {" | 321 "setInterval(function() {" |
| 329 " if (document.body.bgColor == 'magenta') {" | 322 " if (document.body.bgColor == 'magenta') {" |
| 330 " window.domAutomationController.send(true)}}, 100)", | 323 " window.domAutomationController.send(true)}}, 100)", |
| 331 &result)); | 324 &result)); |
| 332 ASSERT_TRUE(result); | 325 ASSERT_TRUE(result); |
| 333 } | 326 } |
| 334 | 327 |
| 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 | 328 // 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 | 329 // an extension that does not request it does supersede the same keybinding by |
| 343 // web pages. | 330 // web pages. |
| 344 IN_PROC_BROWSER_TEST_F( | 331 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
| 345 CommandsApiTest, | 332 OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { |
| 346 MAYBE_OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { | |
| 347 ASSERT_TRUE(test_server()->Start()); | 333 ASSERT_TRUE(test_server()->Start()); |
| 348 | 334 |
| 349 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 335 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 350 | 336 |
| 351 // This functionality requires a feature flag. | 337 // This functionality requires a feature flag. |
| 352 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 338 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 353 "--enable-override-bookmarks-ui", | 339 "--enable-override-bookmarks-ui", |
| 354 "1"); | 340 "1"); |
| 355 | 341 |
| 356 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) | 342 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) |
| 357 << message_; | 343 << message_; |
| 358 | 344 |
| 359 CommandService* command_service = CommandService::Get(browser()->profile()); | 345 CommandService* command_service = CommandService::Get(browser()->profile()); |
| 360 | 346 |
| 361 const Extension* extension = GetSingleLoadedExtension(); | 347 const Extension* extension = GetSingleLoadedExtension(); |
| 362 // Simulate the user setting the keybinding to Ctrl+D. | 348 // Simulate the user setting the keybinding to Ctrl+D. |
| 349 #if defined(OS_MACOSX) |
| 350 const char* hotkey = "Command+D"; |
| 351 #else |
| 352 const char* hotkey = "Ctrl+D"; |
| 353 #endif // defined(OS_MACOSX) |
| 363 command_service->UpdateKeybindingPrefs( | 354 command_service->UpdateKeybindingPrefs( |
| 364 extension->id(), manifest_values::kBrowserActionCommandEvent, "Ctrl+D"); | 355 extension->id(), manifest_values::kBrowserActionCommandEvent, hotkey); |
| 365 | 356 |
| 366 ui_test_utils::NavigateToURL(browser(), | 357 ui_test_utils::NavigateToURL(browser(), |
| 367 test_server()->GetURL( | 358 test_server()->GetURL( |
| 368 "files/extensions/test_file_with_ctrl-d_keybinding.html")); | 359 "files/extensions/test_file_with_ctrl-d_keybinding.html")); |
| 369 | 360 |
| 370 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 361 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 371 ASSERT_TRUE(tab); | 362 ASSERT_TRUE(tab); |
| 372 | 363 |
| 373 // Activate the shortcut (Ctrl+D) which should be handled by the extension and | 364 // Activate the shortcut (Ctrl+D) which should be handled by the extension and |
| 374 // make the background color red. | 365 // make the background color red. |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // Verify the keybinding is still set. | 695 // Verify the keybinding is still set. |
| 705 accelerator = command_service->FindCommandByName( | 696 accelerator = command_service->FindCommandByName( |
| 706 kId, manifest_values::kBrowserActionCommandEvent).accelerator(); | 697 kId, manifest_values::kBrowserActionCommandEvent).accelerator(); |
| 707 EXPECT_EQ(ui::VKEY_G, accelerator.key_code()); | 698 EXPECT_EQ(ui::VKEY_G, accelerator.key_code()); |
| 708 EXPECT_FALSE(accelerator.IsCtrlDown()); | 699 EXPECT_FALSE(accelerator.IsCtrlDown()); |
| 709 EXPECT_TRUE(accelerator.IsShiftDown()); | 700 EXPECT_TRUE(accelerator.IsShiftDown()); |
| 710 EXPECT_TRUE(accelerator.IsAltDown()); | 701 EXPECT_TRUE(accelerator.IsAltDown()); |
| 711 } | 702 } |
| 712 | 703 |
| 713 } // namespace extensions | 704 } // namespace extensions |
| OLD | NEW |