| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 protected: | 47 protected: |
| 48 BrowserActionTestUtil GetBrowserActionsBar() { | 48 BrowserActionTestUtil GetBrowserActionsBar() { |
| 49 return BrowserActionTestUtil(browser()); | 49 return BrowserActionTestUtil(browser()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool IsGrantedForTab(const Extension* extension, | 52 bool IsGrantedForTab(const Extension* extension, |
| 53 const content::WebContents* web_contents) { | 53 const content::WebContents* web_contents) { |
| 54 return extension->permissions_data()->HasAPIPermissionForTab( | 54 return extension->permissions_data()->HasAPIPermissionForTab( |
| 55 SessionTabHelper::IdForTab(web_contents), APIPermission::kTab); | 55 SessionTabHelper::IdForTab(web_contents), APIPermission::kTab); |
| 56 } | 56 } |
| 57 | |
| 58 #if defined(OS_CHROMEOS) | |
| 59 void RunChromeOSConversionTest(const std::string& extension_path) { | |
| 60 // Setup the environment. | |
| 61 ASSERT_TRUE(test_server()->Start()); | |
| 62 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 63 ASSERT_TRUE(RunExtensionTest(extension_path)) << message_; | |
| 64 ui_test_utils::NavigateToURL( | |
| 65 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | |
| 66 | |
| 67 ResultCatcher catcher; | |
| 68 | |
| 69 // Send all expected keys (Search+Shift+{Left, Up, Right, Down}). | |
| 70 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 71 browser(), ui::VKEY_LEFT, false, true, false, true)); | |
| 72 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 73 browser(), ui::VKEY_UP, false, true, false, true)); | |
| 74 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 75 browser(), ui::VKEY_RIGHT, false, true, false, true)); | |
| 76 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
| 77 browser(), ui::VKEY_DOWN, false, true, false, true)); | |
| 78 | |
| 79 ASSERT_TRUE(catcher.GetNextResult()); | |
| 80 } | |
| 81 #endif // OS_CHROMEOS | |
| 82 }; | 57 }; |
| 83 | 58 |
| 84 // Test the basic functionality of the Keybinding API: | 59 // Test the basic functionality of the Keybinding API: |
| 85 // - That pressing the shortcut keys should perform actions (activate the | 60 // - That pressing the shortcut keys should perform actions (activate the |
| 86 // browser action or send an event). | 61 // browser action or send an event). |
| 87 // - Note: Page action keybindings are tested in PageAction test below. | 62 // - Note: Page action keybindings are tested in PageAction test below. |
| 88 // - The shortcut keys taken by one extension are not overwritten by the last | 63 // - The shortcut keys taken by one extension are not overwritten by the last |
| 89 // installed extension. | 64 // installed extension. |
| 90 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { | 65 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { |
| 91 ASSERT_TRUE(test_server()->Start()); | 66 ASSERT_TRUE(test_server()->Start()); |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 browser(), ui::VKEY_F, true, true, false, false)); | 733 browser(), ui::VKEY_F, true, true, false, false)); |
| 759 ASSERT_TRUE(catcher.GetNextResult()); | 734 ASSERT_TRUE(catcher.GetNextResult()); |
| 760 | 735 |
| 761 // The extension should now have removed its |onCommand| event listener. | 736 // The extension should now have removed its |onCommand| event listener. |
| 762 // Finally, the page should again receive the key. | 737 // Finally, the page should again receive the key. |
| 763 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 738 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 764 browser(), ui::VKEY_F, true, true, false, false)); | 739 browser(), ui::VKEY_F, true, true, false, false)); |
| 765 ASSERT_TRUE(catcher.GetNextResult()); | 740 ASSERT_TRUE(catcher.GetNextResult()); |
| 766 } | 741 } |
| 767 | 742 |
| 768 // Test is only applicable on Chrome OS. | |
| 769 #if defined(OS_CHROMEOS) | |
| 770 IN_PROC_BROWSER_TEST_F(CommandsApiTest, ChromeOSConversions) { | |
| 771 RunChromeOSConversionTest("keybinding/chromeos_conversions"); | |
| 772 } | |
| 773 #endif // OS_CHROMEOS | |
| 774 | |
| 775 } // namespace extensions | 743 } // namespace extensions |
| OLD | NEW |