Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: chrome/browser/extensions/extension_keybinding_apitest.cc

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

Powered by Google App Engine
This is Rietveld 408576698