Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / omnibox_view_browsertest.cc
blobd864577a5a9dbdfe87f8d7e841120da2a01566fc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <stdio.h>
7 #include "base/command_line.h"
8 #include "base/scoped_observer.h"
9 #include "base/strings/string16.h"
10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/browser/autocomplete/history_quick_provider.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/search_engines/template_url_service_factory.h"
20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_commands.h"
22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/location_bar/location_bar.h"
24 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
25 #include "chrome/browser/ui/omnibox/omnibox_view.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/toolbar/test_toolbar_model.h"
28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h"
31 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/interactive_test_utils.h"
33 #include "chrome/test/base/ui_test_utils.h"
34 #include "components/bookmarks/browser/bookmark_model.h"
35 #include "components/bookmarks/browser/bookmark_utils.h"
36 #include "components/bookmarks/test/bookmark_test_helpers.h"
37 #include "components/history/core/browser/history_service.h"
38 #include "components/history/core/browser/history_service_observer.h"
39 #include "components/omnibox/autocomplete_input.h"
40 #include "components/omnibox/autocomplete_match.h"
41 #include "components/search_engines/template_url.h"
42 #include "components/search_engines/template_url_service.h"
43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/web_contents.h"
45 #include "net/dns/mock_host_resolver.h"
46 #include "ui/base/clipboard/clipboard.h"
47 #include "ui/base/clipboard/scoped_clipboard_writer.h"
48 #include "ui/events/event_constants.h"
49 #include "ui/events/keycodes/keyboard_codes.h"
50 #include "ui/gfx/geometry/point.h"
52 using base::ASCIIToUTF16;
53 using base::UTF16ToUTF8;
54 using base::Time;
55 using base::TimeDelta;
56 using bookmarks::BookmarkModel;
58 namespace {
60 const char kSearchKeyword[] = "foo";
61 const char kSearchKeyword2[] = "footest.com";
62 const ui::KeyboardCode kSearchKeywordKeys[] = {
63 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, ui::VKEY_UNKNOWN
65 const ui::KeyboardCode kSearchKeywordPrefixKeys[] = {
66 ui::VKEY_F, ui::VKEY_O, ui::VKEY_UNKNOWN
68 const ui::KeyboardCode kSearchKeywordCompletionKeys[] = {
69 ui::VKEY_O, ui::VKEY_UNKNOWN
71 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
72 const char kSearchShortName[] = "foo";
73 const char kSearchText[] = "abc";
74 const ui::KeyboardCode kSearchTextKeys[] = {
75 ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, ui::VKEY_UNKNOWN
77 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
79 const char kInlineAutocompleteText[] = "def";
80 const ui::KeyboardCode kInlineAutocompleteTextKeys[] = {
81 ui::VKEY_D, ui::VKEY_E, ui::VKEY_F, ui::VKEY_UNKNOWN
84 // Hostnames that shall be blocked by host resolver.
85 const char *kBlockedHostnames[] = {
86 "foo",
87 "*.foo.com",
88 "bar",
89 "*.bar.com",
90 "abc",
91 "*.abc.com",
92 "def",
93 "*.def.com",
94 "*.site.com",
95 "history",
96 "z"
99 const struct TestHistoryEntry {
100 const char* url;
101 const char* title;
102 int visit_count;
103 int typed_count;
104 bool starred;
105 } kHistoryEntries[] = {
106 {"http://www.bar.com/1", "Page 1", 10, 10, false },
107 {"http://www.bar.com/2", "Page 2", 9, 9, false },
108 {"http://www.bar.com/3", "Page 3", 8, 8, false },
109 {"http://www.bar.com/4", "Page 4", 7, 7, false },
110 {"http://www.bar.com/5", "Page 5", 6, 6, false },
111 {"http://www.bar.com/6", "Page 6", 5, 5, false },
112 {"http://www.bar.com/7", "Page 7", 4, 4, false },
113 {"http://www.bar.com/8", "Page 8", 3, 3, false },
114 {"http://www.bar.com/9", "Page 9", 2, 2, false },
115 {"http://www.site.com/path/1", "Site 1", 4, 4, false },
116 {"http://www.site.com/path/2", "Site 2", 3, 3, false },
117 {"http://www.site.com/path/3", "Site 3", 2, 2, false },
119 // To trigger inline autocomplete.
120 {"http://www.def.com", "Page def", 10000, 10000, true },
122 // Used in particular for the desired TLD test. This makes it test
123 // the interesting case when there's an intranet host with the same
124 // name as the .com.
125 {"http://bar/", "Bar", 1, 0, false },
128 // Stores the given text to clipboard.
129 void SetClipboardText(const base::string16& text) {
130 ui::ScopedClipboardWriter writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
131 writer.WriteText(text);
134 #if defined(OS_MACOSX)
135 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN;
136 #else
137 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN;
138 #endif
140 } // namespace
142 class OmniboxViewTest : public InProcessBrowserTest,
143 public content::NotificationObserver,
144 public history::HistoryServiceObserver {
145 public:
146 OmniboxViewTest() : observer_(this) {}
148 // history::HisoryServiceObserver
149 void OnHistoryServiceLoaded(
150 history::HistoryService* history_service) override {
151 base::MessageLoop::current()->Quit();
154 protected:
155 void SetUpOnMainThread() override {
156 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
157 ASSERT_NO_FATAL_FAILURE(SetupComponents());
158 chrome::FocusLocationBar(browser());
159 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
162 static void GetOmniboxViewForBrowser(
163 const Browser* browser,
164 OmniboxView** omnibox_view) {
165 BrowserWindow* window = browser->window();
166 ASSERT_TRUE(window);
167 LocationBar* location_bar = window->GetLocationBar();
168 ASSERT_TRUE(location_bar);
169 *omnibox_view = location_bar->GetOmniboxView();
170 ASSERT_TRUE(*omnibox_view);
173 void GetOmniboxView(OmniboxView** omnibox_view) {
174 GetOmniboxViewForBrowser(browser(), omnibox_view);
177 static void SendKeyForBrowser(const Browser* browser,
178 ui::KeyboardCode key,
179 int modifiers) {
180 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
181 browser, key,
182 (modifiers & ui::EF_CONTROL_DOWN) != 0,
183 (modifiers & ui::EF_SHIFT_DOWN) != 0,
184 (modifiers & ui::EF_ALT_DOWN) != 0,
185 (modifiers & ui::EF_COMMAND_DOWN) != 0));
188 void SendKey(ui::KeyboardCode key, int modifiers) {
189 SendKeyForBrowser(browser(), key, modifiers);
192 void SendKeySequence(const ui::KeyboardCode* keys) {
193 for (; *keys != ui::VKEY_UNKNOWN; ++keys)
194 ASSERT_NO_FATAL_FAILURE(SendKey(*keys, 0));
197 bool SendKeyAndWait(const Browser* browser,
198 ui::KeyboardCode key,
199 int modifiers,
200 int type,
201 const content::NotificationSource& source)
202 WARN_UNUSED_RESULT {
203 return ui_test_utils::SendKeyPressAndWait(
204 browser, key,
205 (modifiers & ui::EF_CONTROL_DOWN) != 0,
206 (modifiers & ui::EF_SHIFT_DOWN) != 0,
207 (modifiers & ui::EF_ALT_DOWN) != 0,
208 (modifiers & ui::EF_COMMAND_DOWN) != 0,
209 type, source);
212 void WaitForTabOpenOrCloseForBrowser(const Browser* browser,
213 int expected_tab_count) {
214 int tab_count = browser->tab_strip_model()->count();
215 if (tab_count == expected_tab_count)
216 return;
218 content::NotificationRegistrar registrar;
219 registrar.Add(this,
220 (tab_count < expected_tab_count) ?
221 static_cast<int>(chrome::NOTIFICATION_TAB_PARENTED) :
222 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED),
223 content::NotificationService::AllSources());
225 while (!HasFailure() &&
226 browser->tab_strip_model()->count() != expected_tab_count) {
227 content::RunMessageLoop();
230 ASSERT_EQ(expected_tab_count, browser->tab_strip_model()->count());
233 void WaitForTabOpenOrClose(int expected_tab_count) {
234 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count);
237 void WaitForAutocompleteControllerDone() {
238 OmniboxView* omnibox_view = NULL;
239 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
241 AutocompleteController* controller =
242 omnibox_view->model()->autocomplete_controller();
243 ASSERT_TRUE(controller);
245 if (controller->done())
246 return;
248 content::NotificationRegistrar registrar;
249 registrar.Add(this,
250 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
251 content::Source<AutocompleteController>(controller));
253 while (!HasFailure() && !controller->done())
254 content::RunMessageLoop();
256 ASSERT_TRUE(controller->done());
259 void SetupSearchEngine() {
260 Profile* profile = browser()->profile();
261 TemplateURLService* model =
262 TemplateURLServiceFactory::GetForProfile(profile);
263 ASSERT_TRUE(model);
265 ui_test_utils::WaitForTemplateURLServiceToLoad(model);
267 ASSERT_TRUE(model->loaded());
269 TemplateURLData data;
270 data.short_name = ASCIIToUTF16(kSearchShortName);
271 data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
272 data.SetURL(kSearchURL);
273 TemplateURL* template_url = new TemplateURL(data);
274 model->Add(template_url);
275 model->SetUserSelectedDefaultSearchProvider(template_url);
277 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
278 model->Add(new TemplateURL(data));
280 // Remove built-in template urls, like google.com, bing.com etc., as they
281 // may appear as autocomplete suggests and interfere with our tests.
282 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs();
283 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin();
284 i != urls.end();
285 ++i) {
286 if ((*i)->prepopulate_id() != 0)
287 model->Remove(*i);
291 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
292 Profile* profile = browser()->profile();
293 history::HistoryService* history_service =
294 HistoryServiceFactory::GetForProfile(
295 profile, ServiceAccessType::EXPLICIT_ACCESS);
296 ASSERT_TRUE(history_service);
298 if (!history_service->BackendLoaded()) {
299 observer_.Add(history_service);
300 content::RunMessageLoop();
303 BookmarkModel* bookmark_model =
304 BookmarkModelFactory::GetForProfile(profile);
305 ASSERT_TRUE(bookmark_model);
306 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
308 GURL url(entry.url);
309 // Add everything in order of time. We don't want to have a time that
310 // is "right now" or it will nondeterministically appear in the results.
311 history_service->AddPageWithDetails(url, base::UTF8ToUTF16(entry.title),
312 entry.visit_count,
313 entry.typed_count, time, false,
314 history::SOURCE_BROWSED);
315 if (entry.starred)
316 bookmarks::AddIfNotBookmarked(bookmark_model, url, base::string16());
317 // Wait at least for the AddPageWithDetails() call to finish.
319 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
320 observer(this);
321 observer.Add(history_service);
322 content::RunMessageLoop();
323 // We don't want to return until all observers have processed this
324 // notification, because some (e.g. the in-memory history database) may do
325 // something important. Since we don't know where in the observer list we
326 // stand, just spin the message loop once more to allow the current
327 // callstack to complete.
328 content::RunAllPendingInMessageLoop();
332 void SetupHistory() {
333 // Add enough history pages containing |kSearchText| to trigger
334 // open history page url in autocomplete result.
335 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) {
336 // Add everything in order of time. We don't want to have a time that
337 // is "right now" or it will nondeterministically appear in the results.
338 Time t = Time::Now() - TimeDelta::FromHours(i + 1);
339 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries[i], t));
343 void SetupHostResolver() {
344 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i)
345 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]);
348 void SetupComponents() {
349 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
350 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
351 ASSERT_NO_FATAL_FAILURE(SetupHistory());
354 void Observe(int type,
355 const content::NotificationSource& source,
356 const content::NotificationDetails& details) override {
357 switch (type) {
358 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
359 case chrome::NOTIFICATION_TAB_PARENTED:
360 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
361 break;
362 default:
363 FAIL() << "Unexpected notification type";
365 base::MessageLoop::current()->Quit();
368 void OnURLsModified(history::HistoryService* history_service,
369 const history::URLRows& changed_urls) override {
370 base::MessageLoop::current()->Quit();
373 private:
374 ScopedObserver<history::HistoryService, OmniboxViewTest> observer_;
376 DISALLOW_COPY_AND_ASSIGN(OmniboxViewTest);
379 // Test if ctrl-* accelerators are workable in omnibox.
380 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
382 // Flaky on interactive tests (dbg), http://crbug.com/69433
383 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) {
384 OmniboxView* omnibox_view = NULL;
385 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
387 int tab_count = browser()->tab_strip_model()->count();
389 // Create a new Tab.
390 chrome::NewTab(browser());
391 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
393 // Select the first Tab.
394 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1, kCtrlOrCmdMask));
395 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
397 chrome::FocusLocationBar(browser());
399 // Select the second Tab.
400 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2, kCtrlOrCmdMask));
401 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
403 chrome::FocusLocationBar(browser());
405 // Try ctrl-w to close a Tab.
406 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W, kCtrlOrCmdMask));
407 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count));
409 // Try ctrl-l to focus location bar.
410 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
411 EXPECT_FALSE(omnibox_view->IsSelectAll());
412 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, kCtrlOrCmdMask));
413 EXPECT_TRUE(omnibox_view->IsSelectAll());
415 // Try editing the location bar text.
416 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, 0));
417 EXPECT_FALSE(omnibox_view->IsSelectAll());
418 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, 0));
419 EXPECT_EQ(ASCIIToUTF16("Hello worlds"), omnibox_view->GetText());
421 // Try ctrl-x to cut text.
422 #if defined(OS_MACOSX)
423 // Mac uses alt-left/right to select a word.
424 ASSERT_NO_FATAL_FAILURE(
425 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN));
426 #else
427 ASSERT_NO_FATAL_FAILURE(
428 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN));
429 #endif
430 EXPECT_FALSE(omnibox_view->IsSelectAll());
431 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, kCtrlOrCmdMask));
432 EXPECT_EQ(ASCIIToUTF16("Hello "), omnibox_view->GetText());
434 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
435 // Try alt-f4 to close the browser.
436 ASSERT_TRUE(SendKeyAndWait(
437 browser(), ui::VKEY_F4, ui::EF_ALT_DOWN,
438 chrome::NOTIFICATION_BROWSER_CLOSED,
439 content::Source<Browser>(browser())));
440 #endif
443 // Fails on Linux. http://crbug.com/408634
444 #if defined(OS_LINUX)
445 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators
446 #else
447 #define MAYBE_PopupAccelerators PopupAccelerators
448 #endif
450 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_PopupAccelerators) {
451 // Create a popup.
452 Browser* popup = CreateBrowserForPopup(browser()->profile());
453 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup));
454 OmniboxView* omnibox_view = NULL;
455 ASSERT_NO_FATAL_FAILURE(
456 GetOmniboxViewForBrowser(popup, &omnibox_view));
457 chrome::FocusLocationBar(popup);
458 EXPECT_TRUE(omnibox_view->IsSelectAll());
460 #if !defined(OS_MACOSX)
461 // Try ctrl-w to close the popup.
462 // This piece of code doesn't work on Mac, because the Browser object won't
463 // be destroyed before finishing the current message loop iteration, thus
464 // No BROWSER_CLOSED notification will be sent.
465 ASSERT_TRUE(SendKeyAndWait(
466 popup, ui::VKEY_W, ui::EF_CONTROL_DOWN,
467 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(popup)));
469 // Create another popup.
470 popup = CreateBrowserForPopup(browser()->profile());
471 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup));
472 ASSERT_NO_FATAL_FAILURE(
473 GetOmniboxViewForBrowser(popup, &omnibox_view));
474 #endif
476 // Set the edit text to "Hello world".
477 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
478 chrome::FocusLocationBar(popup);
479 EXPECT_TRUE(omnibox_view->IsSelectAll());
481 // Try editing the location bar text -- should be disallowed.
482 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, 0));
483 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText());
484 EXPECT_TRUE(omnibox_view->IsSelectAll());
486 ASSERT_NO_FATAL_FAILURE(
487 SendKeyForBrowser(popup, ui::VKEY_X, kCtrlOrCmdMask));
488 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText());
489 EXPECT_TRUE(omnibox_view->IsSelectAll());
491 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
492 // Try alt-f4 to close the popup.
493 ASSERT_TRUE(SendKeyAndWait(
494 popup, ui::VKEY_F4, ui::EF_ALT_DOWN,
495 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(popup)));
496 #endif
499 // http://crbug.com/133341
500 #if defined(OS_LINUX)
501 #define MAYBE_BackspaceInKeywordMode DISABLED_BackspaceInKeywordMode
502 #else
503 #define MAYBE_BackspaceInKeywordMode BackspaceInKeywordMode
504 #endif
506 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BackspaceInKeywordMode) {
507 OmniboxView* omnibox_view = NULL;
508 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
510 // Trigger keyword hint mode.
511 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
512 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
513 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
515 // Trigger keyword mode.
516 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
517 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
518 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
520 // Backspace without search text should bring back keyword hint mode.
521 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
522 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
523 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
525 // Trigger keyword mode again.
526 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
527 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
528 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
530 // Input something as search text.
531 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
533 // Should stay in keyword mode while deleting search text by pressing
534 // backspace.
535 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) {
536 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
537 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
538 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
541 // Input something as search text.
542 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
544 // Move cursor to the beginning of the search text.
545 #if defined(OS_MACOSX)
546 // Home doesn't work on Mac trybot.
547 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN));
548 #else
549 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
550 #endif
551 // Backspace at the beginning of the search text shall turn off
552 // the keyword mode.
553 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
554 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
555 ASSERT_EQ(base::string16(), omnibox_view->model()->keyword());
556 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText,
557 UTF16ToUTF8(omnibox_view->GetText()));
560 // http://crbug.com/158913
561 #if defined(USE_AURA)
562 #define MAYBE_Escape DISABLED_Escape
563 #else
564 #define MAYBE_Escape Escape
565 #endif
567 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_Escape) {
568 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
569 chrome::FocusLocationBar(browser());
571 OmniboxView* omnibox_view = NULL;
572 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
574 base::string16 old_text = omnibox_view->GetText();
575 EXPECT_FALSE(old_text.empty());
576 EXPECT_TRUE(omnibox_view->IsSelectAll());
578 // Delete all text in omnibox.
579 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
580 EXPECT_TRUE(omnibox_view->GetText().empty());
582 // Escape shall revert the text in omnibox.
583 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
584 EXPECT_EQ(old_text, omnibox_view->GetText());
585 EXPECT_TRUE(omnibox_view->IsSelectAll());
587 #undef MAYBE_ESCAPE
589 #if defined(OS_LINUX)
590 #define MAYBE_DesiredTLD DISABLED_DesiredTLD
591 #else
592 #define MAYBE_DesiredTLD DesiredTLD
593 #endif
595 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_DesiredTLD) {
596 OmniboxView* omnibox_view = NULL;
597 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
598 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
599 ASSERT_TRUE(popup_model);
601 // Test ctrl-Enter.
602 const ui::KeyboardCode kKeys[] = {
603 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
605 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
606 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
607 ASSERT_TRUE(popup_model->IsOpen());
608 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be
609 // opened.
610 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN,
611 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
612 content::Source<content::NavigationController>(
613 &browser()->tab_strip_model()->GetActiveWebContents()->
614 GetController())));
616 GURL url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
617 EXPECT_EQ("www.bar.com", url.host());
618 EXPECT_EQ("/", url.path());
621 #if defined(OS_LINUX)
622 #define MAYBE_DesiredTLDWithTemporaryText DISABLED_DesiredTLDWithTemporaryText
623 #else
624 #define MAYBE_DesiredTLDWithTemporaryText DesiredTLDWithTemporaryText
625 #endif
627 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_DesiredTLDWithTemporaryText) {
628 OmniboxView* omnibox_view = NULL;
629 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
630 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
631 ASSERT_TRUE(popup_model);
633 Profile* profile = browser()->profile();
634 TemplateURLService* template_url_service =
635 TemplateURLServiceFactory::GetForProfile(profile);
637 // Add a non-substituting keyword. This ensures the popup will have a
638 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we
639 // can set "abc" as temporary text in the omnibox.
640 TemplateURLData data;
641 data.short_name = ASCIIToUTF16("abc");
642 data.SetKeyword(ASCIIToUTF16(kSearchText));
643 data.SetURL("http://abc.com/");
644 template_url_service->Add(new TemplateURL(data));
646 // Send "ab", so that an "abc" entry appears in the popup.
647 const ui::KeyboardCode kSearchTextPrefixKeys[] = {
648 ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN
650 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys));
651 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
652 ASSERT_TRUE(popup_model->IsOpen());
654 // Arrow down to the "abc" entry in the popup.
655 size_t size = popup_model->result().size();
656 while (popup_model->selected_line() < size - 1) {
657 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
658 if (omnibox_view->GetText() == ASCIIToUTF16("abc"))
659 break;
661 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
663 // Hitting ctrl-enter should navigate based on the current text rather than
664 // the original input, i.e. to www.abc.com instead of www.ab.com.
665 ASSERT_TRUE(SendKeyAndWait(
666 browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN,
667 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
668 content::Source<content::NavigationController>(
669 &browser()->tab_strip_model()->GetActiveWebContents()->
670 GetController())));
672 GURL url(browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
673 EXPECT_EQ("www.abc.com", url.host());
674 EXPECT_EQ("/", url.path());
677 // See http://crbug.com/431575.
678 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, ClearUserTextAfterBackgroundCommit) {
679 OmniboxView* omnibox_view = NULL;
680 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
682 // Navigate in first tab and enter text into the omnibox.
683 GURL url1("data:text/html,page1");
684 ui_test_utils::NavigateToURL(browser(), url1);
685 omnibox_view->SetUserText(ASCIIToUTF16("foo"));
686 content::WebContents* contents =
687 browser()->tab_strip_model()->GetActiveWebContents();
689 // Create another tab in the foreground.
690 AddTabAtIndex(1, url1, ui::PAGE_TRANSITION_TYPED);
691 EXPECT_EQ(2, browser()->tab_strip_model()->count());
692 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
694 // Navigate in the first tab, currently in the background.
695 GURL url2("data:text/html,page2");
696 chrome::NavigateParams params(browser(), url2, ui::PAGE_TRANSITION_LINK);
697 params.source_contents = contents;
698 params.disposition = CURRENT_TAB;
699 ui_test_utils::NavigateToURL(&params);
701 // Switch back to the first tab. The user text should be cleared, and the
702 // omnibox should have the new URL.
703 browser()->tab_strip_model()->ActivateTabAt(0, true);
704 EXPECT_EQ(ASCIIToUTF16(url2.spec()), omnibox_view->GetText());
707 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AltEnter) {
708 OmniboxView* omnibox_view = NULL;
709 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
711 omnibox_view->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL));
712 int tab_count = browser()->tab_strip_model()->count();
713 // alt-Enter opens a new tab.
714 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, ui::EF_ALT_DOWN));
715 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
718 // http://crbug.com/133354, http://crbug.com/146953
719 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_EnterToSearch) {
720 OmniboxView* omnibox_view = NULL;
721 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
722 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
723 ASSERT_TRUE(popup_model);
725 // Test Enter to search.
726 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
727 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
728 ASSERT_TRUE(popup_model->IsOpen());
730 // Check if the default match result is Search Primary Provider.
731 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
732 popup_model->result().default_match()->type);
734 // Open the default match.
735 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0,
736 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
737 content::Source<content::NavigationController>(
738 &browser()->tab_strip_model()->GetActiveWebContents()->
739 GetController())));
740 GURL url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
741 EXPECT_EQ(kSearchTextURL, url.spec());
743 // Test that entering a single character then Enter performs a search.
744 const ui::KeyboardCode kSearchSingleCharKeys[] = {
745 ui::VKEY_Z, ui::VKEY_UNKNOWN
747 chrome::FocusLocationBar(browser());
748 EXPECT_TRUE(omnibox_view->IsSelectAll());
749 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys));
750 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
751 ASSERT_TRUE(popup_model->IsOpen());
752 EXPECT_EQ("z", UTF16ToUTF8(omnibox_view->GetText()));
754 // Check if the default match result is Search Primary Provider.
755 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
756 popup_model->result().default_match()->type);
758 // Open the default match.
759 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0,
760 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
761 content::Source<content::NavigationController>(
762 &browser()->tab_strip_model()->GetActiveWebContents()->
763 GetController())));
764 url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
765 EXPECT_EQ("http://www.foo.com/search?q=z", url.spec());
768 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscapeToDefaultMatch) {
769 OmniboxView* omnibox_view = NULL;
770 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
771 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
772 ASSERT_TRUE(popup_model);
774 // Input something to trigger inline autocomplete.
775 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
776 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
777 ASSERT_TRUE(popup_model->IsOpen());
779 base::string16 old_text = omnibox_view->GetText();
781 // Make sure inline autocomplete is triggerred.
782 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
784 size_t old_selected_line = popup_model->selected_line();
785 EXPECT_EQ(0U, old_selected_line);
787 // Move to another line with different text.
788 size_t size = popup_model->result().size();
789 while (popup_model->selected_line() < size - 1) {
790 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
791 ASSERT_NE(old_selected_line, popup_model->selected_line());
792 if (old_text != omnibox_view->GetText())
793 break;
796 EXPECT_NE(old_text, omnibox_view->GetText());
798 // Escape shall revert back to the default match item.
799 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
800 EXPECT_EQ(old_text, omnibox_view->GetText());
801 EXPECT_EQ(old_selected_line, popup_model->selected_line());
804 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BasicTextOperations) {
805 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
806 chrome::FocusLocationBar(browser());
808 OmniboxView* omnibox_view = NULL;
809 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
811 base::string16 old_text = omnibox_view->GetText();
812 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), old_text);
813 EXPECT_TRUE(omnibox_view->IsSelectAll());
815 size_t start, end;
816 omnibox_view->GetSelectionBounds(&start, &end);
817 #if defined(OS_WIN) || defined(OS_LINUX)
818 // Views textfields select-all in reverse to show the leading text.
819 std::swap(start, end);
820 #endif
821 EXPECT_EQ(0U, start);
822 EXPECT_EQ(old_text.size(), end);
824 // Move the cursor to the end.
825 #if defined(OS_MACOSX)
826 // End doesn't work on Mac trybot.
827 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, ui::EF_CONTROL_DOWN));
828 #else
829 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
830 #endif
831 EXPECT_FALSE(omnibox_view->IsSelectAll());
833 // Make sure the cursor is placed correctly.
834 omnibox_view->GetSelectionBounds(&start, &end);
835 EXPECT_EQ(old_text.size(), start);
836 EXPECT_EQ(old_text.size(), end);
838 // Insert one character at the end. Make sure we won't insert
839 // anything after the special ZWS mark used in gtk implementation.
840 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
841 EXPECT_EQ(old_text + base::char16('a'), omnibox_view->GetText());
843 // Delete one character from the end. Make sure we won't delete the special
844 // ZWS mark used in gtk implementation.
845 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
846 EXPECT_EQ(old_text, omnibox_view->GetText());
848 omnibox_view->SelectAll(true);
849 EXPECT_TRUE(omnibox_view->IsSelectAll());
850 omnibox_view->GetSelectionBounds(&start, &end);
851 #if defined(OS_WIN) || defined(OS_LINUX)
852 // Views textfields select-all in reverse to show the leading text.
853 std::swap(start, end);
854 #endif
855 EXPECT_EQ(0U, start);
856 EXPECT_EQ(old_text.size(), end);
858 // Delete the content
859 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0));
860 EXPECT_TRUE(omnibox_view->IsSelectAll());
861 omnibox_view->GetSelectionBounds(&start, &end);
862 EXPECT_EQ(0U, start);
863 EXPECT_EQ(0U, end);
864 EXPECT_TRUE(omnibox_view->GetText().empty());
866 // Check if RevertAll() can set text and cursor correctly.
867 omnibox_view->RevertAll();
868 EXPECT_FALSE(omnibox_view->IsSelectAll());
869 EXPECT_EQ(old_text, omnibox_view->GetText());
870 omnibox_view->GetSelectionBounds(&start, &end);
871 EXPECT_EQ(old_text.size(), start);
872 EXPECT_EQ(old_text.size(), end);
875 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AcceptKeywordBySpace) {
876 OmniboxView* omnibox_view = NULL;
877 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
879 base::string16 search_keyword(ASCIIToUTF16(kSearchKeyword));
881 // Trigger keyword hint mode.
882 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
883 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
884 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
885 ASSERT_EQ(search_keyword, omnibox_view->GetText());
887 // Trigger keyword mode by space.
888 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
889 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
890 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
891 ASSERT_TRUE(omnibox_view->GetText().empty());
893 // Revert to keyword hint mode.
894 omnibox_view->model()->ClearKeyword(base::string16());
895 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
896 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
897 ASSERT_EQ(search_keyword, omnibox_view->GetText());
899 // Keyword should also be accepted by typing an ideographic space.
900 omnibox_view->OnBeforePossibleChange();
901 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
902 base::WideToUTF16(L"\x3000"), search_keyword.length() + 1, false, false);
903 omnibox_view->OnAfterPossibleChange();
904 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
905 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
906 ASSERT_TRUE(omnibox_view->GetText().empty());
908 // Revert to keyword hint mode.
909 omnibox_view->model()->ClearKeyword(base::string16());
910 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
911 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
912 ASSERT_EQ(search_keyword, omnibox_view->GetText());
914 // Keyword shouldn't be accepted by pressing space with a trailing
915 // whitespace.
916 omnibox_view->SetWindowTextAndCaretPos(search_keyword + base::char16(' '),
917 search_keyword.length() + 1, false, false);
918 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
919 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
920 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
921 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
923 // Keyword shouldn't be accepted by deleting the trailing space.
924 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
925 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
926 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
927 ASSERT_EQ(search_keyword + base::char16(' '), omnibox_view->GetText());
929 // Keyword shouldn't be accepted by pressing space before a trailing space.
930 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
931 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
932 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
933 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
934 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
936 // Keyword should be accepted by pressing space in the middle of context and
937 // just after the keyword.
938 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
939 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
940 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
941 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
942 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
943 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
944 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
945 size_t start, end;
946 omnibox_view->GetSelectionBounds(&start, &end);
947 EXPECT_EQ(0U, start);
948 EXPECT_EQ(0U, end);
950 // Keyword shouldn't be accepted by pasting "foo bar".
951 omnibox_view->SetUserText(base::string16());
952 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
953 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
955 omnibox_view->OnBeforePossibleChange();
956 omnibox_view->model()->OnPaste();
957 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
958 ASCIIToUTF16(" bar"), search_keyword.length() + 4, false, false);
959 omnibox_view->OnAfterPossibleChange();
960 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
961 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
962 ASSERT_EQ(search_keyword + ASCIIToUTF16(" bar"), omnibox_view->GetText());
964 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
965 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
966 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
967 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
968 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
969 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
970 ASSERT_EQ(search_keyword + ASCIIToUTF16(" b ar"), omnibox_view->GetText());
972 // Keyword could be accepted by pressing space with a selected range at the
973 // end of text.
974 omnibox_view->OnBeforePossibleChange();
975 omnibox_view->OnInlineAutocompleteTextMaybeChanged(
976 search_keyword + ASCIIToUTF16(" "), search_keyword.length());
977 omnibox_view->OnAfterPossibleChange();
978 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
979 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
980 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
982 omnibox_view->GetSelectionBounds(&start, &end);
983 ASSERT_NE(start, end);
984 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
985 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
986 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
987 ASSERT_EQ(base::string16(), omnibox_view->GetText());
989 // Space should accept keyword even when inline autocomplete is available.
990 omnibox_view->SetUserText(base::string16());
991 const TestHistoryEntry kHistoryFoobar = {
992 "http://www.foobar.com", "Page foobar", 100, 100, true
995 // Add a history entry to trigger inline autocomplete when typing "foo".
996 ASSERT_NO_FATAL_FAILURE(
997 AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1)));
999 // Type "fo" to trigger inline autocomplete.
1000 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordPrefixKeys));
1001 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1002 ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
1003 ASSERT_NE(search_keyword, omnibox_view->GetText());
1005 // Keyword hint shouldn't be visible.
1006 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1007 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
1009 // Add the "o". Inline autocompletion should still happen, but now we
1010 // should also get a keyword hint because we've typed a keyword exactly.
1011 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordCompletionKeys));
1012 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1013 ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
1014 ASSERT_NE(search_keyword, omnibox_view->GetText());
1015 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1016 ASSERT_FALSE(omnibox_view->model()->keyword().empty());
1018 // Trigger keyword mode by space.
1019 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
1020 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1021 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
1022 ASSERT_TRUE(omnibox_view->GetText().empty());
1024 // Space in the middle of a temporary text, which separates the text into
1025 // keyword and replacement portions, should trigger keyword mode.
1026 omnibox_view->SetUserText(base::string16());
1027 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1028 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1029 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1030 ASSERT_TRUE(popup_model->IsOpen());
1031 ASSERT_EQ(ASCIIToUTF16("foobar.com"), omnibox_view->GetText());
1032 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1033 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
1034 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1035 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1036 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1037 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1038 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1039 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1040 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
1041 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
1042 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1043 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
1044 ASSERT_EQ(ASCIIToUTF16("bar.com"), omnibox_view->GetText());
1046 // Space after temporary text that looks like a keyword, when the original
1047 // input does not look like a keyword, should trigger keyword mode.
1048 omnibox_view->SetUserText(base::string16());
1049 const TestHistoryEntry kHistoryFoo = {
1050 "http://footest.com", "Page footest", 1000, 1000, true
1053 // Add a history entry to trigger HQP matching with text == keyword when
1054 // typing "fo te".
1055 ASSERT_NO_FATAL_FAILURE(
1056 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromMinutes(10)));
1058 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_F, 0));
1059 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_O, 0));
1060 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
1061 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_T, 0));
1062 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, 0));
1063 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1064 ASSERT_TRUE(popup_model->IsOpen());
1065 base::string16 search_keyword2(ASCIIToUTF16(kSearchKeyword2));
1066 while ((omnibox_view->GetText() != search_keyword2) &&
1067 (popup_model->selected_line() < popup_model->result().size() - 1))
1068 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1069 ASSERT_EQ(search_keyword2, omnibox_view->GetText());
1070 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
1071 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1072 ASSERT_EQ(search_keyword2, omnibox_view->model()->keyword());
1073 ASSERT_TRUE(omnibox_view->GetText().empty());
1076 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, NonSubstitutingKeywordTest) {
1077 OmniboxView* omnibox_view = NULL;
1078 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1079 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1080 ASSERT_TRUE(popup_model);
1082 Profile* profile = browser()->profile();
1083 TemplateURLService* template_url_service =
1084 TemplateURLServiceFactory::GetForProfile(profile);
1086 // Add a non-default substituting keyword.
1087 TemplateURLData data;
1088 data.short_name = ASCIIToUTF16("Search abc");
1089 data.SetKeyword(ASCIIToUTF16(kSearchText));
1090 data.SetURL("http://abc.com/{searchTerms}");
1091 TemplateURL* template_url = new TemplateURL(data);
1092 template_url_service->Add(template_url);
1094 omnibox_view->SetUserText(base::string16());
1096 // Non-default substituting keyword shouldn't be matched by default.
1097 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1098 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1099 ASSERT_TRUE(popup_model->IsOpen());
1101 // Check if the default match result is Search Primary Provider.
1102 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1103 popup_model->result().default_match()->type);
1104 ASSERT_EQ(kSearchTextURL,
1105 popup_model->result().default_match()->destination_url.spec());
1107 omnibox_view->SetUserText(base::string16());
1108 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1109 ASSERT_FALSE(popup_model->IsOpen());
1111 // Try a non-substituting keyword.
1112 template_url_service->Remove(template_url);
1113 data.short_name = ASCIIToUTF16("abc");
1114 data.SetURL("http://abc.com/");
1115 template_url_service->Add(new TemplateURL(data));
1117 // We always allow exact matches for non-substituting keywords.
1118 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1119 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1120 ASSERT_TRUE(popup_model->IsOpen());
1121 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD,
1122 popup_model->result().default_match()->type);
1123 ASSERT_EQ("http://abc.com/",
1124 popup_model->result().default_match()->destination_url.spec());
1127 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DeleteItem) {
1128 // Disable the search provider, to make sure the popup contains only history
1129 // items.
1130 TemplateURLService* model =
1131 TemplateURLServiceFactory::GetForProfile(browser()->profile());
1132 model->SetUserSelectedDefaultSearchProvider(NULL);
1134 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1135 chrome::FocusLocationBar(browser());
1137 OmniboxView* omnibox_view = NULL;
1138 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1140 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1141 ASSERT_TRUE(popup_model);
1143 base::string16 old_text = omnibox_view->GetText();
1145 // Input something that can match history items.
1146 omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
1147 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1148 ASSERT_TRUE(popup_model->IsOpen());
1150 // Delete the inline autocomplete part.
1151 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0));
1152 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1153 ASSERT_TRUE(popup_model->IsOpen());
1154 ASSERT_GE(popup_model->result().size(), 3U);
1156 base::string16 user_text = omnibox_view->GetText();
1157 ASSERT_EQ(ASCIIToUTF16("site.com/p"), user_text);
1158 omnibox_view->SelectAll(true);
1159 ASSERT_TRUE(omnibox_view->IsSelectAll());
1161 // Move down.
1162 size_t default_line = popup_model->selected_line();
1163 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1164 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1165 base::string16 selected_text =
1166 popup_model->result().match_at(default_line + 1).fill_into_edit;
1167 // Temporary text is shown.
1168 ASSERT_EQ(selected_text, omnibox_view->GetText());
1169 ASSERT_FALSE(omnibox_view->IsSelectAll());
1171 // Delete the item.
1172 popup_model->TryDeletingCurrentItem();
1173 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1174 // The selected line shouldn't be changed, because we have more than two
1175 // items.
1176 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1177 // Make sure the item is really deleted.
1178 ASSERT_NE(selected_text,
1179 popup_model->result().match_at(default_line + 1).fill_into_edit);
1180 selected_text =
1181 popup_model->result().match_at(default_line + 1).fill_into_edit;
1182 // New temporary text is shown.
1183 ASSERT_EQ(selected_text, omnibox_view->GetText());
1185 // Revert to the default match.
1186 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1187 ASSERT_EQ(default_line, popup_model->selected_line());
1188 ASSERT_EQ(user_text, omnibox_view->GetText());
1189 ASSERT_TRUE(omnibox_view->IsSelectAll());
1191 // Move down and up to select the default match as temporary text.
1192 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1193 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1194 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
1195 ASSERT_EQ(default_line, popup_model->selected_line());
1197 selected_text = popup_model->result().match_at(default_line).fill_into_edit;
1198 // New temporary text is shown.
1199 ASSERT_EQ(selected_text, omnibox_view->GetText());
1200 ASSERT_FALSE(omnibox_view->IsSelectAll());
1202 #if 0
1203 // TODO(mrossetti): http://crbug.com/82335
1204 // Delete the default item.
1205 popup_model->TryDeletingCurrentItem();
1206 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1207 // The selected line shouldn't be changed, but the default item should have
1208 // been changed.
1209 ASSERT_EQ(default_line, popup_model->selected_line());
1210 // Make sure the item is really deleted.
1211 EXPECT_NE(selected_text,
1212 popup_model->result().match_at(default_line).fill_into_edit);
1213 selected_text =
1214 popup_model->result().match_at(default_line).fill_into_edit;
1215 // New temporary text is shown.
1216 ASSERT_EQ(selected_text, omnibox_view->GetText());
1217 #endif
1219 // As the current selected item is the new default item, pressing Escape key
1220 // should revert all directly.
1221 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1222 ASSERT_EQ(old_text, omnibox_view->GetText());
1223 ASSERT_TRUE(omnibox_view->IsSelectAll());
1226 // http://crbug.com/133344
1227 #if defined(OS_LINUX)
1228 #define MAYBE_TabAcceptKeyword DISABLED_TabAcceptKeyword
1229 #else
1230 #define MAYBE_TabAcceptKeyword TabAcceptKeyword
1231 #endif
1233 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_TabAcceptKeyword) {
1234 OmniboxView* omnibox_view = NULL;
1235 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1237 base::string16 text = ASCIIToUTF16(kSearchKeyword);
1239 // Trigger keyword hint mode.
1240 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1241 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1242 ASSERT_EQ(text, omnibox_view->model()->keyword());
1243 ASSERT_EQ(text, omnibox_view->GetText());
1245 // Trigger keyword mode by tab.
1246 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1247 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1248 ASSERT_EQ(text, omnibox_view->model()->keyword());
1249 ASSERT_TRUE(omnibox_view->GetText().empty());
1251 // Revert to keyword hint mode.
1252 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1253 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1254 ASSERT_EQ(text, omnibox_view->model()->keyword());
1255 ASSERT_EQ(text, omnibox_view->GetText());
1257 // The location bar should still have focus.
1258 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1260 // Trigger keyword mode by tab.
1261 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1262 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1263 ASSERT_EQ(text, omnibox_view->model()->keyword());
1264 ASSERT_TRUE(omnibox_view->GetText().empty());
1266 // Revert to keyword hint mode with SHIFT+TAB.
1267 #if defined(OS_MACOSX)
1268 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB, 0));
1269 #else
1270 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1271 #endif
1272 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1273 ASSERT_EQ(text, omnibox_view->model()->keyword());
1274 ASSERT_EQ(text, omnibox_view->GetText());
1275 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1278 #if !defined(OS_MACOSX)
1279 // Mac intentionally does not support this behavior.
1281 // http://crbug.com/133360
1282 #if defined(OS_LINUX)
1283 #define MAYBE_TabTraverseResultsTest DISABLED_TabTraverseResultsTest
1284 #else
1285 #define MAYBE_TabTraverseResultsTest TabTraverseResultsTest
1286 #endif
1288 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_TabTraverseResultsTest) {
1289 OmniboxView* omnibox_view = NULL;
1290 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1291 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1292 ASSERT_TRUE(popup_model);
1294 // Input something to trigger results.
1295 const ui::KeyboardCode kKeys[] = {
1296 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
1298 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
1299 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1300 ASSERT_TRUE(popup_model->IsOpen());
1302 size_t old_selected_line = popup_model->selected_line();
1303 EXPECT_EQ(0U, old_selected_line);
1305 // Move down the results.
1306 for (size_t size = popup_model->result().size();
1307 popup_model->selected_line() < size - 1;
1308 old_selected_line = popup_model->selected_line()) {
1309 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1310 ASSERT_LT(old_selected_line, popup_model->selected_line());
1313 // Don't move past the end.
1314 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1315 ASSERT_EQ(old_selected_line, popup_model->selected_line());
1316 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1318 // Move back up the results.
1319 for (; popup_model->selected_line() > 0U;
1320 old_selected_line = popup_model->selected_line()) {
1321 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1322 ASSERT_GT(old_selected_line, popup_model->selected_line());
1325 // Don't move past the beginning.
1326 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1327 ASSERT_EQ(0U, popup_model->selected_line());
1328 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1330 const TestHistoryEntry kHistoryFoo = {
1331 "http://foo/", "Page foo", 1, 1, false
1334 // Add a history entry so "foo" gets multiple matches.
1335 ASSERT_NO_FATAL_FAILURE(
1336 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromHours(1)));
1338 // Load results.
1339 ASSERT_NO_FATAL_FAILURE(omnibox_view->SelectAll(false));
1340 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1341 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1343 // Trigger keyword mode by tab.
1344 base::string16 text = ASCIIToUTF16(kSearchKeyword);
1345 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1346 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1347 ASSERT_EQ(text, omnibox_view->model()->keyword());
1348 ASSERT_TRUE(omnibox_view->GetText().empty());
1350 // The location bar should still have focus.
1351 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1353 // Pressing tab again should move to the next result and clear keyword
1354 // mode.
1355 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1356 ASSERT_EQ(1U, omnibox_view->model()->popup_model()->selected_line());
1357 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1358 ASSERT_NE(text, omnibox_view->model()->keyword());
1360 // The location bar should still have focus.
1361 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1363 // Moving back up should not show keyword mode.
1364 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1365 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1366 ASSERT_EQ(text, omnibox_view->model()->keyword());
1368 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1370 #endif
1373 // http://crbug.com/133347
1374 #if defined(OS_LINUX)
1375 #define MAYBE_PersistKeywordModeOnTabSwitch \
1376 DISABLED_PersistKeywordModeOnTabSwitch
1377 #else
1378 #define MAYBE_PersistKeywordModeOnTabSwitch PersistKeywordModeOnTabSwitch
1379 #endif
1381 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1382 MAYBE_PersistKeywordModeOnTabSwitch) {
1383 OmniboxView* omnibox_view = NULL;
1384 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1386 // Trigger keyword hint mode.
1387 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1388 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1389 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1391 // Trigger keyword mode.
1392 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1393 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1394 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1396 // Input something as search text.
1397 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1399 // Create a new tab.
1400 chrome::NewTab(browser());
1402 // Switch back to the first tab.
1403 browser()->tab_strip_model()->ActivateTabAt(0, true);
1405 // Make sure we're still in keyword mode.
1406 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1409 // http://crbug.com/133355
1410 #if defined(OS_LINUX)
1411 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1412 DISABLED_CtrlKeyPressedWithInlineAutocompleteTest
1413 #else
1414 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1415 CtrlKeyPressedWithInlineAutocompleteTest
1416 #endif
1418 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1419 MAYBE_CtrlKeyPressedWithInlineAutocompleteTest) {
1420 OmniboxView* omnibox_view = NULL;
1421 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1422 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1423 ASSERT_TRUE(popup_model);
1425 // Input something to trigger inline autocomplete.
1426 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
1427 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1428 ASSERT_TRUE(popup_model->IsOpen());
1430 base::string16 old_text = omnibox_view->GetText();
1432 // Make sure inline autocomplete is triggerred.
1433 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
1435 // Press ctrl key.
1436 omnibox_view->model()->OnControlKeyChanged(true);
1438 // Inline autocomplete should still be there.
1439 EXPECT_EQ(old_text, omnibox_view->GetText());
1442 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, UndoRedo) {
1443 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
1444 chrome::FocusLocationBar(browser());
1446 OmniboxView* omnibox_view = NULL;
1447 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1449 base::string16 old_text = omnibox_view->GetText();
1450 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), old_text);
1451 EXPECT_TRUE(omnibox_view->IsSelectAll());
1453 // Delete the text, then undo.
1454 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1455 EXPECT_TRUE(omnibox_view->GetText().empty());
1456 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, kCtrlOrCmdMask));
1457 EXPECT_EQ(old_text, omnibox_view->GetText());
1459 // Redo should delete the text again.
1460 ASSERT_NO_FATAL_FAILURE(
1461 SendKey(ui::VKEY_Z, kCtrlOrCmdMask | ui::EF_SHIFT_DOWN));
1462 EXPECT_TRUE(omnibox_view->GetText().empty());
1464 // The toolkit-views undo manager doesn't support restoring selection. Cocoa
1465 // does, so it needs to be cleared.
1466 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, kCtrlOrCmdMask));
1467 #if defined(OS_MACOSX)
1468 // TODO(tapted): This next line may fail if running a toolkit-views browser
1469 // window on Mac. We should fix the toolkit-views undo manager to restore
1470 // selection rather than deleting this #ifdef.
1471 EXPECT_TRUE(omnibox_view->IsSelectAll());
1472 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, 0));
1473 #endif
1474 EXPECT_FALSE(omnibox_view->IsSelectAll());
1476 // The cursor should be at the end.
1477 size_t start, end;
1478 omnibox_view->GetSelectionBounds(&start, &end);
1479 EXPECT_EQ(old_text.size(), start);
1480 EXPECT_EQ(old_text.size(), end);
1482 // Delete three characters; "about:bl" should not trigger inline autocomplete.
1483 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1484 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1485 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1486 EXPECT_EQ(old_text.substr(0, old_text.size() - 3), omnibox_view->GetText());
1488 // Undo delete.
1489 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, kCtrlOrCmdMask));
1490 EXPECT_EQ(old_text, omnibox_view->GetText());
1492 // Redo delete.
1493 ASSERT_NO_FATAL_FAILURE(
1494 SendKey(ui::VKEY_Z, kCtrlOrCmdMask | ui::EF_SHIFT_DOWN));
1495 EXPECT_EQ(old_text.substr(0, old_text.size() - 3), omnibox_view->GetText());
1497 // Delete everything.
1498 omnibox_view->SelectAll(true);
1499 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1500 EXPECT_TRUE(omnibox_view->GetText().empty());
1502 // Undo delete everything.
1503 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, kCtrlOrCmdMask));
1504 EXPECT_EQ(old_text.substr(0, old_text.size() - 3), omnibox_view->GetText());
1506 // Undo delete two characters.
1507 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, kCtrlOrCmdMask));
1508 EXPECT_EQ(old_text, omnibox_view->GetText());
1511 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BackspaceDeleteHalfWidthKatakana) {
1512 OmniboxView* omnibox_view = NULL;
1513 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1514 // Insert text: ダ. This is two, 3-byte UTF-8 characters:
1515 // U+FF80 "HALFWIDTH KATAKANA LETTER TA" and
1516 // U+FF9E "HALFWIDTH KATAKANA VOICED SOUND MARK".
1517 omnibox_view->SetUserText(base::UTF8ToUTF16("\357\276\200\357\276\236"));
1518 EXPECT_FALSE(omnibox_view->GetText().empty());
1520 // Move the cursor to the end.
1521 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
1523 // Backspace should delete the character. In http://crbug.com/192743, the bug
1524 // was that nothing was deleted.
1525 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1526 #if defined(OS_MACOSX)
1527 // Cocoa text fields attach the sound mark and delete the whole thing. This
1528 // behavior should remain on Mac even when using a toolkit-views browser
1529 // window.
1530 EXPECT_TRUE(omnibox_view->GetText().empty());
1531 #else
1532 // Toolkit-views text fields delete just the sound mark.
1533 EXPECT_EQ(base::UTF8ToUTF16("\357\276\200"), omnibox_view->GetText());
1534 #endif
1537 // Flaky test. crbug.com/356850
1538 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1539 DISABLED_DoesNotUpdateAutocompleteOnBlur) {
1540 OmniboxView* omnibox_view = NULL;
1541 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1542 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1543 ASSERT_TRUE(popup_model);
1545 // Input something to trigger inline autocomplete.
1546 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
1547 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1548 ASSERT_TRUE(popup_model->IsOpen());
1549 size_t start, end;
1550 omnibox_view->GetSelectionBounds(&start, &end);
1551 EXPECT_TRUE(start != end);
1552 base::string16 old_autocomplete_text =
1553 omnibox_view->model()->autocomplete_controller()->input_.text();
1555 // Unfocus the omnibox. This should clear the text field selection and
1556 // close the popup, but should not run autocomplete.
1557 // Note: GTK preserves the selection when the omnibox is unfocused.
1558 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
1559 ASSERT_FALSE(popup_model->IsOpen());
1560 omnibox_view->GetSelectionBounds(&start, &end);
1561 EXPECT_TRUE(start == end);
1563 EXPECT_EQ(old_autocomplete_text,
1564 omnibox_view->model()->autocomplete_controller()->input_.text());
1567 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, Paste) {
1568 OmniboxView* omnibox_view = NULL;
1569 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1570 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1571 ASSERT_TRUE(popup_model);
1572 EXPECT_FALSE(popup_model->IsOpen());
1574 // Paste should yield the expected text and open the popup.
1575 SetClipboardText(ASCIIToUTF16(kSearchText));
1576 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1577 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1578 EXPECT_EQ(ASCIIToUTF16(kSearchText), omnibox_view->GetText());
1579 EXPECT_TRUE(popup_model->IsOpen());
1581 // Close the popup and select all.
1582 omnibox_view->CloseOmniboxPopup();
1583 omnibox_view->SelectAll(false);
1584 EXPECT_FALSE(popup_model->IsOpen());
1586 // Pasting the same text again over itself should re-open the popup.
1587 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1588 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1589 EXPECT_EQ(ASCIIToUTF16(kSearchText), omnibox_view->GetText());
1590 EXPECT_TRUE(popup_model->IsOpen());
1591 omnibox_view->CloseOmniboxPopup();
1592 EXPECT_FALSE(popup_model->IsOpen());
1594 // Pasting amid text should yield the expected text and re-open the popup.
1595 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("abcd"), 2, false, false);
1596 SetClipboardText(ASCIIToUTF16("123"));
1597 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1598 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText());
1599 EXPECT_TRUE(popup_model->IsOpen());
1601 // Ctrl/Cmd+Alt+V should not paste.
1602 ASSERT_NO_FATAL_FAILURE(
1603 SendKey(ui::VKEY_V, kCtrlOrCmdMask | ui::EF_ALT_DOWN));
1604 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText());
1605 // TODO(msw): Test that AltGr+V does not paste.
1608 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) {
1609 // Set permanent text thus making sure that omnibox treats 'google.com'
1610 // as URL (not as ordinary user input).
1611 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1612 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1613 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/"));
1614 browser()->swap_toolbar_models(&toolbar_model);
1615 OmniboxView* omnibox_view = NULL;
1616 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1617 OmniboxEditModel* edit_model = omnibox_view->model();
1618 ASSERT_NE(static_cast<OmniboxEditModel*>(NULL), edit_model);
1619 edit_model->UpdatePermanentText();
1621 const char* target_url = "http://www.google.com/calendar";
1622 omnibox_view->SetUserText(ASCIIToUTF16(target_url));
1624 // Location bar must have focus.
1625 chrome::FocusLocationBar(browser());
1626 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1628 // Select full URL and copy it to clipboard. General text and html should
1629 // be available.
1630 omnibox_view->SelectAll(true);
1631 EXPECT_TRUE(omnibox_view->IsSelectAll());
1632 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1633 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1634 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY));
1635 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText());
1636 EXPECT_TRUE(clipboard->IsFormatAvailable(
1637 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1639 // Make sure HTML format isn't written. See
1640 // BookmarkNodeData::WriteToClipboard() for details.
1641 EXPECT_FALSE(clipboard->IsFormatAvailable(
1642 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1644 // These platforms should read bookmark format.
1645 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1646 base::string16 title;
1647 std::string url;
1648 clipboard->ReadBookmark(&title, &url);
1649 EXPECT_EQ(target_url, url);
1650 EXPECT_EQ(ASCIIToUTF16(target_url), title);
1651 #endif
1654 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CutURLToClipboard) {
1655 // Set permanent text thus making sure that omnibox treats 'google.com'
1656 // as URL (not as ordinary user input).
1657 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1658 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1659 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/"));
1660 browser()->swap_toolbar_models(&toolbar_model);
1661 OmniboxView* omnibox_view = NULL;
1662 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1663 OmniboxEditModel* edit_model = omnibox_view->model();
1664 ASSERT_NE(static_cast<OmniboxEditModel*>(NULL), edit_model);
1665 edit_model->UpdatePermanentText();
1667 const char* target_url = "http://www.google.com/calendar";
1668 omnibox_view->SetUserText(ASCIIToUTF16(target_url));
1670 // Location bar must have focus.
1671 chrome::FocusLocationBar(browser());
1672 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1674 // Select full URL and cut it. General text and html should be available
1675 // in the clipboard.
1676 omnibox_view->SelectAll(true);
1677 EXPECT_TRUE(omnibox_view->IsSelectAll());
1678 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1679 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1680 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT));
1681 EXPECT_EQ(base::string16(), omnibox_view->GetText());
1682 EXPECT_TRUE(clipboard->IsFormatAvailable(
1683 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1685 // Make sure HTML format isn't written. See
1686 // BookmarkNodeData::WriteToClipboard() for details.
1687 EXPECT_FALSE(clipboard->IsFormatAvailable(
1688 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1690 // These platforms should read bookmark format.
1691 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1692 base::string16 title;
1693 std::string url;
1694 clipboard->ReadBookmark(&title, &url);
1695 EXPECT_EQ(target_url, url);
1696 EXPECT_EQ(ASCIIToUTF16(target_url), title);
1697 #endif
1700 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyTextToClipboard) {
1701 OmniboxView* omnibox_view = NULL;
1702 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1703 const char* target_text = "foo";
1704 omnibox_view->SetUserText(ASCIIToUTF16(target_text));
1706 // Location bar must have focus.
1707 chrome::FocusLocationBar(browser());
1708 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1710 // Select full text and copy it to the clipboard.
1711 omnibox_view->SelectAll(true);
1712 EXPECT_TRUE(omnibox_view->IsSelectAll());
1713 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1714 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1715 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY));
1716 EXPECT_TRUE(clipboard->IsFormatAvailable(
1717 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1718 EXPECT_FALSE(clipboard->IsFormatAvailable(
1719 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1720 EXPECT_EQ(ASCIIToUTF16(target_text), omnibox_view->GetText());
1723 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CutTextToClipboard) {
1724 OmniboxView* omnibox_view = NULL;
1725 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1726 const char* target_text = "foo";
1727 omnibox_view->SetUserText(ASCIIToUTF16(target_text));
1729 // Location bar must have focus.
1730 chrome::FocusLocationBar(browser());
1731 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1733 // Select full text and cut it to the clipboard.
1734 omnibox_view->SelectAll(true);
1735 EXPECT_TRUE(omnibox_view->IsSelectAll());
1736 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1737 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1738 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT));
1739 EXPECT_TRUE(clipboard->IsFormatAvailable(
1740 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1741 EXPECT_FALSE(clipboard->IsFormatAvailable(
1742 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1743 EXPECT_EQ(base::string16(), omnibox_view->GetText());
1746 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EditSearchEngines) {
1747 // Disable settings-in-a-window to simplify test.
1748 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1749 ::switches::kDisableSettingsWindow);
1750 OmniboxView* omnibox_view = NULL;
1751 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1752 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_EDIT_SEARCH_ENGINES));
1753 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1754 const std::string target_url =
1755 std::string(chrome::kChromeUISettingsURL) + chrome::kSearchEnginesSubPage;
1756 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText());
1757 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen());
1760 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BeginningShownAfterBlur) {
1761 OmniboxView* omnibox_view = NULL;
1762 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1764 omnibox_view->OnBeforePossibleChange();
1765 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"),
1766 5U, false, false);
1767 omnibox_view->OnAfterPossibleChange();
1768 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1769 size_t start, end;
1770 omnibox_view->GetSelectionBounds(&start, &end);
1771 EXPECT_EQ(5U, start);
1772 EXPECT_EQ(5U, end);
1774 ui_test_utils::FocusView(browser(), VIEW_ID_TAB_CONTAINER);
1775 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1777 omnibox_view->GetSelectionBounds(&start, &end);
1778 EXPECT_EQ(0U, start);
1779 EXPECT_EQ(0U, end);
1782 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) {
1783 OmniboxView* omnibox_view = NULL;
1784 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1785 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1786 ASSERT_TRUE(popup_model);
1788 // Input something to trigger results.
1789 const ui::KeyboardCode kKeys[] = {
1790 ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
1792 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
1793 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1794 ASSERT_TRUE(popup_model->IsOpen());
1796 ASSERT_EQ(ASCIIToUTF16("bar.com/1"), omnibox_view->GetText());
1798 // Arrow down on a suggestion, and omnibox text should be the suggestion.
1799 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
1800 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1801 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText());
1803 // Highlight the last 2 words and the omnibox text should not change.
1804 // Simulating Ctrl-shift-left only once does not seem to highlight anything
1805 // on Linux.
1806 #if defined(OS_MACOSX)
1807 // Mac uses alt-left/right to select a word.
1808 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN;
1809 #else
1810 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN;
1811 #endif
1812 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers));
1813 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers));
1814 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText());
1817 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1818 PersistSearchReplacementAcrossTabSwitch) {
1819 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1820 browser()->toolbar_model()->set_url_replacement_enabled(false);
1822 // Create a new tab.
1823 chrome::NewTab(browser());
1824 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1826 // Switch back to the first tab.
1827 browser()->tab_strip_model()->ActivateTabAt(0, true);
1828 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled());
1831 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1832 DontUpdateURLWhileSearchTermReplacementIsDisabled) {
1833 OmniboxView* omnibox_view = NULL;
1834 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1835 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1836 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1837 browser()->swap_toolbar_models(&toolbar_model);
1839 base::string16 url_a(ASCIIToUTF16("http://www.a.com/"));
1840 base::string16 url_b(ASCIIToUTF16("http://www.b.com/"));
1841 base::string16 url_c(ASCIIToUTF16("http://www.c.com/"));
1842 chrome::FocusLocationBar(browser());
1843 test_toolbar_model->set_text(url_a);
1844 omnibox_view->Update();
1845 EXPECT_EQ(url_a, omnibox_view->GetText());
1847 // Disable URL replacement and update. Because the omnibox has focus, the
1848 // visible text shouldn't change; see comments in
1849 // OmniboxEditModel::UpdatePermanentText().
1850 browser()->toolbar_model()->set_url_replacement_enabled(false);
1851 test_toolbar_model->set_text(url_b);
1852 omnibox_view->Update();
1853 EXPECT_EQ(url_a, omnibox_view->GetText());
1855 // Re-enable URL replacement and ensure updating changes the text.
1856 browser()->toolbar_model()->set_url_replacement_enabled(true);
1857 // We have to change the toolbar model text here, or Update() will do nothing.
1858 // This is because the previous update already updated the permanent text.
1859 test_toolbar_model->set_text(url_c);
1860 omnibox_view->Update();
1861 EXPECT_EQ(url_c, omnibox_view->GetText());
1863 // The same test, but using RevertAll() to reset search term replacement.
1864 test_toolbar_model->set_text(url_a);
1865 omnibox_view->Update();
1866 EXPECT_EQ(url_a, omnibox_view->GetText());
1867 browser()->toolbar_model()->set_url_replacement_enabled(false);
1868 test_toolbar_model->set_text(url_b);
1869 omnibox_view->Update();
1870 EXPECT_EQ(url_a, omnibox_view->GetText());
1871 omnibox_view->RevertAll();
1872 EXPECT_EQ(url_b, omnibox_view->GetText());
1873 test_toolbar_model->set_text(url_c);
1874 omnibox_view->Update();
1875 EXPECT_EQ(url_c, omnibox_view->GetText());