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 } |
| 43 virtual ~ScriptBadgesCommandsApiTest() {} |
| 44 }; |
| 45 |
35 #if !defined(OS_MACOSX) | 46 #if !defined(OS_MACOSX) |
36 // Test the basic functionality of the Keybinding API: | 47 // Test the basic functionality of the Keybinding API: |
37 // - That pressing the shortcut keys should perform actions (activate the | 48 // - That pressing the shortcut keys should perform actions (activate the |
38 // browser action or send an event). | 49 // browser action or send an event). |
39 // - Note: Page action keybindings are tested in PageAction test below. | 50 // - Note: Page action keybindings are tested in PageAction test below. |
40 // - The shortcut keys taken by one extension are not overwritten by the last | 51 // - The shortcut keys taken by one extension are not overwritten by the last |
41 // installed extension. | 52 // installed extension. |
42 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, Basic) { | 53 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { |
43 ASSERT_TRUE(test_server()->Start()); | 54 ASSERT_TRUE(test_server()->Start()); |
44 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; | 55 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; |
45 const extensions::Extension* extension = GetSingleLoadedExtension(); | 56 const extensions::Extension* extension = GetSingleLoadedExtension(); |
46 ASSERT_TRUE(extension) << message_; | 57 ASSERT_TRUE(extension) << message_; |
47 | 58 |
48 // Load this extension, which uses the same keybindings but sets the page | 59 // 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 | 60 // 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 | 61 // don't test this extension in any other way (it should otherwise be |
51 // immaterial to this test). | 62 // immaterial to this test). |
52 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; | 63 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; |
(...skipping 26 matching lines...) Expand all Loading... |
79 result = false; | 90 result = false; |
80 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 91 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
81 tab->GetRenderViewHost(), L"", | 92 tab->GetRenderViewHost(), L"", |
82 L"setInterval(function(){" | 93 L"setInterval(function(){" |
83 L" if(document.body.bgColor == 'blue'){" | 94 L" if(document.body.bgColor == 'blue'){" |
84 L" window.domAutomationController.send(true)}}, 100)", | 95 L" window.domAutomationController.send(true)}}, 100)", |
85 &result)); | 96 &result)); |
86 ASSERT_TRUE(result); | 97 ASSERT_TRUE(result); |
87 } | 98 } |
88 | 99 |
89 IN_PROC_BROWSER_TEST_F(KeybindingApiTest, PageAction) { | 100 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { |
90 ASSERT_TRUE(test_server()->Start()); | 101 ASSERT_TRUE(test_server()->Start()); |
91 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 102 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
92 const extensions::Extension* extension = GetSingleLoadedExtension(); | 103 const extensions::Extension* extension = GetSingleLoadedExtension(); |
93 ASSERT_TRUE(extension) << message_; | 104 ASSERT_TRUE(extension) << message_; |
94 | 105 |
95 { | 106 { |
96 // Load a page, the extension will detect the navigation and request to show | 107 // Load a page, the extension will detect the navigation and request to show |
97 // the page action icon. | 108 // the page action icon. |
98 ResultCatcher catcher; | 109 ResultCatcher catcher; |
99 ui_test_utils::NavigateToURL(browser(), | 110 ui_test_utils::NavigateToURL(browser(), |
(...skipping 18 matching lines...) Expand all Loading... |
118 bool result = false; | 129 bool result = false; |
119 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 130 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
120 tab->GetRenderViewHost(), L"", | 131 tab->GetRenderViewHost(), L"", |
121 L"setInterval(function(){" | 132 L"setInterval(function(){" |
122 L" if(document.body.bgColor == 'red'){" | 133 L" if(document.body.bgColor == 'red'){" |
123 L" window.domAutomationController.send(true)}}, 100)", | 134 L" window.domAutomationController.send(true)}}, 100)", |
124 &result)); | 135 &result)); |
125 ASSERT_TRUE(result); | 136 ASSERT_TRUE(result); |
126 } | 137 } |
127 | 138 |
| 139 // Checked-in in a disabled state, because the necessary functionality to |
| 140 // automatically verify that the test works hasn't been implemented for the |
| 141 // script badges yet (see http://crbug.com/140016). The test results, can be |
| 142 // verified manually by running the test and verifying that the synthesized |
| 143 // popup for script badges appear. When bug 140016 has been fixed, the popup |
| 144 // code can signal to the test that the test passed. |
| 145 // TODO(finnur): Enable this test once the bug is fixed. |
| 146 IN_PROC_BROWSER_TEST_F(ScriptBadgesCommandsApiTest, ScriptBadge_DISABLED) { |
| 147 ASSERT_TRUE(test_server()->Start()); |
| 148 ASSERT_TRUE(RunExtensionTest("keybinding/script_badge")) << message_; |
| 149 const extensions::Extension* extension = GetSingleLoadedExtension(); |
| 150 ASSERT_TRUE(extension) << message_; |
| 151 |
| 152 { |
| 153 ResultCatcher catcher; |
| 154 // Tell the extension to update the script badge state. |
| 155 ui_test_utils::NavigateToURL( |
| 156 browser(), GURL(extension->GetResourceURL("show.html"))); |
| 157 ASSERT_TRUE(catcher.GetNextResult()); |
| 158 } |
| 159 |
| 160 { |
| 161 ResultCatcher catcher; |
| 162 // Activate the shortcut (Ctrl+Shift+F). |
| 163 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 164 browser(), ui::VKEY_F, true, true, false, false)); |
| 165 ASSERT_TRUE(catcher.GetNextResult()); |
| 166 } |
| 167 } |
| 168 |
128 #endif // !OS_MACOSX | 169 #endif // !OS_MACOSX |
OLD | NEW |