Chromium Code Reviews| 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/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" | |
| 14 #include "chrome/browser/sessions/session_tab_helper.h" | 13 #include "chrome/browser/sessions/session_tab_helper.h" |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_command_controller.h" | 15 #include "chrome/browser/ui/browser_command_controller.h" |
| 17 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/test/base/interactive_test_utils.h" | 18 #include "chrome/test/base/interactive_test_utils.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/javascript_test_observer.h" |
| 24 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 25 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 26 #include "extensions/common/feature_switch.h" | 25 #include "extensions/common/feature_switch.h" |
| 27 #include "extensions/common/manifest_constants.h" | 26 #include "extensions/common/manifest_constants.h" |
| 28 #include "extensions/common/permissions/permissions_data.h" | 27 #include "extensions/common/permissions/permissions_data.h" |
| 29 #include "extensions/test/extension_test_message_listener.h" | 28 #include "extensions/test/extension_test_message_listener.h" |
| 30 #include "extensions/test/result_catcher.h" | 29 #include "extensions/test/result_catcher.h" |
| 31 | 30 |
| 32 using content::WebContents; | 31 using content::WebContents; |
| 33 | 32 |
| 34 namespace extensions { | 33 namespace extensions { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 36 | |
| 37 // 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 |
| 38 // extension installs. | 38 // extension installs. |
| 39 const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp"; | 39 const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp"; |
| 40 | 40 |
| 41 // Default keybinding to use for emulating user-defined shortcut overrides. The | 41 // Default keybinding to use for emulating user-defined shortcut overrides. The |
| 42 // test extensions use Alt+Shift+F and Alt+Shift+H. | 42 // test extensions use Alt+Shift+F and Alt+Shift+H. |
| 43 const char kAltShiftG[] = "Alt+Shift+G"; | 43 const char kAltShiftG[] = "Alt+Shift+G"; |
| 44 | 44 |
| 45 // Color name of named command for overwrite_bookmark_shortcut test extension. | 45 // Color name of named command for overwrite_bookmark_shortcut test extension. |
|
Finnur
2015/01/29 09:38:39
nit: The comment is out of date now.
Devlin
2015/01/30 17:21:44
D'oh. Tried to update them all. Done.
| |
| 46 const char kOverwriteBookmarkShortcutCommandColor[] = "green"; | 46 const char kOverwriteBookmarkShortcutCommandName[] = "send message"; |
| 47 | 47 |
| 48 #if defined(OS_MACOSX) | 48 #if defined(OS_MACOSX) |
| 49 const char kBookmarkKeybinding[] = "Command+D"; | 49 const char kBookmarkKeybinding[] = "Command+D"; |
| 50 #else | 50 #else |
| 51 const char kBookmarkKeybinding[] = "Ctrl+D"; | 51 const char kBookmarkKeybinding[] = "Ctrl+D"; |
| 52 #endif // defined(OS_MACOSX) | 52 #endif // defined(OS_MACOSX) |
| 53 | 53 |
| 54 bool SendBookmarkKeyPressSync(Browser* browser) { | 54 bool SendBookmarkKeyPressSync(Browser* browser) { |
| 55 return ui_test_utils::SendKeyPressSync( | 55 return ui_test_utils::SendKeyPressSync( |
| 56 browser, ui::VKEY_D, | 56 browser, ui::VKEY_D, |
| 57 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
| 58 false, false, false, true | 58 false, false, false, true |
| 59 #else | 59 #else |
| 60 true, false, false, false | 60 true, false, false, false |
| 61 #endif | 61 #endif |
| 62 ); | 62 ); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Named command for media key overwrite test. | 65 // Named command for media key overwrite test. |
| 66 const char kMediaKeyTestCommand[] = "test_mediakeys_update"; | 66 const char kMediaKeyTestCommand[] = "test_mediakeys_update"; |
| 67 | 67 |
| 68 // A scoped observer that listens for dom automation messages. | |
| 69 class DomMessageListener : public content::TestMessageHandler { | |
| 70 public: | |
| 71 explicit DomMessageListener(content::WebContents* web_contents); | |
| 72 ~DomMessageListener() override; | |
| 73 | |
| 74 // Wait until a message is received. | |
| 75 void Wait(); | |
| 76 | |
| 77 // Clears and resets the observer. | |
| 78 void Clear(); | |
| 79 | |
| 80 const std::string& message() const { return message_; } | |
| 81 | |
| 82 private: | |
| 83 // content::TestMessageHandler: | |
| 84 MessageResponse HandleMessage(const std::string& json) override; | |
| 85 void Reset() override; | |
| 86 | |
| 87 // The message received. Note that this will be JSON, so if it is a string, | |
| 88 // it will be wrapped in quotes. | |
| 89 std::string message_; | |
| 90 | |
| 91 content::JavascriptTestObserver observer_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(DomMessageListener); | |
| 94 }; | |
| 95 | |
| 96 DomMessageListener::DomMessageListener(content::WebContents* web_contents) | |
| 97 : observer_(web_contents, this) { | |
| 98 } | |
| 99 | |
| 100 DomMessageListener::~DomMessageListener() { | |
| 101 } | |
| 102 | |
| 103 void DomMessageListener::Wait() { | |
| 104 observer_.Run(); | |
| 105 } | |
| 106 | |
| 107 void DomMessageListener::Clear() { | |
| 108 // We don't just call this in DomMessageListener::Reset() because the | |
| 109 // JavascriptTestObserver's Reset() method also resets its handler (this). | |
| 110 observer_.Reset(); | |
| 111 } | |
| 112 | |
| 113 content::TestMessageHandler::MessageResponse DomMessageListener::HandleMessage( | |
| 114 const std::string& json) { | |
| 115 message_ = json; | |
| 116 return DONE; | |
| 117 } | |
| 118 | |
| 119 void DomMessageListener::Reset() { | |
| 120 TestMessageHandler::Reset(); | |
| 121 message_.clear(); | |
| 122 } | |
| 123 | |
| 68 } // namespace | 124 } // namespace |
| 69 | 125 |
| 70 class CommandsApiTest : public ExtensionApiTest { | 126 class CommandsApiTest : public ExtensionApiTest { |
| 71 public: | 127 public: |
| 72 CommandsApiTest() {} | 128 CommandsApiTest() {} |
| 73 ~CommandsApiTest() override {} | 129 ~CommandsApiTest() override {} |
| 74 | 130 |
| 75 protected: | 131 protected: |
| 76 BrowserActionTestUtil GetBrowserActionsBar() { | 132 BrowserActionTestUtil GetBrowserActionsBar() { |
| 77 return BrowserActionTestUtil(browser()); | 133 return BrowserActionTestUtil(browser()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 188 |
| 133 ui_test_utils::NavigateToURL( | 189 ui_test_utils::NavigateToURL( |
| 134 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 190 browser(), test_server()->GetURL("files/extensions/test_file.txt")); |
| 135 | 191 |
| 136 // activeTab shouldn't have been granted yet. | 192 // activeTab shouldn't have been granted yet. |
| 137 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 193 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 138 ASSERT_TRUE(tab); | 194 ASSERT_TRUE(tab); |
| 139 | 195 |
| 140 EXPECT_FALSE(IsGrantedForTab(extension, tab)); | 196 EXPECT_FALSE(IsGrantedForTab(extension, tab)); |
| 141 | 197 |
| 142 // Activate the shortcut (Ctrl+Shift+F). | 198 ExtensionTestMessageListener test_listener(false); // Won't reply. |
| 199 // Activate the browser action shortcut (Ctrl+Shift+F). | |
| 143 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 200 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 144 browser(), ui::VKEY_F, true, true, false, false)); | 201 browser(), ui::VKEY_F, true, true, false, false)); |
| 145 | 202 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
| 146 // activeTab should now be granted. | 203 // activeTab should now be granted. |
| 147 EXPECT_TRUE(IsGrantedForTab(extension, tab)); | 204 EXPECT_TRUE(IsGrantedForTab(extension, tab)); |
| 205 // Verify the command worked. | |
| 206 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); | |
| 148 | 207 |
| 149 // Verify the command worked. | 208 test_listener.Reset(); |
| 150 bool result = false; | 209 // Activate the command shortcut (Ctrl+Shift+Y). |
| 151 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 152 tab, | |
| 153 "setInterval(function(){" | |
| 154 " if(document.body.bgColor == 'red'){" | |
| 155 " window.domAutomationController.send(true)}}, 100)", | |
| 156 &result)); | |
| 157 ASSERT_TRUE(result); | |
| 158 | |
| 159 // Activate the shortcut (Ctrl+Shift+Y). | |
| 160 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 210 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 161 browser(), ui::VKEY_Y, true, true, false, false)); | 211 browser(), ui::VKEY_Y, true, true, false, false)); |
| 162 | 212 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
| 163 result = false; | 213 EXPECT_EQ(std::string("basics command"), test_listener.message()); |
| 164 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 165 tab, | |
| 166 "setInterval(function(){" | |
| 167 " if(document.body.bgColor == 'blue'){" | |
| 168 " window.domAutomationController.send(true)}}, 100)", | |
| 169 &result)); | |
| 170 ASSERT_TRUE(result); | |
| 171 } | 214 } |
| 172 | 215 |
| 173 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { | 216 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { |
| 174 ASSERT_TRUE(test_server()->Start()); | 217 ASSERT_TRUE(test_server()->Start()); |
| 175 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 218 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
| 176 const Extension* extension = GetSingleLoadedExtension(); | 219 const Extension* extension = GetSingleLoadedExtension(); |
| 177 ASSERT_TRUE(extension) << message_; | 220 ASSERT_TRUE(extension) << message_; |
| 178 | 221 |
| 179 { | 222 { |
| 180 // Load a page, the extension will detect the navigation and request to show | 223 // Load a page, the extension will detect the navigation and request to show |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 IN_PROC_BROWSER_TEST_F(CommandsApiTest, DontOverwriteSystemShortcuts) { | 293 IN_PROC_BROWSER_TEST_F(CommandsApiTest, DontOverwriteSystemShortcuts) { |
| 251 ASSERT_TRUE(test_server()->Start()); | 294 ASSERT_TRUE(test_server()->Start()); |
| 252 | 295 |
| 253 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 296 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 254 | 297 |
| 255 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; | 298 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; |
| 256 | 299 |
| 257 ui_test_utils::NavigateToURL( | 300 ui_test_utils::NavigateToURL( |
| 258 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 301 browser(), test_server()->GetURL("files/extensions/test_file.txt")); |
| 259 | 302 |
| 260 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 303 // Activate the regular shortcut (Alt+Shift+F). |
| 261 ASSERT_TRUE(tab); | 304 ExtensionTestMessageListener alt_shift_f_listener("alt_shift_f", false); |
| 305 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 306 browser(), ui::VKEY_F, false, true, true, false)); | |
| 307 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); | |
| 262 | 308 |
| 263 // Activate the shortcut (Alt+Shift+F) to make the page blue. | 309 // Try to activate the bookmark shortcut (Ctrl+D). This should not work |
| 310 // without requesting via chrome_settings_overrides. | |
| 311 // | |
| 312 // Since keypresses are sent synchronously, we can check this by first sending | |
| 313 // Ctrl+D (which shouldn't work), followed by Alt+Shift+F (which should work), | |
| 314 // and listening for both. If, by the time we receive the Alt+Shift+F | |
| 315 // response, we haven't received a response for Ctrl+D, it is safe to say we | |
| 316 // won't receive one. | |
| 264 { | 317 { |
| 265 ResultCatcher catcher; | 318 ExtensionTestMessageListener ctrl_d_listener("ctrl_d", false); |
| 319 alt_shift_f_listener.Reset(); | |
| 320 // Send Ctrl+D. | |
| 321 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | |
| 322 // Send Alt+Shift+F. | |
| 266 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 323 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 267 browser(), ui::VKEY_F, false, true, true, false)); | 324 browser(), ui::VKEY_F, false, true, true, false)); |
| 268 ASSERT_TRUE(catcher.GetNextResult()); | 325 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); |
| 326 EXPECT_FALSE(ctrl_d_listener.was_satisfied()); | |
| 269 } | 327 } |
| 270 | 328 |
| 271 bool result = false; | 329 // Try to activate the Ctrl+F shortcut (shouldn't work). |
| 272 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 330 { |
| 273 tab, | 331 ExtensionTestMessageListener ctrl_f_listener("ctrl_f", false); |
| 274 "setInterval(function() {" | 332 alt_shift_f_listener.Reset(); |
| 275 " if (document.body.bgColor == 'blue') {" | 333 // Send Ctrl+F. |
| 276 " window.domAutomationController.send(true)}}, 100)", | 334 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 277 &result)); | 335 browser(), ui::VKEY_F, true, false, false, false)); |
| 278 ASSERT_TRUE(result); | 336 // Send Alt+Shift+F. |
| 279 | 337 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 280 // Activate the bookmark shortcut (Ctrl+D) to make the page green (should not | 338 browser(), ui::VKEY_F, false, true, true, false)); |
| 281 // work without requesting via chrome_settings_overrides). | 339 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); |
| 282 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 340 EXPECT_FALSE(ctrl_f_listener.was_satisfied()); |
| 283 | 341 } |
| 284 // The page should still be blue. | |
| 285 result = false; | |
| 286 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 287 tab, | |
| 288 "setInterval(function() {" | |
| 289 " if (document.body.bgColor == 'blue') {" | |
| 290 " window.domAutomationController.send(true)}}, 100)", | |
| 291 &result)); | |
| 292 ASSERT_TRUE(result); | |
| 293 | |
| 294 // Activate the shortcut (Ctrl+F) to make the page red (should not work). | |
| 295 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 296 browser(), ui::VKEY_F, true, false, false, false)); | |
| 297 | |
| 298 // The page should still be blue. | |
| 299 result = false; | |
| 300 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 301 tab, | |
| 302 "setInterval(function() {" | |
| 303 " if (document.body.bgColor == 'blue') {" | |
| 304 " window.domAutomationController.send(true)}}, 100)", | |
| 305 &result)); | |
| 306 ASSERT_TRUE(result); | |
| 307 } | 342 } |
| 308 | 343 |
| 309 // This test validates that an extension can remove the Chrome bookmark shortcut | 344 // This test validates that an extension can remove the Chrome bookmark shortcut |
| 310 // if it has requested to do so. | 345 // if it has requested to do so. |
| 311 IN_PROC_BROWSER_TEST_F(CommandsApiTest, RemoveBookmarkShortcut) { | 346 IN_PROC_BROWSER_TEST_F(CommandsApiTest, RemoveBookmarkShortcut) { |
| 312 ASSERT_TRUE(test_server()->Start()); | 347 ASSERT_TRUE(test_server()->Start()); |
| 313 | 348 |
| 314 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 349 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 315 | 350 |
| 316 // This functionality requires a feature flag. | 351 // This functionality requires a feature flag. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 // This functionality requires a feature flag. | 412 // This functionality requires a feature flag. |
| 378 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 413 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 379 "--enable-override-bookmarks-ui", "1"); | 414 "--enable-override-bookmarks-ui", "1"); |
| 380 | 415 |
| 381 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 416 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
| 382 << message_; | 417 << message_; |
| 383 | 418 |
| 384 ui_test_utils::NavigateToURL( | 419 ui_test_utils::NavigateToURL( |
| 385 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 420 browser(), test_server()->GetURL("files/extensions/test_file.txt")); |
| 386 | 421 |
| 387 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 422 // Activate the shortcut (Ctrl+D) to send a test message. |
| 388 ASSERT_TRUE(tab); | 423 ExtensionTestMessageListener test_listener(false); // Won't reply. |
| 389 | 424 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
| 390 // Activate the shortcut (Ctrl+D) to make the page green. | 425 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
| 391 { | 426 EXPECT_EQ(std::string(kOverwriteBookmarkShortcutCommandName), |
| 392 ResultCatcher catcher; | 427 test_listener.message()); |
| 393 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | |
| 394 ASSERT_TRUE(catcher.GetNextResult()); | |
| 395 } | |
| 396 | |
| 397 bool result = false; | |
| 398 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 399 tab, | |
| 400 std::string("setInterval(function() {") + | |
| 401 " if (document.body.bgColor == '" + | |
| 402 kOverwriteBookmarkShortcutCommandColor + "') {" + | |
| 403 " window.domAutomationController.send(true)}}, 100)", | |
| 404 &result)); | |
| 405 ASSERT_TRUE(result); | |
| 406 } | 428 } |
| 407 | 429 |
| 408 // This test validates that an extension that requests to override the Chrome | 430 // This test validates that an extension that requests to override the Chrome |
| 409 // bookmark shortcut, but does not get the keybinding, does not remove the | 431 // bookmark shortcut, but does not get the keybinding, does not remove the |
| 410 // bookmark UI. | 432 // bookmark UI. |
| 411 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 433 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
| 412 OverwriteBookmarkShortcutWithoutKeybinding) { | 434 OverwriteBookmarkShortcutWithoutKeybinding) { |
| 413 // This functionality requires a feature flag. | 435 // This functionality requires a feature flag. |
| 414 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 436 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 415 "--enable-override-bookmarks-ui", "1"); | 437 "--enable-override-bookmarks-ui", "1"); |
| 416 | 438 |
| 417 ASSERT_TRUE(test_server()->Start()); | 439 ASSERT_TRUE(test_server()->Start()); |
| 418 | 440 |
| 419 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 441 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
| 420 | 442 |
| 421 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 443 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
| 422 << message_; | 444 << message_; |
| 423 | 445 |
| 424 const Extension* extension = GetSingleLoadedExtension(); | 446 const Extension* extension = GetSingleLoadedExtension(); |
| 425 CommandService* command_service = CommandService::Get(browser()->profile()); | 447 CommandService* command_service = CommandService::Get(browser()->profile()); |
| 426 CommandMap commands; | 448 CommandMap commands; |
| 427 // Verify the expected command is present. | 449 // Verify the expected command is present. |
| 428 EXPECT_TRUE(command_service->GetNamedCommands( | 450 EXPECT_TRUE(command_service->GetNamedCommands( |
| 429 extension->id(), CommandService::SUGGESTED, CommandService::ANY_SCOPE, | 451 extension->id(), CommandService::SUGGESTED, CommandService::ANY_SCOPE, |
| 430 &commands)); | 452 &commands)); |
| 431 EXPECT_EQ(1u, commands.count(kOverwriteBookmarkShortcutCommandColor)); | 453 EXPECT_EQ(1u, commands.count(kOverwriteBookmarkShortcutCommandName)); |
| 432 | 454 |
| 433 // Simulate the user removing the Ctrl+D keybinding from the command. | 455 // Simulate the user removing the Ctrl+D keybinding from the command. |
| 434 command_service->RemoveKeybindingPrefs( | 456 command_service->RemoveKeybindingPrefs( |
| 435 extension->id(), kOverwriteBookmarkShortcutCommandColor); | 457 extension->id(), kOverwriteBookmarkShortcutCommandName); |
| 436 | 458 |
| 437 // Force the command enable state to be recalculated. | 459 // Force the command enable state to be recalculated. |
| 438 browser()->command_controller()->ExtensionStateChanged(); | 460 browser()->command_controller()->ExtensionStateChanged(); |
| 439 | 461 |
| 440 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 462 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
| 441 } | 463 } |
| 442 | 464 |
| 443 // This test validates that an extension override of the Chrome bookmark | 465 // This test validates that an extension override of the Chrome bookmark |
| 444 // shortcut does not supersede the same keybinding by web pages. | 466 // shortcut does not supersede the same keybinding by web pages. |
| 445 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 467 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 456 << message_; | 478 << message_; |
| 457 | 479 |
| 458 ui_test_utils::NavigateToURL( | 480 ui_test_utils::NavigateToURL( |
| 459 browser(), | 481 browser(), |
| 460 test_server()->GetURL( | 482 test_server()->GetURL( |
| 461 "files/extensions/test_file_with_ctrl-d_keybinding.html")); | 483 "files/extensions/test_file_with_ctrl-d_keybinding.html")); |
| 462 | 484 |
| 463 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 485 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 464 ASSERT_TRUE(tab); | 486 ASSERT_TRUE(tab); |
| 465 | 487 |
| 466 // Activate the shortcut (Ctrl+D) which should be handled by the page and make | 488 // Activate the shortcut (Ctrl+D) which should be handled by the page and send |
| 467 // the background color magenta. | 489 // a test message. |
| 490 DomMessageListener listener(tab); | |
| 468 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 491 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
| 469 | 492 listener.Wait(); |
| 470 bool result = false; | 493 EXPECT_EQ(std::string("\"web page received\""), listener.message()); |
| 471 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 472 tab, | |
| 473 "setInterval(function() {" | |
| 474 " if (document.body.bgColor == 'magenta') {" | |
| 475 " window.domAutomationController.send(true)}}, 100)", | |
| 476 &result)); | |
| 477 ASSERT_TRUE(result); | |
| 478 } | 494 } |
| 479 | 495 |
| 480 // This test validates that user-set override of the Chrome bookmark shortcut in | 496 // This test validates that user-set override of the Chrome bookmark shortcut in |
| 481 // an extension that does not request it does supersede the same keybinding by | 497 // an extension that does not request it does supersede the same keybinding by |
| 482 // web pages. | 498 // web pages. |
| 483 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 499 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
| 484 OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { | 500 OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { |
| 485 ASSERT_TRUE(test_server()->Start()); | 501 ASSERT_TRUE(test_server()->Start()); |
| 486 | 502 |
| 487 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 503 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 499 // Simulate the user setting the keybinding to Ctrl+D. | 515 // Simulate the user setting the keybinding to Ctrl+D. |
| 500 command_service->UpdateKeybindingPrefs( | 516 command_service->UpdateKeybindingPrefs( |
| 501 extension->id(), manifest_values::kBrowserActionCommandEvent, | 517 extension->id(), manifest_values::kBrowserActionCommandEvent, |
| 502 kBookmarkKeybinding); | 518 kBookmarkKeybinding); |
| 503 | 519 |
| 504 ui_test_utils::NavigateToURL( | 520 ui_test_utils::NavigateToURL( |
| 505 browser(), | 521 browser(), |
| 506 test_server()->GetURL( | 522 test_server()->GetURL( |
| 507 "files/extensions/test_file_with_ctrl-d_keybinding.html")); | 523 "files/extensions/test_file_with_ctrl-d_keybinding.html")); |
| 508 | 524 |
| 509 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 525 ExtensionTestMessageListener test_listener(false); // Won't reply. |
| 510 ASSERT_TRUE(tab); | 526 // Activate the shortcut (Ctrl+D) which should be handled by the extension. |
| 511 | |
| 512 // Activate the shortcut (Ctrl+D) which should be handled by the extension and | |
| 513 // make the background color red. | |
| 514 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 527 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
| 515 | 528 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
| 516 bool result = false; | 529 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); |
| 517 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 518 tab, | |
| 519 "setInterval(function() {" | |
| 520 " if (document.body.bgColor == 'red') {" | |
| 521 " window.domAutomationController.send(true)}}, 100)", | |
| 522 &result)); | |
| 523 ASSERT_TRUE(result); | |
| 524 } | 530 } |
| 525 | 531 |
| 526 #if defined(OS_WIN) | 532 #if defined(OS_WIN) |
| 527 // Currently this feature is implemented on Windows only. | 533 // Currently this feature is implemented on Windows only. |
| 528 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys | 534 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys |
| 529 #else | 535 #else |
| 530 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys | 536 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys |
| 531 #endif | 537 #endif |
| 532 | 538 |
| 533 // Test that media keys go to all extensions that register for them. | 539 // Test that media keys go to all extensions that register for them. |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 #define MAYBE_ChromeOSConversions DISABLED_ChromeOSConversions | 948 #define MAYBE_ChromeOSConversions DISABLED_ChromeOSConversions |
| 943 #else | 949 #else |
| 944 #define MAYBE_ChromeOSConversions ChromeOSConversions | 950 #define MAYBE_ChromeOSConversions ChromeOSConversions |
| 945 #endif | 951 #endif |
| 946 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) { | 952 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) { |
| 947 RunChromeOSConversionTest("keybinding/chromeos_conversions"); | 953 RunChromeOSConversionTest("keybinding/chromeos_conversions"); |
| 948 } | 954 } |
| 949 #endif // OS_CHROMEOS | 955 #endif // OS_CHROMEOS |
| 950 | 956 |
| 951 } // namespace extensions | 957 } // namespace extensions |
| OLD | NEW |