| 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 "chrome/browser/extensions/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 7 #include "chrome/browser/sessions/restore_tab_helper.h" | 7 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | 9 #include "chrome/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_action.h" | 13 #include "chrome/common/extensions/extension_action.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 | 18 |
| 19 using content::WebContents; | 19 using content::WebContents; |
| 20 | 20 |
| 21 class KeybindingApiTest : public ExtensionApiTest { | 21 class CommandsApiTest : public ExtensionApiTest { |
| 22 public: | 22 public: |
| 23 KeybindingApiTest() { | 23 CommandsApiTest() { |
| 24 CommandLine::ForCurrentProcess()->AppendSwitch( | 24 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 25 switches::kEnableExperimentalExtensionApis); | 25 switches::kEnableExperimentalExtensionApis); |
| 26 } | 26 } |
| 27 virtual ~KeybindingApiTest() {} | 27 virtual ~CommandsApiTest() {} |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 BrowserActionTestUtil GetBrowserActionsBar() { | 30 BrowserActionTestUtil GetBrowserActionsBar() { |
| 31 return BrowserActionTestUtil(browser()); | 31 return BrowserActionTestUtil(browser()); |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class ScriptBadgesCommandsApiTest : public ExtensionApiTest { |
| 36 public: |
| 37 ScriptBadgesCommandsApiTest() { |
| 38 // We cannot add this to CommandsApiTest because then PageActions get |
| 39 // treated like BrowserActions and the PageAction test starts failing. |
| 40 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 41 switches::kEnableScriptBadges); |
| 42 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 43 switches::kEnableExperimentalExtensionApis); |
| 44 } |
| 45 virtual ~ScriptBadgesCommandsApiTest() {} |
| 46 }; |
| 47 |
| 35 #if !defined(OS_MACOSX) | 48 #if !defined(OS_MACOSX) |
| 36 // Test the basic functionality of the Keybinding API: | 49 // Test the basic functionality of the Keybinding API: |
| 37 // - That pressing the shortcut keys should perform actions (activate the | 50 // - That pressing the shortcut keys should perform actions (activate the |
| 38 // browser action or send an event). | 51 // browser action or send an event). |
| 39 // - Note: Page action keybindings are tested in PageAction test below. | 52 // - Note: Page action keybindings are tested in PageAction test below. |
| 40 // - The shortcut keys taken by one extension are not overwritten by the last | 53 // - The shortcut keys taken by one extension are not overwritten by the last |
| 41 // installed extension. | 54 // installed extension. |
| 42 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) { | 55 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { |
| 43 ASSERT_TRUE(test_server()->Start()); | 56 ASSERT_TRUE(test_server()->Start()); |
| 44 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; | 57 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; |
| 45 const extensions::Extension* extension = GetSingleLoadedExtension(); | 58 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 46 ASSERT_TRUE(extension) << message_; | 59 ASSERT_TRUE(extension) << message_; |
| 47 | 60 |
| 48 // Load this extension, which uses the same keybindings but sets the page | 61 // Load this extension, which uses the same keybindings but sets the page |
| 49 // to different colors. This is so we can see that it doesn't interfere. We | 62 // to different colors. This is so we can see that it doesn't interfere. We |
| 50 // don't test this extension in any other way (it should otherwise be | 63 // don't test this extension in any other way (it should otherwise be |
| 51 // immaterial to this test). | 64 // immaterial to this test). |
| 52 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; | 65 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 79 result = false; | 92 result = false; |
| 80 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 93 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 81 tab->GetRenderViewHost(), L"", | 94 tab->GetRenderViewHost(), L"", |
| 82 L"setInterval(function(){" | 95 L"setInterval(function(){" |
| 83 L" if(document.body.bgColor == 'blue'){" | 96 L" if(document.body.bgColor == 'blue'){" |
| 84 L" window.domAutomationController.send(true)}}, 100)", | 97 L" window.domAutomationController.send(true)}}, 100)", |
| 85 &result)); | 98 &result)); |
| 86 ASSERT_TRUE(result); | 99 ASSERT_TRUE(result); |
| 87 } | 100 } |
| 88 | 101 |
| 89 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, PageAction) { | 102 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { |
| 90 ASSERT_TRUE(test_server()->Start()); | 103 ASSERT_TRUE(test_server()->Start()); |
| 91 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 104 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
| 92 const extensions::Extension* extension = GetSingleLoadedExtension(); | 105 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 93 ASSERT_TRUE(extension) << message_; | 106 ASSERT_TRUE(extension) << message_; |
| 94 | 107 |
| 95 { | 108 { |
| 96 // Load a page, the extension will detect the navigation and request to show | 109 // Load a page, the extension will detect the navigation and request to show |
| 97 // the page action icon. | 110 // the page action icon. |
| 98 ResultCatcher catcher; | 111 ResultCatcher catcher; |
| 99 ui_test_utils::NavigateToURL(browser(), | 112 ui_test_utils::NavigateToURL(browser(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 118 bool result = false; | 131 bool result = false; |
| 119 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 132 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 120 tab->GetRenderViewHost(), L"", | 133 tab->GetRenderViewHost(), L"", |
| 121 L"setInterval(function(){" | 134 L"setInterval(function(){" |
| 122 L" if(document.body.bgColor == 'red'){" | 135 L" if(document.body.bgColor == 'red'){" |
| 123 L" window.domAutomationController.send(true)}}, 100)", | 136 L" window.domAutomationController.send(true)}}, 100)", |
| 124 &result)); | 137 &result)); |
| 125 ASSERT_TRUE(result); | 138 ASSERT_TRUE(result); |
| 126 } | 139 } |
| 127 | 140 |
| 141 // Checked-in in a disabled state, because the necessary functionality to |
| 142 // automatically verify that the test works hasn't been implemented for the |
| 143 // script badges yet (see http://crbug.com/140016). The test results, can be |
| 144 // verified manually by running the test and verifying that the synthesized |
| 145 // popup for script badges appear. When bug 140016 has been fixed, the popup |
| 146 // code can signal to the test that the test passed. |
| 147 // TODO(finnur): Enable this test once the bug is fixed. |
| 148 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) { |
| 149 ASSERT_TRUE(test_server()->Start()); |
| 150 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_; |
| 151 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 152 ASSERT_TRUE(extension) << message_; |
| 153 |
| 154 { |
| 155 ResultCatcher catcher; |
| 156 // Tell the extension to update the script badge state. |
| 157 ui_test_utils::NavigateToURL( |
| 158 browser(), GURL(extension->GetResourceURL("show.html"))); |
| 159 ASSERT_TRUE(catcher.GetNextResult()); |
| 160 } |
| 161 |
| 162 { |
| 163 ResultCatcher catcher; |
| 164 // Activate the shortcut (Ctrl+Shift+F). |
| 165 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 166 browser(), ui::VKEY_F, true, true, false, false)); |
| 167 ASSERT_TRUE(catcher.GetNextResult()); |
| 168 } |
| 169 } |
| 170 |
| 128 #endif // !OS_MACOSX | 171 #endif // !OS_MACOSX |
| OLD | NEW |