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/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
7 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 7 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
9 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
10 #include "chrome/browser/extensions/component_loader.h" | 10 #include "chrome/browser/extensions/component_loader.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 protected: | 135 protected: |
136 bool IsGrantedForTab(const Extension* extension, | 136 bool IsGrantedForTab(const Extension* extension, |
137 const content::WebContents* web_contents) { | 137 const content::WebContents* web_contents) { |
138 return extension->permissions_data()->HasAPIPermissionForTab( | 138 return extension->permissions_data()->HasAPIPermissionForTab( |
139 SessionTabHelper::IdForTab(web_contents), APIPermission::kTab); | 139 SessionTabHelper::IdForTab(web_contents), APIPermission::kTab); |
140 } | 140 } |
141 | 141 |
142 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
143 void RunChromeOSConversionTest(const std::string& extension_path) { | 143 void RunChromeOSConversionTest(const std::string& extension_path) { |
144 // Setup the environment. | 144 // Setup the environment. |
145 ASSERT_TRUE(test_server()->Start()); | 145 ASSERT_TRUE(embedded_test_server()->Start()); |
146 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 146 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
147 ASSERT_TRUE(RunExtensionTest(extension_path)) << message_; | 147 ASSERT_TRUE(RunExtensionTest(extension_path)) << message_; |
148 ui_test_utils::NavigateToURL( | 148 ui_test_utils::NavigateToURL( |
149 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 149 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
150 | 150 |
151 ResultCatcher catcher; | 151 ResultCatcher catcher; |
152 | 152 |
153 // Send all expected keys (Search+Shift+{Left, Up, Right, Down}). | 153 // Send all expected keys (Search+Shift+{Left, Up, Right, Down}). |
154 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 154 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
155 browser(), ui::VKEY_LEFT, false, true, false, true)); | 155 browser(), ui::VKEY_LEFT, false, true, false, true)); |
156 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 156 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
157 browser(), ui::VKEY_UP, false, true, false, true)); | 157 browser(), ui::VKEY_UP, false, true, false, true)); |
158 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 158 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
159 browser(), ui::VKEY_RIGHT, false, true, false, true)); | 159 browser(), ui::VKEY_RIGHT, false, true, false, true)); |
160 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 160 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
161 browser(), ui::VKEY_DOWN, false, true, false, true)); | 161 browser(), ui::VKEY_DOWN, false, true, false, true)); |
162 | 162 |
163 ASSERT_TRUE(catcher.GetNextResult()); | 163 ASSERT_TRUE(catcher.GetNextResult()); |
164 } | 164 } |
165 #endif // OS_CHROMEOS | 165 #endif // OS_CHROMEOS |
166 }; | 166 }; |
167 | 167 |
168 // Test the basic functionality of the Keybinding API: | 168 // Test the basic functionality of the Keybinding API: |
169 // - That pressing the shortcut keys should perform actions (activate the | 169 // - That pressing the shortcut keys should perform actions (activate the |
170 // browser action or send an event). | 170 // browser action or send an event). |
171 // - Note: Page action keybindings are tested in PageAction test below. | 171 // - Note: Page action keybindings are tested in PageAction test below. |
172 // - The shortcut keys taken by one extension are not overwritten by the last | 172 // - The shortcut keys taken by one extension are not overwritten by the last |
173 // installed extension. | 173 // installed extension. |
174 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { | 174 IN_PROC_BROWSER_TEST_F(CommandsApiTest, Basic) { |
175 ASSERT_TRUE(test_server()->Start()); | 175 ASSERT_TRUE(embedded_test_server()->Start()); |
176 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; | 176 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_; |
177 const Extension* extension = GetSingleLoadedExtension(); | 177 const Extension* extension = GetSingleLoadedExtension(); |
178 ASSERT_TRUE(extension) << message_; | 178 ASSERT_TRUE(extension) << message_; |
179 | 179 |
180 // Load this extension, which uses the same keybindings but sets the page | 180 // Load this extension, which uses the same keybindings but sets the page |
181 // to different colors. This is so we can see that it doesn't interfere. We | 181 // to different colors. This is so we can see that it doesn't interfere. We |
182 // don't test this extension in any other way (it should otherwise be | 182 // don't test this extension in any other way (it should otherwise be |
183 // immaterial to this test). | 183 // immaterial to this test). |
184 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; | 184 ASSERT_TRUE(RunExtensionTest("keybinding/conflicting")) << message_; |
185 | 185 |
186 BrowserActionTestUtil browser_actions_bar(browser()); | 186 BrowserActionTestUtil browser_actions_bar(browser()); |
187 // Test that there are two browser actions in the toolbar. | 187 // Test that there are two browser actions in the toolbar. |
188 ASSERT_EQ(2, browser_actions_bar.NumberOfBrowserActions()); | 188 ASSERT_EQ(2, browser_actions_bar.NumberOfBrowserActions()); |
189 | 189 |
190 ui_test_utils::NavigateToURL( | 190 ui_test_utils::NavigateToURL( |
191 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 191 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
192 | 192 |
193 // activeTab shouldn't have been granted yet. | 193 // activeTab shouldn't have been granted yet. |
194 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 194 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
195 ASSERT_TRUE(tab); | 195 ASSERT_TRUE(tab); |
196 | 196 |
197 EXPECT_FALSE(IsGrantedForTab(extension, tab)); | 197 EXPECT_FALSE(IsGrantedForTab(extension, tab)); |
198 | 198 |
199 ExtensionTestMessageListener test_listener(false); // Won't reply. | 199 ExtensionTestMessageListener test_listener(false); // Won't reply. |
200 // Activate the browser action shortcut (Ctrl+Shift+F). | 200 // Activate the browser action shortcut (Ctrl+Shift+F). |
201 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 201 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
202 browser(), ui::VKEY_F, true, true, false, false)); | 202 browser(), ui::VKEY_F, true, true, false, false)); |
203 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); | 203 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
204 // activeTab should now be granted. | 204 // activeTab should now be granted. |
205 EXPECT_TRUE(IsGrantedForTab(extension, tab)); | 205 EXPECT_TRUE(IsGrantedForTab(extension, tab)); |
206 // Verify the command worked. | 206 // Verify the command worked. |
207 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); | 207 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); |
208 | 208 |
209 test_listener.Reset(); | 209 test_listener.Reset(); |
210 // Activate the command shortcut (Ctrl+Shift+Y). | 210 // Activate the command shortcut (Ctrl+Shift+Y). |
211 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 211 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
212 browser(), ui::VKEY_Y, true, true, false, false)); | 212 browser(), ui::VKEY_Y, true, true, false, false)); |
213 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); | 213 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
214 EXPECT_EQ(std::string(kBasicsShortcutCommandName), test_listener.message()); | 214 EXPECT_EQ(std::string(kBasicsShortcutCommandName), test_listener.message()); |
215 } | 215 } |
216 | 216 |
217 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { | 217 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageAction) { |
218 ASSERT_TRUE(test_server()->Start()); | 218 ASSERT_TRUE(embedded_test_server()->Start()); |
219 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 219 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
220 const Extension* extension = GetSingleLoadedExtension(); | 220 const Extension* extension = GetSingleLoadedExtension(); |
221 ASSERT_TRUE(extension) << message_; | 221 ASSERT_TRUE(extension) << message_; |
222 | 222 |
223 { | 223 { |
224 // Load a page, the extension will detect the navigation and request to show | 224 // Load a page, the extension will detect the navigation and request to show |
225 // the page action icon. | 225 // the page action icon. |
226 ResultCatcher catcher; | 226 ResultCatcher catcher; |
227 ui_test_utils::NavigateToURL( | 227 ui_test_utils::NavigateToURL( |
228 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 228 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
229 ASSERT_TRUE(catcher.GetNextResult()); | 229 ASSERT_TRUE(catcher.GetNextResult()); |
230 } | 230 } |
231 | 231 |
232 // Make sure it appears and is the right one. | 232 // Make sure it appears and is the right one. |
233 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); | 233 ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); |
234 int tab_id = SessionTabHelper::FromWebContents( | 234 int tab_id = SessionTabHelper::FromWebContents( |
235 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); | 235 browser()->tab_strip_model()->GetActiveWebContents())->session_id().id(); |
236 ExtensionAction* action = | 236 ExtensionAction* action = |
237 ExtensionActionManager::Get(browser()->profile())-> | 237 ExtensionActionManager::Get(browser()->profile())-> |
238 GetPageAction(*extension); | 238 GetPageAction(*extension); |
239 ASSERT_TRUE(action); | 239 ASSERT_TRUE(action); |
240 EXPECT_EQ("Send message", action->GetTitle(tab_id)); | 240 EXPECT_EQ("Send message", action->GetTitle(tab_id)); |
241 | 241 |
242 ExtensionTestMessageListener test_listener(false); // Won't reply. | 242 ExtensionTestMessageListener test_listener(false); // Won't reply. |
243 test_listener.set_extension_id(extension->id()); | 243 test_listener.set_extension_id(extension->id()); |
244 | 244 |
245 // Activate the shortcut (Alt+Shift+F). | 245 // Activate the shortcut (Alt+Shift+F). |
246 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 246 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
247 browser(), ui::VKEY_F, false, true, true, false)); | 247 browser(), ui::VKEY_F, false, true, true, false)); |
248 | 248 |
249 test_listener.WaitUntilSatisfied(); | 249 test_listener.WaitUntilSatisfied(); |
250 EXPECT_EQ("clicked", test_listener.message()); | 250 EXPECT_EQ("clicked", test_listener.message()); |
251 } | 251 } |
252 | 252 |
253 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionKeyUpdated) { | 253 IN_PROC_BROWSER_TEST_F(CommandsApiTest, PageActionKeyUpdated) { |
254 ASSERT_TRUE(test_server()->Start()); | 254 ASSERT_TRUE(embedded_test_server()->Start()); |
255 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; | 255 ASSERT_TRUE(RunExtensionTest("keybinding/page_action")) << message_; |
256 const Extension* extension = GetSingleLoadedExtension(); | 256 const Extension* extension = GetSingleLoadedExtension(); |
257 ASSERT_TRUE(extension) << message_; | 257 ASSERT_TRUE(extension) << message_; |
258 | 258 |
259 CommandService* command_service = CommandService::Get(browser()->profile()); | 259 CommandService* command_service = CommandService::Get(browser()->profile()); |
260 // Simulate the user setting the keybinding to Alt+Shift+G. | 260 // Simulate the user setting the keybinding to Alt+Shift+G. |
261 command_service->UpdateKeybindingPrefs( | 261 command_service->UpdateKeybindingPrefs( |
262 extension->id(), manifest_values::kPageActionCommandEvent, kAltShiftG); | 262 extension->id(), manifest_values::kPageActionCommandEvent, kAltShiftG); |
263 | 263 |
264 { | 264 { |
265 // Load a page. The extension will detect the navigation and request to show | 265 // Load a page. The extension will detect the navigation and request to show |
266 // the page action icon. | 266 // the page action icon. |
267 ResultCatcher catcher; | 267 ResultCatcher catcher; |
268 ui_test_utils::NavigateToURL( | 268 ui_test_utils::NavigateToURL( |
269 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 269 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
270 ASSERT_TRUE(catcher.GetNextResult()); | 270 ASSERT_TRUE(catcher.GetNextResult()); |
271 } | 271 } |
272 | 272 |
273 ExtensionTestMessageListener test_listener(false); // Won't reply. | 273 ExtensionTestMessageListener test_listener(false); // Won't reply. |
274 test_listener.set_extension_id(extension->id()); | 274 test_listener.set_extension_id(extension->id()); |
275 | 275 |
276 // Activate the shortcut. | 276 // Activate the shortcut. |
277 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 277 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
278 browser(), ui::VKEY_G, false, true, true, false)); | 278 browser(), ui::VKEY_G, false, true, true, false)); |
279 | 279 |
280 test_listener.WaitUntilSatisfied(); | 280 test_listener.WaitUntilSatisfied(); |
281 EXPECT_EQ("clicked", test_listener.message()); | 281 EXPECT_EQ("clicked", test_listener.message()); |
282 } | 282 } |
283 | 283 |
284 // This test validates that the getAll query API function returns registered | 284 // This test validates that the getAll query API function returns registered |
285 // commands as well as synthesized ones and that inactive commands (like the | 285 // commands as well as synthesized ones and that inactive commands (like the |
286 // synthesized ones are in nature) have no shortcuts. | 286 // synthesized ones are in nature) have no shortcuts. |
287 IN_PROC_BROWSER_TEST_F(CommandsApiTest, SynthesizedCommand) { | 287 IN_PROC_BROWSER_TEST_F(CommandsApiTest, SynthesizedCommand) { |
288 ASSERT_TRUE(test_server()->Start()); | 288 ASSERT_TRUE(embedded_test_server()->Start()); |
289 ASSERT_TRUE(RunExtensionTest("keybinding/synthesized")) << message_; | 289 ASSERT_TRUE(RunExtensionTest("keybinding/synthesized")) << message_; |
290 } | 290 } |
291 | 291 |
292 // This test validates that an extension cannot request a shortcut that is | 292 // This test validates that an extension cannot request a shortcut that is |
293 // already in use by Chrome. | 293 // already in use by Chrome. |
294 IN_PROC_BROWSER_TEST_F(CommandsApiTest, DontOverwriteSystemShortcuts) { | 294 IN_PROC_BROWSER_TEST_F(CommandsApiTest, DontOverwriteSystemShortcuts) { |
295 ASSERT_TRUE(test_server()->Start()); | 295 ASSERT_TRUE(embedded_test_server()->Start()); |
296 | 296 |
297 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 297 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
298 | 298 |
299 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; | 299 ASSERT_TRUE(RunExtensionTest("keybinding/dont_overwrite_system")) << message_; |
300 | 300 |
301 ui_test_utils::NavigateToURL( | 301 ui_test_utils::NavigateToURL( |
302 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 302 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
303 | 303 |
304 // Activate the regular shortcut (Alt+Shift+F). | 304 // Activate the regular shortcut (Alt+Shift+F). |
305 ExtensionTestMessageListener alt_shift_f_listener("alt_shift_f", false); | 305 ExtensionTestMessageListener alt_shift_f_listener("alt_shift_f", false); |
306 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 306 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
307 browser(), ui::VKEY_F, false, true, true, false)); | 307 browser(), ui::VKEY_F, false, true, true, false)); |
308 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); | 308 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); |
309 | 309 |
310 // Try to activate the bookmark shortcut (Ctrl+D). This should not work | 310 // Try to activate the bookmark shortcut (Ctrl+D). This should not work |
311 // without requesting via chrome_settings_overrides. | 311 // without requesting via chrome_settings_overrides. |
312 // | 312 // |
(...skipping 25 matching lines...) Expand all Loading... |
338 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 338 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
339 browser(), ui::VKEY_F, false, true, true, false)); | 339 browser(), ui::VKEY_F, false, true, true, false)); |
340 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); | 340 EXPECT_TRUE(alt_shift_f_listener.WaitUntilSatisfied()); |
341 EXPECT_FALSE(ctrl_f_listener.was_satisfied()); | 341 EXPECT_FALSE(ctrl_f_listener.was_satisfied()); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 // This test validates that an extension can remove the Chrome bookmark shortcut | 345 // This test validates that an extension can remove the Chrome bookmark shortcut |
346 // if it has requested to do so. | 346 // if it has requested to do so. |
347 IN_PROC_BROWSER_TEST_F(CommandsApiTest, RemoveBookmarkShortcut) { | 347 IN_PROC_BROWSER_TEST_F(CommandsApiTest, RemoveBookmarkShortcut) { |
348 ASSERT_TRUE(test_server()->Start()); | 348 ASSERT_TRUE(embedded_test_server()->Start()); |
349 | 349 |
350 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 350 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
351 | 351 |
352 // This functionality requires a feature flag. | 352 // This functionality requires a feature flag. |
353 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 353 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
354 "--enable-override-bookmarks-ui", "1"); | 354 "--enable-override-bookmarks-ui", "1"); |
355 | 355 |
356 ASSERT_TRUE(RunExtensionTest("keybinding/remove_bookmark_shortcut")) | 356 ASSERT_TRUE(RunExtensionTest("keybinding/remove_bookmark_shortcut")) |
357 << message_; | 357 << message_; |
358 | 358 |
359 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 359 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
360 } | 360 } |
361 | 361 |
362 // This test validates that an extension cannot remove the Chrome bookmark | 362 // This test validates that an extension cannot remove the Chrome bookmark |
363 // shortcut without being given permission with a feature flag. | 363 // shortcut without being given permission with a feature flag. |
364 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 364 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
365 RemoveBookmarkShortcutWithoutPermission) { | 365 RemoveBookmarkShortcutWithoutPermission) { |
366 ASSERT_TRUE(test_server()->Start()); | 366 ASSERT_TRUE(embedded_test_server()->Start()); |
367 | 367 |
368 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 368 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
369 | 369 |
370 EXPECT_TRUE(RunExtensionTestIgnoreManifestWarnings( | 370 EXPECT_TRUE(RunExtensionTestIgnoreManifestWarnings( |
371 "keybinding/remove_bookmark_shortcut")); | 371 "keybinding/remove_bookmark_shortcut")); |
372 | 372 |
373 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 373 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
374 } | 374 } |
375 | 375 |
376 // This test validates that an extension that removes the Chrome bookmark | 376 // This test validates that an extension that removes the Chrome bookmark |
377 // shortcut continues to remove the bookmark shortcut with a user-assigned | 377 // shortcut continues to remove the bookmark shortcut with a user-assigned |
378 // Ctrl+D shortcut (i.e. it does not trigger the overwrite functionality). | 378 // Ctrl+D shortcut (i.e. it does not trigger the overwrite functionality). |
379 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 379 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
380 RemoveBookmarkShortcutWithUserKeyBinding) { | 380 RemoveBookmarkShortcutWithUserKeyBinding) { |
381 ASSERT_TRUE(test_server()->Start()); | 381 ASSERT_TRUE(embedded_test_server()->Start()); |
382 | 382 |
383 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 383 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
384 | 384 |
385 // This functionality requires a feature flag. | 385 // This functionality requires a feature flag. |
386 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 386 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
387 "--enable-override-bookmarks-ui", "1"); | 387 "--enable-override-bookmarks-ui", "1"); |
388 | 388 |
389 ASSERT_TRUE(RunExtensionTest("keybinding/remove_bookmark_shortcut")) | 389 ASSERT_TRUE(RunExtensionTest("keybinding/remove_bookmark_shortcut")) |
390 << message_; | 390 << message_; |
391 | 391 |
392 // Check that the shortcut is removed. | 392 // Check that the shortcut is removed. |
393 CommandService* command_service = CommandService::Get(browser()->profile()); | 393 CommandService* command_service = CommandService::Get(browser()->profile()); |
394 const Extension* extension = GetSingleLoadedExtension(); | 394 const Extension* extension = GetSingleLoadedExtension(); |
395 // Simulate the user setting a keybinding to Ctrl+D. | 395 // Simulate the user setting a keybinding to Ctrl+D. |
396 command_service->UpdateKeybindingPrefs( | 396 command_service->UpdateKeybindingPrefs( |
397 extension->id(), manifest_values::kBrowserActionCommandEvent, | 397 extension->id(), manifest_values::kBrowserActionCommandEvent, |
398 kBookmarkKeybinding); | 398 kBookmarkKeybinding); |
399 | 399 |
400 // Force the command enable state to be recalculated. | 400 // Force the command enable state to be recalculated. |
401 browser()->command_controller()->ExtensionStateChanged(); | 401 browser()->command_controller()->ExtensionStateChanged(); |
402 | 402 |
403 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 403 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
404 } | 404 } |
405 | 405 |
406 // This test validates that an extension can override the Chrome bookmark | 406 // This test validates that an extension can override the Chrome bookmark |
407 // shortcut if it has requested to do so. | 407 // shortcut if it has requested to do so. |
408 IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) { | 408 IN_PROC_BROWSER_TEST_F(CommandsApiTest, OverwriteBookmarkShortcut) { |
409 ASSERT_TRUE(test_server()->Start()); | 409 ASSERT_TRUE(embedded_test_server()->Start()); |
410 | 410 |
411 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 411 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
412 | 412 |
413 // This functionality requires a feature flag. | 413 // This functionality requires a feature flag. |
414 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 414 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
415 "--enable-override-bookmarks-ui", "1"); | 415 "--enable-override-bookmarks-ui", "1"); |
416 | 416 |
417 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 417 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
418 << message_; | 418 << message_; |
419 | 419 |
420 ui_test_utils::NavigateToURL( | 420 ui_test_utils::NavigateToURL( |
421 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 421 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
422 | 422 |
423 // Activate the shortcut (Ctrl+D) to send a test message. | 423 // Activate the shortcut (Ctrl+D) to send a test message. |
424 ExtensionTestMessageListener test_listener(false); // Won't reply. | 424 ExtensionTestMessageListener test_listener(false); // Won't reply. |
425 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 425 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
426 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); | 426 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
427 EXPECT_EQ(std::string(kOverwriteBookmarkShortcutCommandName), | 427 EXPECT_EQ(std::string(kOverwriteBookmarkShortcutCommandName), |
428 test_listener.message()); | 428 test_listener.message()); |
429 } | 429 } |
430 | 430 |
431 // This test validates that an extension that requests to override the Chrome | 431 // This test validates that an extension that requests to override the Chrome |
432 // bookmark shortcut, but does not get the keybinding, does not remove the | 432 // bookmark shortcut, but does not get the keybinding, does not remove the |
433 // bookmark UI. | 433 // bookmark UI. |
434 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 434 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
435 OverwriteBookmarkShortcutWithoutKeybinding) { | 435 OverwriteBookmarkShortcutWithoutKeybinding) { |
436 // This functionality requires a feature flag. | 436 // This functionality requires a feature flag. |
437 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 437 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
438 "--enable-override-bookmarks-ui", "1"); | 438 "--enable-override-bookmarks-ui", "1"); |
439 | 439 |
440 ASSERT_TRUE(test_server()->Start()); | 440 ASSERT_TRUE(embedded_test_server()->Start()); |
441 | 441 |
442 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 442 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
443 | 443 |
444 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 444 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
445 << message_; | 445 << message_; |
446 | 446 |
447 const Extension* extension = GetSingleLoadedExtension(); | 447 const Extension* extension = GetSingleLoadedExtension(); |
448 CommandService* command_service = CommandService::Get(browser()->profile()); | 448 CommandService* command_service = CommandService::Get(browser()->profile()); |
449 CommandMap commands; | 449 CommandMap commands; |
450 // Verify the expected command is present. | 450 // Verify the expected command is present. |
451 EXPECT_TRUE(command_service->GetNamedCommands( | 451 EXPECT_TRUE(command_service->GetNamedCommands( |
452 extension->id(), CommandService::SUGGESTED, CommandService::ANY_SCOPE, | 452 extension->id(), CommandService::SUGGESTED, CommandService::ANY_SCOPE, |
453 &commands)); | 453 &commands)); |
454 EXPECT_EQ(1u, commands.count(kOverwriteBookmarkShortcutCommandName)); | 454 EXPECT_EQ(1u, commands.count(kOverwriteBookmarkShortcutCommandName)); |
455 | 455 |
456 // Simulate the user removing the Ctrl+D keybinding from the command. | 456 // Simulate the user removing the Ctrl+D keybinding from the command. |
457 command_service->RemoveKeybindingPrefs( | 457 command_service->RemoveKeybindingPrefs( |
458 extension->id(), kOverwriteBookmarkShortcutCommandName); | 458 extension->id(), kOverwriteBookmarkShortcutCommandName); |
459 | 459 |
460 // Force the command enable state to be recalculated. | 460 // Force the command enable state to be recalculated. |
461 browser()->command_controller()->ExtensionStateChanged(); | 461 browser()->command_controller()->ExtensionStateChanged(); |
462 | 462 |
463 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); | 463 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_BOOKMARK_PAGE)); |
464 } | 464 } |
465 | 465 |
466 // This test validates that an extension override of the Chrome bookmark | 466 // This test validates that an extension override of the Chrome bookmark |
467 // shortcut does not supersede the same keybinding by web pages. | 467 // shortcut does not supersede the same keybinding by web pages. |
468 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 468 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
469 OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding) { | 469 OverwriteBookmarkShortcutDoesNotOverrideWebKeybinding) { |
470 ASSERT_TRUE(test_server()->Start()); | 470 ASSERT_TRUE(embedded_test_server()->Start()); |
471 | 471 |
472 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 472 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
473 | 473 |
474 // This functionality requires a feature flag. | 474 // This functionality requires a feature flag. |
475 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 475 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
476 "--enable-override-bookmarks-ui", "1"); | 476 "--enable-override-bookmarks-ui", "1"); |
477 | 477 |
478 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) | 478 ASSERT_TRUE(RunExtensionTest("keybinding/overwrite_bookmark_shortcut")) |
479 << message_; | 479 << message_; |
480 | 480 |
481 ui_test_utils::NavigateToURL( | 481 ui_test_utils::NavigateToURL( |
482 browser(), | 482 browser(), embedded_test_server()->GetURL( |
483 test_server()->GetURL( | 483 "/extensions/test_file_with_ctrl-d_keybinding.html")); |
484 "files/extensions/test_file_with_ctrl-d_keybinding.html")); | |
485 | 484 |
486 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 485 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
487 ASSERT_TRUE(tab); | 486 ASSERT_TRUE(tab); |
488 | 487 |
489 // Activate the shortcut (Ctrl+D) which should be handled by the page and send | 488 // Activate the shortcut (Ctrl+D) which should be handled by the page and send |
490 // a test message. | 489 // a test message. |
491 DomMessageListener listener(tab); | 490 DomMessageListener listener(tab); |
492 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 491 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
493 listener.Wait(); | 492 listener.Wait(); |
494 EXPECT_EQ(std::string("\"web page received\""), listener.message()); | 493 EXPECT_EQ(std::string("\"web page received\""), listener.message()); |
495 } | 494 } |
496 | 495 |
497 // This test validates that user-set override of the Chrome bookmark shortcut in | 496 // This test validates that user-set override of the Chrome bookmark shortcut in |
498 // an extension that does not request it does supersede the same keybinding by | 497 // an extension that does not request it does supersede the same keybinding by |
499 // web pages. | 498 // web pages. |
500 IN_PROC_BROWSER_TEST_F(CommandsApiTest, | 499 IN_PROC_BROWSER_TEST_F(CommandsApiTest, |
501 OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { | 500 OverwriteBookmarkShortcutByUserOverridesWebKeybinding) { |
502 ASSERT_TRUE(test_server()->Start()); | 501 ASSERT_TRUE(embedded_test_server()->Start()); |
503 | 502 |
504 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 503 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
505 | 504 |
506 // This functionality requires a feature flag. | 505 // This functionality requires a feature flag. |
507 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 506 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
508 "--enable-override-bookmarks-ui", "1"); | 507 "--enable-override-bookmarks-ui", "1"); |
509 | 508 |
510 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) | 509 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) |
511 << message_; | 510 << message_; |
512 | 511 |
513 CommandService* command_service = CommandService::Get(browser()->profile()); | 512 CommandService* command_service = CommandService::Get(browser()->profile()); |
514 | 513 |
515 const Extension* extension = GetSingleLoadedExtension(); | 514 const Extension* extension = GetSingleLoadedExtension(); |
516 // Simulate the user setting the keybinding to Ctrl+D. | 515 // Simulate the user setting the keybinding to Ctrl+D. |
517 command_service->UpdateKeybindingPrefs( | 516 command_service->UpdateKeybindingPrefs( |
518 extension->id(), manifest_values::kBrowserActionCommandEvent, | 517 extension->id(), manifest_values::kBrowserActionCommandEvent, |
519 kBookmarkKeybinding); | 518 kBookmarkKeybinding); |
520 | 519 |
521 ui_test_utils::NavigateToURL( | 520 ui_test_utils::NavigateToURL( |
522 browser(), | 521 browser(), embedded_test_server()->GetURL( |
523 test_server()->GetURL( | 522 "/extensions/test_file_with_ctrl-d_keybinding.html")); |
524 "files/extensions/test_file_with_ctrl-d_keybinding.html")); | |
525 | 523 |
526 ExtensionTestMessageListener test_listener(false); // Won't reply. | 524 ExtensionTestMessageListener test_listener(false); // Won't reply. |
527 // Activate the shortcut (Ctrl+D) which should be handled by the extension. | 525 // Activate the shortcut (Ctrl+D) which should be handled by the extension. |
528 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); | 526 ASSERT_TRUE(SendBookmarkKeyPressSync(browser())); |
529 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); | 527 EXPECT_TRUE(test_listener.WaitUntilSatisfied()); |
530 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); | 528 EXPECT_EQ(std::string("basics browser action"), test_listener.message()); |
531 } | 529 } |
532 | 530 |
533 #if defined(OS_WIN) | 531 #if defined(OS_WIN) |
534 // Currently this feature is implemented on Windows only. | 532 // Currently this feature is implemented on Windows only. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 // | 905 // |
908 #if defined(OS_CHROMEOS) && !defined(NDEBUG) | 906 #if defined(OS_CHROMEOS) && !defined(NDEBUG) |
909 // TODO(dtseng): Test times out on Chrome OS debug. See http://crbug.com/412456. | 907 // TODO(dtseng): Test times out on Chrome OS debug. See http://crbug.com/412456. |
910 #define MAYBE_ContinuePropagation DISABLED_ContinuePropagation | 908 #define MAYBE_ContinuePropagation DISABLED_ContinuePropagation |
911 #else | 909 #else |
912 #define MAYBE_ContinuePropagation ContinuePropagation | 910 #define MAYBE_ContinuePropagation ContinuePropagation |
913 #endif | 911 #endif |
914 | 912 |
915 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ContinuePropagation) { | 913 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ContinuePropagation) { |
916 // Setup the environment. | 914 // Setup the environment. |
917 ASSERT_TRUE(test_server()->Start()); | 915 ASSERT_TRUE(embedded_test_server()->Start()); |
918 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 916 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
919 ASSERT_TRUE(RunExtensionTest("keybinding/continue_propagation")) << message_; | 917 ASSERT_TRUE(RunExtensionTest("keybinding/continue_propagation")) << message_; |
920 ui_test_utils::NavigateToURL( | 918 ui_test_utils::NavigateToURL( |
921 browser(), test_server()->GetURL("files/extensions/test_file.txt")); | 919 browser(), embedded_test_server()->GetURL("/extensions/test_file.txt")); |
922 | 920 |
923 ResultCatcher catcher; | 921 ResultCatcher catcher; |
924 | 922 |
925 // Activate the shortcut (Ctrl+Shift+F). The page should capture the | 923 // Activate the shortcut (Ctrl+Shift+F). The page should capture the |
926 // keystroke and not the extension since |onCommand| has no event listener | 924 // keystroke and not the extension since |onCommand| has no event listener |
927 // initially. | 925 // initially. |
928 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 926 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
929 browser(), ui::VKEY_F, true, true, false, false)); | 927 browser(), ui::VKEY_F, true, true, false, false)); |
930 ASSERT_TRUE(catcher.GetNextResult()); | 928 ASSERT_TRUE(catcher.GetNextResult()); |
931 | 929 |
(...skipping 19 matching lines...) Expand all Loading... |
951 #define MAYBE_ChromeOSConversions ChromeOSConversions | 949 #define MAYBE_ChromeOSConversions ChromeOSConversions |
952 #endif | 950 #endif |
953 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) { | 951 IN_PROC_BROWSER_TEST_F(CommandsApiTest, MAYBE_ChromeOSConversions) { |
954 RunChromeOSConversionTest("keybinding/chromeos_conversions"); | 952 RunChromeOSConversionTest("keybinding/chromeos_conversions"); |
955 } | 953 } |
956 #endif // OS_CHROMEOS | 954 #endif // OS_CHROMEOS |
957 | 955 |
958 // Make sure component extensions retain keybindings after removal then | 956 // Make sure component extensions retain keybindings after removal then |
959 // re-adding. | 957 // re-adding. |
960 IN_PROC_BROWSER_TEST_F(CommandsApiTest, AddRemoveAddComponentExtension) { | 958 IN_PROC_BROWSER_TEST_F(CommandsApiTest, AddRemoveAddComponentExtension) { |
961 ASSERT_TRUE(test_server()->Start()); | 959 ASSERT_TRUE(embedded_test_server()->Start()); |
962 ASSERT_TRUE(RunComponentExtensionTest("keybinding/component")) << message_; | 960 ASSERT_TRUE(RunComponentExtensionTest("keybinding/component")) << message_; |
963 | 961 |
964 extensions::ExtensionSystem::Get(browser()->profile()) | 962 extensions::ExtensionSystem::Get(browser()->profile()) |
965 ->extension_service() | 963 ->extension_service() |
966 ->component_loader() | 964 ->component_loader() |
967 ->Remove("pkplfbidichfdicaijlchgnapepdginl"); | 965 ->Remove("pkplfbidichfdicaijlchgnapepdginl"); |
968 | 966 |
969 ASSERT_TRUE(RunComponentExtensionTest("keybinding/component")) << message_; | 967 ASSERT_TRUE(RunComponentExtensionTest("keybinding/component")) << message_; |
970 } | 968 } |
971 | 969 |
972 } // namespace extensions | 970 } // namespace extensions |
OLD | NEW |