Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / omnibox / omnibox_view_browsertest.cc
blobc51bb2a027e0c3a81b358a805f9558e7fed56b39
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/strings/string16.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/autocomplete/autocomplete_input.h"
13 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "chrome/browser/autocomplete/history_quick_provider.h"
15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
17 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
18 #include "chrome/browser/bookmarks/bookmark_utils.h"
19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/history/history_service.h"
21 #include "chrome/browser/history/history_service_factory.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/search_engines/template_url.h"
24 #include "chrome/browser/search_engines/template_url_service.h"
25 #include "chrome/browser/search_engines/template_url_service_factory.h"
26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/omnibox/location_bar.h"
30 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
31 #include "chrome/browser/ui/omnibox/omnibox_view.h"
32 #include "chrome/browser/ui/tabs/tab_strip_model.h"
33 #include "chrome/browser/ui/toolbar/test_toolbar_model.h"
34 #include "chrome/common/chrome_paths.h"
35 #include "chrome/common/url_constants.h"
36 #include "chrome/test/base/in_process_browser_test.h"
37 #include "chrome/test/base/interactive_test_utils.h"
38 #include "chrome/test/base/ui_test_utils.h"
39 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/web_contents.h"
41 #include "net/dns/mock_host_resolver.h"
42 #include "ui/base/clipboard/clipboard.h"
43 #include "ui/base/clipboard/scoped_clipboard_writer.h"
44 #include "ui/events/event_constants.h"
45 #include "ui/events/keycodes/keyboard_codes.h"
46 #include "ui/gfx/point.h"
48 #if defined(TOOLKIT_GTK)
49 #include <gdk/gdk.h>
50 #include <gtk/gtk.h>
51 #endif
53 using base::ASCIIToUTF16;
54 using base::UTF16ToUTF8;
55 using base::Time;
56 using base::TimeDelta;
58 namespace {
60 const char kSearchKeyword[] = "foo";
61 const char kSearchKeyword2[] = "footest.com";
62 const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 };
63 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
64 const char kSearchShortName[] = "foo";
65 const char kSearchText[] = "abc";
66 const wchar_t kSearchTextKeys[] = { ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, 0 };
67 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
69 const char kInlineAutocompleteText[] = "def";
70 const wchar_t kInlineAutocompleteTextKeys[] = {
71 ui::VKEY_D, ui::VKEY_E, ui::VKEY_F, 0
74 // Hostnames that shall be blocked by host resolver.
75 const char *kBlockedHostnames[] = {
76 "foo",
77 "*.foo.com",
78 "bar",
79 "*.bar.com",
80 "abc",
81 "*.abc.com",
82 "def",
83 "*.def.com",
84 "*.site.com",
85 "history",
86 "z"
89 const struct TestHistoryEntry {
90 const char* url;
91 const char* title;
92 int visit_count;
93 int typed_count;
94 bool starred;
95 } kHistoryEntries[] = {
96 {"http://www.bar.com/1", "Page 1", 10, 10, false },
97 {"http://www.bar.com/2", "Page 2", 9, 9, false },
98 {"http://www.bar.com/3", "Page 3", 8, 8, false },
99 {"http://www.bar.com/4", "Page 4", 7, 7, false },
100 {"http://www.bar.com/5", "Page 5", 6, 6, false },
101 {"http://www.bar.com/6", "Page 6", 5, 5, false },
102 {"http://www.bar.com/7", "Page 7", 4, 4, false },
103 {"http://www.bar.com/8", "Page 8", 3, 3, false },
104 {"http://www.bar.com/9", "Page 9", 2, 2, false },
105 {"http://www.site.com/path/1", "Site 1", 4, 4, false },
106 {"http://www.site.com/path/2", "Site 2", 3, 3, false },
107 {"http://www.site.com/path/3", "Site 3", 2, 2, false },
109 // To trigger inline autocomplete.
110 {"http://www.def.com", "Page def", 10000, 10000, true },
112 // Used in particular for the desired TLD test. This makes it test
113 // the interesting case when there's an intranet host with the same
114 // name as the .com.
115 {"http://bar/", "Bar", 1, 0, false },
118 #if defined(TOOLKIT_GTK)
119 // Returns the text stored in the PRIMARY clipboard.
120 std::string GetPrimarySelectionText() {
121 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
122 DCHECK(clipboard);
124 gchar* selection_text = gtk_clipboard_wait_for_text(clipboard);
125 std::string result(selection_text ? selection_text : "");
126 g_free(selection_text);
127 return result;
129 #endif
131 // Stores the given text to clipboard.
132 void SetClipboardText(const base::string16& text) {
133 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
134 ui::ScopedClipboardWriter writer(clipboard, ui::CLIPBOARD_TYPE_COPY_PASTE);
135 writer.WriteText(text);
138 #if defined(OS_MACOSX)
139 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN;
140 #else
141 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN;
142 #endif
144 } // namespace
146 class OmniboxViewTest : public InProcessBrowserTest,
147 public content::NotificationObserver {
148 protected:
149 virtual void SetUpOnMainThread() OVERRIDE {
150 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
151 ASSERT_NO_FATAL_FAILURE(SetupComponents());
152 chrome::FocusLocationBar(browser());
153 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
156 static void GetOmniboxViewForBrowser(
157 const Browser* browser,
158 OmniboxView** omnibox_view) {
159 BrowserWindow* window = browser->window();
160 ASSERT_TRUE(window);
161 LocationBar* location_bar = window->GetLocationBar();
162 ASSERT_TRUE(location_bar);
163 *omnibox_view = location_bar->GetOmniboxView();
164 ASSERT_TRUE(*omnibox_view);
167 void GetOmniboxView(OmniboxView** omnibox_view) {
168 GetOmniboxViewForBrowser(browser(), omnibox_view);
171 static void SendKeyForBrowser(const Browser* browser,
172 ui::KeyboardCode key,
173 int modifiers) {
174 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
175 browser, key,
176 (modifiers & ui::EF_CONTROL_DOWN) != 0,
177 (modifiers & ui::EF_SHIFT_DOWN) != 0,
178 (modifiers & ui::EF_ALT_DOWN) != 0,
179 (modifiers & ui::EF_COMMAND_DOWN) != 0));
182 void SendKey(ui::KeyboardCode key, int modifiers) {
183 SendKeyForBrowser(browser(), key, modifiers);
186 void SendKeySequence(const wchar_t* keys) {
187 for (; *keys; ++keys)
188 ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<ui::KeyboardCode>(*keys), 0));
191 bool SendKeyAndWait(const Browser* browser,
192 ui::KeyboardCode key,
193 int modifiers,
194 int type,
195 const content::NotificationSource& source)
196 WARN_UNUSED_RESULT {
197 return ui_test_utils::SendKeyPressAndWait(
198 browser, key,
199 (modifiers & ui::EF_CONTROL_DOWN) != 0,
200 (modifiers & ui::EF_SHIFT_DOWN) != 0,
201 (modifiers & ui::EF_ALT_DOWN) != 0,
202 (modifiers & ui::EF_COMMAND_DOWN) != 0,
203 type, source);
206 void WaitForTabOpenOrCloseForBrowser(const Browser* browser,
207 int expected_tab_count) {
208 int tab_count = browser->tab_strip_model()->count();
209 if (tab_count == expected_tab_count)
210 return;
212 content::NotificationRegistrar registrar;
213 registrar.Add(this,
214 (tab_count < expected_tab_count) ?
215 static_cast<int>(chrome::NOTIFICATION_TAB_PARENTED) :
216 static_cast<int>(content::NOTIFICATION_WEB_CONTENTS_DESTROYED),
217 content::NotificationService::AllSources());
219 while (!HasFailure() &&
220 browser->tab_strip_model()->count() != expected_tab_count) {
221 content::RunMessageLoop();
224 ASSERT_EQ(expected_tab_count, browser->tab_strip_model()->count());
227 void WaitForTabOpenOrClose(int expected_tab_count) {
228 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count);
231 void WaitForAutocompleteControllerDone() {
232 OmniboxView* omnibox_view = NULL;
233 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
235 AutocompleteController* controller =
236 omnibox_view->model()->autocomplete_controller();
237 ASSERT_TRUE(controller);
239 if (controller->done())
240 return;
242 content::NotificationRegistrar registrar;
243 registrar.Add(this,
244 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
245 content::Source<AutocompleteController>(controller));
247 while (!HasFailure() && !controller->done())
248 content::RunMessageLoop();
250 ASSERT_TRUE(controller->done());
253 void SetupSearchEngine() {
254 Profile* profile = browser()->profile();
255 TemplateURLService* model =
256 TemplateURLServiceFactory::GetForProfile(profile);
257 ASSERT_TRUE(model);
259 ui_test_utils::WaitForTemplateURLServiceToLoad(model);
261 ASSERT_TRUE(model->loaded());
262 // Remove built-in template urls, like google.com, bing.com etc., as they
263 // may appear as autocomplete suggests and interfere with our tests.
264 model->SetDefaultSearchProvider(NULL);
265 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs();
266 for (TemplateURLService::TemplateURLVector::const_iterator
267 i = builtins.begin(); i != builtins.end(); ++i)
268 model->Remove(*i);
270 TemplateURLData data;
271 data.short_name = ASCIIToUTF16(kSearchShortName);
272 data.SetKeyword(ASCIIToUTF16(kSearchKeyword));
273 data.SetURL(kSearchURL);
274 TemplateURL* template_url = new TemplateURL(profile, data);
275 model->Add(template_url);
276 model->SetDefaultSearchProvider(template_url);
278 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2));
279 model->Add(new TemplateURL(profile, data));
282 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
283 Profile* profile = browser()->profile();
284 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
285 profile, Profile::EXPLICIT_ACCESS);
286 ASSERT_TRUE(history_service);
288 if (!history_service->BackendLoaded()) {
289 content::NotificationRegistrar registrar;
290 registrar.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
291 content::Source<Profile>(profile));
292 content::RunMessageLoop();
295 BookmarkModel* bookmark_model =
296 BookmarkModelFactory::GetForProfile(profile);
297 ASSERT_TRUE(bookmark_model);
298 test::WaitForBookmarkModelToLoad(bookmark_model);
300 GURL url(entry.url);
301 // Add everything in order of time. We don't want to have a time that
302 // is "right now" or it will nondeterministically appear in the results.
303 history_service->AddPageWithDetails(url, base::UTF8ToUTF16(entry.title),
304 entry.visit_count,
305 entry.typed_count, time, false,
306 history::SOURCE_BROWSED);
307 if (entry.starred)
308 bookmark_utils::AddIfNotBookmarked(bookmark_model, url, base::string16());
309 // Wait at least for the AddPageWithDetails() call to finish.
311 content::NotificationRegistrar registrar;
312 registrar.Add(this, chrome::NOTIFICATION_HISTORY_URLS_MODIFIED,
313 content::Source<Profile>(profile));
314 content::RunMessageLoop();
315 // We don't want to return until all observers have processed this
316 // notification, because some (e.g. the in-memory history database) may do
317 // something important. Since we don't know where in the observer list we
318 // stand, just spin the message loop once more to allow the current
319 // callstack to complete.
320 content::RunAllPendingInMessageLoop();
324 void SetupHistory() {
325 // Add enough history pages containing |kSearchText| to trigger
326 // open history page url in autocomplete result.
327 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) {
328 // Add everything in order of time. We don't want to have a time that
329 // is "right now" or it will nondeterministically appear in the results.
330 Time t = Time::Now() - TimeDelta::FromHours(i + 1);
331 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries[i], t));
335 void SetupHostResolver() {
336 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i)
337 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]);
340 void SetupComponents() {
341 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
342 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
343 ASSERT_NO_FATAL_FAILURE(SetupHistory());
346 virtual void Observe(int type,
347 const content::NotificationSource& source,
348 const content::NotificationDetails& details) OVERRIDE {
349 switch (type) {
350 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
351 case chrome::NOTIFICATION_TAB_PARENTED:
352 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
353 case chrome::NOTIFICATION_HISTORY_LOADED:
354 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
355 break;
356 default:
357 FAIL() << "Unexpected notification type";
359 base::MessageLoop::current()->Quit();
363 // Test if ctrl-* accelerators are workable in omnibox.
364 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
366 // Flaky on interactive tests (dbg), http://crbug.com/69433
367 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) {
368 OmniboxView* omnibox_view = NULL;
369 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
371 int tab_count = browser()->tab_strip_model()->count();
373 // Create a new Tab.
374 chrome::NewTab(browser());
375 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
377 // Select the first Tab.
378 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_1, kCtrlOrCmdMask));
379 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
381 chrome::FocusLocationBar(browser());
383 // Select the second Tab.
384 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_2, kCtrlOrCmdMask));
385 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
387 chrome::FocusLocationBar(browser());
389 // Try ctrl-w to close a Tab.
390 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_W, kCtrlOrCmdMask));
391 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count));
393 // Try ctrl-l to focus location bar.
394 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
395 EXPECT_FALSE(omnibox_view->IsSelectAll());
396 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_L, kCtrlOrCmdMask));
397 EXPECT_TRUE(omnibox_view->IsSelectAll());
399 // Try editing the location bar text.
400 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, 0));
401 EXPECT_FALSE(omnibox_view->IsSelectAll());
402 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_S, 0));
403 EXPECT_EQ(ASCIIToUTF16("Hello worlds"), omnibox_view->GetText());
405 // Try ctrl-x to cut text.
406 #if defined(OS_MACOSX)
407 // Mac uses alt-left/right to select a word.
408 ASSERT_NO_FATAL_FAILURE(
409 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN));
410 #else
411 ASSERT_NO_FATAL_FAILURE(
412 SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN));
413 #endif
414 EXPECT_FALSE(omnibox_view->IsSelectAll());
415 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_X, kCtrlOrCmdMask));
416 EXPECT_EQ(ASCIIToUTF16("Hello "), omnibox_view->GetText());
418 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
419 // Try alt-f4 to close the browser.
420 ASSERT_TRUE(SendKeyAndWait(
421 browser(), ui::VKEY_F4, ui::EF_ALT_DOWN,
422 chrome::NOTIFICATION_BROWSER_CLOSED,
423 content::Source<Browser>(browser())));
424 #endif
427 // Flakily fails and times out on Win only. http://crbug.com/69941
428 #if defined(OS_WIN)
429 #define MAYBE_PopupAccelerators DISABLED_PopupAccelerators
430 #else
431 #define MAYBE_PopupAccelerators PopupAccelerators
432 #endif
434 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_PopupAccelerators) {
435 // Create a popup.
436 Browser* popup = CreateBrowserForPopup(browser()->profile());
437 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup));
438 OmniboxView* omnibox_view = NULL;
439 ASSERT_NO_FATAL_FAILURE(
440 GetOmniboxViewForBrowser(popup, &omnibox_view));
441 chrome::FocusLocationBar(popup);
442 EXPECT_TRUE(omnibox_view->IsSelectAll());
444 #if !defined(OS_MACOSX)
445 // Try ctrl-w to close the popup.
446 // This piece of code doesn't work on Mac, because the Browser object won't
447 // be destroyed before finishing the current message loop iteration, thus
448 // No BROWSER_CLOSED notification will be sent.
449 ASSERT_TRUE(SendKeyAndWait(
450 popup, ui::VKEY_W, ui::EF_CONTROL_DOWN,
451 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(popup)));
453 // Create another popup.
454 popup = CreateBrowserForPopup(browser()->profile());
455 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(popup));
456 ASSERT_NO_FATAL_FAILURE(
457 GetOmniboxViewForBrowser(popup, &omnibox_view));
458 #endif
460 // Set the edit text to "Hello world".
461 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
462 chrome::FocusLocationBar(popup);
463 EXPECT_TRUE(omnibox_view->IsSelectAll());
465 // Try editing the location bar text -- should be disallowed.
466 ASSERT_NO_FATAL_FAILURE(SendKeyForBrowser(popup, ui::VKEY_S, 0));
467 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText());
468 EXPECT_TRUE(omnibox_view->IsSelectAll());
470 ASSERT_NO_FATAL_FAILURE(
471 SendKeyForBrowser(popup, ui::VKEY_X, kCtrlOrCmdMask));
472 EXPECT_EQ(ASCIIToUTF16("Hello world"), omnibox_view->GetText());
473 EXPECT_TRUE(omnibox_view->IsSelectAll());
475 #if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
476 // Try alt-f4 to close the popup.
477 ASSERT_TRUE(SendKeyAndWait(
478 popup, ui::VKEY_F4, ui::EF_ALT_DOWN,
479 chrome::NOTIFICATION_BROWSER_CLOSED, content::Source<Browser>(popup)));
480 #endif
483 // http://crbug.com/133341
484 #if defined(OS_LINUX)
485 #define MAYBE_BackspaceInKeywordMode DISABLED_BackspaceInKeywordMode
486 #else
487 #define MAYBE_BackspaceInKeywordMode BackspaceInKeywordMode
488 #endif
490 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BackspaceInKeywordMode) {
491 OmniboxView* omnibox_view = NULL;
492 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
494 // Trigger keyword hint mode.
495 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
496 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
497 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
499 // Trigger keyword mode.
500 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
501 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
502 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
504 // Backspace without search text should bring back keyword hint mode.
505 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
506 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
507 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
509 // Trigger keyword mode again.
510 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
511 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
512 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
514 // Input something as search text.
515 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
517 // Should stay in keyword mode while deleting search text by pressing
518 // backspace.
519 for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) {
520 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
521 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
522 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
525 // Input something as search text.
526 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
528 // Move cursor to the beginning of the search text.
529 #if defined(OS_MACOSX)
530 // Home doesn't work on Mac trybot.
531 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, ui::EF_CONTROL_DOWN));
532 #else
533 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, 0));
534 #endif
535 // Backspace at the beginning of the search text shall turn off
536 // the keyword mode.
537 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
538 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
539 ASSERT_EQ(base::string16(), omnibox_view->model()->keyword());
540 ASSERT_EQ(std::string(kSearchKeyword) + kSearchText,
541 UTF16ToUTF8(omnibox_view->GetText()));
544 // http://crbug.com/158913
545 #if defined(OS_CHROMEOS) || defined(OS_WIN)
546 #define MAYBE_Escape DISABLED_Escape
547 #else
548 #define MAYBE_Escape Escape
549 #endif
550 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_Escape) {
551 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIHistoryURL));
552 chrome::FocusLocationBar(browser());
554 OmniboxView* omnibox_view = NULL;
555 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
557 base::string16 old_text = omnibox_view->GetText();
558 EXPECT_FALSE(old_text.empty());
559 EXPECT_TRUE(omnibox_view->IsSelectAll());
561 // Delete all text in omnibox.
562 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
563 EXPECT_TRUE(omnibox_view->GetText().empty());
565 // Escape shall revert the text in omnibox.
566 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
567 EXPECT_EQ(old_text, omnibox_view->GetText());
568 EXPECT_TRUE(omnibox_view->IsSelectAll());
570 #undef MAYBE_ESCAPE
572 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DesiredTLD) {
573 OmniboxView* omnibox_view = NULL;
574 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
575 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
576 ASSERT_TRUE(popup_model);
578 // Test ctrl-Enter.
579 const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
580 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
581 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
582 ASSERT_TRUE(popup_model->IsOpen());
583 // ctrl-Enter triggers desired_tld feature, thus www.bar.com shall be
584 // opened.
585 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN,
586 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
587 content::Source<content::NavigationController>(
588 &browser()->tab_strip_model()->GetActiveWebContents()->
589 GetController())));
591 GURL url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
592 EXPECT_EQ("www.bar.com", url.host());
593 EXPECT_EQ("/", url.path());
596 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DesiredTLDWithTemporaryText) {
597 OmniboxView* omnibox_view = NULL;
598 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
599 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
600 ASSERT_TRUE(popup_model);
602 Profile* profile = browser()->profile();
603 TemplateURLService* template_url_service =
604 TemplateURLServiceFactory::GetForProfile(profile);
606 // Add a non-substituting keyword. This ensures the popup will have a
607 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we
608 // can set "abc" as temporary text in the omnibox.
609 TemplateURLData data;
610 data.short_name = ASCIIToUTF16("abc");
611 data.SetKeyword(ASCIIToUTF16(kSearchText));
612 data.SetURL("http://abc.com/");
613 template_url_service->Add(new TemplateURL(profile, data));
615 // Send "ab", so that an "abc" entry appears in the popup.
616 const wchar_t kSearchTextPrefixKeys[] = { ui::VKEY_A, ui::VKEY_B, 0 };
617 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys));
618 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
619 ASSERT_TRUE(popup_model->IsOpen());
621 // Arrow down to the "abc" entry in the popup.
622 size_t size = popup_model->result().size();
623 while (popup_model->selected_line() < size - 1) {
624 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
625 if (omnibox_view->GetText() == ASCIIToUTF16("abc"))
626 break;
628 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
630 // Hitting ctrl-enter should navigate based on the current text rather than
631 // the original input, i.e. to www.abc.com instead of www.ab.com.
632 ASSERT_TRUE(SendKeyAndWait(
633 browser(), ui::VKEY_RETURN, ui::EF_CONTROL_DOWN,
634 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
635 content::Source<content::NavigationController>(
636 &browser()->tab_strip_model()->GetActiveWebContents()->
637 GetController())));
639 GURL url(browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
640 EXPECT_EQ("www.abc.com", url.host());
641 EXPECT_EQ("/", url.path());
644 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, AltEnter) {
645 OmniboxView* omnibox_view = NULL;
646 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
648 omnibox_view->SetUserText(ASCIIToUTF16(chrome::kChromeUIHistoryURL));
649 int tab_count = browser()->tab_strip_model()->count();
650 // alt-Enter opens a new tab.
651 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN, ui::EF_ALT_DOWN));
652 ASSERT_NO_FATAL_FAILURE(WaitForTabOpenOrClose(tab_count + 1));
655 // http://crbug.com/133354, http://crbug.com/146953
656 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_EnterToSearch) {
657 OmniboxView* omnibox_view = NULL;
658 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
659 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
660 ASSERT_TRUE(popup_model);
662 // Test Enter to search.
663 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
664 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
665 ASSERT_TRUE(popup_model->IsOpen());
667 // Check if the default match result is Search Primary Provider.
668 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
669 popup_model->result().default_match()->type);
671 // Open the default match.
672 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0,
673 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
674 content::Source<content::NavigationController>(
675 &browser()->tab_strip_model()->GetActiveWebContents()->
676 GetController())));
677 GURL url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
678 EXPECT_EQ(kSearchTextURL, url.spec());
680 // Test that entering a single character then Enter performs a search.
681 const wchar_t kSearchSingleCharKeys[] = { ui::VKEY_Z, 0 };
682 chrome::FocusLocationBar(browser());
683 EXPECT_TRUE(omnibox_view->IsSelectAll());
684 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys));
685 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
686 ASSERT_TRUE(popup_model->IsOpen());
687 EXPECT_EQ("z", UTF16ToUTF8(omnibox_view->GetText()));
689 // Check if the default match result is Search Primary Provider.
690 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
691 popup_model->result().default_match()->type);
693 // Open the default match.
694 ASSERT_TRUE(SendKeyAndWait(browser(), ui::VKEY_RETURN, 0,
695 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
696 content::Source<content::NavigationController>(
697 &browser()->tab_strip_model()->GetActiveWebContents()->
698 GetController())));
699 url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
700 EXPECT_EQ("http://www.foo.com/search?q=z", url.spec());
703 // http://crbug.com/131179
704 #if defined(OS_LINUX)
705 #define MAYBE_EscapeToDefaultMatch DISABLED_EscapeToDefaultMatch
706 #else
707 #define MAYBE_EscapeToDefaultMatch EscapeToDefaultMatch
708 #endif
709 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_EscapeToDefaultMatch) {
710 OmniboxView* omnibox_view = NULL;
711 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
712 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
713 ASSERT_TRUE(popup_model);
715 // Input something to trigger inline autocomplete.
716 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
717 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
718 ASSERT_TRUE(popup_model->IsOpen());
720 base::string16 old_text = omnibox_view->GetText();
722 // Make sure inline autocomplete is triggerred.
723 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
725 size_t old_selected_line = popup_model->selected_line();
726 EXPECT_EQ(0U, old_selected_line);
728 // Move to another line with different text.
729 size_t size = popup_model->result().size();
730 while (popup_model->selected_line() < size - 1) {
731 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
732 ASSERT_NE(old_selected_line, popup_model->selected_line());
733 if (old_text != omnibox_view->GetText())
734 break;
737 EXPECT_NE(old_text, omnibox_view->GetText());
739 // Escape shall revert back to the default match item.
740 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
741 EXPECT_EQ(old_text, omnibox_view->GetText());
742 EXPECT_EQ(old_selected_line, popup_model->selected_line());
745 // http://crbug.com/131179, http://crbug.com/146619
746 #if defined(OS_LINUX) || defined(OS_WIN)
747 #define MAYBE_BasicTextOperations DISABLED_BasicTextOperations
748 #else
749 #define MAYBE_BasicTextOperations BasicTextOperations
750 #endif
751 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_BasicTextOperations) {
752 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
753 chrome::FocusLocationBar(browser());
755 OmniboxView* omnibox_view = NULL;
756 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
758 base::string16 old_text = omnibox_view->GetText();
759 EXPECT_EQ(base::UTF8ToUTF16(content::kAboutBlankURL), old_text);
760 EXPECT_TRUE(omnibox_view->IsSelectAll());
762 size_t start, end;
763 omnibox_view->GetSelectionBounds(&start, &end);
764 EXPECT_EQ(0U, start);
765 EXPECT_EQ(old_text.size(), end);
767 // Move the cursor to the end.
768 #if defined(OS_MACOSX)
769 // End doesn't work on Mac trybot.
770 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, ui::EF_CONTROL_DOWN));
771 #else
772 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
773 #endif
774 EXPECT_FALSE(omnibox_view->IsSelectAll());
776 // Make sure the cursor is placed correctly.
777 omnibox_view->GetSelectionBounds(&start, &end);
778 EXPECT_EQ(old_text.size(), start);
779 EXPECT_EQ(old_text.size(), end);
781 // Insert one character at the end. Make sure we won't insert
782 // anything after the special ZWS mark used in gtk implementation.
783 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
784 EXPECT_EQ(old_text + base::char16('a'), omnibox_view->GetText());
786 // Delete one character from the end. Make sure we won't delete the special
787 // ZWS mark used in gtk implementation.
788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
789 EXPECT_EQ(old_text, omnibox_view->GetText());
791 omnibox_view->SelectAll(true);
792 EXPECT_TRUE(omnibox_view->IsSelectAll());
793 omnibox_view->GetSelectionBounds(&start, &end);
794 EXPECT_EQ(0U, start);
795 EXPECT_EQ(old_text.size(), end);
797 // Delete the content
798 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0));
799 EXPECT_TRUE(omnibox_view->IsSelectAll());
800 omnibox_view->GetSelectionBounds(&start, &end);
801 EXPECT_EQ(0U, start);
802 EXPECT_EQ(0U, end);
803 EXPECT_TRUE(omnibox_view->GetText().empty());
805 // Check if RevertAll() can set text and cursor correctly.
806 omnibox_view->RevertAll();
807 EXPECT_FALSE(omnibox_view->IsSelectAll());
808 EXPECT_EQ(old_text, omnibox_view->GetText());
809 omnibox_view->GetSelectionBounds(&start, &end);
810 EXPECT_EQ(old_text.size(), start);
811 EXPECT_EQ(old_text.size(), end);
814 // http://crbug.com/131179
815 #if defined(OS_LINUX)
816 #define MAYBE_AcceptKeywordBySpace DISABLED_AcceptKeywordBySpace
817 #else
818 #define MAYBE_AcceptKeywordBySpace AcceptKeywordBySpace
819 #endif
821 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_AcceptKeywordBySpace) {
822 OmniboxView* omnibox_view = NULL;
823 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
825 base::string16 search_keyword(ASCIIToUTF16(kSearchKeyword));
827 // Trigger keyword hint mode.
828 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
829 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
830 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
831 ASSERT_EQ(search_keyword, omnibox_view->GetText());
833 // Trigger keyword mode by space.
834 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
835 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
836 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
837 ASSERT_TRUE(omnibox_view->GetText().empty());
839 // Revert to keyword hint mode.
840 omnibox_view->model()->ClearKeyword(base::string16());
841 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
842 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
843 ASSERT_EQ(search_keyword, omnibox_view->GetText());
845 // Keyword should also be accepted by typing an ideographic space.
846 omnibox_view->OnBeforePossibleChange();
847 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
848 base::WideToUTF16(L"\x3000"), search_keyword.length() + 1, false, false);
849 omnibox_view->OnAfterPossibleChange();
850 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
851 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
852 ASSERT_TRUE(omnibox_view->GetText().empty());
854 // Revert to keyword hint mode.
855 omnibox_view->model()->ClearKeyword(base::string16());
856 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
857 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
858 ASSERT_EQ(search_keyword, omnibox_view->GetText());
860 // Keyword shouldn't be accepted by pressing space with a trailing
861 // whitespace.
862 omnibox_view->SetWindowTextAndCaretPos(search_keyword + base::char16(' '),
863 search_keyword.length() + 1, false, false);
864 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
865 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
866 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
867 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
869 // Keyword shouldn't be accepted by deleting the trailing space.
870 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
871 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
872 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
873 ASSERT_EQ(search_keyword + base::char16(' '), omnibox_view->GetText());
875 // Keyword shouldn't be accepted by pressing space before a trailing space.
876 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
877 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
878 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
879 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
880 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
882 // Keyword should be accepted by pressing space in the middle of context and
883 // just after the keyword.
884 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
885 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
886 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
887 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
888 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
889 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
890 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
891 size_t start, end;
892 omnibox_view->GetSelectionBounds(&start, &end);
893 EXPECT_EQ(0U, start);
894 EXPECT_EQ(0U, end);
896 // Keyword shouldn't be accepted by pasting "foo bar".
897 omnibox_view->SetUserText(base::string16());
898 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
899 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
901 omnibox_view->OnBeforePossibleChange();
902 omnibox_view->model()->OnPaste();
903 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
904 ASCIIToUTF16(" bar"), search_keyword.length() + 4, false, false);
905 omnibox_view->OnAfterPossibleChange();
906 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
907 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
908 ASSERT_EQ(search_keyword + ASCIIToUTF16(" bar"), omnibox_view->GetText());
910 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
911 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
912 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
913 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
914 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
915 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
916 ASSERT_EQ(search_keyword + ASCIIToUTF16(" b ar"), omnibox_view->GetText());
918 // Keyword could be accepted by pressing space with a selected range at the
919 // end of text.
920 omnibox_view->OnBeforePossibleChange();
921 omnibox_view->OnInlineAutocompleteTextMaybeChanged(
922 search_keyword + ASCIIToUTF16(" "), search_keyword.length());
923 omnibox_view->OnAfterPossibleChange();
924 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
925 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
926 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
928 omnibox_view->GetSelectionBounds(&start, &end);
929 ASSERT_NE(start, end);
930 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
931 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
932 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
933 ASSERT_EQ(base::string16(), omnibox_view->GetText());
935 // Space should accept keyword even when inline autocomplete is available.
936 omnibox_view->SetUserText(base::string16());
937 const TestHistoryEntry kHistoryFoobar = {
938 "http://www.foobar.com", "Page foobar", 100, 100, true
941 // Add a history entry to trigger inline autocomplete when typing "foo".
942 ASSERT_NO_FATAL_FAILURE(
943 AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1)));
945 // Type "foo" to trigger inline autocomplete.
946 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
947 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
948 ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
949 ASSERT_NE(search_keyword, omnibox_view->GetText());
951 // Keyword hint shouldn't be visible.
952 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
953 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
955 // Trigger keyword mode by space.
956 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
957 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
958 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
959 ASSERT_TRUE(omnibox_view->GetText().empty());
961 // Space in the middle of a temporary text, which separates the text into
962 // keyword and replacement portions, should trigger keyword mode.
963 omnibox_view->SetUserText(base::string16());
964 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
965 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
966 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
967 ASSERT_TRUE(popup_model->IsOpen());
968 ASSERT_EQ(ASCIIToUTF16("foobar.com"), omnibox_view->GetText());
969 omnibox_view->model()->OnUpOrDownKeyPressed(1);
970 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
971 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
972 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
973 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
974 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
975 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
976 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
977 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
978 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
979 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
980 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
981 ASSERT_EQ(ASCIIToUTF16("bar.com"), omnibox_view->GetText());
983 // Space after temporary text that looks like a keyword, when the original
984 // input does not look like a keyword, should trigger keyword mode.
985 omnibox_view->SetUserText(base::string16());
986 const TestHistoryEntry kHistoryFoo = {
987 "http://footest.com", "Page footest", 1000, 1000, true
990 // Add a history entry to trigger HQP matching with text == keyword when
991 // typing "fo te".
992 ASSERT_NO_FATAL_FAILURE(
993 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromMinutes(10)));
995 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_F, 0));
996 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_O, 0));
997 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
998 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_T, 0));
999 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, 0));
1000 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1001 ASSERT_TRUE(popup_model->IsOpen());
1002 base::string16 search_keyword2(ASCIIToUTF16(kSearchKeyword2));
1003 while ((omnibox_view->GetText() != search_keyword2) &&
1004 (popup_model->selected_line() < popup_model->result().size() - 1))
1005 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1006 ASSERT_EQ(search_keyword2, omnibox_view->GetText());
1007 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
1008 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1009 ASSERT_EQ(search_keyword2, omnibox_view->model()->keyword());
1010 ASSERT_TRUE(omnibox_view->GetText().empty());
1013 // http://crbug.com/131179
1014 #if defined(OS_LINUX)
1015 #define MAYBE_NonSubstitutingKeywordTest DISABLED_NonSubstitutingKeywordTest
1016 #else
1017 #define MAYBE_NonSubstitutingKeywordTest NonSubstitutingKeywordTest
1018 #endif
1020 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_NonSubstitutingKeywordTest) {
1021 OmniboxView* omnibox_view = NULL;
1022 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1023 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1024 ASSERT_TRUE(popup_model);
1026 Profile* profile = browser()->profile();
1027 TemplateURLService* template_url_service =
1028 TemplateURLServiceFactory::GetForProfile(profile);
1030 // Add a non-default substituting keyword.
1031 TemplateURLData data;
1032 data.short_name = ASCIIToUTF16("Search abc");
1033 data.SetKeyword(ASCIIToUTF16(kSearchText));
1034 data.SetURL("http://abc.com/{searchTerms}");
1035 TemplateURL* template_url = new TemplateURL(profile, data);
1036 template_url_service->Add(template_url);
1038 omnibox_view->SetUserText(base::string16());
1040 // Non-default substituting keyword shouldn't be matched by default.
1041 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1042 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1043 ASSERT_TRUE(popup_model->IsOpen());
1045 // Check if the default match result is Search Primary Provider.
1046 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1047 popup_model->result().default_match()->type);
1048 ASSERT_EQ(kSearchTextURL,
1049 popup_model->result().default_match()->destination_url.spec());
1051 omnibox_view->SetUserText(base::string16());
1052 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1053 ASSERT_FALSE(popup_model->IsOpen());
1055 // Try a non-substituting keyword.
1056 template_url_service->Remove(template_url);
1057 data.short_name = ASCIIToUTF16("abc");
1058 data.SetURL("http://abc.com/");
1059 template_url_service->Add(new TemplateURL(profile, data));
1061 // We always allow exact matches for non-substituting keywords.
1062 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1063 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1064 ASSERT_TRUE(popup_model->IsOpen());
1065 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD,
1066 popup_model->result().default_match()->type);
1067 ASSERT_EQ("http://abc.com/",
1068 popup_model->result().default_match()->destination_url.spec());
1071 // http://crbug.com/131179 http://crbug.com/165765
1072 #if defined(OS_LINUX) || defined(OS_WIN) || defined(OS_MACOSX)
1073 #define MAYBE_DeleteItem DISABLED_DeleteItem
1074 #else
1075 #define MAYBE_DeleteItem DeleteItem
1076 #endif
1077 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_DeleteItem) {
1078 // Disable the search provider, to make sure the popup contains only history
1079 // items.
1080 TemplateURLService* model =
1081 TemplateURLServiceFactory::GetForProfile(browser()->profile());
1082 model->SetDefaultSearchProvider(NULL);
1084 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
1085 chrome::FocusLocationBar(browser());
1087 OmniboxView* omnibox_view = NULL;
1088 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1090 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1091 ASSERT_TRUE(popup_model);
1093 base::string16 old_text = omnibox_view->GetText();
1095 // Input something that can match history items.
1096 omnibox_view->SetUserText(ASCIIToUTF16("site.com/p"));
1097 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1098 ASSERT_TRUE(popup_model->IsOpen());
1100 // Delete the inline autocomplete part.
1101 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DELETE, 0));
1102 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1103 ASSERT_TRUE(popup_model->IsOpen());
1104 ASSERT_GE(popup_model->result().size(), 3U);
1106 base::string16 user_text = omnibox_view->GetText();
1107 ASSERT_EQ(ASCIIToUTF16("site.com/p"), user_text);
1108 omnibox_view->SelectAll(true);
1109 ASSERT_TRUE(omnibox_view->IsSelectAll());
1111 // Move down.
1112 size_t default_line = popup_model->selected_line();
1113 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1114 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1115 base::string16 selected_text =
1116 popup_model->result().match_at(default_line + 1).fill_into_edit;
1117 // Temporary text is shown.
1118 ASSERT_EQ(selected_text, omnibox_view->GetText());
1119 ASSERT_FALSE(omnibox_view->IsSelectAll());
1121 // Delete the item.
1122 popup_model->TryDeletingCurrentItem();
1123 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1124 // The selected line shouldn't be changed, because we have more than two
1125 // items.
1126 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1127 // Make sure the item is really deleted.
1128 ASSERT_NE(selected_text,
1129 popup_model->result().match_at(default_line + 1).fill_into_edit);
1130 selected_text =
1131 popup_model->result().match_at(default_line + 1).fill_into_edit;
1132 // New temporary text is shown.
1133 ASSERT_EQ(selected_text, omnibox_view->GetText());
1135 // Revert to the default match.
1136 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1137 ASSERT_EQ(default_line, popup_model->selected_line());
1138 ASSERT_EQ(user_text, omnibox_view->GetText());
1139 ASSERT_TRUE(omnibox_view->IsSelectAll());
1141 // Move down and up to select the default match as temporary text.
1142 omnibox_view->model()->OnUpOrDownKeyPressed(1);
1143 ASSERT_EQ(default_line + 1, popup_model->selected_line());
1144 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
1145 ASSERT_EQ(default_line, popup_model->selected_line());
1147 selected_text = popup_model->result().match_at(default_line).fill_into_edit;
1148 // New temporary text is shown.
1149 ASSERT_EQ(selected_text, omnibox_view->GetText());
1150 ASSERT_FALSE(omnibox_view->IsSelectAll());
1152 #if 0
1153 // TODO(mrossetti): http://crbug.com/82335
1154 // Delete the default item.
1155 popup_model->TryDeletingCurrentItem();
1156 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1157 // The selected line shouldn't be changed, but the default item should have
1158 // been changed.
1159 ASSERT_EQ(default_line, popup_model->selected_line());
1160 // Make sure the item is really deleted.
1161 EXPECT_NE(selected_text,
1162 popup_model->result().match_at(default_line).fill_into_edit);
1163 selected_text =
1164 popup_model->result().match_at(default_line).fill_into_edit;
1165 // New temporary text is shown.
1166 ASSERT_EQ(selected_text, omnibox_view->GetText());
1167 #endif
1169 // As the current selected item is the new default item, pressing Escape key
1170 // should revert all directly.
1171 ASSERT_TRUE(omnibox_view->model()->OnEscapeKeyPressed());
1172 ASSERT_EQ(old_text, omnibox_view->GetText());
1173 ASSERT_TRUE(omnibox_view->IsSelectAll());
1176 // http://crbug.com/133344
1177 #if defined(OS_LINUX)
1178 #define MAYBE_TabAcceptKeyword DISABLED_TabAcceptKeyword
1179 #else
1180 #define MAYBE_TabAcceptKeyword TabAcceptKeyword
1181 #endif
1183 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_TabAcceptKeyword) {
1184 OmniboxView* omnibox_view = NULL;
1185 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1187 base::string16 text = ASCIIToUTF16(kSearchKeyword);
1189 // Trigger keyword hint mode.
1190 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1191 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1192 ASSERT_EQ(text, omnibox_view->model()->keyword());
1193 ASSERT_EQ(text, omnibox_view->GetText());
1195 // Trigger keyword mode by tab.
1196 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1197 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1198 ASSERT_EQ(text, omnibox_view->model()->keyword());
1199 ASSERT_TRUE(omnibox_view->GetText().empty());
1201 // Revert to keyword hint mode.
1202 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1203 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1204 ASSERT_EQ(text, omnibox_view->model()->keyword());
1205 ASSERT_EQ(text, omnibox_view->GetText());
1207 // The location bar should still have focus.
1208 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1210 // Trigger keyword mode by tab.
1211 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1212 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1213 ASSERT_EQ(text, omnibox_view->model()->keyword());
1214 ASSERT_TRUE(omnibox_view->GetText().empty());
1216 // Revert to keyword hint mode with SHIFT+TAB.
1217 #if defined(OS_MACOSX)
1218 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACKTAB, 0));
1219 #else
1220 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1221 #endif
1222 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1223 ASSERT_EQ(text, omnibox_view->model()->keyword());
1224 ASSERT_EQ(text, omnibox_view->GetText());
1225 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1228 #if !defined(OS_MACOSX)
1229 // Mac intentionally does not support this behavior.
1231 // http://crbug.com/133360
1232 #if defined(OS_LINUX)
1233 #define MAYBE_TabTraverseResultsTest DISABLED_TabTraverseResultsTest
1234 #else
1235 #define MAYBE_TabTraverseResultsTest TabTraverseResultsTest
1236 #endif
1238 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_TabTraverseResultsTest) {
1239 OmniboxView* omnibox_view = NULL;
1240 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1241 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1242 ASSERT_TRUE(popup_model);
1244 // Input something to trigger results.
1245 const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
1246 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
1247 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1248 ASSERT_TRUE(popup_model->IsOpen());
1250 size_t old_selected_line = popup_model->selected_line();
1251 EXPECT_EQ(0U, old_selected_line);
1253 // Move down the results.
1254 for (size_t size = popup_model->result().size();
1255 popup_model->selected_line() < size - 1;
1256 old_selected_line = popup_model->selected_line()) {
1257 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1258 ASSERT_LT(old_selected_line, popup_model->selected_line());
1261 // Don't move past the end.
1262 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1263 ASSERT_EQ(old_selected_line, popup_model->selected_line());
1264 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1266 // Move back up the results.
1267 for (; popup_model->selected_line() > 0U;
1268 old_selected_line = popup_model->selected_line()) {
1269 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1270 ASSERT_GT(old_selected_line, popup_model->selected_line());
1273 // Don't move past the beginning.
1274 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1275 ASSERT_EQ(0U, popup_model->selected_line());
1276 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1278 const TestHistoryEntry kHistoryFoo = {
1279 "http://foo/", "Page foo", 1, 1, false
1282 // Add a history entry so "foo" gets multiple matches.
1283 ASSERT_NO_FATAL_FAILURE(
1284 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromHours(1)));
1286 // Load results.
1287 ASSERT_NO_FATAL_FAILURE(omnibox_view->SelectAll(false));
1288 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1289 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1291 // Trigger keyword mode by tab.
1292 base::string16 text = ASCIIToUTF16(kSearchKeyword);
1293 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1294 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1295 ASSERT_EQ(text, omnibox_view->model()->keyword());
1296 ASSERT_TRUE(omnibox_view->GetText().empty());
1298 // The location bar should still have focus.
1299 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1301 // Pressing tab again should move to the next result and clear keyword
1302 // mode.
1303 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1304 ASSERT_EQ(1U, omnibox_view->model()->popup_model()->selected_line());
1305 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1306 ASSERT_NE(text, omnibox_view->model()->keyword());
1308 // The location bar should still have focus.
1309 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1311 // Moving back up should not show keyword mode.
1312 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, ui::EF_SHIFT_DOWN));
1313 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1314 ASSERT_EQ(text, omnibox_view->model()->keyword());
1316 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1318 #endif
1321 // http://crbug.com/133347
1322 #if defined(OS_LINUX)
1323 #define MAYBE_PersistKeywordModeOnTabSwitch DISABLED_PersistKeywordModeOnTabSwitch
1324 #else
1325 #define MAYBE_PersistKeywordModeOnTabSwitch PersistKeywordModeOnTabSwitch
1326 #endif
1328 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1329 MAYBE_PersistKeywordModeOnTabSwitch) {
1330 OmniboxView* omnibox_view = NULL;
1331 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1333 // Trigger keyword hint mode.
1334 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
1335 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
1336 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1338 // Trigger keyword mode.
1339 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB, 0));
1340 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
1341 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1343 // Input something as search text.
1344 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys));
1346 // Create a new tab.
1347 chrome::NewTab(browser());
1349 // Switch back to the first tab.
1350 browser()->tab_strip_model()->ActivateTabAt(0, true);
1352 // Make sure we're still in keyword mode.
1353 ASSERT_EQ(kSearchKeyword, UTF16ToUTF8(omnibox_view->model()->keyword()));
1356 // http://crbug.com/133355
1357 #if defined(OS_LINUX)
1358 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest DISABLED_CtrlKeyPressedWithInlineAutocompleteTest
1359 #else
1360 #define MAYBE_CtrlKeyPressedWithInlineAutocompleteTest CtrlKeyPressedWithInlineAutocompleteTest
1361 #endif
1363 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1364 MAYBE_CtrlKeyPressedWithInlineAutocompleteTest) {
1365 OmniboxView* omnibox_view = NULL;
1366 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1367 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1368 ASSERT_TRUE(popup_model);
1370 // Input something to trigger inline autocomplete.
1371 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
1372 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1373 ASSERT_TRUE(popup_model->IsOpen());
1375 base::string16 old_text = omnibox_view->GetText();
1377 // Make sure inline autocomplete is triggerred.
1378 EXPECT_GT(old_text.length(), arraysize(kInlineAutocompleteText) - 1);
1380 // Press ctrl key.
1381 omnibox_view->model()->OnControlKeyChanged(true);
1383 // Inline autocomplete should still be there.
1384 EXPECT_EQ(old_text, omnibox_view->GetText());
1387 #if defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS)
1388 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, UndoRedo) {
1389 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
1390 chrome::FocusLocationBar(browser());
1392 OmniboxView* omnibox_view = NULL;
1393 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1395 base::string16 old_text = omnibox_view->GetText();
1396 EXPECT_EQ(base::UTF8ToUTF16(content::kAboutBlankURL), old_text);
1397 EXPECT_TRUE(omnibox_view->IsSelectAll());
1399 // Delete the text, then undo.
1400 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1401 EXPECT_TRUE(omnibox_view->GetText().empty());
1402 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN));
1403 EXPECT_EQ(old_text, omnibox_view->GetText());
1405 // Redo should delete the text again.
1406 ASSERT_NO_FATAL_FAILURE(
1407 SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN));
1408 EXPECT_TRUE(omnibox_view->GetText().empty());
1410 // Looks like the undo manager doesn't support restoring selection.
1411 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN));
1412 EXPECT_FALSE(omnibox_view->IsSelectAll());
1414 // The cursor should be at the end.
1415 size_t start, end;
1416 omnibox_view->GetSelectionBounds(&start, &end);
1417 EXPECT_EQ(old_text.size(), start);
1418 EXPECT_EQ(old_text.size(), end);
1420 // Delete two characters.
1421 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1422 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1423 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), omnibox_view->GetText());
1425 // Undo delete.
1426 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN));
1427 EXPECT_EQ(old_text, omnibox_view->GetText());
1429 // Redo delete.
1430 ASSERT_NO_FATAL_FAILURE(
1431 SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN));
1432 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), omnibox_view->GetText());
1434 // Delete everything.
1435 omnibox_view->SelectAll(true);
1436 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1437 EXPECT_TRUE(omnibox_view->GetText().empty());
1439 // Undo delete everything.
1440 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN));
1441 EXPECT_EQ(old_text.substr(0, old_text.size() - 2), omnibox_view->GetText());
1443 // Undo delete two characters.
1444 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_Z, ui::EF_CONTROL_DOWN));
1445 EXPECT_EQ(old_text, omnibox_view->GetText());
1448 // See http://crosbug.com/10306
1449 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1450 BackspaceDeleteHalfWidthKatakana) {
1451 OmniboxView* omnibox_view = NULL;
1452 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1453 // Insert text: ダ
1454 omnibox_view->SetUserText(base::UTF8ToUTF16("\357\276\200\357\276\236"));
1456 // Move the cursor to the end.
1457 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
1459 // Backspace should delete one character.
1460 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
1461 EXPECT_EQ(base::UTF8ToUTF16("\357\276\200"), omnibox_view->GetText());
1463 #endif // defined(TOOLKIT_GTK) || defined(TOOLKIT_VIEWS)
1465 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DoesNotUpdateAutocompleteOnBlur) {
1466 OmniboxView* omnibox_view = NULL;
1467 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1468 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1469 ASSERT_TRUE(popup_model);
1471 // Input something to trigger inline autocomplete.
1472 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kInlineAutocompleteTextKeys));
1473 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1474 ASSERT_TRUE(popup_model->IsOpen());
1475 size_t start, end;
1476 omnibox_view->GetSelectionBounds(&start, &end);
1477 EXPECT_TRUE(start != end);
1478 base::string16 old_autocomplete_text =
1479 omnibox_view->model()->autocomplete_controller()->input().text();
1481 // Unfocus the omnibox. This should clear the text field selection and
1482 // close the popup, but should not run autocomplete.
1483 // Note: GTK preserves the selection when the omnibox is unfocused.
1484 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
1485 ASSERT_FALSE(popup_model->IsOpen());
1486 omnibox_view->GetSelectionBounds(&start, &end);
1487 #if !defined(TOOLKIT_GTK)
1488 EXPECT_TRUE(start == end);
1489 #endif
1491 EXPECT_EQ(old_autocomplete_text,
1492 omnibox_view->model()->autocomplete_controller()->input().text());
1495 #if defined(TOOLKIT_GTK)
1496 // See http://crbug.com/63860
1497 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, PrimarySelection) {
1498 OmniboxView* omnibox_view = NULL;
1499 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1500 omnibox_view->SetUserText(ASCIIToUTF16("Hello world"));
1501 EXPECT_FALSE(omnibox_view->IsSelectAll());
1503 // Move the cursor to the end.
1504 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
1506 // Select all text by pressing Shift+Home
1507 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_HOME, ui::EF_SHIFT_DOWN));
1508 EXPECT_TRUE(omnibox_view->IsSelectAll());
1510 // The selected content should be saved to the PRIMARY clipboard.
1511 EXPECT_EQ("Hello world", GetPrimarySelectionText());
1513 // Move the cursor to the end.
1514 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_END, 0));
1515 EXPECT_FALSE(omnibox_view->IsSelectAll());
1517 // The content in the PRIMARY clipboard should not be cleared.
1518 EXPECT_EQ("Hello world", GetPrimarySelectionText());
1520 #endif // defined(TOOLKIT_GTK)
1522 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, Paste) {
1523 OmniboxView* omnibox_view = NULL;
1524 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1525 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1526 ASSERT_TRUE(popup_model);
1527 EXPECT_FALSE(popup_model->IsOpen());
1529 // Paste should yield the expected text and open the popup.
1530 SetClipboardText(ASCIIToUTF16(kSearchText));
1531 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1532 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1533 EXPECT_EQ(ASCIIToUTF16(kSearchText), omnibox_view->GetText());
1534 EXPECT_TRUE(popup_model->IsOpen());
1536 // Close the popup and select all.
1537 omnibox_view->CloseOmniboxPopup();
1538 omnibox_view->SelectAll(false);
1539 EXPECT_FALSE(popup_model->IsOpen());
1541 // Pasting the same text again over itself should re-open the popup.
1542 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1543 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1544 EXPECT_EQ(ASCIIToUTF16(kSearchText), omnibox_view->GetText());
1545 // This fails on GTK, see http://crbug.com/131179
1546 #if !defined(TOOLKIT_GTK)
1547 EXPECT_TRUE(popup_model->IsOpen());
1548 #endif
1549 omnibox_view->CloseOmniboxPopup();
1550 EXPECT_FALSE(popup_model->IsOpen());
1552 // Pasting amid text should yield the expected text and re-open the popup.
1553 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("abcd"), 2, false, false);
1554 SetClipboardText(ASCIIToUTF16("123"));
1555 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, kCtrlOrCmdMask));
1556 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText());
1557 EXPECT_TRUE(popup_model->IsOpen());
1559 // Ctrl/Cmd+Alt+V should not paste.
1560 ASSERT_NO_FATAL_FAILURE(
1561 SendKey(ui::VKEY_V, kCtrlOrCmdMask | ui::EF_ALT_DOWN));
1562 EXPECT_EQ(ASCIIToUTF16("ab123cd"), omnibox_view->GetText());
1563 // TODO(msw): Test that AltGr+V does not paste.
1566 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyURLToClipboard) {
1567 // Set permanent text thus making sure that omnibox treats 'google.com'
1568 // as URL (not as ordinary user input).
1569 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1570 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1571 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/"));
1572 browser()->swap_toolbar_models(&toolbar_model);
1573 OmniboxView* omnibox_view = NULL;
1574 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1575 OmniboxEditModel* edit_model = omnibox_view->model();
1576 ASSERT_NE(static_cast<OmniboxEditModel*>(NULL), edit_model);
1577 edit_model->UpdatePermanentText();
1579 const char* target_url = "http://www.google.com/calendar";
1580 omnibox_view->SetUserText(ASCIIToUTF16(target_url));
1582 // Location bar must have focus.
1583 chrome::FocusLocationBar(browser());
1584 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1586 // Select full URL and copy it to clipboard. General text and html should
1587 // be available.
1588 omnibox_view->SelectAll(true);
1589 EXPECT_TRUE(omnibox_view->IsSelectAll());
1590 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1591 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1592 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY));
1593 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText());
1594 EXPECT_TRUE(clipboard->IsFormatAvailable(
1595 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1597 // Make sure HTML format isn't written. See
1598 // BookmarkNodeData::WriteToClipboard() for details.
1599 EXPECT_FALSE(clipboard->IsFormatAvailable(
1600 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1602 // These platforms should read bookmark format.
1603 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1604 base::string16 title;
1605 std::string url;
1606 clipboard->ReadBookmark(&title, &url);
1607 EXPECT_EQ(target_url, url);
1608 EXPECT_EQ(ASCIIToUTF16(target_url), title);
1609 #endif
1612 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CutURLToClipboard) {
1613 // Set permanent text thus making sure that omnibox treats 'google.com'
1614 // as URL (not as ordinary user input).
1615 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1616 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1617 test_toolbar_model->set_text(ASCIIToUTF16("http://www.google.com/"));
1618 browser()->swap_toolbar_models(&toolbar_model);
1619 OmniboxView* omnibox_view = NULL;
1620 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1621 OmniboxEditModel* edit_model = omnibox_view->model();
1622 ASSERT_NE(static_cast<OmniboxEditModel*>(NULL), edit_model);
1623 edit_model->UpdatePermanentText();
1625 const char* target_url = "http://www.google.com/calendar";
1626 omnibox_view->SetUserText(ASCIIToUTF16(target_url));
1628 // Location bar must have focus.
1629 chrome::FocusLocationBar(browser());
1630 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1632 // Select full URL and cut it. General text and html should be available
1633 // in the clipboard.
1634 omnibox_view->SelectAll(true);
1635 EXPECT_TRUE(omnibox_view->IsSelectAll());
1636 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1637 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1638 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT));
1639 EXPECT_EQ(base::string16(), omnibox_view->GetText());
1640 EXPECT_TRUE(clipboard->IsFormatAvailable(
1641 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1643 // Make sure HTML format isn't written. See
1644 // BookmarkNodeData::WriteToClipboard() for details.
1645 EXPECT_FALSE(clipboard->IsFormatAvailable(
1646 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1648 // These platforms should read bookmark format.
1649 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1650 base::string16 title;
1651 std::string url;
1652 clipboard->ReadBookmark(&title, &url);
1653 EXPECT_EQ(target_url, url);
1654 EXPECT_EQ(ASCIIToUTF16(target_url), title);
1655 #endif
1658 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CopyTextToClipboard) {
1659 OmniboxView* omnibox_view = NULL;
1660 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1661 const char* target_text = "foo";
1662 omnibox_view->SetUserText(ASCIIToUTF16(target_text));
1664 // Location bar must have focus.
1665 chrome::FocusLocationBar(browser());
1666 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1668 // Select full text and copy it to the clipboard.
1669 omnibox_view->SelectAll(true);
1670 EXPECT_TRUE(omnibox_view->IsSelectAll());
1671 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1672 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1673 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_COPY));
1674 EXPECT_TRUE(clipboard->IsFormatAvailable(
1675 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1676 EXPECT_FALSE(clipboard->IsFormatAvailable(
1677 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1678 EXPECT_EQ(ASCIIToUTF16(target_text), omnibox_view->GetText());
1681 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CutTextToClipboard) {
1682 OmniboxView* omnibox_view = NULL;
1683 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1684 const char* target_text = "foo";
1685 omnibox_view->SetUserText(ASCIIToUTF16(target_text));
1687 // Location bar must have focus.
1688 chrome::FocusLocationBar(browser());
1689 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1691 // Select full text and cut it to the clipboard.
1692 omnibox_view->SelectAll(true);
1693 EXPECT_TRUE(omnibox_view->IsSelectAll());
1694 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
1695 clipboard->Clear(ui::CLIPBOARD_TYPE_COPY_PASTE);
1696 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_CUT));
1697 EXPECT_TRUE(clipboard->IsFormatAvailable(
1698 ui::Clipboard::GetPlainTextFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1699 EXPECT_FALSE(clipboard->IsFormatAvailable(
1700 ui::Clipboard::GetHtmlFormatType(), ui::CLIPBOARD_TYPE_COPY_PASTE));
1701 EXPECT_EQ(base::string16(), omnibox_view->GetText());
1704 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EditSearchEngines) {
1705 OmniboxView* omnibox_view = NULL;
1706 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1707 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_EDIT_SEARCH_ENGINES));
1708 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1709 const std::string target_url =
1710 std::string(chrome::kChromeUISettingsURL) + chrome::kSearchEnginesSubPage;
1711 EXPECT_EQ(ASCIIToUTF16(target_url), omnibox_view->GetText());
1712 EXPECT_FALSE(omnibox_view->model()->popup_model()->IsOpen());
1715 #if !defined(TOOLKIT_GTK)
1716 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, BeginningShownAfterBlur) {
1717 OmniboxView* omnibox_view = NULL;
1718 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1720 omnibox_view->OnBeforePossibleChange();
1721 omnibox_view->SetWindowTextAndCaretPos(ASCIIToUTF16("data:text/plain,test"),
1722 5U, false, false);
1723 omnibox_view->OnAfterPossibleChange();
1724 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1725 size_t start, end;
1726 omnibox_view->GetSelectionBounds(&start, &end);
1727 ASSERT_EQ(5U, start);
1728 ASSERT_EQ(5U, end);
1730 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
1731 ASSERT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
1733 omnibox_view->GetSelectionBounds(&start, &end);
1734 ASSERT_EQ(0U, start);
1735 ASSERT_EQ(0U, end);
1737 #endif // !defined(TOOLKIT_GTK)
1739 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) {
1740 OmniboxView* omnibox_view = NULL;
1741 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1742 OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
1743 ASSERT_TRUE(popup_model);
1745 // Input something to trigger results.
1746 const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
1747 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
1748 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1749 ASSERT_TRUE(popup_model->IsOpen());
1751 ASSERT_EQ(ASCIIToUTF16("bar.com/1"), omnibox_view->GetText());
1753 // Arrow down on a suggestion, and omnibox text should be the suggestion.
1754 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_DOWN, 0));
1755 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1756 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText());
1758 // Highlight the last 2 words and the omnibox text should not change.
1759 // Simulating Ctrl-shift-left only once does not seem to highlight anything
1760 // on Linux.
1761 #if defined(OS_MACOSX)
1762 // Mac uses alt-left/right to select a word.
1763 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN;
1764 #else
1765 const int modifiers = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN;
1766 #endif
1767 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers));
1768 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, modifiers));
1769 ASSERT_EQ(ASCIIToUTF16("www.bar.com/2"), omnibox_view->GetText());
1772 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1773 PersistSearchReplacementAcrossTabSwitch) {
1774 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1775 browser()->toolbar_model()->set_url_replacement_enabled(false);
1777 // Create a new tab.
1778 chrome::NewTab(browser());
1779 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());
1781 // Switch back to the first tab.
1782 browser()->tab_strip_model()->ActivateTabAt(0, true);
1783 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled());
1786 IN_PROC_BROWSER_TEST_F(OmniboxViewTest,
1787 DontUpdateURLWhileSearchTermReplacementIsDisabled) {
1788 OmniboxView* omnibox_view = NULL;
1789 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
1790 TestToolbarModel* test_toolbar_model = new TestToolbarModel;
1791 scoped_ptr<ToolbarModel> toolbar_model(test_toolbar_model);
1792 browser()->swap_toolbar_models(&toolbar_model);
1794 base::string16 url_a(ASCIIToUTF16("http://www.a.com/"));
1795 base::string16 url_b(ASCIIToUTF16("http://www.b.com/"));
1796 base::string16 url_c(ASCIIToUTF16("http://www.c.com/"));
1797 chrome::FocusLocationBar(browser());
1798 test_toolbar_model->set_text(url_a);
1799 omnibox_view->Update();
1800 EXPECT_EQ(url_a, omnibox_view->GetText());
1802 // Disable URL replacement and update. Because the omnibox has focus, the
1803 // visible text shouldn't change; see comments in
1804 // OmniboxEditModel::UpdatePermanentText().
1805 browser()->toolbar_model()->set_url_replacement_enabled(false);
1806 test_toolbar_model->set_text(url_b);
1807 omnibox_view->Update();
1808 EXPECT_EQ(url_a, omnibox_view->GetText());
1810 // Re-enable URL replacement and ensure updating changes the text.
1811 browser()->toolbar_model()->set_url_replacement_enabled(true);
1812 // We have to change the toolbar model text here, or Update() will do nothing.
1813 // This is because the previous update already updated the permanent text.
1814 test_toolbar_model->set_text(url_c);
1815 omnibox_view->Update();
1816 EXPECT_EQ(url_c, omnibox_view->GetText());
1818 // The same test, but using RevertAll() to reset search term replacement.
1819 test_toolbar_model->set_text(url_a);
1820 omnibox_view->Update();
1821 EXPECT_EQ(url_a, omnibox_view->GetText());
1822 browser()->toolbar_model()->set_url_replacement_enabled(false);
1823 test_toolbar_model->set_text(url_b);
1824 omnibox_view->Update();
1825 EXPECT_EQ(url_a, omnibox_view->GetText());
1826 omnibox_view->RevertAll();
1827 EXPECT_EQ(url_b, omnibox_view->GetText());
1828 test_toolbar_model->set_text(url_c);
1829 omnibox_view->Update();
1830 EXPECT_EQ(url_c, omnibox_view->GetText());
1833 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, InputResetsSearchTermReplacement) {
1834 browser()->toolbar_model()->set_url_replacement_enabled(false);
1835 chrome::FocusLocationBar(browser());
1836 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
1837 EXPECT_TRUE(browser()->toolbar_model()->url_replacement_enabled());