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