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.
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.h"
18 #include "chrome/browser/history/history_service_factory.h"
19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_commands.h"
23 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/location_bar/location_bar.h"
25 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
26 #include "chrome/browser/ui/omnibox/omnibox_view.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/toolbar/test_toolbar_model.h"
29 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/interactive_test_utils.h"
34 #include "chrome/test/base/ui_test_utils.h"
35 #include "components/bookmarks/browser/bookmark_model.h"
36 #include "components/bookmarks/browser/bookmark_utils.h"
37 #include "components/bookmarks/test/bookmark_test_helpers.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
;
55 using base::TimeDelta
;
56 using bookmarks::BookmarkModel
;
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
[] = {
99 const struct TestHistoryEntry
{
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
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
;
137 const int kCtrlOrCmdMask
= ui::EF_CONTROL_DOWN
;
142 class OmniboxViewTest
: public InProcessBrowserTest
,
143 public content::NotificationObserver
,
144 public history::HistoryServiceObserver
{
146 OmniboxViewTest() : observer_(this) {}
148 // history::HisoryServiceObserver
149 void OnHistoryServiceLoaded(HistoryService
* history_service
) override
{
150 base::MessageLoop::current()->Quit();
154 void SetUpOnMainThread() override
{
155 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
156 ASSERT_NO_FATAL_FAILURE(SetupComponents());
157 chrome::FocusLocationBar(browser());
158 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
161 static void GetOmniboxViewForBrowser(
162 const Browser
* browser
,
163 OmniboxView
** omnibox_view
) {
164 BrowserWindow
* window
= browser
->window();
166 LocationBar
* location_bar
= window
->GetLocationBar();
167 ASSERT_TRUE(location_bar
);
168 *omnibox_view
= location_bar
->GetOmniboxView();
169 ASSERT_TRUE(*omnibox_view
);
172 void GetOmniboxView(OmniboxView
** omnibox_view
) {
173 GetOmniboxViewForBrowser(browser(), omnibox_view
);
176 static void SendKeyForBrowser(const Browser
* browser
,
177 ui::KeyboardCode key
,
179 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
181 (modifiers
& ui::EF_CONTROL_DOWN
) != 0,
182 (modifiers
& ui::EF_SHIFT_DOWN
) != 0,
183 (modifiers
& ui::EF_ALT_DOWN
) != 0,
184 (modifiers
& ui::EF_COMMAND_DOWN
) != 0));
187 void SendKey(ui::KeyboardCode key
, int modifiers
) {
188 SendKeyForBrowser(browser(), key
, modifiers
);
191 void SendKeySequence(const ui::KeyboardCode
* keys
) {
192 for (; *keys
!= ui::VKEY_UNKNOWN
; ++keys
)
193 ASSERT_NO_FATAL_FAILURE(SendKey(*keys
, 0));
196 bool SendKeyAndWait(const Browser
* browser
,
197 ui::KeyboardCode key
,
200 const content::NotificationSource
& source
)
202 return ui_test_utils::SendKeyPressAndWait(
204 (modifiers
& ui::EF_CONTROL_DOWN
) != 0,
205 (modifiers
& ui::EF_SHIFT_DOWN
) != 0,
206 (modifiers
& ui::EF_ALT_DOWN
) != 0,
207 (modifiers
& ui::EF_COMMAND_DOWN
) != 0,
211 void WaitForTabOpenOrCloseForBrowser(const Browser
* browser
,
212 int expected_tab_count
) {
213 int tab_count
= browser
->tab_strip_model()->count();
214 if (tab_count
== expected_tab_count
)
217 content::NotificationRegistrar registrar
;
219 (tab_count
< expected_tab_count
) ?
220 static_cast<int>(chrome::NOTIFICATION_TAB_PARENTED
) :
221 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED
),
222 content::NotificationService::AllSources());
224 while (!HasFailure() &&
225 browser
->tab_strip_model()->count() != expected_tab_count
) {
226 content::RunMessageLoop();
229 ASSERT_EQ(expected_tab_count
, browser
->tab_strip_model()->count());
232 void WaitForTabOpenOrClose(int expected_tab_count
) {
233 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count
);
236 void WaitForAutocompleteControllerDone() {
237 OmniboxView
* omnibox_view
= NULL
;
238 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
240 AutocompleteController
* controller
=
241 omnibox_view
->model()->autocomplete_controller();
242 ASSERT_TRUE(controller
);
244 if (controller
->done())
247 content::NotificationRegistrar registrar
;
249 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY
,
250 content::Source
<AutocompleteController
>(controller
));
252 while (!HasFailure() && !controller
->done())
253 content::RunMessageLoop();
255 ASSERT_TRUE(controller
->done());
258 void SetupSearchEngine() {
259 Profile
* profile
= browser()->profile();
260 TemplateURLService
* model
=
261 TemplateURLServiceFactory::GetForProfile(profile
);
264 ui_test_utils::WaitForTemplateURLServiceToLoad(model
);
266 ASSERT_TRUE(model
->loaded());
268 TemplateURLData data
;
269 data
.short_name
= ASCIIToUTF16(kSearchShortName
);
270 data
.SetKeyword(ASCIIToUTF16(kSearchKeyword
));
271 data
.SetURL(kSearchURL
);
272 TemplateURL
* template_url
= new TemplateURL(data
);
273 model
->Add(template_url
);
274 model
->SetUserSelectedDefaultSearchProvider(template_url
);
276 data
.SetKeyword(ASCIIToUTF16(kSearchKeyword2
));
277 model
->Add(new TemplateURL(data
));
279 // Remove built-in template urls, like google.com, bing.com etc., as they
280 // may appear as autocomplete suggests and interfere with our tests.
281 TemplateURLService::TemplateURLVector urls
= model
->GetTemplateURLs();
282 for (TemplateURLService::TemplateURLVector::const_iterator i
= urls
.begin();
285 if ((*i
)->prepopulate_id() != 0)
290 void AddHistoryEntry(const TestHistoryEntry
& entry
, const Time
& time
) {
291 Profile
* profile
= browser()->profile();
292 HistoryService
* history_service
= HistoryServiceFactory::GetForProfile(
293 profile
, ServiceAccessType::EXPLICIT_ACCESS
);
294 ASSERT_TRUE(history_service
);
296 if (!history_service
->BackendLoaded()) {
297 observer_
.Add(history_service
);
298 content::RunMessageLoop();
301 BookmarkModel
* bookmark_model
=
302 BookmarkModelFactory::GetForProfile(profile
);
303 ASSERT_TRUE(bookmark_model
);
304 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model
);
307 // Add everything in order of time. We don't want to have a time that
308 // is "right now" or it will nondeterministically appear in the results.
309 history_service
->AddPageWithDetails(url
, base::UTF8ToUTF16(entry
.title
),
311 entry
.typed_count
, time
, false,
312 history::SOURCE_BROWSED
);
314 bookmarks::AddIfNotBookmarked(bookmark_model
, url
, base::string16());
315 // Wait at least for the AddPageWithDetails() call to finish.
317 ScopedObserver
<HistoryService
, history::HistoryServiceObserver
> observer(
319 observer
.Add(history_service
);
320 content::RunMessageLoop();
321 // We don't want to return until all observers have processed this
322 // notification, because some (e.g. the in-memory history database) may do
323 // something important. Since we don't know where in the observer list we
324 // stand, just spin the message loop once more to allow the current
325 // callstack to complete.
326 content::RunAllPendingInMessageLoop();
330 void SetupHistory() {
331 // Add enough history pages containing |kSearchText| to trigger
332 // open history page url in autocomplete result.
333 for (size_t i
= 0; i
< arraysize(kHistoryEntries
); i
++) {
334 // Add everything in order of time. We don't want to have a time that
335 // is "right now" or it will nondeterministically appear in the results.
336 Time t
= Time::Now() - TimeDelta::FromHours(i
+ 1);
337 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries
[i
], t
));
341 void SetupHostResolver() {
342 for (size_t i
= 0; i
< arraysize(kBlockedHostnames
); ++i
)
343 host_resolver()->AddSimulatedFailure(kBlockedHostnames
[i
]);
346 void SetupComponents() {
347 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
348 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
349 ASSERT_NO_FATAL_FAILURE(SetupHistory());
352 void Observe(int type
,
353 const content::NotificationSource
& source
,
354 const content::NotificationDetails
& details
) override
{
356 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED
:
357 case chrome::NOTIFICATION_TAB_PARENTED
:
358 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY
:
361 FAIL() << "Unexpected notification type";
363 base::MessageLoop::current()->Quit();
366 void OnURLsModified(HistoryService
* history_service
,
367 const history::URLRows
& changed_urls
) override
{
368 base::MessageLoop::current()->Quit();
372 ScopedObserver
<HistoryService
, OmniboxViewTest
> observer_
;
374 DISALLOW_COPY_AND_ASSIGN(OmniboxViewTest
);
377 // Test if ctrl-* accelerators are workable in omnibox.
378 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
380 // Flaky on interactive tests (dbg), http://crbug.com/69433
381 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, DISABLED_BrowserAccelerators
) {
382 OmniboxView
* omnibox_view
= NULL
;
383 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
385 int tab_count
= browser()->tab_strip_model()->count();
388 chrome::NewTab(browser());
389 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count
+ 1));
391 // Select the first Tab.
392 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1
, kCtrlOrCmdMask
));
393 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
395 chrome::FocusLocationBar(browser());
397 // Select the second Tab.
398 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2
, kCtrlOrCmdMask
));
399 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
401 chrome::FocusLocationBar(browser());
403 // Try ctrl-w to close a Tab.
404 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W
, kCtrlOrCmdMask
));
405 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count
));
407 // Try ctrl-l to focus location bar.
408 omnibox_view
->SetUserText(ASCIIToUTF16("Hello world"));
409 EXPECT_FALSE(omnibox_view
->IsSelectAll());
410 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L
, kCtrlOrCmdMask
));
411 EXPECT_TRUE(omnibox_view
->IsSelectAll());
413 // Try editing the location bar text.
414 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT
, 0));
415 EXPECT_FALSE(omnibox_view
->IsSelectAll());
416 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S
, 0));
417 EXPECT_EQ(ASCIIToUTF16("Hello worlds"), omnibox_view
->GetText());
419 // Try ctrl-x to cut text.
420 #if defined(OS_MACOSX)
421 // Mac uses alt-left/right to select a word.
422 ASSERT_NO_FATAL_FAILURE(
423 SendKey(ui::VKEY_LEFT
, ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
));
425 ASSERT_NO_FATAL_FAILURE(
426 SendKey(ui::VKEY_LEFT
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
));
428 EXPECT_FALSE(omnibox_view
->IsSelectAll());
429 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X
, kCtrlOrCmdMask
));
430 EXPECT_EQ(ASCIIToUTF16("Hello "), omnibox_view
->GetText());
432 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
433 // Try alt-f4 to close the browser.
434 ASSERT_TRUE(SendKeyAndWait(
435 browser(), ui::VKEY_F4
, ui::EF_ALT_DOWN
,
436 chrome::NOTIFICATION_BROWSER_CLOSED
,
437 content::Source
<Browser
>(browser())));
441 // Fails on Linux. http://crbug.com/408634
442 #if defined(OS_LINUX)
443 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators
445 #define MAYBE_PopupAccelerators PopupAccelerators
448 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_PopupAccelerators
) {
450 Browser
* popup
= CreateBrowserForPopup(browser()->profile());
451 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup
));
452 OmniboxView
* omnibox_view
= NULL
;
453 ASSERT_NO_FATAL_FAILURE(
454 GetOmniboxViewForBrowser(popup
, &omnibox_view
));
455 chrome::FocusLocationBar(popup
);
456 EXPECT_TRUE(omnibox_view
->IsSelectAll());
458 #if !defined(OS_MACOSX)
459 // Try ctrl-w to close the popup.
460 // This piece of code doesn't work on Mac, because the Browser object won't
461 // be destroyed before finishing the current message loop iteration, thus
462 // No BROWSER_CLOSED notification will be sent.
463 ASSERT_TRUE(SendKeyAndWait(
464 popup
, ui::VKEY_W
, ui::EF_CONTROL_DOWN
,
465 chrome::NOTIFICATION_BROWSER_CLOSED
, content::Source
<Browser
>(popup
)));
467 // Create another popup.
468 popup
= CreateBrowserForPopup(browser()->profile());
469 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup
));
470 ASSERT_NO_FATAL_FAILURE(
471 GetOmniboxViewForBrowser(popup
, &omnibox_view
));
474 // Set the edit text to "Hello world".
475 omnibox_view
->SetUserText(ASCIIToUTF16("Hello world"));
476 chrome::FocusLocationBar(popup
);
477 EXPECT_TRUE(omnibox_view
->IsSelectAll());
479 // Try editing the location bar text -- should be disallowed.
480 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup
, ui::VKEY_S
, 0));
481 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view
->GetText());
482 EXPECT_TRUE(omnibox_view
->IsSelectAll());
484 ASSERT_NO_FATAL_FAILURE(
485 SendKeyForBrowser(popup
, ui::VKEY_X
, kCtrlOrCmdMask
));
486 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view
->GetText());
487 EXPECT_TRUE(omnibox_view
->IsSelectAll());
489 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
490 // Try alt-f4 to close the popup.
491 ASSERT_TRUE(SendKeyAndWait(
492 popup
, ui::VKEY_F4
, ui::EF_ALT_DOWN
,
493 chrome::NOTIFICATION_BROWSER_CLOSED
, content::Source
<Browser
>(popup
)));
497 // http://crbug.com/133341
498 #if defined(OS_LINUX)
499 #define MAYBE_BackspaceInKeywordMode DISABLED_BackspaceInKeywordMode
501 #define MAYBE_BackspaceInKeywordMode BackspaceInKeywordMode
504 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_BackspaceInKeywordMode
) {
505 OmniboxView
* omnibox_view
= NULL
;
506 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
508 // Trigger keyword hint mode.
509 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
510 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
511 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
513 // Trigger keyword mode.
514 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
515 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
516 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
518 // Backspace without search text should bring back keyword hint mode.
519 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
520 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
521 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
523 // Trigger keyword mode again.
524 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
525 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
526 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
528 // Input something as search text.
529 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
531 // Should stay in keyword mode while deleting search text by pressing
533 for (size_t i
= 0; i
< arraysize(kSearchText
) - 1; ++i
) {
534 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
535 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
536 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
539 // Input something as search text.
540 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
542 // Move cursor to the beginning of the search text.
543 #if defined(OS_MACOSX)
544 // Home doesn't work on Mac trybot.
545 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A
, ui::EF_CONTROL_DOWN
));
547 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME
, 0));
549 // Backspace at the beginning of the search text shall turn off
551 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
552 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
553 ASSERT_EQ(base::string16(), omnibox_view
->model()->keyword());
554 ASSERT_EQ(std::string(kSearchKeyword
) + kSearchText
,
555 UTF16ToUTF8(omnibox_view
->GetText()));
558 // http://crbug.com/158913
559 #if defined(USE_AURA)
560 #define MAYBE_Escape DISABLED_Escape
562 #define MAYBE_Escape Escape
565 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_Escape
) {
566 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL
));
567 chrome::FocusLocationBar(browser());
569 OmniboxView
* omnibox_view
= NULL
;
570 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
572 base::string16 old_text
= omnibox_view
->GetText();
573 EXPECT_FALSE(old_text
.empty());
574 EXPECT_TRUE(omnibox_view
->IsSelectAll());
576 // Delete all text in omnibox.
577 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
578 EXPECT_TRUE(omnibox_view
->GetText().empty());
580 // Escape shall revert the text in omnibox.
581 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE
, 0));
582 EXPECT_EQ(old_text
, omnibox_view
->GetText());
583 EXPECT_TRUE(omnibox_view
->IsSelectAll());
587 #if defined(OS_LINUX)
588 #define MAYBE_DesiredTLD DISABLED_DesiredTLD
590 #define MAYBE_DesiredTLD DesiredTLD
593 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_DesiredTLD
) {
594 OmniboxView
* omnibox_view
= NULL
;
595 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
596 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
597 ASSERT_TRUE(popup_model
);
600 const ui::KeyboardCode kKeys
[] = {
601 ui::VKEY_B
, ui::VKEY_A
, ui::VKEY_R
, ui::VKEY_UNKNOWN
603 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys
));
604 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
605 ASSERT_TRUE(popup_model
->IsOpen());
606 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be
608 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN
, ui::EF_CONTROL_DOWN
,
609 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
610 content::Source
<content::NavigationController
>(
611 &browser()->tab_strip_model()->GetActiveWebContents()->
614 GURL url
= browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
615 EXPECT_EQ("www.bar.com", url
.host());
616 EXPECT_EQ("/", url
.path());
619 #if defined(OS_LINUX)
620 #define MAYBE_DesiredTLDWithTemporaryText DISABLED_DesiredTLDWithTemporaryText
622 #define MAYBE_DesiredTLDWithTemporaryText DesiredTLDWithTemporaryText
625 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_DesiredTLDWithTemporaryText
) {
626 OmniboxView
* omnibox_view
= NULL
;
627 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
628 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
629 ASSERT_TRUE(popup_model
);
631 Profile
* profile
= browser()->profile();
632 TemplateURLService
* template_url_service
=
633 TemplateURLServiceFactory::GetForProfile(profile
);
635 // Add a non-substituting keyword. This ensures the popup will have a
636 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we
637 // can set "abc" as temporary text in the omnibox.
638 TemplateURLData data
;
639 data
.short_name
= ASCIIToUTF16("abc");
640 data
.SetKeyword(ASCIIToUTF16(kSearchText
));
641 data
.SetURL("http://abc.com/");
642 template_url_service
->Add(new TemplateURL(data
));
644 // Send "ab", so that an "abc" entry appears in the popup.
645 const ui::KeyboardCode kSearchTextPrefixKeys
[] = {
646 ui::VKEY_A
, ui::VKEY_B
, ui::VKEY_UNKNOWN
648 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys
));
649 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
650 ASSERT_TRUE(popup_model
->IsOpen());
652 // Arrow down to the "abc" entry in the popup.
653 size_t size
= popup_model
->result().size();
654 while (popup_model
->selected_line() < size
- 1) {
655 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN
, 0));
656 if (omnibox_view
->GetText() == ASCIIToUTF16("abc"))
659 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view
->GetText());
661 // Hitting ctrl-enter should navigate based on the current text rather than
662 // the original input, i.e. to www.abc.com instead of www.ab.com.
663 ASSERT_TRUE(SendKeyAndWait(
664 browser(), ui::VKEY_RETURN
, ui::EF_CONTROL_DOWN
,
665 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
666 content::Source
<content::NavigationController
>(
667 &browser()->tab_strip_model()->GetActiveWebContents()->
670 GURL
url(browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
671 EXPECT_EQ("www.abc.com", url
.host());
672 EXPECT_EQ("/", url
.path());
675 // See http://crbug.com/431575.
676 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, ClearUserTextAfterBackgroundCommit
) {
677 OmniboxView
* omnibox_view
= NULL
;
678 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
680 // Navigate in first tab and enter text into the omnibox.
681 GURL
url1("data:text/html,page1");
682 ui_test_utils::NavigateToURL(browser(), url1
);
683 omnibox_view
->SetUserText(ASCIIToUTF16("foo"));
684 content::WebContents
* contents
=
685 browser()->tab_strip_model()->GetActiveWebContents();
687 // Create another tab in the foreground.
688 AddTabAtIndex(1, url1
, ui::PAGE_TRANSITION_TYPED
);
689 EXPECT_EQ(2, browser()->tab_strip_model()->count());
690 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
692 // Navigate in the first tab, currently in the background.
693 GURL
url2("data:text/html,page2");
694 chrome::NavigateParams
params(browser(), url2
, ui::PAGE_TRANSITION_LINK
);
695 params
.source_contents
= contents
;
696 params
.disposition
= CURRENT_TAB
;
697 ui_test_utils::NavigateToURL(¶ms
);
699 // Switch back to the first tab. The user text should be cleared, and the
700 // omnibox should have the new URL.
701 browser()->tab_strip_model()->ActivateTabAt(0, true);
702 EXPECT_EQ(ASCIIToUTF16(url2
.spec()), omnibox_view
->GetText());
705 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, AltEnter
) {
706 OmniboxView
* omnibox_view
= NULL
;
707 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
709 omnibox_view
->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL
));
710 int tab_count
= browser()->tab_strip_model()->count();
711 // alt-Enter opens a new tab.
712 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN
, ui::EF_ALT_DOWN
));
713 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count
+ 1));
716 // http://crbug.com/133354, http://crbug.com/146953
717 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, DISABLED_EnterToSearch
) {
718 OmniboxView
* omnibox_view
= NULL
;
719 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
720 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
721 ASSERT_TRUE(popup_model
);
723 // Test Enter to search.
724 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
725 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
726 ASSERT_TRUE(popup_model
->IsOpen());
728 // Check if the default match result is Search Primary Provider.
729 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED
,
730 popup_model
->result().default_match()->type
);
732 // Open the default match.
733 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN
, 0,
734 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
735 content::Source
<content::NavigationController
>(
736 &browser()->tab_strip_model()->GetActiveWebContents()->
738 GURL url
= browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
739 EXPECT_EQ(kSearchTextURL
, url
.spec());
741 // Test that entering a single character then Enter performs a search.
742 const ui::KeyboardCode kSearchSingleCharKeys
[] = {
743 ui::VKEY_Z
, ui::VKEY_UNKNOWN
745 chrome::FocusLocationBar(browser());
746 EXPECT_TRUE(omnibox_view
->IsSelectAll());
747 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys
));
748 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
749 ASSERT_TRUE(popup_model
->IsOpen());
750 EXPECT_EQ("z", UTF16ToUTF8(omnibox_view
->GetText()));
752 // Check if the default match result is Search Primary Provider.
753 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED
,
754 popup_model
->result().default_match()->type
);
756 // Open the default match.
757 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN
, 0,
758 content::NOTIFICATION_NAV_ENTRY_COMMITTED
,
759 content::Source
<content::NavigationController
>(
760 &browser()->tab_strip_model()->GetActiveWebContents()->
762 url
= browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
763 EXPECT_EQ("http://www.foo.com/search?q=z", url
.spec());
766 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, EscapeToDefaultMatch
) {
767 OmniboxView
* omnibox_view
= NULL
;
768 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
769 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
770 ASSERT_TRUE(popup_model
);
772 // Input something to trigger inline autocomplete.
773 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys
));
774 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
775 ASSERT_TRUE(popup_model
->IsOpen());
777 base::string16 old_text
= omnibox_view
->GetText();
779 // Make sure inline autocomplete is triggerred.
780 EXPECT_GT(old_text
.length(), arraysize(kInlineAutocompleteText
) - 1);
782 size_t old_selected_line
= popup_model
->selected_line();
783 EXPECT_EQ(0U, old_selected_line
);
785 // Move to another line with different text.
786 size_t size
= popup_model
->result().size();
787 while (popup_model
->selected_line() < size
- 1) {
788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN
, 0));
789 ASSERT_NE(old_selected_line
, popup_model
->selected_line());
790 if (old_text
!= omnibox_view
->GetText())
794 EXPECT_NE(old_text
, omnibox_view
->GetText());
796 // Escape shall revert back to the default match item.
797 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE
, 0));
798 EXPECT_EQ(old_text
, omnibox_view
->GetText());
799 EXPECT_EQ(old_selected_line
, popup_model
->selected_line());
802 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, BasicTextOperations
) {
803 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL
));
804 chrome::FocusLocationBar(browser());
806 OmniboxView
* omnibox_view
= NULL
;
807 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
809 base::string16 old_text
= omnibox_view
->GetText();
810 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL
), old_text
);
811 EXPECT_TRUE(omnibox_view
->IsSelectAll());
814 omnibox_view
->GetSelectionBounds(&start
, &end
);
815 #if defined(OS_WIN) || defined(OS_LINUX)
816 // Views textfields select-all in reverse to show the leading text.
817 std::swap(start
, end
);
819 EXPECT_EQ(0U, start
);
820 EXPECT_EQ(old_text
.size(), end
);
822 // Move the cursor to the end.
823 #if defined(OS_MACOSX)
824 // End doesn't work on Mac trybot.
825 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E
, ui::EF_CONTROL_DOWN
));
827 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END
, 0));
829 EXPECT_FALSE(omnibox_view
->IsSelectAll());
831 // Make sure the cursor is placed correctly.
832 omnibox_view
->GetSelectionBounds(&start
, &end
);
833 EXPECT_EQ(old_text
.size(), start
);
834 EXPECT_EQ(old_text
.size(), end
);
836 // Insert one character at the end. Make sure we won't insert
837 // anything after the special ZWS mark used in gtk implementation.
838 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A
, 0));
839 EXPECT_EQ(old_text
+ base::char16('a'), omnibox_view
->GetText());
841 // Delete one character from the end. Make sure we won't delete the special
842 // ZWS mark used in gtk implementation.
843 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
844 EXPECT_EQ(old_text
, omnibox_view
->GetText());
846 omnibox_view
->SelectAll(true);
847 EXPECT_TRUE(omnibox_view
->IsSelectAll());
848 omnibox_view
->GetSelectionBounds(&start
, &end
);
849 #if defined(OS_WIN) || defined(OS_LINUX)
850 // Views textfields select-all in reverse to show the leading text.
851 std::swap(start
, end
);
853 EXPECT_EQ(0U, start
);
854 EXPECT_EQ(old_text
.size(), end
);
856 // Delete the content
857 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE
, 0));
858 EXPECT_TRUE(omnibox_view
->IsSelectAll());
859 omnibox_view
->GetSelectionBounds(&start
, &end
);
860 EXPECT_EQ(0U, start
);
862 EXPECT_TRUE(omnibox_view
->GetText().empty());
864 // Check if RevertAll() can set text and cursor correctly.
865 omnibox_view
->RevertAll();
866 EXPECT_FALSE(omnibox_view
->IsSelectAll());
867 EXPECT_EQ(old_text
, omnibox_view
->GetText());
868 omnibox_view
->GetSelectionBounds(&start
, &end
);
869 EXPECT_EQ(old_text
.size(), start
);
870 EXPECT_EQ(old_text
.size(), end
);
873 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, AcceptKeywordBySpace
) {
874 OmniboxView
* omnibox_view
= NULL
;
875 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
877 base::string16
search_keyword(ASCIIToUTF16(kSearchKeyword
));
879 // Trigger keyword hint mode.
880 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
881 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
882 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
883 ASSERT_EQ(search_keyword
, omnibox_view
->GetText());
885 // Trigger keyword mode by space.
886 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
887 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
888 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
889 ASSERT_TRUE(omnibox_view
->GetText().empty());
891 // Revert to keyword hint mode.
892 omnibox_view
->model()->ClearKeyword(base::string16());
893 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
894 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
895 ASSERT_EQ(search_keyword
, omnibox_view
->GetText());
897 // Keyword should also be accepted by typing an ideographic space.
898 omnibox_view
->OnBeforePossibleChange();
899 omnibox_view
->SetWindowTextAndCaretPos(search_keyword
+
900 base::WideToUTF16(L
"\x3000"), search_keyword
.length() + 1, false, false);
901 omnibox_view
->OnAfterPossibleChange();
902 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
903 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
904 ASSERT_TRUE(omnibox_view
->GetText().empty());
906 // Revert to keyword hint mode.
907 omnibox_view
->model()->ClearKeyword(base::string16());
908 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
909 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
910 ASSERT_EQ(search_keyword
, omnibox_view
->GetText());
912 // Keyword shouldn't be accepted by pressing space with a trailing
914 omnibox_view
->SetWindowTextAndCaretPos(search_keyword
+ base::char16(' '),
915 search_keyword
.length() + 1, false, false);
916 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
917 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
918 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
919 ASSERT_EQ(search_keyword
+ ASCIIToUTF16(" "), omnibox_view
->GetText());
921 // Keyword shouldn't be accepted by deleting the trailing space.
922 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
923 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
924 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
925 ASSERT_EQ(search_keyword
+ base::char16(' '), omnibox_view
->GetText());
927 // Keyword shouldn't be accepted by pressing space before a trailing space.
928 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
929 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
930 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
931 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
932 ASSERT_EQ(search_keyword
+ ASCIIToUTF16(" "), omnibox_view
->GetText());
934 // Keyword should be accepted by pressing space in the middle of context and
935 // just after the keyword.
936 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
937 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A
, 0));
938 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
939 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
940 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
941 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
942 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view
->GetText());
944 omnibox_view
->GetSelectionBounds(&start
, &end
);
945 EXPECT_EQ(0U, start
);
948 // Keyword shouldn't be accepted by pasting "foo bar".
949 omnibox_view
->SetUserText(base::string16());
950 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
951 ASSERT_TRUE(omnibox_view
->model()->keyword().empty());
953 omnibox_view
->OnBeforePossibleChange();
954 omnibox_view
->model()->OnPaste();
955 omnibox_view
->SetWindowTextAndCaretPos(search_keyword
+
956 ASCIIToUTF16(" bar"), search_keyword
.length() + 4, false, false);
957 omnibox_view
->OnAfterPossibleChange();
958 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
959 ASSERT_TRUE(omnibox_view
->model()->keyword().empty());
960 ASSERT_EQ(search_keyword
+ ASCIIToUTF16(" bar"), omnibox_view
->GetText());
962 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
963 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
964 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
965 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
966 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
967 ASSERT_TRUE(omnibox_view
->model()->keyword().empty());
968 ASSERT_EQ(search_keyword
+ ASCIIToUTF16(" b ar"), omnibox_view
->GetText());
970 // Keyword could be accepted by pressing space with a selected range at the
972 omnibox_view
->OnBeforePossibleChange();
973 omnibox_view
->OnInlineAutocompleteTextMaybeChanged(
974 search_keyword
+ ASCIIToUTF16(" "), search_keyword
.length());
975 omnibox_view
->OnAfterPossibleChange();
976 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
977 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
978 ASSERT_EQ(search_keyword
+ ASCIIToUTF16(" "), omnibox_view
->GetText());
980 omnibox_view
->GetSelectionBounds(&start
, &end
);
981 ASSERT_NE(start
, end
);
982 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
983 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
984 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
985 ASSERT_EQ(base::string16(), omnibox_view
->GetText());
987 // Space should accept keyword even when inline autocomplete is available.
988 omnibox_view
->SetUserText(base::string16());
989 const TestHistoryEntry kHistoryFoobar
= {
990 "http://www.foobar.com", "Page foobar", 100, 100, true
993 // Add a history entry to trigger inline autocomplete when typing "foo".
994 ASSERT_NO_FATAL_FAILURE(
995 AddHistoryEntry(kHistoryFoobar
, Time::Now() - TimeDelta::FromHours(1)));
997 // Type "fo" to trigger inline autocomplete.
998 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordPrefixKeys
));
999 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1000 ASSERT_TRUE(omnibox_view
->model()->popup_model()->IsOpen());
1001 ASSERT_NE(search_keyword
, omnibox_view
->GetText());
1003 // Keyword hint shouldn't be visible.
1004 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1005 ASSERT_TRUE(omnibox_view
->model()->keyword().empty());
1007 // Add the "o". Inline autocompletion should still happen, but now we
1008 // should also get a keyword hint because we've typed a keyword exactly.
1009 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordCompletionKeys
));
1010 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1011 ASSERT_TRUE(omnibox_view
->model()->popup_model()->IsOpen());
1012 ASSERT_NE(search_keyword
, omnibox_view
->GetText());
1013 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1014 ASSERT_FALSE(omnibox_view
->model()->keyword().empty());
1016 // Trigger keyword mode by space.
1017 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
1018 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1019 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
1020 ASSERT_TRUE(omnibox_view
->GetText().empty());
1022 // Space in the middle of a temporary text, which separates the text into
1023 // keyword and replacement portions, should trigger keyword mode.
1024 omnibox_view
->SetUserText(base::string16());
1025 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
1026 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1027 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1028 ASSERT_TRUE(popup_model
->IsOpen());
1029 ASSERT_EQ(ASCIIToUTF16("foobar.com"), omnibox_view
->GetText());
1030 omnibox_view
->model()->OnUpOrDownKeyPressed(1);
1031 omnibox_view
->model()->OnUpOrDownKeyPressed(-1);
1032 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
1033 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, 0));
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_SPACE
, 0));
1040 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1041 ASSERT_EQ(search_keyword
, omnibox_view
->model()->keyword());
1042 ASSERT_EQ(ASCIIToUTF16("bar.com"), omnibox_view
->GetText());
1044 // Space after temporary text that looks like a keyword, when the original
1045 // input does not look like a keyword, should trigger keyword mode.
1046 omnibox_view
->SetUserText(base::string16());
1047 const TestHistoryEntry kHistoryFoo
= {
1048 "http://footest.com", "Page footest", 1000, 1000, true
1051 // Add a history entry to trigger HQP matching with text == keyword when
1053 ASSERT_NO_FATAL_FAILURE(
1054 AddHistoryEntry(kHistoryFoo
, Time::Now() - TimeDelta::FromMinutes(10)));
1056 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_F
, 0));
1057 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_O
, 0));
1058 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
1059 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_T
, 0));
1060 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E
, 0));
1061 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1062 ASSERT_TRUE(popup_model
->IsOpen());
1063 base::string16
search_keyword2(ASCIIToUTF16(kSearchKeyword2
));
1064 while ((omnibox_view
->GetText() != search_keyword2
) &&
1065 (popup_model
->selected_line() < popup_model
->result().size() - 1))
1066 omnibox_view
->model()->OnUpOrDownKeyPressed(1);
1067 ASSERT_EQ(search_keyword2
, omnibox_view
->GetText());
1068 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE
, 0));
1069 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1070 ASSERT_EQ(search_keyword2
, omnibox_view
->model()->keyword());
1071 ASSERT_TRUE(omnibox_view
->GetText().empty());
1074 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, NonSubstitutingKeywordTest
) {
1075 OmniboxView
* omnibox_view
= NULL
;
1076 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1077 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1078 ASSERT_TRUE(popup_model
);
1080 Profile
* profile
= browser()->profile();
1081 TemplateURLService
* template_url_service
=
1082 TemplateURLServiceFactory::GetForProfile(profile
);
1084 // Add a non-default substituting keyword.
1085 TemplateURLData data
;
1086 data
.short_name
= ASCIIToUTF16("Search abc");
1087 data
.SetKeyword(ASCIIToUTF16(kSearchText
));
1088 data
.SetURL("http://abc.com/{searchTerms}");
1089 TemplateURL
* template_url
= new TemplateURL(data
);
1090 template_url_service
->Add(template_url
);
1092 omnibox_view
->SetUserText(base::string16());
1094 // Non-default substituting keyword shouldn't be matched by default.
1095 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
1096 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1097 ASSERT_TRUE(popup_model
->IsOpen());
1099 // Check if the default match result is Search Primary Provider.
1100 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED
,
1101 popup_model
->result().default_match()->type
);
1102 ASSERT_EQ(kSearchTextURL
,
1103 popup_model
->result().default_match()->destination_url
.spec());
1105 omnibox_view
->SetUserText(base::string16());
1106 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1107 ASSERT_FALSE(popup_model
->IsOpen());
1109 // Try a non-substituting keyword.
1110 template_url_service
->Remove(template_url
);
1111 data
.short_name
= ASCIIToUTF16("abc");
1112 data
.SetURL("http://abc.com/");
1113 template_url_service
->Add(new TemplateURL(data
));
1115 // We always allow exact matches for non-substituting keywords.
1116 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
1117 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1118 ASSERT_TRUE(popup_model
->IsOpen());
1119 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD
,
1120 popup_model
->result().default_match()->type
);
1121 ASSERT_EQ("http://abc.com/",
1122 popup_model
->result().default_match()->destination_url
.spec());
1125 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, DeleteItem
) {
1126 // Disable the search provider, to make sure the popup contains only history
1128 TemplateURLService
* model
=
1129 TemplateURLServiceFactory::GetForProfile(browser()->profile());
1130 model
->SetUserSelectedDefaultSearchProvider(NULL
);
1132 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL
));
1133 chrome::FocusLocationBar(browser());
1135 OmniboxView
* omnibox_view
= NULL
;
1136 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1138 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1139 ASSERT_TRUE(popup_model
);
1141 base::string16 old_text
= omnibox_view
->GetText();
1143 // Input something that can match history items.
1144 omnibox_view
->SetUserText(ASCIIToUTF16("site.com/p"));
1145 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1146 ASSERT_TRUE(popup_model
->IsOpen());
1148 // Delete the inline autocomplete part.
1149 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE
, 0));
1150 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1151 ASSERT_TRUE(popup_model
->IsOpen());
1152 ASSERT_GE(popup_model
->result().size(), 3U);
1154 base::string16 user_text
= omnibox_view
->GetText();
1155 ASSERT_EQ(ASCIIToUTF16("site.com/p"), user_text
);
1156 omnibox_view
->SelectAll(true);
1157 ASSERT_TRUE(omnibox_view
->IsSelectAll());
1160 size_t default_line
= popup_model
->selected_line();
1161 omnibox_view
->model()->OnUpOrDownKeyPressed(1);
1162 ASSERT_EQ(default_line
+ 1, popup_model
->selected_line());
1163 base::string16 selected_text
=
1164 popup_model
->result().match_at(default_line
+ 1).fill_into_edit
;
1165 // Temporary text is shown.
1166 ASSERT_EQ(selected_text
, omnibox_view
->GetText());
1167 ASSERT_FALSE(omnibox_view
->IsSelectAll());
1170 popup_model
->TryDeletingCurrentItem();
1171 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1172 // The selected line shouldn't be changed, because we have more than two
1174 ASSERT_EQ(default_line
+ 1, popup_model
->selected_line());
1175 // Make sure the item is really deleted.
1176 ASSERT_NE(selected_text
,
1177 popup_model
->result().match_at(default_line
+ 1).fill_into_edit
);
1179 popup_model
->result().match_at(default_line
+ 1).fill_into_edit
;
1180 // New temporary text is shown.
1181 ASSERT_EQ(selected_text
, omnibox_view
->GetText());
1183 // Revert to the default match.
1184 ASSERT_TRUE(omnibox_view
->model()->OnEscapeKeyPressed());
1185 ASSERT_EQ(default_line
, popup_model
->selected_line());
1186 ASSERT_EQ(user_text
, omnibox_view
->GetText());
1187 ASSERT_TRUE(omnibox_view
->IsSelectAll());
1189 // Move down and up to select the default match as temporary text.
1190 omnibox_view
->model()->OnUpOrDownKeyPressed(1);
1191 ASSERT_EQ(default_line
+ 1, popup_model
->selected_line());
1192 omnibox_view
->model()->OnUpOrDownKeyPressed(-1);
1193 ASSERT_EQ(default_line
, popup_model
->selected_line());
1195 selected_text
= popup_model
->result().match_at(default_line
).fill_into_edit
;
1196 // New temporary text is shown.
1197 ASSERT_EQ(selected_text
, omnibox_view
->GetText());
1198 ASSERT_FALSE(omnibox_view
->IsSelectAll());
1201 // TODO(mrossetti): http://crbug.com/82335
1202 // Delete the default item.
1203 popup_model
->TryDeletingCurrentItem();
1204 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1205 // The selected line shouldn't be changed, but the default item should have
1207 ASSERT_EQ(default_line
, popup_model
->selected_line());
1208 // Make sure the item is really deleted.
1209 EXPECT_NE(selected_text
,
1210 popup_model
->result().match_at(default_line
).fill_into_edit
);
1212 popup_model
->result().match_at(default_line
).fill_into_edit
;
1213 // New temporary text is shown.
1214 ASSERT_EQ(selected_text
, omnibox_view
->GetText());
1217 // As the current selected item is the new default item, pressing Escape key
1218 // should revert all directly.
1219 ASSERT_TRUE(omnibox_view
->model()->OnEscapeKeyPressed());
1220 ASSERT_EQ(old_text
, omnibox_view
->GetText());
1221 ASSERT_TRUE(omnibox_view
->IsSelectAll());
1224 // http://crbug.com/133344
1225 #if defined(OS_LINUX)
1226 #define MAYBE_TabAcceptKeyword DISABLED_TabAcceptKeyword
1228 #define MAYBE_TabAcceptKeyword TabAcceptKeyword
1231 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_TabAcceptKeyword
) {
1232 OmniboxView
* omnibox_view
= NULL
;
1233 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1235 base::string16 text
= ASCIIToUTF16(kSearchKeyword
);
1237 // Trigger keyword hint mode.
1238 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
1239 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1240 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1241 ASSERT_EQ(text
, omnibox_view
->GetText());
1243 // Trigger keyword mode by tab.
1244 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1245 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1246 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1247 ASSERT_TRUE(omnibox_view
->GetText().empty());
1249 // Revert to keyword hint mode.
1250 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1251 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1252 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1253 ASSERT_EQ(text
, omnibox_view
->GetText());
1255 // The location bar should still have focus.
1256 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1258 // Trigger keyword mode by tab.
1259 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1260 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1261 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1262 ASSERT_TRUE(omnibox_view
->GetText().empty());
1264 // Revert to keyword hint mode with SHIFT+TAB.
1265 #if defined(OS_MACOSX)
1266 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB
, 0));
1268 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
));
1270 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1271 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1272 ASSERT_EQ(text
, omnibox_view
->GetText());
1273 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1276 #if !defined(OS_MACOSX)
1277 // Mac intentionally does not support this behavior.
1279 // http://crbug.com/133360
1280 #if defined(OS_LINUX)
1281 #define MAYBE_TabTraverseResultsTest DISABLED_TabTraverseResultsTest
1283 #define MAYBE_TabTraverseResultsTest TabTraverseResultsTest
1286 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, MAYBE_TabTraverseResultsTest
) {
1287 OmniboxView
* omnibox_view
= NULL
;
1288 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1289 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1290 ASSERT_TRUE(popup_model
);
1292 // Input something to trigger results.
1293 const ui::KeyboardCode kKeys
[] = {
1294 ui::VKEY_B
, ui::VKEY_A
, ui::VKEY_R
, ui::VKEY_UNKNOWN
1296 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys
));
1297 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1298 ASSERT_TRUE(popup_model
->IsOpen());
1300 size_t old_selected_line
= popup_model
->selected_line();
1301 EXPECT_EQ(0U, old_selected_line
);
1303 // Move down the results.
1304 for (size_t size
= popup_model
->result().size();
1305 popup_model
->selected_line() < size
- 1;
1306 old_selected_line
= popup_model
->selected_line()) {
1307 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1308 ASSERT_LT(old_selected_line
, popup_model
->selected_line());
1311 // Don't move past the end.
1312 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1313 ASSERT_EQ(old_selected_line
, popup_model
->selected_line());
1314 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1316 // Move back up the results.
1317 for (; popup_model
->selected_line() > 0U;
1318 old_selected_line
= popup_model
->selected_line()) {
1319 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
));
1320 ASSERT_GT(old_selected_line
, popup_model
->selected_line());
1323 // Don't move past the beginning.
1324 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
));
1325 ASSERT_EQ(0U, popup_model
->selected_line());
1326 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1328 const TestHistoryEntry kHistoryFoo
= {
1329 "http://foo/", "Page foo", 1, 1, false
1332 // Add a history entry so "foo" gets multiple matches.
1333 ASSERT_NO_FATAL_FAILURE(
1334 AddHistoryEntry(kHistoryFoo
, Time::Now() - TimeDelta::FromHours(1)));
1337 ASSERT_NO_FATAL_FAILURE(omnibox_view
->SelectAll(false));
1338 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
1339 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1341 // Trigger keyword mode by tab.
1342 base::string16 text
= ASCIIToUTF16(kSearchKeyword
);
1343 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1344 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1345 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1346 ASSERT_TRUE(omnibox_view
->GetText().empty());
1348 // The location bar should still have focus.
1349 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1351 // Pressing tab again should move to the next result and clear keyword
1353 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1354 ASSERT_EQ(1U, omnibox_view
->model()->popup_model()->selected_line());
1355 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1356 ASSERT_NE(text
, omnibox_view
->model()->keyword());
1358 // The location bar should still have focus.
1359 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1361 // Moving back up should not show keyword mode.
1362 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
));
1363 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1364 ASSERT_EQ(text
, omnibox_view
->model()->keyword());
1366 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1371 // http://crbug.com/133347
1372 #if defined(OS_LINUX)
1373 #define MAYBE_PersistKeywordModeOnTabSwitch \
1374 DISABLED_PersistKeywordModeOnTabSwitch
1376 #define MAYBE_PersistKeywordModeOnTabSwitch PersistKeywordModeOnTabSwitch
1379 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
,
1380 MAYBE_PersistKeywordModeOnTabSwitch
) {
1381 OmniboxView
* omnibox_view
= NULL
;
1382 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1384 // Trigger keyword hint mode.
1385 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys
));
1386 ASSERT_TRUE(omnibox_view
->model()->is_keyword_hint());
1387 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
1389 // Trigger keyword mode.
1390 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB
, 0));
1391 ASSERT_FALSE(omnibox_view
->model()->is_keyword_hint());
1392 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
1394 // Input something as search text.
1395 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys
));
1397 // Create a new tab.
1398 chrome::NewTab(browser());
1400 // Switch back to the first tab.
1401 browser()->tab_strip_model()->ActivateTabAt(0, true);
1403 // Make sure we're still in keyword mode.
1404 ASSERT_EQ(kSearchKeyword
, UTF16ToUTF8(omnibox_view
->model()->keyword()));
1407 // http://crbug.com/133355
1408 #if defined(OS_LINUX)
1409 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1410 DISABLED_CtrlKeyPressedWithInlineAutocompleteTest
1412 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest \
1413 CtrlKeyPressedWithInlineAutocompleteTest
1416 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
,
1417 MAYBE_CtrlKeyPressedWithInlineAutocompleteTest
) {
1418 OmniboxView
* omnibox_view
= NULL
;
1419 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1420 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1421 ASSERT_TRUE(popup_model
);
1423 // Input something to trigger inline autocomplete.
1424 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys
));
1425 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1426 ASSERT_TRUE(popup_model
->IsOpen());
1428 base::string16 old_text
= omnibox_view
->GetText();
1430 // Make sure inline autocomplete is triggerred.
1431 EXPECT_GT(old_text
.length(), arraysize(kInlineAutocompleteText
) - 1);
1434 omnibox_view
->model()->OnControlKeyChanged(true);
1436 // Inline autocomplete should still be there.
1437 EXPECT_EQ(old_text
, omnibox_view
->GetText());
1440 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, UndoRedo
) {
1441 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL
));
1442 chrome::FocusLocationBar(browser());
1444 OmniboxView
* omnibox_view
= NULL
;
1445 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1447 base::string16 old_text
= omnibox_view
->GetText();
1448 EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL
), old_text
);
1449 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1451 // Delete the text, then undo.
1452 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1453 EXPECT_TRUE(omnibox_view
->GetText().empty());
1454 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
));
1455 EXPECT_EQ(old_text
, omnibox_view
->GetText());
1457 // Redo should delete the text again.
1458 ASSERT_NO_FATAL_FAILURE(
1459 SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
| ui::EF_SHIFT_DOWN
));
1460 EXPECT_TRUE(omnibox_view
->GetText().empty());
1462 // The toolkit-views undo manager doesn't support restoring selection. Cocoa
1463 // does, so it needs to be cleared.
1464 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
));
1465 #if defined(OS_MACOSX)
1466 // TODO(tapted): This next line may fail if running a toolkit-views browser
1467 // window on Mac. We should fix the toolkit-views undo manager to restore
1468 // selection rather than deleting this #ifdef.
1469 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1470 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT
, 0));
1472 EXPECT_FALSE(omnibox_view
->IsSelectAll());
1474 // The cursor should be at the end.
1476 omnibox_view
->GetSelectionBounds(&start
, &end
);
1477 EXPECT_EQ(old_text
.size(), start
);
1478 EXPECT_EQ(old_text
.size(), end
);
1480 // Delete three characters; "about:bl" should not trigger inline autocomplete.
1481 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1482 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1483 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1484 EXPECT_EQ(old_text
.substr(0, old_text
.size() - 3), omnibox_view
->GetText());
1487 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
));
1488 EXPECT_EQ(old_text
, omnibox_view
->GetText());
1491 ASSERT_NO_FATAL_FAILURE(
1492 SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
| ui::EF_SHIFT_DOWN
));
1493 EXPECT_EQ(old_text
.substr(0, old_text
.size() - 3), omnibox_view
->GetText());
1495 // Delete everything.
1496 omnibox_view
->SelectAll(true);
1497 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1498 EXPECT_TRUE(omnibox_view
->GetText().empty());
1500 // Undo delete everything.
1501 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
));
1502 EXPECT_EQ(old_text
.substr(0, old_text
.size() - 3), omnibox_view
->GetText());
1504 // Undo delete two characters.
1505 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z
, kCtrlOrCmdMask
));
1506 EXPECT_EQ(old_text
, omnibox_view
->GetText());
1509 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, BackspaceDeleteHalfWidthKatakana
) {
1510 OmniboxView
* omnibox_view
= NULL
;
1511 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1512 // Insert text: ダ. This is two, 3-byte UTF-8 characters:
1513 // U+FF80 "HALFWIDTH KATAKANA LETTER TA" and
1514 // U+FF9E "HALFWIDTH KATAKANA VOICED SOUND MARK".
1515 omnibox_view
->SetUserText(base::UTF8ToUTF16("\357\276\200\357\276\236"));
1516 EXPECT_FALSE(omnibox_view
->GetText().empty());
1518 // Move the cursor to the end.
1519 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END
, 0));
1521 // Backspace should delete the character. In http://crbug.com/192743, the bug
1522 // was that nothing was deleted.
1523 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK
, 0));
1524 #if defined(OS_MACOSX)
1525 // Cocoa text fields attach the sound mark and delete the whole thing. This
1526 // behavior should remain on Mac even when using a toolkit-views browser
1528 EXPECT_TRUE(omnibox_view
->GetText().empty());
1530 // Toolkit-views text fields delete just the sound mark.
1531 EXPECT_EQ(base::UTF8ToUTF16("\357\276\200"), omnibox_view
->GetText());
1535 // Flaky test. crbug.com/356850
1536 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
,
1537 DISABLED_DoesNotUpdateAutocompleteOnBlur
) {
1538 OmniboxView
* omnibox_view
= NULL
;
1539 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1540 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1541 ASSERT_TRUE(popup_model
);
1543 // Input something to trigger inline autocomplete.
1544 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys
));
1545 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1546 ASSERT_TRUE(popup_model
->IsOpen());
1548 omnibox_view
->GetSelectionBounds(&start
, &end
);
1549 EXPECT_TRUE(start
!= end
);
1550 base::string16 old_autocomplete_text
=
1551 omnibox_view
->model()->autocomplete_controller()->input_
.text();
1553 // Unfocus the omnibox. This should clear the text field selection and
1554 // close the popup, but should not run autocomplete.
1555 // Note: GTK preserves the selection when the omnibox is unfocused.
1556 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER
);
1557 ASSERT_FALSE(popup_model
->IsOpen());
1558 omnibox_view
->GetSelectionBounds(&start
, &end
);
1559 EXPECT_TRUE(start
== end
);
1561 EXPECT_EQ(old_autocomplete_text
,
1562 omnibox_view
->model()->autocomplete_controller()->input_
.text());
1565 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, Paste
) {
1566 OmniboxView
* omnibox_view
= NULL
;
1567 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1568 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1569 ASSERT_TRUE(popup_model
);
1570 EXPECT_FALSE(popup_model
->IsOpen());
1572 // Paste should yield the expected text and open the popup.
1573 SetClipboardText(ASCIIToUTF16(kSearchText
));
1574 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V
, kCtrlOrCmdMask
));
1575 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1576 EXPECT_EQ(ASCIIToUTF16(kSearchText
), omnibox_view
->GetText());
1577 EXPECT_TRUE(popup_model
->IsOpen());
1579 // Close the popup and select all.
1580 omnibox_view
->CloseOmniboxPopup();
1581 omnibox_view
->SelectAll(false);
1582 EXPECT_FALSE(popup_model
->IsOpen());
1584 // Pasting the same text again over itself should re-open the popup.
1585 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V
, kCtrlOrCmdMask
));
1586 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1587 EXPECT_EQ(ASCIIToUTF16(kSearchText
), omnibox_view
->GetText());
1588 EXPECT_TRUE(popup_model
->IsOpen());
1589 omnibox_view
->CloseOmniboxPopup();
1590 EXPECT_FALSE(popup_model
->IsOpen());
1592 // Pasting amid text should yield the expected text and re-open the popup.
1593 omnibox_view
->SetWindowTextAndCaretPos(ASCIIToUTF16("abcd"), 2, false, false);
1594 SetClipboardText(ASCIIToUTF16("123"));
1595 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V
, kCtrlOrCmdMask
));
1596 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view
->GetText());
1597 EXPECT_TRUE(popup_model
->IsOpen());
1599 // Ctrl/Cmd+Alt+V should not paste.
1600 ASSERT_NO_FATAL_FAILURE(
1601 SendKey(ui::VKEY_V
, kCtrlOrCmdMask
| ui::EF_ALT_DOWN
));
1602 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view
->GetText());
1603 // TODO(msw): Test that AltGr+V does not paste.
1606 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, CopyURLToClipboard
) {
1607 // Set permanent text thus making sure that omnibox treats 'google.com'
1608 // as URL (not as ordinary user input).
1609 TestToolbarModel
* test_toolbar_model
= new TestToolbarModel
;
1610 scoped_ptr
<ToolbarModel
> toolbar_model(test_toolbar_model
);
1611 test_toolbar_model
->set_text(ASCIIToUTF16("http://www.google.com/"));
1612 browser()->swap_toolbar_models(&toolbar_model
);
1613 OmniboxView
* omnibox_view
= NULL
;
1614 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1615 OmniboxEditModel
* edit_model
= omnibox_view
->model();
1616 ASSERT_NE(static_cast<OmniboxEditModel
*>(NULL
), edit_model
);
1617 edit_model
->UpdatePermanentText();
1619 const char* target_url
= "http://www.google.com/calendar";
1620 omnibox_view
->SetUserText(ASCIIToUTF16(target_url
));
1622 // Location bar must have focus.
1623 chrome::FocusLocationBar(browser());
1624 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1626 // Select full URL and copy it to clipboard. General text and html should
1628 omnibox_view
->SelectAll(true);
1629 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1630 ui::Clipboard
* clipboard
= ui::Clipboard::GetForCurrentThread();
1631 clipboard
->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE
);
1632 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY
));
1633 EXPECT_EQ(ASCIIToUTF16(target_url
), omnibox_view
->GetText());
1634 EXPECT_TRUE(clipboard
->IsFormatAvailable(
1635 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1637 // Make sure HTML format isn't written. See
1638 // BookmarkNodeData::WriteToClipboard() for details.
1639 EXPECT_FALSE(clipboard
->IsFormatAvailable(
1640 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1642 // These platforms should read bookmark format.
1643 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1644 base::string16 title
;
1646 clipboard
->ReadBookmark(&title
, &url
);
1647 EXPECT_EQ(target_url
, url
);
1648 EXPECT_EQ(ASCIIToUTF16(target_url
), title
);
1652 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, CutURLToClipboard
) {
1653 // Set permanent text thus making sure that omnibox treats 'google.com'
1654 // as URL (not as ordinary user input).
1655 TestToolbarModel
* test_toolbar_model
= new TestToolbarModel
;
1656 scoped_ptr
<ToolbarModel
> toolbar_model(test_toolbar_model
);
1657 test_toolbar_model
->set_text(ASCIIToUTF16("http://www.google.com/"));
1658 browser()->swap_toolbar_models(&toolbar_model
);
1659 OmniboxView
* omnibox_view
= NULL
;
1660 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1661 OmniboxEditModel
* edit_model
= omnibox_view
->model();
1662 ASSERT_NE(static_cast<OmniboxEditModel
*>(NULL
), edit_model
);
1663 edit_model
->UpdatePermanentText();
1665 const char* target_url
= "http://www.google.com/calendar";
1666 omnibox_view
->SetUserText(ASCIIToUTF16(target_url
));
1668 // Location bar must have focus.
1669 chrome::FocusLocationBar(browser());
1670 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1672 // Select full URL and cut it. General text and html should be available
1673 // in the clipboard.
1674 omnibox_view
->SelectAll(true);
1675 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1676 ui::Clipboard
* clipboard
= ui::Clipboard::GetForCurrentThread();
1677 clipboard
->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE
);
1678 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT
));
1679 EXPECT_EQ(base::string16(), omnibox_view
->GetText());
1680 EXPECT_TRUE(clipboard
->IsFormatAvailable(
1681 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1683 // Make sure HTML format isn't written. See
1684 // BookmarkNodeData::WriteToClipboard() for details.
1685 EXPECT_FALSE(clipboard
->IsFormatAvailable(
1686 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1688 // These platforms should read bookmark format.
1689 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1690 base::string16 title
;
1692 clipboard
->ReadBookmark(&title
, &url
);
1693 EXPECT_EQ(target_url
, url
);
1694 EXPECT_EQ(ASCIIToUTF16(target_url
), title
);
1698 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, CopyTextToClipboard
) {
1699 OmniboxView
* omnibox_view
= NULL
;
1700 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1701 const char* target_text
= "foo";
1702 omnibox_view
->SetUserText(ASCIIToUTF16(target_text
));
1704 // Location bar must have focus.
1705 chrome::FocusLocationBar(browser());
1706 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1708 // Select full text and copy it to the clipboard.
1709 omnibox_view
->SelectAll(true);
1710 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1711 ui::Clipboard
* clipboard
= ui::Clipboard::GetForCurrentThread();
1712 clipboard
->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE
);
1713 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY
));
1714 EXPECT_TRUE(clipboard
->IsFormatAvailable(
1715 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1716 EXPECT_FALSE(clipboard
->IsFormatAvailable(
1717 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1718 EXPECT_EQ(ASCIIToUTF16(target_text
), omnibox_view
->GetText());
1721 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, CutTextToClipboard
) {
1722 OmniboxView
* omnibox_view
= NULL
;
1723 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1724 const char* target_text
= "foo";
1725 omnibox_view
->SetUserText(ASCIIToUTF16(target_text
));
1727 // Location bar must have focus.
1728 chrome::FocusLocationBar(browser());
1729 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1731 // Select full text and cut it to the clipboard.
1732 omnibox_view
->SelectAll(true);
1733 EXPECT_TRUE(omnibox_view
->IsSelectAll());
1734 ui::Clipboard
* clipboard
= ui::Clipboard::GetForCurrentThread();
1735 clipboard
->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE
);
1736 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT
));
1737 EXPECT_TRUE(clipboard
->IsFormatAvailable(
1738 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1739 EXPECT_FALSE(clipboard
->IsFormatAvailable(
1740 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE
));
1741 EXPECT_EQ(base::string16(), omnibox_view
->GetText());
1744 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, EditSearchEngines
) {
1745 // Disable settings-in-a-window to simplify test.
1746 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1747 ::switches::kDisableSettingsWindow
);
1748 OmniboxView
* omnibox_view
= NULL
;
1749 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1750 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_EDIT_SEARCH_ENGINES
));
1751 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1752 const std::string target_url
=
1753 std::string(chrome::kChromeUISettingsURL
) + chrome::kSearchEnginesSubPage
;
1754 EXPECT_EQ(ASCIIToUTF16(target_url
), omnibox_view
->GetText());
1755 EXPECT_FALSE(omnibox_view
->model()->popup_model()->IsOpen());
1758 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, BeginningShownAfterBlur
) {
1759 OmniboxView
* omnibox_view
= NULL
;
1760 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1762 omnibox_view
->OnBeforePossibleChange();
1763 omnibox_view
->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"),
1765 omnibox_view
->OnAfterPossibleChange();
1766 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1768 omnibox_view
->GetSelectionBounds(&start
, &end
);
1769 EXPECT_EQ(5U, start
);
1772 ui_test_utils::FocusView(browser(), VIEW_ID_TAB_CONTAINER
);
1773 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX
));
1775 omnibox_view
->GetSelectionBounds(&start
, &end
);
1776 EXPECT_EQ(0U, start
);
1780 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
, CtrlArrowAfterArrowSuggestions
) {
1781 OmniboxView
* omnibox_view
= NULL
;
1782 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1783 OmniboxPopupModel
* popup_model
= omnibox_view
->model()->popup_model();
1784 ASSERT_TRUE(popup_model
);
1786 // Input something to trigger results.
1787 const ui::KeyboardCode kKeys
[] = {
1788 ui::VKEY_B
, ui::VKEY_A
, ui::VKEY_R
, ui::VKEY_UNKNOWN
1790 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys
));
1791 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1792 ASSERT_TRUE(popup_model
->IsOpen());
1794 ASSERT_EQ(ASCIIToUTF16("bar.com/1"), omnibox_view
->GetText());
1796 // Arrow down on a suggestion, and omnibox text should be the suggestion.
1797 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN
, 0));
1798 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1799 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view
->GetText());
1801 // Highlight the last 2 words and the omnibox text should not change.
1802 // Simulating Ctrl-shift-left only once does not seem to highlight anything
1804 #if defined(OS_MACOSX)
1805 // Mac uses alt-left/right to select a word.
1806 const int modifiers
= ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
;
1808 const int modifiers
= ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
;
1810 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, modifiers
));
1811 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT
, modifiers
));
1812 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view
->GetText());
1815 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
,
1816 PersistSearchReplacementAcrossTabSwitch
) {
1817 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1818 browser()->toolbar_model()->set_url_replacement_enabled(false);
1820 // Create a new tab.
1821 chrome::NewTab(browser());
1822 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1824 // Switch back to the first tab.
1825 browser()->tab_strip_model()->ActivateTabAt(0, true);
1826 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled());
1829 IN_PROC_BROWSER_TEST_F(OmniboxViewTest
,
1830 DontUpdateURLWhileSearchTermReplacementIsDisabled
) {
1831 OmniboxView
* omnibox_view
= NULL
;
1832 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view
));
1833 TestToolbarModel
* test_toolbar_model
= new TestToolbarModel
;
1834 scoped_ptr
<ToolbarModel
> toolbar_model(test_toolbar_model
);
1835 browser()->swap_toolbar_models(&toolbar_model
);
1837 base::string16
url_a(ASCIIToUTF16("http://www.a.com/"));
1838 base::string16
url_b(ASCIIToUTF16("http://www.b.com/"));
1839 base::string16
url_c(ASCIIToUTF16("http://www.c.com/"));
1840 chrome::FocusLocationBar(browser());
1841 test_toolbar_model
->set_text(url_a
);
1842 omnibox_view
->Update();
1843 EXPECT_EQ(url_a
, omnibox_view
->GetText());
1845 // Disable URL replacement and update. Because the omnibox has focus, the
1846 // visible text shouldn't change; see comments in
1847 // OmniboxEditModel::UpdatePermanentText().
1848 browser()->toolbar_model()->set_url_replacement_enabled(false);
1849 test_toolbar_model
->set_text(url_b
);
1850 omnibox_view
->Update();
1851 EXPECT_EQ(url_a
, omnibox_view
->GetText());
1853 // Re-enable URL replacement and ensure updating changes the text.
1854 browser()->toolbar_model()->set_url_replacement_enabled(true);
1855 // We have to change the toolbar model text here, or Update() will do nothing.
1856 // This is because the previous update already updated the permanent text.
1857 test_toolbar_model
->set_text(url_c
);
1858 omnibox_view
->Update();
1859 EXPECT_EQ(url_c
, omnibox_view
->GetText());
1861 // The same test, but using RevertAll() to reset search term replacement.
1862 test_toolbar_model
->set_text(url_a
);
1863 omnibox_view
->Update();
1864 EXPECT_EQ(url_a
, omnibox_view
->GetText());
1865 browser()->toolbar_model()->set_url_replacement_enabled(false);
1866 test_toolbar_model
->set_text(url_b
);
1867 omnibox_view
->Update();
1868 EXPECT_EQ(url_a
, omnibox_view
->GetText());
1869 omnibox_view
->RevertAll();
1870 EXPECT_EQ(url_b
, omnibox_view
->GetText());
1871 test_toolbar_model
->set_text(url_c
);
1872 omnibox_view
->Update();
1873 EXPECT_EQ(url_c
, omnibox_view
->GetText());