summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc
blob: b75ee6bfebc98d1e2b4a9d814ace0ff269b63ec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/string_util.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/search/instant_overlay.h"
#include "chrome/browser/ui/search/instant_test_utils.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/search_types.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "googleurl/src/gurl.h"
#include "net/dns/mock_host_resolver.h"

// !!! IMPORTANT !!!
// These tests are run against a mock GWS using the web-page-replay system.
// If you change a test, you MUST re-record the mock GWS session.
// See: src/chrome/test/data/search/tools/instant_extended_manual_tests.py
// for details.

// Instant extended tests that need to be run manually because they need to
// talk to the external network. All tests in this file should be marked as
// "MANUAL_" unless they are disabled.
class InstantExtendedManualTest : public InProcessBrowserTest,
                                  public InstantTestBase {
 public:
  InstantExtendedManualTest() {
    host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
    host_resolver_proc_->AllowDirectLookup("*");
    scoped_host_resolver_proc_.reset(
        new net::ScopedDefaultHostResolverProc(host_resolver_proc_.get()));
  }

  virtual ~InstantExtendedManualTest() {
    scoped_host_resolver_proc_.reset();
    host_resolver_proc_ = NULL;
  }

  virtual void SetUpOnMainThread() OVERRIDE {
    const testing::TestInfo* const test_info =
        testing::UnitTest::GetInstance()->current_test_info();
    ASSERT_TRUE(StartsWithASCII(test_info->name(), "MANUAL_", true) ||
                StartsWithASCII(test_info->name(), "DISABLED_", true));
  }

 protected:
  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
    chrome::EnableInstantExtendedAPIForTesting();
  }

  content::WebContents* active_tab() {
    return browser()->tab_strip_model()->GetActiveWebContents();
  }

  bool PressBackspace() {
    return ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK,
                                           false, false, false, false);
  }

  bool PressBackspaceAndWaitForSuggestions() {
    content::WindowedNotificationObserver observer(
        chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
        content::NotificationService::AllSources());
    bool result = PressBackspace();
    observer.Wait();
    return result;
  }

  bool PressBackspaceAndWaitForOverlayToShow() {
    InstantTestModelObserver observer(
        instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
    return PressBackspace() && observer.WaitForExpectedOverlayState() ==
        SearchMode::MODE_SEARCH_SUGGESTIONS;
  }

  void PressEnterAndWaitForNavigation() {
    content::WindowedNotificationObserver nav_observer(
        content::NOTIFICATION_NAV_ENTRY_COMMITTED,
        content::NotificationService::AllSources());
    browser()->window()->GetLocationBar()->AcceptInput();
    nav_observer.Wait();
  }

  bool PressEnterAndWaitForNavigationWithTitle(content::WebContents* contents,
                                               const string16& title) {
    content::TitleWatcher title_watcher(contents, title);
    content::WindowedNotificationObserver nav_observer(
        content::NOTIFICATION_NAV_ENTRY_COMMITTED,
        content::NotificationService::AllSources());
    browser()->window()->GetLocationBar()->AcceptInput();
    nav_observer.Wait();
    return title_watcher.WaitAndGetTitle() == title;
  }

  GURL GetActiveTabURL() {
    return active_tab()->GetController().GetActiveEntry()->GetURL();
  }

  bool GetSelectionState(bool* selected) {
    return GetBoolFromJS(instant()->GetOverlayContents(),
                         "google.ac.gs().api.i()", selected);
  }

  bool OverlayIsGoogle() {
    content::WebContents* overlay_contents = instant()->GetOverlayContents();
    return overlay_contents &&
        overlay_contents->GetTitle() == ASCIIToUTF16("Google");
  }

 private:
  scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
  scoped_ptr<net::ScopedDefaultHostResolverProc> scoped_host_resolver_proc_;
};

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_OmniboxFocusLoadsInstant) {
  set_browser(browser());

  // Explicitly unfocus the omnibox.
  EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
  ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);

  EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
  EXPECT_FALSE(omnibox()->model()->has_focus());

  // Delete any existing overlay.
  instant()->overlay_.reset();
  EXPECT_FALSE(instant()->GetOverlayContents());

  // Refocus the omnibox. The InstantController should've preloaded Instant.
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
  EXPECT_TRUE(omnibox()->model()->has_focus());

  // Check that the page supports Instant, but it isn't showing.
  ASSERT_TRUE(instant()->overlay());
  EXPECT_TRUE(instant()->overlay()->supports_instant());
  EXPECT_FALSE(instant()->IsOverlayingSearchResults());
  EXPECT_TRUE(instant()->model()->mode().is_default());
}

// TODO: http://crbug.com/230940
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       DISABLED_BackspaceFromQueryToSameQueryAndSearch) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "face" and expect Google to set gray text for "book" to suggest
  // [facebook], the query.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("face"));
  EXPECT_EQ(ASCIIToUTF16("face"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("book"), GetGrayText());

  // Backspace to the text "fac".
  EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
  EXPECT_EQ(ASCIIToUTF16("fac"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("ebook"), GetGrayText());

  // Press Enter. The page should show search results for [fac].
  EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
      instant()->GetOverlayContents(),
      ASCIIToUTF16("fac - Google Search")));
}

// TODO: http://crbug.com/230940
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       DISABLED_BackspaceFromQueryToOtherQueryAndSearch) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "fan" and expect Google to set gray text to "dango" to suggest
  // [fandango], the query.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("fan"));
  EXPECT_EQ(ASCIIToUTF16("fan"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("dango"), GetGrayText());

  // Backspace to the text "fa". Expect Google to set gray text for "cebook" to
  // suggest [facebook], the query.
  EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
  EXPECT_EQ(ASCIIToUTF16("fa"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("cebook"), GetGrayText());

  // Press Enter. Instant should clear gray text and submit the query [fa].
  EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
      instant()->GetOverlayContents(),
      ASCIIToUTF16("fa - Google Search")));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_BackspaceFromUrlToNonSelectedUrlAndSearch) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "facebook.c" and expect Google to set blue text to "om" to suggest
  // http://www.facebook.com/, the URL.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("facebook.c"));
  EXPECT_EQ(ASCIIToUTF16("facebook.com"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("om"), GetBlueText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Backspace to the text "facebook.c". Expect no suggestion text and no
  // selected suggestion.
  // Page won't actually show because it's showing "press enter to search".
  EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
  EXPECT_EQ(ASCIIToUTF16("facebook.c"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_FALSE(selected);

  // Press Enter. Instant should submit the query "facebook.c".
  EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
      active_tab(), ASCIIToUTF16("facebook.c - Google Search")));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_BackspaceFromUrlToUrlAndNavigate) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "facebook.com/" and expect Google to set blue text to "login.php" to
  // suggest http://www.facebook.com/login.php, the URL.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("facebook.com/"));
  EXPECT_EQ(ASCIIToUTF16("facebook.com/login.php"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("login.php"), GetBlueText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Backspace to the text "facebook.com/". There should be no suggestion text,
  // but the first suggestion should be selected.
  EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
  EXPECT_EQ(ASCIIToUTF16("facebook.com/"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
  selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Press Enter. Instant should navigate to facebook.com.
  PressEnterAndWaitForNavigation();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_BackspaceFromQueryToSelectedUrlAndNavigate) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "a.cop" and expect top match to be a search, not a url.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("a.cop"));
  EXPECT_EQ(ASCIIToUTF16("a.cop"), omnibox()->GetText());
  EXPECT_TRUE(instant()->last_match_was_search_);

  // Backspace to the text "a.co". Expect no suggestion text, but the
  // first suggestion should be selected URL "a.co".
  EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
  EXPECT_EQ(ASCIIToUTF16("a.co"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Press Enter. Instant should navigate to a.co/.
  PressEnterAndWaitForNavigation();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("amazon.com"));
}

// TODO: http://crbug.com/230491
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       DISABLED_BackspaceFromSelectedUrlToQueryAndSearch) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "e.co/" and expect the top suggestion to be the URL "e.co/".
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("e.co/"));
  EXPECT_EQ(ASCIIToUTF16("e.co/"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Backspace to the text "e.co". Expect Google to suggest the query [e.coli].
  EXPECT_TRUE(PressBackspaceAndWaitForOverlayToShow());
  EXPECT_EQ(ASCIIToUTF16("e.co"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  EXPECT_EQ(ASCIIToUTF16("li"), GetGrayText());
  selected = true;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_FALSE(selected);

  // Press Enter. Instant should search for "e.co".
  EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
      instant()->GetOverlayContents(),
      ASCIIToUTF16("e.co - Google Search")));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_TypeURLAndPressEnter) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "www.facebook.com" and expect the top suggestion to be the URL
  // facebook.com.
  ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("www.facebook.com"));
  EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Press Enter. Should navigate to facebook.com.
  PressEnterAndWaitForNavigation();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
}

// TODO: http://crbug.com/232088
IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       DISABLED_TypeAutocompletedURLAndPressEnter) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "www.facebook." and expect the top suggestion to be the URL
  // www.facebook.com.
  SetOmniboxTextAndWaitForSuggestion("www.facebook.");
  EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
  EXPECT_EQ(ASCIIToUTF16("com"), GetBlueText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Press Enter. Should navigate to facebook.com.
  PressEnterAndWaitForNavigation();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_PasteURLAndPressEnter) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Paste "www.facebook.com" and expect the top suggestion to be the URL
  // facebook.com.
  InstantTestModelObserver observer(
      instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
  omnibox()->OnBeforePossibleChange();
  omnibox()->model()->on_paste();
  SetOmniboxText("www.facebook.com");
  omnibox()->OnAfterPossibleChange();
  ASSERT_EQ(SearchMode::MODE_SEARCH_SUGGESTIONS,
            observer.WaitForExpectedOverlayState());
  EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
  EXPECT_EQ(string16(), GetBlueText());
  bool selected = false;
  EXPECT_TRUE(GetSelectionState(&selected));
  EXPECT_TRUE(selected);

  // Press Enter. Should navigate to facebook.com.
  PressEnterAndWaitForNavigation();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_PasteAndGo) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // "Paste and Go" with the text www.facebook.com.
  content::WindowedNotificationObserver nav_observer(
      content::NOTIFICATION_NAV_ENTRY_COMMITTED,
      content::NotificationService::AllSources());
  omnibox()->model()->PasteAndGo(ASCIIToUTF16("www.facebook.com"));
  nav_observer.Wait();
  EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
}

IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
                       MANUAL_TypeSearchAndPressControlEnter) {
  set_browser(browser());
  FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
  EXPECT_TRUE(OverlayIsGoogle());

  // Type "example" and expect Google to suggest a query, i.e., no blue text.
  SetOmniboxTextAndWaitForSuggestion("example");
  EXPECT_EQ(ASCIIToUTF16("example"), omnibox()->GetText());
  EXPECT_EQ(string16(), GetBlueText());

  // Press ctrl+enter and expect to navigate to example.com.
  content::WindowedNotificationObserver nav_observer(
      content::NOTIFICATION_NAV_ENTRY_COMMITTED,
      content::NotificationService::AllSources());
  omnibox()->model()->OnControlKeyChanged(true);
  browser()->window()->GetLocationBar()->AcceptInput();
  nav_observer.Wait();
  // example.com redirects to iana.
  EXPECT_TRUE(GetActiveTabURL().DomainIs("example.com") ||
              GetActiveTabURL().DomainIs("iana.org"));
}