OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/test/ui_test_utils.h" | 31 #include "chrome/test/ui_test_utils.h" |
32 #include "net/base/mock_host_resolver.h" | 32 #include "net/base/mock_host_resolver.h" |
33 #include "ui/base/keycodes/keyboard_codes.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 #if defined(TOOLKIT_VIEWS) |
| 42 #include "views/controls/textfield/native_textfield_views.h" |
| 43 #endif |
| 44 |
41 using base::Time; | 45 using base::Time; |
42 using base::TimeDelta; | 46 using base::TimeDelta; |
43 | 47 |
44 namespace { | 48 namespace { |
45 | 49 |
46 const char kSearchKeyword[] = "foo"; | 50 const char kSearchKeyword[] = "foo"; |
47 const wchar_t kSearchKeywordKeys[] = { | 51 const wchar_t kSearchKeywordKeys[] = { |
48 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 | 52 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 |
49 }; | 53 }; |
50 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; | 54 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 public NotificationObserver { | 137 public NotificationObserver { |
134 protected: | 138 protected: |
135 AutocompleteEditViewTest() { | 139 AutocompleteEditViewTest() { |
136 set_show_window(true); | 140 set_show_window(true); |
137 } | 141 } |
138 | 142 |
139 virtual void SetUpOnMainThread() { | 143 virtual void SetUpOnMainThread() { |
140 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 144 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
141 ASSERT_NO_FATAL_FAILURE(SetupComponents()); | 145 ASSERT_NO_FATAL_FAILURE(SetupComponents()); |
142 browser()->FocusLocationBar(); | 146 browser()->FocusLocationBar(); |
143 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_LOCATION_BAR)); | 147 #if defined(TOOLKIT_VIEWS) |
| 148 if (views::NativeTextfieldViews::IsTextfieldViewsEnabled()) |
| 149 return; |
| 150 #endif |
| 151 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), |
| 152 VIEW_ID_LOCATION_BAR)); |
144 } | 153 } |
145 | 154 |
146 static void GetAutocompleteEditViewForBrowser( | 155 static void GetAutocompleteEditViewForBrowser( |
147 const Browser* browser, | 156 const Browser* browser, |
148 AutocompleteEditView** edit_view) { | 157 AutocompleteEditView** edit_view) { |
149 BrowserWindow* window = browser->window(); | 158 BrowserWindow* window = browser->window(); |
150 ASSERT_TRUE(window); | 159 ASSERT_TRUE(window); |
151 LocationBar* loc_bar = window->GetLocationBar(); | 160 LocationBar* loc_bar = window->GetLocationBar(); |
152 ASSERT_TRUE(loc_bar); | 161 ASSERT_TRUE(loc_bar); |
153 *edit_view = loc_bar->location_entry(); | 162 *edit_view = loc_bar->location_entry(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 BookmarkModel* bookmark_model = profile->GetBookmarkModel(); | 270 BookmarkModel* bookmark_model = profile->GetBookmarkModel(); |
262 ASSERT_TRUE(bookmark_model); | 271 ASSERT_TRUE(bookmark_model); |
263 | 272 |
264 if (!bookmark_model->IsLoaded()) { | 273 if (!bookmark_model->IsLoaded()) { |
265 NotificationRegistrar registrar; | 274 NotificationRegistrar registrar; |
266 registrar.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, | 275 registrar.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, |
267 Source<Profile>(profile)); | 276 Source<Profile>(profile)); |
268 ui_test_utils::RunMessageLoop(); | 277 ui_test_utils::RunMessageLoop(); |
269 } | 278 } |
270 | 279 |
271 // Add enough history pages containing |kSearchText| to trigger open history | 280 // Add enough history pages containing |kSearchText| to trigger |
272 // page url in autocomplete result. | 281 // open history page url in autocomplete result. |
273 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) { | 282 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) { |
274 const TestHistoryEntry& cur = kHistoryEntries[i]; | 283 const TestHistoryEntry& cur = kHistoryEntries[i]; |
275 GURL url(cur.url); | 284 GURL url(cur.url); |
276 // Add everything in order of time. We don't want to have a time that | 285 // Add everything in order of time. We don't want to have a time that |
277 // is "right now" or it will nondeterministically appear in the results. | 286 // is "right now" or it will nondeterministically appear in the results. |
278 Time t = Time::Now() - TimeDelta::FromHours(i + 1); | 287 Time t = Time::Now() - TimeDelta::FromHours(i + 1); |
279 history_service->AddPageWithDetails(url, UTF8ToUTF16(cur.title), | 288 history_service->AddPageWithDetails(url, UTF8ToUTF16(cur.title), |
280 cur.visit_count, | 289 cur.visit_count, |
281 cur.typed_count, t, false, | 290 cur.typed_count, t, false, |
282 history::SOURCE_BROWSED); | 291 history::SOURCE_BROWSED); |
(...skipping 24 matching lines...) Expand all Loading... |
307 case NotificationType::TEMPLATE_URL_MODEL_LOADED: | 316 case NotificationType::TEMPLATE_URL_MODEL_LOADED: |
308 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: | 317 case NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED: |
309 case NotificationType::HISTORY_LOADED: | 318 case NotificationType::HISTORY_LOADED: |
310 case NotificationType::BOOKMARK_MODEL_LOADED: | 319 case NotificationType::BOOKMARK_MODEL_LOADED: |
311 break; | 320 break; |
312 default: | 321 default: |
313 FAIL() << "Unexpected notification type"; | 322 FAIL() << "Unexpected notification type"; |
314 } | 323 } |
315 MessageLoopForUI::current()->Quit(); | 324 MessageLoopForUI::current()->Quit(); |
316 } | 325 } |
| 326 |
| 327 void BrowserAcceleratorsTest() { |
| 328 AutocompleteEditView* edit_view = NULL; |
| 329 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 330 |
| 331 int tab_count = browser()->tab_count(); |
| 332 |
| 333 // Create a new Tab. |
| 334 browser()->NewTab(); |
| 335 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); |
| 336 |
| 337 // Select the first Tab. |
| 338 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1, true, false, false)); |
| 339 ASSERT_EQ(0, browser()->selected_index()); |
| 340 |
| 341 browser()->FocusLocationBar(); |
| 342 |
| 343 // Select the second Tab. |
| 344 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2, true, false, false)); |
| 345 ASSERT_EQ(1, browser()->selected_index()); |
| 346 |
| 347 browser()->FocusLocationBar(); |
| 348 |
| 349 // Try ctrl-w to close a Tab. |
| 350 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W, true, false, false)); |
| 351 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count)); |
| 352 |
| 353 // Try ctrl-l to focus location bar. |
| 354 edit_view->SetUserText(L"Hello world"); |
| 355 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 356 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, true, false, false)); |
| 357 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 358 |
| 359 // Try editing the location bar text. |
| 360 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, false, false, false)); |
| 361 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 362 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, false, false, false)); |
| 363 EXPECT_EQ(L"Hello worlds", edit_view->GetText()); |
| 364 |
| 365 // Try ctrl-x to cut text. |
| 366 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, true, true, false)); |
| 367 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 368 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, true, false, false)); |
| 369 EXPECT_EQ(L"Hello ", edit_view->GetText()); |
| 370 |
| 371 #if !defined(OS_CHROMEOS) |
| 372 // Try alt-f4 to close the browser. |
| 373 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 374 browser(), ui::VKEY_F4, false, false, true, false, |
| 375 NotificationType::BROWSER_CLOSED, Source<Browser>(browser()))); |
| 376 #endif |
| 377 } |
| 378 |
| 379 void PopupAcceleratorsTest() { |
| 380 // Create a popup. |
| 381 Browser* popup = CreateBrowserForPopup(browser()->profile()); |
| 382 AutocompleteEditView* edit_view = NULL; |
| 383 ASSERT_NO_FATAL_FAILURE( |
| 384 GetAutocompleteEditViewForBrowser(popup, &edit_view)); |
| 385 popup->FocusLocationBar(); |
| 386 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 387 |
| 388 // Try ctrl-w to close the popup. |
| 389 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 390 popup, ui::VKEY_W, true, false, false, false, |
| 391 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); |
| 392 |
| 393 // Create another popup. |
| 394 popup = CreateBrowserForPopup(browser()->profile()); |
| 395 ASSERT_NO_FATAL_FAILURE( |
| 396 GetAutocompleteEditViewForBrowser(popup, &edit_view)); |
| 397 |
| 398 // Set the edit text to "Hello world". |
| 399 edit_view->SetUserText(L"Hello world"); |
| 400 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 401 popup->FocusLocationBar(); |
| 402 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 403 |
| 404 // Try editing the location bar text -- should be disallowed. |
| 405 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_RIGHT, false, |
| 406 false, false)); |
| 407 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 408 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, false, false, |
| 409 false)); |
| 410 EXPECT_EQ(L"Hello world", edit_view->GetText()); |
| 411 |
| 412 // Try ctrl-x to cut text -- should be disallowed. |
| 413 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_LEFT, true, true, |
| 414 false)); |
| 415 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 416 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_X, true, false, |
| 417 false)); |
| 418 EXPECT_EQ(L"Hello world", edit_view->GetText()); |
| 419 |
| 420 #if !defined(OS_CHROMEOS) |
| 421 // Try alt-f4 to close the popup. |
| 422 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
| 423 popup, ui::VKEY_F4, false, false, true, false, |
| 424 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); |
| 425 #endif |
| 426 } |
| 427 |
| 428 void BackspaceInKeywordModeTest() { |
| 429 AutocompleteEditView* edit_view = NULL; |
| 430 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 431 |
| 432 // Trigger keyword hint mode. |
| 433 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 434 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 435 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); |
| 436 |
| 437 // Trigger keyword mode. |
| 438 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); |
| 439 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 440 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); |
| 441 |
| 442 // Backspace without search text should bring back keyword hint mode. |
| 443 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 444 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 445 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); |
| 446 |
| 447 // Trigger keyword mode again. |
| 448 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); |
| 449 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 450 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); |
| 451 |
| 452 // Input something as search text. |
| 453 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 454 |
| 455 // Should stay in keyword mode while deleting search text by pressing |
| 456 // backspace. |
| 457 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { |
| 458 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 459 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 460 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); |
| 461 } |
| 462 |
| 463 // Input something as search text. |
| 464 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 465 |
| 466 // Move cursor to the beginning of the search text. |
| 467 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, false, false)); |
| 468 // Backspace at the beginning of the search text shall turn off |
| 469 // the keyword mode. |
| 470 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 471 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 472 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); |
| 473 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, |
| 474 WideToUTF8(edit_view->GetText())); |
| 475 } |
| 476 |
| 477 void EscapeTest() { |
| 478 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); |
| 479 browser()->FocusLocationBar(); |
| 480 |
| 481 AutocompleteEditView* edit_view = NULL; |
| 482 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 483 |
| 484 std::wstring old_text = edit_view->GetText(); |
| 485 EXPECT_FALSE(old_text.empty()); |
| 486 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 487 |
| 488 // Delete all text in omnibox. |
| 489 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 490 EXPECT_TRUE(edit_view->GetText().empty()); |
| 491 |
| 492 // Escape shall revert the text in omnibox. |
| 493 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); |
| 494 EXPECT_EQ(old_text, edit_view->GetText()); |
| 495 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 496 } |
| 497 |
| 498 void DesiredTLDTest() { |
| 499 AutocompleteEditView* edit_view = NULL; |
| 500 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 501 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); |
| 502 ASSERT_TRUE(popup_model); |
| 503 |
| 504 // Test ctrl-Enter. |
| 505 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); |
| 506 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 507 ASSERT_TRUE(popup_model->IsOpen()); |
| 508 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened
. |
| 509 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); |
| 510 |
| 511 GURL url = browser()->GetSelectedTabContents()->GetURL(); |
| 512 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); |
| 513 } |
| 514 |
| 515 void AltEnterTest() { |
| 516 AutocompleteEditView* edit_view = NULL; |
| 517 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 518 |
| 519 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); |
| 520 int tab_count = browser()->tab_count(); |
| 521 // alt-Enter opens a new tab. |
| 522 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true)); |
| 523 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); |
| 524 } |
| 525 |
| 526 void EnterToSearchTest() { |
| 527 AutocompleteEditView* edit_view = NULL; |
| 528 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 529 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); |
| 530 ASSERT_TRUE(popup_model); |
| 531 |
| 532 // Test Enter to search. |
| 533 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 534 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 535 ASSERT_TRUE(popup_model->IsOpen()); |
| 536 |
| 537 // Check if the default match result is Search Primary Provider. |
| 538 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
| 539 popup_model->result().default_match()->type); |
| 540 |
| 541 // Open the default match. |
| 542 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); |
| 543 GURL url = browser()->GetSelectedTabContents()->GetURL(); |
| 544 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); |
| 545 |
| 546 // Test that entering a single character then Enter performs a search. |
| 547 browser()->FocusLocationBar(); |
| 548 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 549 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); |
| 550 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 551 ASSERT_TRUE(popup_model->IsOpen()); |
| 552 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); |
| 553 |
| 554 // Check if the default match result is Search Primary Provider. |
| 555 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, |
| 556 popup_model->result().default_match()->type); |
| 557 |
| 558 // Open the default match. |
| 559 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); |
| 560 url = browser()->GetSelectedTabContents()->GetURL(); |
| 561 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); |
| 562 } |
| 563 |
| 564 void EscapeToDefaultMatchTest() { |
| 565 AutocompleteEditView* edit_view = NULL; |
| 566 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 567 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); |
| 568 ASSERT_TRUE(popup_model); |
| 569 |
| 570 // Input something to trigger inline autocomplete. |
| 571 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys)); |
| 572 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 573 ASSERT_TRUE(popup_model->IsOpen()); |
| 574 |
| 575 std::wstring old_text = edit_view->GetText(); |
| 576 |
| 577 // Make sure inline autocomplete is triggerred. |
| 578 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); |
| 579 |
| 580 size_t old_selected_line = popup_model->selected_line(); |
| 581 EXPECT_EQ(0U, old_selected_line); |
| 582 |
| 583 // Move to another line with different text. |
| 584 size_t size = popup_model->result().size(); |
| 585 while (popup_model->selected_line() < size - 1) { |
| 586 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false)); |
| 587 ASSERT_NE(old_selected_line, popup_model->selected_line()); |
| 588 if (old_text != edit_view->GetText()) |
| 589 break; |
| 590 } |
| 591 |
| 592 EXPECT_NE(old_text, edit_view->GetText()); |
| 593 |
| 594 // Escape shall revert back to the default match item. |
| 595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); |
| 596 EXPECT_EQ(old_text, edit_view->GetText()); |
| 597 EXPECT_EQ(old_selected_line, popup_model->selected_line()); |
| 598 } |
| 599 |
| 600 void BasicTextOperationsTest() { |
| 601 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
| 602 browser()->FocusLocationBar(); |
| 603 |
| 604 AutocompleteEditView* edit_view = NULL; |
| 605 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 606 |
| 607 std::wstring old_text = edit_view->GetText(); |
| 608 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); |
| 609 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 610 |
| 611 std::wstring::size_type start, end; |
| 612 edit_view->GetSelectionBounds(&start, &end); |
| 613 EXPECT_EQ(0U, start); |
| 614 EXPECT_EQ(old_text.size(), end); |
| 615 |
| 616 // Move the cursor to the end. |
| 617 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); |
| 618 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 619 |
| 620 // Make sure the cursor is placed correctly. |
| 621 edit_view->GetSelectionBounds(&start, &end); |
| 622 EXPECT_EQ(old_text.size(), start); |
| 623 EXPECT_EQ(old_text.size(), end); |
| 624 |
| 625 // Insert one character at the end. Make sure we won't insert |
| 626 // anything after the special ZWS mark used in gtk implementation. |
| 627 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, false, false, false)); |
| 628 EXPECT_EQ(old_text + L"a", edit_view->GetText()); |
| 629 |
| 630 // Delete one character from the end. Make sure we won't delete the special |
| 631 // ZWS mark used in gtk implementation. |
| 632 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 633 EXPECT_EQ(old_text, edit_view->GetText()); |
| 634 |
| 635 edit_view->SelectAll(true); |
| 636 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 637 edit_view->GetSelectionBounds(&start, &end); |
| 638 EXPECT_EQ(0U, start); |
| 639 EXPECT_EQ(old_text.size(), end); |
| 640 |
| 641 // Delete the content |
| 642 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false)); |
| 643 EXPECT_TRUE(edit_view->IsSelectAll()); |
| 644 edit_view->GetSelectionBounds(&start, &end); |
| 645 EXPECT_EQ(0U, start); |
| 646 EXPECT_EQ(0U, end); |
| 647 EXPECT_TRUE(edit_view->GetText().empty()); |
| 648 |
| 649 // Check if RevertAll() can set text and cursor correctly. |
| 650 edit_view->RevertAll(); |
| 651 EXPECT_FALSE(edit_view->IsSelectAll()); |
| 652 EXPECT_EQ(old_text, edit_view->GetText()); |
| 653 edit_view->GetSelectionBounds(&start, &end); |
| 654 EXPECT_EQ(old_text.size(), start); |
| 655 EXPECT_EQ(old_text.size(), end); |
| 656 } |
| 657 |
| 658 void AcceptKeywordBySpaceTest() { |
| 659 AutocompleteEditView* edit_view = NULL; |
| 660 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
| 661 |
| 662 std::wstring text = UTF8ToWide(kSearchKeyword); |
| 663 |
| 664 // Trigger keyword hint mode. |
| 665 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); |
| 666 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 667 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 668 ASSERT_EQ(text, edit_view->GetText()); |
| 669 |
| 670 // Trigger keyword mode by space. |
| 671 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
| 672 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 673 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 674 ASSERT_TRUE(edit_view->GetText().empty()); |
| 675 |
| 676 // Revert to keyword hint mode. |
| 677 edit_view->model()->ClearKeyword(std::wstring()); |
| 678 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 679 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 680 ASSERT_EQ(text, edit_view->GetText()); |
| 681 |
| 682 // Keyword should also be accepted by typing an ideographic space. |
| 683 edit_view->OnBeforePossibleChange(); |
| 684 edit_view->SetWindowTextAndCaretPos(text + L"\x3000", text.length() + 1); |
| 685 edit_view->OnAfterPossibleChange(); |
| 686 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 687 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 688 ASSERT_TRUE(edit_view->GetText().empty()); |
| 689 |
| 690 // Revert to keyword hint mode. |
| 691 edit_view->model()->ClearKeyword(std::wstring()); |
| 692 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 693 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 694 ASSERT_EQ(text, edit_view->GetText()); |
| 695 |
| 696 // Keyword shouldn't be accepted by pasting. |
| 697 // Simulate pasting a whitespace to the end of content. |
| 698 edit_view->OnBeforePossibleChange(); |
| 699 edit_view->model()->on_paste(); |
| 700 edit_view->SetWindowTextAndCaretPos(text + L" ", text.length() + 1); |
| 701 edit_view->OnAfterPossibleChange(); |
| 702 // Should be still in keyword hint mode. |
| 703 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 704 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 705 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 706 |
| 707 // Keyword shouldn't be accepted by pressing space with a trailing |
| 708 // whitespace. |
| 709 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
| 710 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 711 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 712 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 713 |
| 714 // Keyword shouldn't be accepted by deleting the trailing space. |
| 715 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); |
| 716 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 717 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 718 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 719 |
| 720 // Keyword shouldn't be accepted by pressing space in the middle |
| 721 // of content. |
| 722 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, false, false, false)); |
| 723 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
| 724 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 725 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 726 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 727 |
| 728 // Keyword shouldn't be accepted by pasting "foo bar". |
| 729 edit_view->SetUserText(std::wstring()); |
| 730 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 731 ASSERT_TRUE(edit_view->model()->keyword().empty()); |
| 732 |
| 733 edit_view->OnBeforePossibleChange(); |
| 734 edit_view->model()->on_paste(); |
| 735 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4); |
| 736 edit_view->OnAfterPossibleChange(); |
| 737 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); |
| 738 ASSERT_TRUE(edit_view->model()->keyword().empty()); |
| 739 ASSERT_EQ(text + L" bar", edit_view->GetText()); |
| 740 |
| 741 // Keyword shouldn't be accepted by pressing space with a selected range. |
| 742 edit_view->OnBeforePossibleChange(); |
| 743 edit_view->OnInlineAutocompleteTextMaybeChanged( |
| 744 text + L" ", text.length()); |
| 745 edit_view->OnAfterPossibleChange(); |
| 746 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 747 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 748 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 749 |
| 750 std::wstring::size_type start, end; |
| 751 edit_view->GetSelectionBounds(&start, &end); |
| 752 ASSERT_NE(start, end); |
| 753 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); |
| 754 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); |
| 755 ASSERT_EQ(text, edit_view->model()->keyword()); |
| 756 ASSERT_EQ(text + L" ", edit_view->GetText()); |
| 757 |
| 758 edit_view->GetSelectionBounds(&start, &end); |
| 759 ASSERT_EQ(start, end); |
| 760 } |
| 761 |
317 }; | 762 }; |
318 | 763 |
319 // Test if ctrl-* accelerators are workable in omnibox. | 764 // Test if ctrl-* accelerators are workable in omnibox. |
320 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 765 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
321 // | 766 // |
322 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 767 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
323 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { | 768 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { |
324 AutocompleteEditView* edit_view = NULL; | 769 BrowserAcceleratorsTest(); |
325 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
326 | |
327 int tab_count = browser()->tab_count(); | |
328 | |
329 // Create a new Tab. | |
330 browser()->NewTab(); | |
331 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); | |
332 | |
333 // Select the first Tab. | |
334 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1, true, false, false)); | |
335 ASSERT_EQ(0, browser()->selected_index()); | |
336 | |
337 browser()->FocusLocationBar(); | |
338 | |
339 // Select the second Tab. | |
340 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2, true, false, false)); | |
341 ASSERT_EQ(1, browser()->selected_index()); | |
342 | |
343 browser()->FocusLocationBar(); | |
344 | |
345 // Try ctrl-w to close a Tab. | |
346 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W, true, false, false)); | |
347 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count)); | |
348 | |
349 // Try ctrl-l to focus location bar. | |
350 edit_view->SetUserText(L"Hello world"); | |
351 EXPECT_FALSE(edit_view->IsSelectAll()); | |
352 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, true, false, false)); | |
353 EXPECT_TRUE(edit_view->IsSelectAll()); | |
354 | |
355 // Try editing the location bar text. | |
356 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, false, false, false)); | |
357 EXPECT_FALSE(edit_view->IsSelectAll()); | |
358 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, false, false, false)); | |
359 EXPECT_EQ(L"Hello worlds", edit_view->GetText()); | |
360 | |
361 // Try ctrl-x to cut text. | |
362 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, true, true, false)); | |
363 EXPECT_FALSE(edit_view->IsSelectAll()); | |
364 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, true, false, false)); | |
365 EXPECT_EQ(L"Hello ", edit_view->GetText()); | |
366 | |
367 #if !defined(OS_CHROMEOS) | |
368 // Try alt-f4 to close the browser. | |
369 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | |
370 browser(), ui::VKEY_F4, false, false, true, false, | |
371 NotificationType::BROWSER_CLOSED, Source<Browser>(browser()))); | |
372 #endif | |
373 } | 770 } |
374 | 771 |
375 // Flakily fails and times out on Win only. http://crbug.com/69941 | 772 // Flakily fails and times out on Win only. http://crbug.com/69941 |
376 #if defined(OS_WIN) | 773 #if defined(OS_WIN) |
377 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators | 774 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators |
378 #else | 775 #else |
379 #define MAYBE_PopupAccelerators PopupAccelerators | 776 #define MAYBE_PopupAccelerators PopupAccelerators |
380 #endif | 777 #endif |
| 778 |
381 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, MAYBE_PopupAccelerators) { | 779 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, MAYBE_PopupAccelerators) { |
382 // Create a popup. | 780 PopupAcceleratorsTest(); |
383 Browser* popup = CreateBrowserForPopup(browser()->profile()); | |
384 AutocompleteEditView* edit_view = NULL; | |
385 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view)); | |
386 popup->FocusLocationBar(); | |
387 EXPECT_TRUE(edit_view->IsSelectAll()); | |
388 | |
389 // Try ctrl-w to close the popup. | |
390 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | |
391 popup, ui::VKEY_W, true, false, false, false, | |
392 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); | |
393 | |
394 // Create another popup. | |
395 popup = CreateBrowserForPopup(browser()->profile()); | |
396 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditViewForBrowser(popup, &edit_view)); | |
397 | |
398 // Set the edit text to "Hello world". | |
399 edit_view->SetUserText(L"Hello world"); | |
400 EXPECT_FALSE(edit_view->IsSelectAll()); | |
401 popup->FocusLocationBar(); | |
402 EXPECT_TRUE(edit_view->IsSelectAll()); | |
403 | |
404 // Try editing the location bar text -- should be disallowed. | |
405 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_RIGHT, false, | |
406 false, false)); | |
407 EXPECT_FALSE(edit_view->IsSelectAll()); | |
408 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, false, false, | |
409 false)); | |
410 EXPECT_EQ(L"Hello world", edit_view->GetText()); | |
411 | |
412 // Try ctrl-x to cut text -- should be disallowed. | |
413 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_LEFT, true, true, | |
414 false)); | |
415 EXPECT_FALSE(edit_view->IsSelectAll()); | |
416 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_X, true, false, | |
417 false)); | |
418 EXPECT_EQ(L"Hello world", edit_view->GetText()); | |
419 | |
420 #if !defined(OS_CHROMEOS) | |
421 // Try alt-f4 to close the popup. | |
422 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | |
423 popup, ui::VKEY_F4, false, false, true, false, | |
424 NotificationType::BROWSER_CLOSED, Source<Browser>(popup))); | |
425 #endif | |
426 } | 781 } |
427 | 782 |
428 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { | 783 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { |
429 AutocompleteEditView* edit_view = NULL; | 784 BackspaceInKeywordModeTest(); |
430 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
431 | |
432 // Trigger keyword hint mode. | |
433 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | |
434 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
435 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); | |
436 | |
437 // Trigger keyword mode. | |
438 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); | |
439 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
440 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); | |
441 | |
442 // Backspace without search text should bring back keyword hint mode. | |
443 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
444 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
445 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); | |
446 | |
447 // Trigger keyword mode again. | |
448 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, false, false, false)); | |
449 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
450 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); | |
451 | |
452 // Input something as search text. | |
453 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | |
454 | |
455 // Should stay in keyword mode while deleting search text by pressing | |
456 // backspace. | |
457 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { | |
458 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
459 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
460 ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); | |
461 } | |
462 | |
463 // Input something as search text. | |
464 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | |
465 | |
466 // Move cursor to the beginning of the search text. | |
467 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, false, false, false)); | |
468 // Backspace at the beginning of the search text shall turn off | |
469 // the keyword mode. | |
470 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
471 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
472 ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); | |
473 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, | |
474 WideToUTF8(edit_view->GetText())); | |
475 } | 785 } |
476 | 786 |
477 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { | 787 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { |
478 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL)); | 788 EscapeTest(); |
479 browser()->FocusLocationBar(); | |
480 | |
481 AutocompleteEditView* edit_view = NULL; | |
482 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
483 | |
484 std::wstring old_text = edit_view->GetText(); | |
485 EXPECT_FALSE(old_text.empty()); | |
486 EXPECT_TRUE(edit_view->IsSelectAll()); | |
487 | |
488 // Delete all text in omnibox. | |
489 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
490 EXPECT_TRUE(edit_view->GetText().empty()); | |
491 | |
492 // Escape shall revert the text in omnibox. | |
493 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); | |
494 EXPECT_EQ(old_text, edit_view->GetText()); | |
495 EXPECT_TRUE(edit_view->IsSelectAll()); | |
496 } | 789 } |
497 | 790 |
498 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) { | 791 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, DesiredTLD) { |
499 AutocompleteEditView* edit_view = NULL; | 792 DesiredTLDTest(); |
500 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
501 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
502 ASSERT_TRUE(popup_model); | |
503 | |
504 // Test ctrl-Enter. | |
505 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kDesiredTLDKeys)); | |
506 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
507 ASSERT_TRUE(popup_model->IsOpen()); | |
508 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be opened. | |
509 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, true, false, false)); | |
510 | |
511 GURL url = browser()->GetSelectedTabContents()->GetURL(); | |
512 EXPECT_STREQ(kDesiredTLDHostname, url.host().c_str()); | |
513 } | 793 } |
514 | 794 |
515 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) { | 795 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AltEnter) { |
516 AutocompleteEditView* edit_view = NULL; | 796 AltEnterTest(); |
517 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
518 | |
519 edit_view->SetUserText(ASCIIToWide(chrome::kChromeUIHistoryURL)); | |
520 int tab_count = browser()->tab_count(); | |
521 // alt-Enter opens a new tab. | |
522 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, true)); | |
523 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1)); | |
524 } | 797 } |
525 | 798 |
526 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { | 799 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { |
527 AutocompleteEditView* edit_view = NULL; | 800 EnterToSearchTest(); |
528 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
529 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
530 ASSERT_TRUE(popup_model); | |
531 | |
532 // Test Enter to search. | |
533 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | |
534 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
535 ASSERT_TRUE(popup_model->IsOpen()); | |
536 | |
537 // Check if the default match result is Search Primary Provider. | |
538 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | |
539 popup_model->result().default_match()->type); | |
540 | |
541 // Open the default match. | |
542 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); | |
543 GURL url = browser()->GetSelectedTabContents()->GetURL(); | |
544 EXPECT_STREQ(kSearchTextURL, url.spec().c_str()); | |
545 | |
546 // Test that entering a single character then Enter performs a search. | |
547 browser()->FocusLocationBar(); | |
548 EXPECT_TRUE(edit_view->IsSelectAll()); | |
549 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); | |
550 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
551 ASSERT_TRUE(popup_model->IsOpen()); | |
552 EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); | |
553 | |
554 // Check if the default match result is Search Primary Provider. | |
555 ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, | |
556 popup_model->result().default_match()->type); | |
557 | |
558 // Open the default match. | |
559 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, false, false, false)); | |
560 url = browser()->GetSelectedTabContents()->GetURL(); | |
561 EXPECT_STREQ(kSearchSingleCharURL, url.spec().c_str()); | |
562 } | 801 } |
563 | 802 |
564 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { | 803 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EscapeToDefaultMatch) { |
565 AutocompleteEditView* edit_view = NULL; | 804 EscapeToDefaultMatchTest(); |
566 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
567 AutocompletePopupModel* popup_model = edit_view->model()->popup_model(); | |
568 ASSERT_TRUE(popup_model); | |
569 | |
570 // Input something to trigger inline autocomplete. | |
571 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys)); | |
572 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | |
573 ASSERT_TRUE(popup_model->IsOpen()); | |
574 | |
575 std::wstring old_text = edit_view->GetText(); | |
576 | |
577 // Make sure inline autocomplete is triggerred. | |
578 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1); | |
579 | |
580 size_t old_selected_line = popup_model->selected_line(); | |
581 EXPECT_EQ(0U, old_selected_line); | |
582 | |
583 // Move to another line with different text. | |
584 size_t size = popup_model->result().size(); | |
585 while (popup_model->selected_line() < size - 1) { | |
586 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, false, false, false)); | |
587 ASSERT_NE(old_selected_line, popup_model->selected_line()); | |
588 if (old_text != edit_view->GetText()) | |
589 break; | |
590 } | |
591 | |
592 EXPECT_NE(old_text, edit_view->GetText()); | |
593 | |
594 // Escape shall revert back to the default match item. | |
595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, false, false, false)); | |
596 EXPECT_EQ(old_text, edit_view->GetText()); | |
597 EXPECT_EQ(old_selected_line, popup_model->selected_line()); | |
598 } | 805 } |
599 | 806 |
600 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { | 807 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BasicTextOperations) { |
601 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 808 BasicTextOperationsTest(); |
602 browser()->FocusLocationBar(); | |
603 | |
604 AutocompleteEditView* edit_view = NULL; | |
605 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
606 | |
607 std::wstring old_text = edit_view->GetText(); | |
608 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); | |
609 EXPECT_TRUE(edit_view->IsSelectAll()); | |
610 | |
611 std::wstring::size_type start, end; | |
612 edit_view->GetSelectionBounds(&start, &end); | |
613 EXPECT_EQ(0U, start); | |
614 EXPECT_EQ(old_text.size(), end); | |
615 | |
616 // Move the cursor to the end. | |
617 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, false, false, false)); | |
618 EXPECT_FALSE(edit_view->IsSelectAll()); | |
619 | |
620 // Make sure the cursor is placed correctly. | |
621 edit_view->GetSelectionBounds(&start, &end); | |
622 EXPECT_EQ(old_text.size(), start); | |
623 EXPECT_EQ(old_text.size(), end); | |
624 | |
625 // Insert one character at the end. Make sure we won't insert anything after | |
626 // the special ZWS mark used in gtk implementation. | |
627 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, false, false, false)); | |
628 EXPECT_EQ(old_text + L"a", edit_view->GetText()); | |
629 | |
630 // Delete one character from the end. Make sure we won't delete the special | |
631 // ZWS mark used in gtk implementation. | |
632 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
633 EXPECT_EQ(old_text, edit_view->GetText()); | |
634 | |
635 edit_view->SelectAll(true); | |
636 EXPECT_TRUE(edit_view->IsSelectAll()); | |
637 edit_view->GetSelectionBounds(&start, &end); | |
638 EXPECT_EQ(0U, start); | |
639 EXPECT_EQ(old_text.size(), end); | |
640 | |
641 // Delete the content | |
642 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, false, false, false)); | |
643 EXPECT_TRUE(edit_view->IsSelectAll()); | |
644 edit_view->GetSelectionBounds(&start, &end); | |
645 EXPECT_EQ(0U, start); | |
646 EXPECT_EQ(0U, end); | |
647 EXPECT_TRUE(edit_view->GetText().empty()); | |
648 | |
649 // Check if RevertAll() can set text and cursor correctly. | |
650 edit_view->RevertAll(); | |
651 EXPECT_FALSE(edit_view->IsSelectAll()); | |
652 EXPECT_EQ(old_text, edit_view->GetText()); | |
653 edit_view->GetSelectionBounds(&start, &end); | |
654 EXPECT_EQ(old_text.size(), start); | |
655 EXPECT_EQ(old_text.size(), end); | |
656 } | 809 } |
657 | 810 |
658 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { | 811 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, AcceptKeywordBySpace) { |
659 AutocompleteEditView* edit_view = NULL; | 812 AcceptKeywordBySpaceTest(); |
660 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | |
661 | |
662 std::wstring text = UTF8ToWide(kSearchKeyword); | |
663 | |
664 // Trigger keyword hint mode. | |
665 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); | |
666 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
667 ASSERT_EQ(text, edit_view->model()->keyword()); | |
668 ASSERT_EQ(text, edit_view->GetText()); | |
669 | |
670 // Trigger keyword mode by space. | |
671 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | |
672 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
673 ASSERT_EQ(text, edit_view->model()->keyword()); | |
674 ASSERT_TRUE(edit_view->GetText().empty()); | |
675 | |
676 // Revert to keyword hint mode. | |
677 edit_view->model()->ClearKeyword(std::wstring()); | |
678 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
679 ASSERT_EQ(text, edit_view->model()->keyword()); | |
680 ASSERT_EQ(text, edit_view->GetText()); | |
681 | |
682 // Keyword should also be accepted by typing an ideographic space. | |
683 edit_view->OnBeforePossibleChange(); | |
684 edit_view->SetWindowTextAndCaretPos(text + L"\x3000", text.length() + 1); | |
685 edit_view->OnAfterPossibleChange(); | |
686 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
687 ASSERT_EQ(text, edit_view->model()->keyword()); | |
688 ASSERT_TRUE(edit_view->GetText().empty()); | |
689 | |
690 // Revert to keyword hint mode. | |
691 edit_view->model()->ClearKeyword(std::wstring()); | |
692 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
693 ASSERT_EQ(text, edit_view->model()->keyword()); | |
694 ASSERT_EQ(text, edit_view->GetText()); | |
695 | |
696 // Keyword shouldn't be accepted by pasting. | |
697 // Simulate pasting a whitespace to the end of content. | |
698 edit_view->OnBeforePossibleChange(); | |
699 edit_view->model()->on_paste(); | |
700 edit_view->SetWindowTextAndCaretPos(text + L" ", text.length() + 1); | |
701 edit_view->OnAfterPossibleChange(); | |
702 // Should be still in keyword hint mode. | |
703 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
704 ASSERT_EQ(text, edit_view->model()->keyword()); | |
705 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
706 | |
707 // Keyword shouldn't be accepted by pressing space with a trailing whitespace. | |
708 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | |
709 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
710 ASSERT_EQ(text, edit_view->model()->keyword()); | |
711 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
712 | |
713 // Keyword shouldn't be accepted by deleting the trailing space. | |
714 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, false, false, false)); | |
715 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
716 ASSERT_EQ(text, edit_view->model()->keyword()); | |
717 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
718 | |
719 // Keyword shouldn't be accepted by pressing space in the middle of content. | |
720 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, false, false, false)); | |
721 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | |
722 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
723 ASSERT_EQ(text, edit_view->model()->keyword()); | |
724 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
725 | |
726 // Keyword shouldn't be accepted by pasting "foo bar". | |
727 edit_view->SetUserText(std::wstring()); | |
728 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
729 ASSERT_TRUE(edit_view->model()->keyword().empty()); | |
730 | |
731 edit_view->OnBeforePossibleChange(); | |
732 edit_view->model()->on_paste(); | |
733 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4); | |
734 edit_view->OnAfterPossibleChange(); | |
735 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); | |
736 ASSERT_TRUE(edit_view->model()->keyword().empty()); | |
737 ASSERT_EQ(text + L" bar", edit_view->GetText()); | |
738 | |
739 // Keyword shouldn't be accepted by pressing space with a selected range. | |
740 edit_view->OnBeforePossibleChange(); | |
741 edit_view->OnInlineAutocompleteTextMaybeChanged(text + L" ", text.length()); | |
742 edit_view->OnAfterPossibleChange(); | |
743 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
744 ASSERT_EQ(text, edit_view->model()->keyword()); | |
745 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
746 | |
747 std::wstring::size_type start, end; | |
748 edit_view->GetSelectionBounds(&start, &end); | |
749 ASSERT_NE(start, end); | |
750 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); | |
751 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); | |
752 ASSERT_EQ(text, edit_view->model()->keyword()); | |
753 ASSERT_EQ(text + L" ", edit_view->GetText()); | |
754 | |
755 edit_view->GetSelectionBounds(&start, &end); | |
756 ASSERT_EQ(start, end); | |
757 } | 813 } |
758 | 814 |
759 #if defined(OS_LINUX) | 815 #if defined(OS_LINUX) |
| 816 // TODO(oshima): enable these tests for views-implmentation when |
| 817 // these featuers are supported. |
| 818 |
760 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { | 819 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, UndoRedoLinux) { |
761 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | 820 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); |
762 browser()->FocusLocationBar(); | 821 browser()->FocusLocationBar(); |
763 | 822 |
764 AutocompleteEditView* edit_view = NULL; | 823 AutocompleteEditView* edit_view = NULL; |
765 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); | 824 ASSERT_NO_FATAL_FAILURE(GetAutocompleteEditView(&edit_view)); |
766 | 825 |
767 std::wstring old_text = edit_view->GetText(); | 826 std::wstring old_text = edit_view->GetText(); |
768 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); | 827 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), old_text); |
769 EXPECT_TRUE(edit_view->IsSelectAll()); | 828 EXPECT_TRUE(edit_view->IsSelectAll()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 | 931 |
873 // Paste text. | 932 // Paste text. |
874 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false)); | 933 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, true, false, false)); |
875 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 934 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
876 ASSERT_TRUE(popup_model->IsOpen()); | 935 ASSERT_TRUE(popup_model->IsOpen()); |
877 | 936 |
878 // Inline autocomplete shouldn't be triggered. | 937 // Inline autocomplete shouldn't be triggered. |
879 ASSERT_EQ(L"abc", edit_view->GetText()); | 938 ASSERT_EQ(L"abc", edit_view->GetText()); |
880 } | 939 } |
881 #endif | 940 #endif |
| 941 |
| 942 #if defined(TOOLKIT_VIEWS) |
| 943 class AutocompleteEditViewViewsTest : public AutocompleteEditViewTest { |
| 944 public: |
| 945 AutocompleteEditViewViewsTest() { |
| 946 views::NativeTextfieldViews::SetEnableTextfieldViews(true); |
| 947 } |
| 948 }; |
| 949 |
| 950 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, |
| 951 FLAKY_BrowserAccelerators) { |
| 952 BrowserAcceleratorsTest(); |
| 953 } |
| 954 |
| 955 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, MAYBE_PopupAccelerators) { |
| 956 PopupAcceleratorsTest(); |
| 957 } |
| 958 |
| 959 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BackspaceInKeywordMode) { |
| 960 BackspaceInKeywordModeTest(); |
| 961 } |
| 962 |
| 963 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, Escape) { |
| 964 EscapeTest(); |
| 965 } |
| 966 |
| 967 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, DesiredTLD) { |
| 968 DesiredTLDTest(); |
| 969 } |
| 970 |
| 971 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AltEnter) { |
| 972 AltEnterTest(); |
| 973 } |
| 974 |
| 975 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, EnterToSearch) { |
| 976 EnterToSearchTest(); |
| 977 } |
| 978 |
| 979 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, EscapeToDefaultMatch) { |
| 980 EscapeToDefaultMatchTest(); |
| 981 } |
| 982 |
| 983 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { |
| 984 BasicTextOperationsTest(); |
| 985 } |
| 986 |
| 987 #endif |
OLD | NEW |