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 "chrome/browser/extensions/active_tab_permission_granter.h" | 6 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
6 #include "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.h" |
7 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
8 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
11 #include "chrome/browser/sessions/session_tab_helper.h" | 12 #include "chrome/browser/sessions/session_tab_helper.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/test/base/interactive_test_utils.h" | 15 #include "chrome/test/base/interactive_test_utils.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 182 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
182 | 183 |
183 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; | 184 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; |
184 | 185 |
185 ui_test_utils::NavigateToURL(browser(), | 186 ui_test_utils::NavigateToURL(browser(), |
186 test_server()->GetURL("files/extensions/test_file.txt")); | 187 test_server()->GetURL("files/extensions/test_file.txt")); |
187 | 188 |
188 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 189 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
189 ASSERT_TRUE(tab); | 190 ASSERT_TRUE(tab); |
190 | 191 |
191 // Activate the shortcut (Alt+Shift+F) to make page blue. | 192 // Activate the shortcut (Alt+Shift+F) to make the page blue. |
192 { | 193 { |
193 ResultCatcher catcher; | 194 ResultCatcher catcher; |
194 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 195 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
195 browser(), ui::VKEY_F, false, true, true, false)); | 196 browser(), ui::VKEY_F, false, true, true, false)); |
196 ASSERT_TRUE(catcher.GetNextResult()); | 197 ASSERT_TRUE(catcher.GetNextResult()); |
197 } | 198 } |
198 | 199 |
199 bool result = false; | 200 bool result = false; |
200 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 201 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
201 tab, | 202 tab, |
202 "setInterval(function() {" | 203 "setInterval(function() {" |
203 " if (document.body.bgColor == 'blue') {" | 204 " if (document.body.bgColor == 'blue') {" |
204 " window.domAutomationController.send(true)}}, 100)", | 205 " window.domAutomationController.send(true)}}, 100)", |
205 &result)); | 206 &result)); |
206 ASSERT_TRUE(result); | 207 ASSERT_TRUE(result); |
207 | 208 |
208 // Activate the shortcut (Ctrl+F) to make page red (should not work). | 209 // Activate the bookmark shortcut (Ctrl+D) to make the page green (should not |
| 210 // work without requesting via chrome_settings_overrides). |
| 211 #if defined(OS_MACOSX) |
| 212 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 213 browser(), ui::VKEY_D, false, false, false, true)); |
| 214 #else |
| 215 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 216 browser(), ui::VKEY_D, true, false, false, false)); |
| 217 #endif |
| 218 |
| 219 // The page should still be blue. |
| 220 result = false; |
| 221 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 222 tab, |
| 223 "setInterval(function() {" |
| 224 " if (document.body.bgColor == 'blue') {" |
| 225 " window.domAutomationController.send(true)}}, 100)", |
| 226 &result)); |
| 227 ASSERT_TRUE(result); |
| 228 |
| 229 // Activate the shortcut (Ctrl+F) to make the page red (should not work). |
209 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 230 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
210 browser(), ui::VKEY_F, true, false, false, false)); | 231 browser(), ui::VKEY_F, true, false, false, false)); |
211 | 232 |
212 // The page should still be blue. | 233 // The page should still be blue. |
213 result = false; | 234 result = false; |
214 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 235 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
215 tab, | 236 tab, |
216 "setInterval(function() {" | 237 "setInterval(function() {" |
217 " if (document.body.bgColor == 'blue') {" | 238 " if (document.body.bgColor == 'blue') {" |
218 " window.domAutomationController.send(true)}}, 100)", | 239 " window.domAutomationController.send(true)}}, 100)", |
219 &result)); | 240 &result)); |
220 ASSERT_TRUE(result); | 241 ASSERT_TRUE(result); |
221 } | 242 } |
222 | 243 |
| 244 // This test validates that an extension can override the Chrome bookmark |
| 245 // shortcut if it has requested to do so. |
| 246 IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) { |
| 247 ASSERT_TRUE(test_server()->Start()); |
| 248 |
| 249 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 250 |
| 251 // This functionality requires a feature flag. |
| 252 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 253 "--enable-override-bookmarks-ui", |
| 254 "1"); |
| 255 |
| 256 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
| 257 << message_; |
| 258 |
| 259 ui_test_utils::NavigateToURL(browser(), |
| 260 test_server()->GetURL("files/extensions/test_file.txt")); |
| 261 |
| 262 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 263 ASSERT_TRUE(tab); |
| 264 |
| 265 // Activate the shortcut (Ctrl+D) to make the page green. |
| 266 { |
| 267 ResultCatcher catcher; |
| 268 #if defined(OS_MACOSX) |
| 269 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 270 browser(), ui::VKEY_D, false, false, false, true)); |
| 271 #else |
| 272 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| 273 browser(), ui::VKEY_D, true, false, false, false)); |
| 274 #endif |
| 275 ASSERT_TRUE(catcher.GetNextResult()); |
| 276 } |
| 277 |
| 278 bool result = false; |
| 279 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 280 tab, |
| 281 "setInterval(function() {" |
| 282 " if (document.body.bgColor == 'green') {" |
| 283 " window.domAutomationController.send(true)}}, 100)", |
| 284 &result)); |
| 285 ASSERT_TRUE(result); |
| 286 } |
| 287 |
223 #if defined(OS_WIN) | 288 #if defined(OS_WIN) |
224 // Currently this feature is implemented on Windows only. | 289 // Currently this feature is implemented on Windows only. |
225 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys | 290 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys |
226 #else | 291 #else |
227 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys | 292 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys |
228 #endif | 293 #endif |
229 | 294 |
230 // Test that media keys go to all extensions that register for them. | 295 // Test that media keys go to all extensions that register for them. |
231 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { | 296 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { |
232 ResultCatcher catcher; | 297 ResultCatcher catcher; |
233 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0")) | 298 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0")) |
234 << message_; | 299 << message_; |
235 ASSERT_TRUE(catcher.GetNextResult()); | 300 ASSERT_TRUE(catcher.GetNextResult()); |
236 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1")) | 301 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1")) |
237 << message_; | 302 << message_; |
238 ASSERT_TRUE(catcher.GetNextResult()); | 303 ASSERT_TRUE(catcher.GetNextResult()); |
239 | 304 |
240 // Activate the Media Stop key. | 305 // Activate the Media Stop key. |
241 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 306 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
242 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false)); | 307 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false)); |
243 | 308 |
244 // We should get two success result. | 309 // We should get two success result. |
245 ASSERT_TRUE(catcher.GetNextResult()); | 310 ASSERT_TRUE(catcher.GetNextResult()); |
246 ASSERT_TRUE(catcher.GetNextResult()); | 311 ASSERT_TRUE(catcher.GetNextResult()); |
247 } | 312 } |
248 | 313 |
249 } // namespace extensions | 314 } // namespace extensions |
OLD | NEW |