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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
209 // Activate the bookmark shortcut (Ctrl+D) to make page green (should not work | |
Finnur
2014/02/10 10:14:18
nit: the page
Mike Wittman
2014/02/11 23:09:45
Done.
| |
210 // without requesting via chrome_settings_overrides). | |
211 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
212 browser(), ui::VKEY_D, true, false, false, false)); | |
213 | |
214 // The page should still be blue. | |
215 result = false; | |
216 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
217 tab, | |
218 "setInterval(function() {" | |
219 " if (document.body.bgColor == 'blue') {" | |
220 " window.domAutomationController.send(true)}}, 100)", | |
221 &result)); | |
222 ASSERT_TRUE(result); | |
223 | |
208 // Activate the shortcut (Ctrl+F) to make page red (should not work). | 224 // Activate the shortcut (Ctrl+F) to make page red (should not work). |
209 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 225 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
210 browser(), ui::VKEY_F, true, false, false, false)); | 226 browser(), ui::VKEY_F, true, false, false, false)); |
211 | 227 |
212 // The page should still be blue. | 228 // The page should still be blue. |
213 result = false; | 229 result = false; |
214 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 230 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
215 tab, | 231 tab, |
216 "setInterval(function() {" | 232 "setInterval(function() {" |
217 " if (document.body.bgColor == 'blue') {" | 233 " if (document.body.bgColor == 'blue') {" |
218 " window.domAutomationController.send(true)}}, 100)", | 234 " window.domAutomationController.send(true)}}, 100)", |
219 &result)); | 235 &result)); |
220 ASSERT_TRUE(result); | 236 ASSERT_TRUE(result); |
221 } | 237 } |
222 | 238 |
239 // This test validates that an extension can override the Chrome bookmark | |
240 // shortcut if it has requested to do so. | |
241 IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) { | |
242 ASSERT_TRUE(test_server()->Start()); | |
243 | |
244 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
245 | |
246 // This functionality requires a feature flag. | |
247 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
248 "--enable-override-bookmarks-ui", | |
249 "1"); | |
250 | |
251 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | |
252 << message_; | |
253 | |
254 ui_test_utils::NavigateToURL(browser(), | |
255 test_server()->GetURL("files/extensions/test_file.txt")); | |
256 | |
257 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
258 ASSERT_TRUE(tab); | |
259 | |
260 // Activate the shortcut (Ctrl+D) to make page green. | |
261 { | |
262 ResultCatcher catcher; | |
263 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | |
264 browser(), ui::VKEY_D, true, false, false, false)); | |
265 ASSERT_TRUE(catcher.GetNextResult()); | |
266 } | |
267 | |
268 bool result = false; | |
269 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
270 tab, | |
271 "setInterval(function() {" | |
272 " if (document.body.bgColor == 'green') {" | |
273 " window.domAutomationController.send(true)}}, 100)", | |
274 &result)); | |
275 ASSERT_TRUE(result); | |
276 } | |
277 | |
223 #if defined(OS_WIN) | 278 #if defined(OS_WIN) |
224 // Currently this feature is implemented on Windows only. | 279 // Currently this feature is implemented on Windows only. |
225 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys | 280 #define MAYBE_AllowDuplicatedMediaKeys AllowDuplicatedMediaKeys |
226 #else | 281 #else |
227 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys | 282 #define MAYBE_AllowDuplicatedMediaKeys DISABLED_AllowDuplicatedMediaKeys |
228 #endif | 283 #endif |
229 | 284 |
230 // Test that media keys go to all extensions that register for them. | 285 // Test that media keys go to all extensions that register for them. |
231 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { | 286 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_AllowDuplicatedMediaKeys) { |
232 ResultCatcher catcher; | 287 ResultCatcher catcher; |
233 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0")) | 288 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_0")) |
234 << message_; | 289 << message_; |
235 ASSERT_TRUE(catcher.GetNextResult()); | 290 ASSERT_TRUE(catcher.GetNextResult()); |
236 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1")) | 291 ASSERT_TRUE(RunExtensionTest("keybinding/non_global_media_keys_1")) |
237 << message_; | 292 << message_; |
238 ASSERT_TRUE(catcher.GetNextResult()); | 293 ASSERT_TRUE(catcher.GetNextResult()); |
239 | 294 |
240 // Activate the Media Stop key. | 295 // Activate the Media Stop key. |
241 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 296 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
242 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false)); | 297 browser(), ui::VKEY_MEDIA_STOP, false, false, false, false)); |
243 | 298 |
244 // We should get two success result. | 299 // We should get two success result. |
245 ASSERT_TRUE(catcher.GetNextResult()); | 300 ASSERT_TRUE(catcher.GetNextResult()); |
246 ASSERT_TRUE(catcher.GetNextResult()); | 301 ASSERT_TRUE(catcher.GetNextResult()); |
247 } | 302 } |
248 | 303 |
249 } // namespace extensions | 304 } // namespace extensions |
OLD | NEW |