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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc

Issue 6246001: Move app/key* to ui/base/keycodes/* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « app/menus/accelerator_gtk.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include "app/keyboard_codes.h"
8 #include "base/message_loop.h" 7 #include "base/message_loop.h"
9 #include "base/string16.h" 8 #include "base/string16.h"
10 #include "base/string_util.h" 9 #include "base/string_util.h"
11 #include "base/time.h" 10 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/autocomplete/autocomplete.h" 13 #include "chrome/browser/autocomplete/autocomplete.h"
15 #include "chrome/browser/autocomplete/autocomplete_edit.h" 14 #include "chrome/browser/autocomplete/autocomplete_edit.h"
16 #include "chrome/browser/autocomplete/autocomplete_match.h" 15 #include "chrome/browser/autocomplete/autocomplete_match.h"
17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
18 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" 17 #include "chrome/browser/autocomplete/autocomplete_edit_view.h"
19 #include "chrome/browser/bookmarks/bookmark_model.h" 18 #include "chrome/browser/bookmarks/bookmark_model.h"
20 #include "chrome/browser/browser_window.h" 19 #include "chrome/browser/browser_window.h"
21 #include "chrome/browser/history/history.h" 20 #include "chrome/browser/history/history.h"
22 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/search_engines/template_url.h" 22 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/search_engines/template_url_model.h" 23 #include "chrome/browser/search_engines/template_url_model.h"
25 #include "chrome/browser/tab_contents/tab_contents.h" 24 #include "chrome/browser/tab_contents/tab_contents.h"
26 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/omnibox/location_bar.h" 26 #include "chrome/browser/ui/omnibox/location_bar.h"
28 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/notification_service.h" 28 #include "chrome/common/notification_service.h"
30 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
31 #include "chrome/test/in_process_browser_test.h" 30 #include "chrome/test/in_process_browser_test.h"
32 #include "chrome/test/ui_test_utils.h" 31 #include "chrome/test/ui_test_utils.h"
33 #include "net/base/mock_host_resolver.h" 32 #include "net/base/mock_host_resolver.h"
33 #include "ui/base/keycodes/keyboard_codes.h"
34 #include "views/event.h" 34 #include "views/event.h"
35 35
36 #if defined(OS_LINUX) 36 #if defined(OS_LINUX)
37 #include <gdk/gdk.h> 37 #include <gdk/gdk.h>
38 #include <gtk/gtk.h> 38 #include <gtk/gtk.h>
39 #endif 39 #endif
40 40
41 using base::Time; 41 using base::Time;
42 using base::TimeDelta; 42 using base::TimeDelta;
43 43
44 namespace { 44 namespace {
45 45
46 const char kSearchKeyword[] = "foo"; 46 const char kSearchKeyword[] = "foo";
47 const wchar_t kSearchKeywordKeys[] = { 47 const wchar_t kSearchKeywordKeys[] = {
48 app::VKEY_F, app::VKEY_O, app::VKEY_O, 0 48 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0
49 }; 49 };
50 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; 50 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
51 const char kSearchShortName[] = "foo"; 51 const char kSearchShortName[] = "foo";
52 const char kSearchText[] = "abc"; 52 const char kSearchText[] = "abc";
53 const wchar_t kSearchTextKeys[] = { 53 const wchar_t kSearchTextKeys[] = {
54 app::VKEY_A, app::VKEY_B, app::VKEY_C, 0 54 ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, 0
55 }; 55 };
56 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc"; 56 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
57 const char kSearchSingleChar[] = "z"; 57 const char kSearchSingleChar[] = "z";
58 const wchar_t kSearchSingleCharKeys[] = { app::VKEY_Z, 0 }; 58 const wchar_t kSearchSingleCharKeys[] = { ui::VKEY_Z, 0 };
59 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z"; 59 const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z";
60 60
61 const char kHistoryPageURL[] = "chrome://history/#q=abc"; 61 const char kHistoryPageURL[] = "chrome://history/#q=abc";
62 62
63 const char kDesiredTLDHostname[] = "www.bar.com"; 63 const char kDesiredTLDHostname[] = "www.bar.com";
64 const wchar_t kDesiredTLDKeys[] = { 64 const wchar_t kDesiredTLDKeys[] = {
65 app::VKEY_B, app::VKEY_A, app::VKEY_R, 0 65 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0
66 }; 66 };
67 67
68 // Hostnames that shall be blocked by host resolver. 68 // Hostnames that shall be blocked by host resolver.
69 const char *kBlockedHostnames[] = { 69 const char *kBlockedHostnames[] = {
70 "foo", 70 "foo",
71 "*.foo.com", 71 "*.foo.com",
72 "bar", 72 "bar",
73 "*.bar.com", 73 "*.bar.com",
74 "abc", 74 "abc",
75 "*.abc.com", 75 "*.abc.com",
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 ASSERT_TRUE(loc_bar); 138 ASSERT_TRUE(loc_bar);
139 *edit_view = loc_bar->location_entry(); 139 *edit_view = loc_bar->location_entry();
140 ASSERT_TRUE(*edit_view); 140 ASSERT_TRUE(*edit_view);
141 } 141 }
142 142
143 void GetAutocompleteEditView(AutocompleteEditView** edit_view) { 143 void GetAutocompleteEditView(AutocompleteEditView** edit_view) {
144 GetAutocompleteEditViewForBrowser(browser(), edit_view); 144 GetAutocompleteEditViewForBrowser(browser(), edit_view);
145 } 145 }
146 146
147 static void SendKeyForBrowser(const Browser* browser, 147 static void SendKeyForBrowser(const Browser* browser,
148 app::KeyboardCode key, 148 ui::KeyboardCode key,
149 bool control, 149 bool control,
150 bool shift, 150 bool shift,
151 bool alt) { 151 bool alt) {
152 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 152 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
153 browser, key, control, shift, alt, false /* command */)); 153 browser, key, control, shift, alt, false /* command */));
154 } 154 }
155 155
156 void SendKey(app::KeyboardCode key, bool control, bool shift, bool alt) { 156 void SendKey(ui::KeyboardCode key, bool control, bool shift, bool alt) {
157 SendKeyForBrowser(browser(), key, control, shift, alt); 157 SendKeyForBrowser(browser(), key, control, shift, alt);
158 } 158 }
159 159
160 void SendKeySequence(const wchar_t* keys) { 160 void SendKeySequence(const wchar_t* keys) {
161 for (; *keys; ++keys) 161 for (; *keys; ++keys)
162 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<app::KeyboardCode>(*keys), 162 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<ui::KeyboardCode>(*keys),
163 false, false, false)); 163 false, false, false));
164 } 164 }
165 165
166 void WaitForTabOpenOrCloseForBrowser(const Browser* browser, 166 void WaitForTabOpenOrCloseForBrowser(const Browser* browser,
167 int expected_tab_count) { 167 int expected_tab_count) {
168 int tab_count = browser->tab_count(); 168 int tab_count = browser->tab_count();
169 if (tab_count == expected_tab_count) 169 if (tab_count == expected_tab_count)
170 return; 170 return;
171 171
172 NotificationRegistrar registrar; 172 NotificationRegistrar registrar;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 AutocompleteEditView* edit_view = NULL; 313 AutocompleteEditView* edit_view = NULL;
314 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 314 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
315 315
316 int tab_count = browser()->tab_count(); 316 int tab_count = browser()->tab_count();
317 317
318 // Create a new Tab. 318 // Create a new Tab.
319 browser()->NewTab(); 319 browser()->NewTab();
320 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 320 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
321 321
322 // Select the first Tab. 322 // Select the first Tab.
323 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_1, true, false, false)); 323 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1, true, false, false));
324 ASSERT_EQ(0, browser()->selected_index()); 324 ASSERT_EQ(0, browser()->selected_index());
325 325
326 browser()->FocusLocationBar(); 326 browser()->FocusLocationBar();
327 327
328 // Select the second Tab. 328 // Select the second Tab.
329 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_2, true, false, false)); 329 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2, true, false, false));
330 ASSERT_EQ(1, browser()->selected_index()); 330 ASSERT_EQ(1, browser()->selected_index());
331 331
332 browser()->FocusLocationBar(); 332 browser()->FocusLocationBar();
333 333
334 // Try ctrl-w to close a Tab. 334 // Try ctrl-w to close a Tab.
335 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_W, true, false, false)); 335 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W, true, false, false));
336 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count)); 336 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count));
337 337
338 // Try ctrl-l to focus location bar. 338 // Try ctrl-l to focus location bar.
339 edit_view->SetUserText(L"Hello world"); 339 edit_view->SetUserText(L"Hello world");
340 EXPECT_FALSE(edit_view->IsSelectAll()); 340 EXPECT_FALSE(edit_view->IsSelectAll());
341 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_L, true, false, false)); 341 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, true, false, false));
342 EXPECT_TRUE(edit_view->IsSelectAll()); 342 EXPECT_TRUE(edit_view->IsSelectAll());
343 343
344 // Try editing the location bar text. 344 // Try editing the location bar text.
345 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RIGHT, false, false, false)); 345 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, false, false, false));
346 EXPECT_FALSE(edit_view->IsSelectAll()); 346 EXPECT_FALSE(edit_view->IsSelectAll());
347 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_S, false, false, false)); 347 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, false, false, false));
348 EXPECT_EQ(L"Hello worlds", edit_view->GetText()); 348 EXPECT_EQ(L"Hello worlds", edit_view->GetText());
349 349
350 // Try ctrl-x to cut text. 350 // Try ctrl-x to cut text.
351 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_LEFT, true, true, false)); 351 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, true, true, false));
352 EXPECT_FALSE(edit_view->IsSelectAll()); 352 EXPECT_FALSE(edit_view->IsSelectAll());
353 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_X, true, false, false)); 353 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, true, false, false));
354 EXPECT_EQ(L"Hello ", edit_view->GetText()); 354 EXPECT_EQ(L"Hello ", edit_view->GetText());
355 355
356 #if !defined(OS_CHROMEOS) 356 #if !defined(OS_CHROMEOS)
357 // Try alt-f4 to close the browser. 357 // Try alt-f4 to close the browser.
358 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 358 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
359 browser(), app::VKEY_F4, false, false, true, false, 359 browser(), ui::VKEY_F4, false, false, true, false,
360 NotificationType::BROWSER_CLOSED, Source<Browser>(browser()))); 360 NotificationType::BROWSER_CLOSED, Source<Browser>(browser())));
361 #endif 361 #endif
362 } 362 }
363 363
364 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PopupAccelerators) { 364 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PopupAccelerators) {
365 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 365 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
366 366
367 // Create a popup. 367 // Create a popup.
368 Browser* popup = CreateBrowserForPopup(browser()->profile()); 368 Browser* popup = CreateBrowserForPopup(browser()->profile());
369 AutocompleteEditView* edit_view = NULL; 369 AutocompleteEditView* edit_view = NULL;
370 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view)); 370 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view));
371 popup->FocusLocationBar(); 371 popup->FocusLocationBar();
372 EXPECT_TRUE(edit_view->IsSelectAll()); 372 EXPECT_TRUE(edit_view->IsSelectAll());
373 373
374 // Try ctrl-w to close the popup. 374 // Try ctrl-w to close the popup.
375 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 375 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
376 popup, app::VKEY_W, true, false, false, false, 376 popup, ui::VKEY_W, true, false, false, false,
377 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); 377 NotificationType::BROWSER_CLOSED, Source<Browser>(popup)));
378 378
379 // Create another popup. 379 // Create another popup.
380 popup = CreateBrowserForPopup(browser()->profile()); 380 popup = CreateBrowserForPopup(browser()->profile());
381 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view)); 381 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view));
382 382
383 // Set the edit text to "Hello world". 383 // Set the edit text to "Hello world".
384 edit_view->SetUserText(L"Hello world"); 384 edit_view->SetUserText(L"Hello world");
385 EXPECT_FALSE(edit_view->IsSelectAll()); 385 EXPECT_FALSE(edit_view->IsSelectAll());
386 popup->FocusLocationBar(); 386 popup->FocusLocationBar();
387 EXPECT_TRUE(edit_view->IsSelectAll()); 387 EXPECT_TRUE(edit_view->IsSelectAll());
388 388
389 // Try editing the location bar text -- should be disallowed. 389 // Try editing the location bar text -- should be disallowed.
390 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, app::VKEY_RIGHT, false, 390 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_RIGHT, false,
391 false, false)); 391 false, false));
392 EXPECT_FALSE(edit_view->IsSelectAll()); 392 EXPECT_FALSE(edit_view->IsSelectAll());
393 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, app::VKEY_S, false, false, 393 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, false, false,
394 false)); 394 false));
395 EXPECT_EQ(L"Hello world", edit_view->GetText()); 395 EXPECT_EQ(L"Hello world", edit_view->GetText());
396 396
397 // Try ctrl-x to cut text -- should be disallowed. 397 // Try ctrl-x to cut text -- should be disallowed.
398 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, app::VKEY_LEFT, true, true, 398 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_LEFT, true, true,
399 false)); 399 false));
400 EXPECT_FALSE(edit_view->IsSelectAll()); 400 EXPECT_FALSE(edit_view->IsSelectAll());
401 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, app::VKEY_X, true, false, 401 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_X, true, false,
402 false)); 402 false));
403 EXPECT_EQ(L"Hello world", edit_view->GetText()); 403 EXPECT_EQ(L"Hello world", edit_view->GetText());
404 404
405 #if !defined(OS_CHROMEOS) 405 #if !defined(OS_CHROMEOS)
406 // Try alt-f4 to close the popup. 406 // Try alt-f4 to close the popup.
407 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 407 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
408 popup, app::VKEY_F4, false, false, true, false, 408 popup, ui::VKEY_F4, false, false, true, false,
409 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); 409 NotificationType::BROWSER_CLOSED, Source<Browser>(popup)));
410 #endif 410 #endif
411 } 411 }
412 412
413 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { 413 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) {
414 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 414 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
415 415
416 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 416 ASSERT_NO_FATAL_FAILURE(SetupComponents());
417 browser()->FocusLocationBar(); 417 browser()->FocusLocationBar();
418 418
419 AutocompleteEditView* edit_view = NULL; 419 AutocompleteEditView* edit_view = NULL;
420 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 420 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
421 421
422 // Trigger keyword hint mode. 422 // Trigger keyword hint mode.
423 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 423 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
424 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 424 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
425 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 425 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
426 426
427 // Trigger keyword mode. 427 // Trigger keyword mode.
428 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB, false, false, false)); 428 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false));
429 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 429 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
430 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 430 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
431 431
432 // Backspace without search text should bring back keyword hint mode. 432 // Backspace without search text should bring back keyword hint mode.
433 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 433 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
434 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 434 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
435 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 435 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
436 436
437 // Trigger keyword mode again. 437 // Trigger keyword mode again.
438 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB, false, false, false)); 438 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false));
439 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 439 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
440 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 440 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
441 441
442 // Input something as search text. 442 // Input something as search text.
443 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 443 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
444 444
445 // Should stay in keyword mode while deleting search text by pressing 445 // Should stay in keyword mode while deleting search text by pressing
446 // backspace. 446 // backspace.
447 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { 447 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) {
448 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 448 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
449 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 449 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
450 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); 450 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword()));
451 } 451 }
452 452
453 // Input something as search text. 453 // Input something as search text.
454 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 454 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
455 455
456 // Move cursor to the beginning of the search text. 456 // Move cursor to the beginning of the search text.
457 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_HOME, false, false, false)); 457 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, false, false));
458 // Backspace at the beginning of the search text shall turn off 458 // Backspace at the beginning of the search text shall turn off
459 // the keyword mode. 459 // the keyword mode.
460 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 460 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
461 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 461 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
462 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); 462 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword()));
463 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, 463 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText,
464 WideToUTF8(edit_view->GetText())); 464 WideToUTF8(edit_view->GetText()));
465 } 465 }
466 466
467 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { 467 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) {
468 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 468 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
469 469
470 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 470 ASSERT_NO_FATAL_FAILURE(SetupComponents());
471 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); 471 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
472 browser()->FocusLocationBar(); 472 browser()->FocusLocationBar();
473 473
474 AutocompleteEditView* edit_view = NULL; 474 AutocompleteEditView* edit_view = NULL;
475 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 475 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
476 476
477 std::wstring old_text = edit_view->GetText(); 477 std::wstring old_text = edit_view->GetText();
478 EXPECT_FALSE(old_text.empty()); 478 EXPECT_FALSE(old_text.empty());
479 EXPECT_TRUE(edit_view->IsSelectAll()); 479 EXPECT_TRUE(edit_view->IsSelectAll());
480 480
481 // Delete all text in omnibox. 481 // Delete all text in omnibox.
482 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 482 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
483 EXPECT_TRUE(edit_view->GetText().empty()); 483 EXPECT_TRUE(edit_view->GetText().empty());
484 484
485 // Escape shall revert the text in omnibox. 485 // Escape shall revert the text in omnibox.
486 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false)); 486 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false));
487 EXPECT_EQ(old_text, edit_view->GetText()); 487 EXPECT_EQ(old_text, edit_view->GetText());
488 EXPECT_TRUE(edit_view->IsSelectAll()); 488 EXPECT_TRUE(edit_view->IsSelectAll());
489 } 489 }
490 490
491 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) { 491 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) {
492 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 492 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
493 493
494 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 494 ASSERT_NO_FATAL_FAILURE(SetupComponents());
495 browser()->FocusLocationBar(); 495 browser()->FocusLocationBar();
496 496
497 AutocompleteEditView* edit_view = NULL; 497 AutocompleteEditView* edit_view = NULL;
498 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 498 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
499 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 499 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
500 ASSERT_TRUE(popup_model); 500 ASSERT_TRUE(popup_model);
501 501
502 // Test ctrl-Enter. 502 // Test ctrl-Enter.
503 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); 503 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys));
504 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 504 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
505 ASSERT_TRUE(popup_model->IsOpen()); 505 ASSERT_TRUE(popup_model->IsOpen());
506 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened. 506 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened.
507 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, true, false, false)); 507 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false));
508 508
509 GURL url = browser()->GetSelectedTabContents()->GetURL(); 509 GURL url = browser()->GetSelectedTabContents()->GetURL();
510 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); 510 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str());
511 } 511 }
512 512
513 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) { 513 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) {
514 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 514 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
515 515
516 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 516 ASSERT_NO_FATAL_FAILURE(SetupComponents());
517 browser()->FocusLocationBar(); 517 browser()->FocusLocationBar();
518 518
519 AutocompleteEditView* edit_view = NULL; 519 AutocompleteEditView* edit_view = NULL;
520 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 520 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
521 521
522 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); 522 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL));
523 int tab_count = browser()->tab_count(); 523 int tab_count = browser()->tab_count();
524 // alt-Enter opens a new tab. 524 // alt-Enter opens a new tab.
525 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, true)); 525 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true));
526 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); 526 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
527 } 527 }
528 528
529 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { 529 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) {
530 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 530 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
531 531
532 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); 532 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
533 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine()); 533 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
534 browser()->FocusLocationBar(); 534 browser()->FocusLocationBar();
535 535
536 AutocompleteEditView* edit_view = NULL; 536 AutocompleteEditView* edit_view = NULL;
537 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 537 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
538 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 538 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
539 ASSERT_TRUE(popup_model); 539 ASSERT_TRUE(popup_model);
540 540
541 // Test Enter to search. 541 // Test Enter to search.
542 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 542 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
543 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 543 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
544 ASSERT_TRUE(popup_model->IsOpen()); 544 ASSERT_TRUE(popup_model->IsOpen());
545 545
546 // Check if the default match result is Search Primary Provider. 546 // Check if the default match result is Search Primary Provider.
547 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 547 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
548 popup_model->result().default_match()->type); 548 popup_model->result().default_match()->type);
549 549
550 // Open the default match. 550 // Open the default match.
551 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false)); 551 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false));
552 GURL url = browser()->GetSelectedTabContents()->GetURL(); 552 GURL url = browser()->GetSelectedTabContents()->GetURL();
553 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); 553 EXPECT_STREQ(kSearchTextURL, url.spec().c_str());
554 554
555 // Test that entering a single character then Enter performs a search. 555 // Test that entering a single character then Enter performs a search.
556 browser()->FocusLocationBar(); 556 browser()->FocusLocationBar();
557 EXPECT_TRUE(edit_view->IsSelectAll()); 557 EXPECT_TRUE(edit_view->IsSelectAll());
558 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); 558 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys));
559 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 559 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
560 ASSERT_TRUE(popup_model->IsOpen()); 560 ASSERT_TRUE(popup_model->IsOpen());
561 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); 561 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText()));
562 562
563 // Check if the default match result is Search Primary Provider. 563 // Check if the default match result is Search Primary Provider.
564 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, 564 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED,
565 popup_model->result().default_match()->type); 565 popup_model->result().default_match()->type);
566 566
567 // Open the default match. 567 // Open the default match.
568 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false)); 568 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false));
569 url = browser()->GetSelectedTabContents()->GetURL(); 569 url = browser()->GetSelectedTabContents()->GetURL();
570 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); 570 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str());
571 } 571 }
572 572
573 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for 573 // See http://crbug.com/20934: Omnibox keyboard behavior wrong for
574 // "See recent pages in history" 574 // "See recent pages in history"
575 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) { 575 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToOpenHistoryPage) {
576 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 576 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
577 577
578 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 578 ASSERT_NO_FATAL_FAILURE(SetupComponents());
579 browser()->FocusLocationBar(); 579 browser()->FocusLocationBar();
580 580
581 AutocompleteEditView* edit_view = NULL; 581 AutocompleteEditView* edit_view = NULL;
582 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 582 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
583 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 583 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
584 ASSERT_TRUE(popup_model); 584 ASSERT_TRUE(popup_model);
585 585
586 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); 586 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
587 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 587 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
588 ASSERT_TRUE(popup_model->IsOpen()); 588 ASSERT_TRUE(popup_model->IsOpen());
589 EXPECT_EQ(0U, popup_model->selected_line()); 589 EXPECT_EQ(0U, popup_model->selected_line());
590 590
591 // Move to the history page item. 591 // Move to the history page item.
592 size_t size = popup_model->result().size(); 592 size_t size = popup_model->result().size();
593 while (true) { 593 while (true) {
594 if (popup_model->result().match_at(popup_model->selected_line()).type == 594 if (popup_model->result().match_at(popup_model->selected_line()).type ==
595 AutocompleteMatch::OPEN_HISTORY_PAGE) 595 AutocompleteMatch::OPEN_HISTORY_PAGE)
596 break; 596 break;
597 size_t old_selected_line = popup_model->selected_line(); 597 size_t old_selected_line = popup_model->selected_line();
598 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DOWN, false, false, false)); 598 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false));
599 ASSERT_EQ(old_selected_line + 1, popup_model->selected_line()); 599 ASSERT_EQ(old_selected_line + 1, popup_model->selected_line());
600 if (popup_model->selected_line() == size - 1) 600 if (popup_model->selected_line() == size - 1)
601 break; 601 break;
602 } 602 }
603 603
604 // Make sure the history page item is selected. 604 // Make sure the history page item is selected.
605 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE, 605 ASSERT_EQ(AutocompleteMatch::OPEN_HISTORY_PAGE,
606 popup_model->result().match_at(popup_model->selected_line()).type); 606 popup_model->result().match_at(popup_model->selected_line()).type);
607 607
608 // Open the history page item. 608 // Open the history page item.
609 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_RETURN, false, false, false)); 609 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false));
610 GURL url = browser()->GetSelectedTabContents()->GetURL(); 610 GURL url = browser()->GetSelectedTabContents()->GetURL();
611 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str()); 611 EXPECT_STREQ(kHistoryPageURL, url.spec().c_str());
612 } 612 }
613 613
614 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { 614 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) {
615 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 615 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
616 616
617 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 617 ASSERT_NO_FATAL_FAILURE(SetupComponents());
618 browser()->FocusLocationBar(); 618 browser()->FocusLocationBar();
619 619
(...skipping 11 matching lines...) Expand all
631 631
632 // Make sure inline autocomplete is triggerred. 632 // Make sure inline autocomplete is triggerred.
633 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1); 633 EXPECT_GT(old_text.length(), arraysize(kSearchText) - 1);
634 634
635 size_t old_selected_line = popup_model->selected_line(); 635 size_t old_selected_line = popup_model->selected_line();
636 EXPECT_EQ(0U, old_selected_line); 636 EXPECT_EQ(0U, old_selected_line);
637 637
638 // Move to another line with different text. 638 // Move to another line with different text.
639 size_t size = popup_model->result().size(); 639 size_t size = popup_model->result().size();
640 while (popup_model->selected_line() < size - 1) { 640 while (popup_model->selected_line() < size - 1) {
641 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DOWN, false, false, false)); 641 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false));
642 ASSERT_NE(old_selected_line, popup_model->selected_line()); 642 ASSERT_NE(old_selected_line, popup_model->selected_line());
643 if (old_text != edit_view->GetText()) 643 if (old_text != edit_view->GetText())
644 break; 644 break;
645 } 645 }
646 646
647 EXPECT_NE(old_text, edit_view->GetText()); 647 EXPECT_NE(old_text, edit_view->GetText());
648 648
649 // Escape shall revert back to the default match item. 649 // Escape shall revert back to the default match item.
650 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_ESCAPE, false, false, false)); 650 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false));
651 EXPECT_EQ(old_text, edit_view->GetText()); 651 EXPECT_EQ(old_text, edit_view->GetText());
652 EXPECT_EQ(old_selected_line, popup_model->selected_line()); 652 EXPECT_EQ(old_selected_line, popup_model->selected_line());
653 } 653 }
654 654
655 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { 655 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) {
656 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 656 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
657 657
658 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 658 ASSERT_NO_FATAL_FAILURE(SetupComponents());
659 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); 659 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL));
660 browser()->FocusLocationBar(); 660 browser()->FocusLocationBar();
661 661
662 AutocompleteEditView* edit_view = NULL; 662 AutocompleteEditView* edit_view = NULL;
663 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 663 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
664 664
665 std::wstring old_text = edit_view->GetText(); 665 std::wstring old_text = edit_view->GetText();
666 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 666 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
667 EXPECT_TRUE(edit_view->IsSelectAll()); 667 EXPECT_TRUE(edit_view->IsSelectAll());
668 668
669 std::wstring::size_type start, end; 669 std::wstring::size_type start, end;
670 edit_view->GetSelectionBounds(&start, &end); 670 edit_view->GetSelectionBounds(&start, &end);
671 EXPECT_EQ(0U, start); 671 EXPECT_EQ(0U, start);
672 EXPECT_EQ(old_text.size(), end); 672 EXPECT_EQ(old_text.size(), end);
673 673
674 // Move the cursor to the end. 674 // Move the cursor to the end.
675 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_END, false, false, false)); 675 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
676 EXPECT_FALSE(edit_view->IsSelectAll()); 676 EXPECT_FALSE(edit_view->IsSelectAll());
677 677
678 // Make sure the cursor is placed correctly. 678 // Make sure the cursor is placed correctly.
679 edit_view->GetSelectionBounds(&start, &end); 679 edit_view->GetSelectionBounds(&start, &end);
680 EXPECT_EQ(old_text.size(), start); 680 EXPECT_EQ(old_text.size(), start);
681 EXPECT_EQ(old_text.size(), end); 681 EXPECT_EQ(old_text.size(), end);
682 682
683 // Insert one character at the end. Make sure we won't insert anything after 683 // Insert one character at the end. Make sure we won't insert anything after
684 // the special ZWS mark used in gtk implementation. 684 // the special ZWS mark used in gtk implementation.
685 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_A, false, false, false)); 685 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, false, false, false));
686 EXPECT_EQ(old_text + L"a", edit_view->GetText()); 686 EXPECT_EQ(old_text + L"a", edit_view->GetText());
687 687
688 // Delete one character from the end. Make sure we won't delete the special 688 // Delete one character from the end. Make sure we won't delete the special
689 // ZWS mark used in gtk implementation. 689 // ZWS mark used in gtk implementation.
690 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 690 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
691 EXPECT_EQ(old_text, edit_view->GetText()); 691 EXPECT_EQ(old_text, edit_view->GetText());
692 692
693 edit_view->SelectAll(true); 693 edit_view->SelectAll(true);
694 EXPECT_TRUE(edit_view->IsSelectAll()); 694 EXPECT_TRUE(edit_view->IsSelectAll());
695 edit_view->GetSelectionBounds(&start, &end); 695 edit_view->GetSelectionBounds(&start, &end);
696 EXPECT_EQ(0U, start); 696 EXPECT_EQ(0U, start);
697 EXPECT_EQ(old_text.size(), end); 697 EXPECT_EQ(old_text.size(), end);
698 698
699 // Delete the content 699 // Delete the content
700 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_DELETE, false, false, false)); 700 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false));
701 EXPECT_TRUE(edit_view->IsSelectAll()); 701 EXPECT_TRUE(edit_view->IsSelectAll());
702 edit_view->GetSelectionBounds(&start, &end); 702 edit_view->GetSelectionBounds(&start, &end);
703 EXPECT_EQ(0U, start); 703 EXPECT_EQ(0U, start);
704 EXPECT_EQ(0U, end); 704 EXPECT_EQ(0U, end);
705 EXPECT_TRUE(edit_view->GetText().empty()); 705 EXPECT_TRUE(edit_view->GetText().empty());
706 706
707 // Check if RevertAll() can set text and cursor correctly. 707 // Check if RevertAll() can set text and cursor correctly.
708 edit_view->RevertAll(); 708 edit_view->RevertAll();
709 EXPECT_FALSE(edit_view->IsSelectAll()); 709 EXPECT_FALSE(edit_view->IsSelectAll());
710 EXPECT_EQ(old_text, edit_view->GetText()); 710 EXPECT_EQ(old_text, edit_view->GetText());
(...skipping 11 matching lines...) Expand all
722 browser()->FocusLocationBar(); 722 browser()->FocusLocationBar();
723 723
724 AutocompleteEditView* edit_view = NULL; 724 AutocompleteEditView* edit_view = NULL;
725 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 725 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
726 726
727 std::wstring old_text = edit_view->GetText(); 727 std::wstring old_text = edit_view->GetText();
728 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); 728 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text);
729 EXPECT_TRUE(edit_view->IsSelectAll()); 729 EXPECT_TRUE(edit_view->IsSelectAll());
730 730
731 // Undo should clear the omnibox. 731 // Undo should clear the omnibox.
732 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 732 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
733 EXPECT_TRUE(edit_view->GetText().empty()); 733 EXPECT_TRUE(edit_view->GetText().empty());
734 734
735 // Nothing should happen if undo again. 735 // Nothing should happen if undo again.
736 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 736 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
737 EXPECT_TRUE(edit_view->GetText().empty()); 737 EXPECT_TRUE(edit_view->GetText().empty());
738 738
739 // Redo should restore the original text. 739 // Redo should restore the original text.
740 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, true, false)); 740 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, true, false));
741 EXPECT_EQ(old_text, edit_view->GetText()); 741 EXPECT_EQ(old_text, edit_view->GetText());
742 742
743 // Looks like the undo manager doesn't support restoring selection. 743 // Looks like the undo manager doesn't support restoring selection.
744 EXPECT_FALSE(edit_view->IsSelectAll()); 744 EXPECT_FALSE(edit_view->IsSelectAll());
745 745
746 // The cursor should be at the end. 746 // The cursor should be at the end.
747 std::wstring::size_type start, end; 747 std::wstring::size_type start, end;
748 edit_view->GetSelectionBounds(&start, &end); 748 edit_view->GetSelectionBounds(&start, &end);
749 EXPECT_EQ(old_text.size(), start); 749 EXPECT_EQ(old_text.size(), start);
750 EXPECT_EQ(old_text.size(), end); 750 EXPECT_EQ(old_text.size(), end);
751 751
752 // Delete two characters. 752 // Delete two characters.
753 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 753 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
754 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 754 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
755 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText()); 755 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
756 756
757 // Undo delete. 757 // Undo delete.
758 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 758 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
759 EXPECT_EQ(old_text, edit_view->GetText()); 759 EXPECT_EQ(old_text, edit_view->GetText());
760 760
761 // Redo delete. 761 // Redo delete.
762 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, true, false)); 762 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, true, false));
763 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText()); 763 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
764 764
765 // Delete everything. 765 // Delete everything.
766 edit_view->SelectAll(true); 766 edit_view->SelectAll(true);
767 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 767 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
768 EXPECT_TRUE(edit_view->GetText().empty()); 768 EXPECT_TRUE(edit_view->GetText().empty());
769 769
770 // Undo delete everything. 770 // Undo delete everything.
771 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 771 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
772 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText()); 772 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), edit_view->GetText());
773 773
774 // Undo delete two characters. 774 // Undo delete two characters.
775 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 775 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
776 EXPECT_EQ(old_text, edit_view->GetText()); 776 EXPECT_EQ(old_text, edit_view->GetText());
777 777
778 // Undo again. 778 // Undo again.
779 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_Z, true, false, false)); 779 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, true, false, false));
780 EXPECT_TRUE(edit_view->GetText().empty()); 780 EXPECT_TRUE(edit_view->GetText().empty());
781 } 781 }
782 782
783 // See http://crbug.com/63860 783 // See http://crbug.com/63860
784 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) { 784 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PrimarySelection) {
785 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 785 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
786 786
787 browser()->FocusLocationBar(); 787 browser()->FocusLocationBar();
788 AutocompleteEditView* edit_view = NULL; 788 AutocompleteEditView* edit_view = NULL;
789 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 789 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
790 edit_view->SetUserText(L"Hello world"); 790 edit_view->SetUserText(L"Hello world");
791 EXPECT_FALSE(edit_view->IsSelectAll()); 791 EXPECT_FALSE(edit_view->IsSelectAll());
792 792
793 // Move the cursor to the end. 793 // Move the cursor to the end.
794 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_END, false, false, false)); 794 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
795 795
796 // Select all text by pressing Shift+Home 796 // Select all text by pressing Shift+Home
797 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_HOME, false, true, false)); 797 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, true, false));
798 EXPECT_TRUE(edit_view->IsSelectAll()); 798 EXPECT_TRUE(edit_view->IsSelectAll());
799 799
800 // The selected content should be saved to the PRIMARY clipboard. 800 // The selected content should be saved to the PRIMARY clipboard.
801 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 801 EXPECT_EQ("Hello world", GetPrimarySelectionText());
802 802
803 // Move the cursor to the end. 803 // Move the cursor to the end.
804 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_END, false, false, false)); 804 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
805 EXPECT_FALSE(edit_view->IsSelectAll()); 805 EXPECT_FALSE(edit_view->IsSelectAll());
806 806
807 // The content in the PRIMARY clipboard should not be cleared. 807 // The content in the PRIMARY clipboard should not be cleared.
808 EXPECT_EQ("Hello world", GetPrimarySelectionText()); 808 EXPECT_EQ("Hello world", GetPrimarySelectionText());
809 } 809 }
810 810
811 // See http://crosbug.com/10306 811 // See http://crosbug.com/10306
812 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, 812 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest,
813 BackspaceDeleteHalfWidthKatakana) { 813 BackspaceDeleteHalfWidthKatakana) {
814 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 814 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
815 815
816 browser()->FocusLocationBar(); 816 browser()->FocusLocationBar();
817 AutocompleteEditView* edit_view = NULL; 817 AutocompleteEditView* edit_view = NULL;
818 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 818 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
819 // Insert text: ダ 819 // Insert text: ダ
820 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236")); 820 edit_view->SetUserText(UTF8ToWide("\357\276\200\357\276\236"));
821 821
822 // Move the cursor to the end. 822 // Move the cursor to the end.
823 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_END, false, false, false)); 823 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false));
824 824
825 // Backspace should delete one character. 825 // Backspace should delete one character.
826 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_BACK, false, false, false)); 826 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false));
827 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText()); 827 EXPECT_EQ(UTF8ToWide("\357\276\200"), edit_view->GetText());
828 } 828 }
829 829
830 // http://crbug.com/12316 830 // http://crbug.com/12316
831 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) { 831 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, PasteReplacingAll) {
832 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 832 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
833 833
834 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 834 ASSERT_NO_FATAL_FAILURE(SetupComponents());
835 browser()->FocusLocationBar(); 835 browser()->FocusLocationBar();
836 836
837 AutocompleteEditView* edit_view = NULL; 837 AutocompleteEditView* edit_view = NULL;
838 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); 838 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view));
839 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); 839 AutocompletePopupModel* popup_model = edit_view->model()->popup_model();
840 ASSERT_TRUE(popup_model); 840 ASSERT_TRUE(popup_model);
841 841
842 SetClipboardText(kSearchText); 842 SetClipboardText(kSearchText);
843 843
844 // Paste text. 844 // Paste text.
845 ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_V, true, false, false)); 845 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false));
846 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 846 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
847 ASSERT_TRUE(popup_model->IsOpen()); 847 ASSERT_TRUE(popup_model->IsOpen());
848 848
849 // Inline autocomplete shouldn't be triggered. 849 // Inline autocomplete shouldn't be triggered.
850 ASSERT_EQ(L"abc", edit_view->GetText()); 850 ASSERT_EQ(L"abc", edit_view->GetText());
851 } 851 }
852 #endif 852 #endif
OLDNEW
« no previous file with comments | « app/menus/accelerator_gtk.h ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698