Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: chrome/browser/ui/search/instant_extended_manual_browsertest.cc

Issue 14235006: Rename Instant browser tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@storage_unit_test
Patch Set: Rebase to upstream to avoid AUTHORS conflict Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 #include "base/string_util.h"
6 #include "chrome/browser/search/search.h"
7 #include "chrome/browser/task_manager/task_manager.h"
8 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/host_desktop.h"
12 #include "chrome/browser/ui/omnibox/omnibox_view.h"
13 #include "chrome/browser/ui/search/instant_overlay.h"
14 #include "chrome/browser/ui/search/instant_test_utils.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/search_types.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/interactive_test_utils.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/navigation_controller.h"
22 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h"
27 #include "googleurl/src/gurl.h"
28 #include "net/dns/mock_host_resolver.h"
29
30 // !!! IMPORTANT !!!
31 // These tests are run against a mock GWS using the web-page-replay system.
32 // If you change a test, you MUST re-record the mock GWS session.
33 // See: src/chrome/test/data/search/tools/instant_extended_manual_tests.py
34 // for details.
35
36 // Instant extended tests that need to be run manually because they need to
37 // talk to the external network. All tests in this file should be marked as
38 // "MANUAL_" unless they are disabled.
39 class InstantExtendedManualTest : public InProcessBrowserTest,
40 public InstantTestBase {
41 public:
42 InstantExtendedManualTest() {
43 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL);
44 host_resolver_proc_->AllowDirectLookup("*");
45 scoped_host_resolver_proc_.reset(
46 new net::ScopedDefaultHostResolverProc(host_resolver_proc_.get()));
47 }
48
49 virtual ~InstantExtendedManualTest() {
50 scoped_host_resolver_proc_.reset();
51 host_resolver_proc_ = NULL;
52 }
53
54 virtual void SetUpOnMainThread() OVERRIDE {
55 const testing::TestInfo* const test_info =
56 testing::UnitTest::GetInstance()->current_test_info();
57 ASSERT_TRUE(StartsWithASCII(test_info->name(), "MANUAL_", true) ||
58 StartsWithASCII(test_info->name(), "DISABLED_", true));
59 }
60
61 protected:
62 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
63 chrome::EnableInstantExtendedAPIForTesting();
64 }
65
66 content::WebContents* active_tab() {
67 return browser()->tab_strip_model()->GetActiveWebContents();
68 }
69
70 bool PressBackspace() {
71 return ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_BACK,
72 false, false, false, false);
73 }
74
75 bool PressBackspaceAndWaitForSuggestions() {
76 content::WindowedNotificationObserver observer(
77 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
78 content::NotificationService::AllSources());
79 bool result = PressBackspace();
80 observer.Wait();
81 return result;
82 }
83
84 bool PressBackspaceAndWaitForOverlayToShow() {
85 InstantTestModelObserver observer(
86 instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
87 return PressBackspace() && observer.WaitForExpectedOverlayState();
88 }
89
90 void PressEnterAndWaitForNavigation() {
91 content::WindowedNotificationObserver nav_observer(
92 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
93 content::NotificationService::AllSources());
94 browser()->window()->GetLocationBar()->AcceptInput();
95 nav_observer.Wait();
96 }
97
98 bool PressEnterAndWaitForNavigationWithTitle(content::WebContents* contents,
99 const string16& title) {
100 content::TitleWatcher title_watcher(contents, title);
101 content::WindowedNotificationObserver nav_observer(
102 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
103 content::NotificationService::AllSources());
104 browser()->window()->GetLocationBar()->AcceptInput();
105 nav_observer.Wait();
106 return title_watcher.WaitAndGetTitle() == title;
107 }
108
109 GURL GetActiveTabURL() {
110 return active_tab()->GetController().GetActiveEntry()->GetURL();
111 }
112
113 bool GetSelectionState(bool* selected) {
114 return GetBoolFromJS(instant()->GetOverlayContents(),
115 "google.ac.gs().api.i()", selected);
116 }
117
118 bool OverlayIsGoogle() {
119 content::WebContents* overlay_contents = instant()->GetOverlayContents();
120 return overlay_contents &&
121 overlay_contents->GetTitle() == ASCIIToUTF16("Google");
122 }
123
124 private:
125 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_;
126 scoped_ptr<net::ScopedDefaultHostResolverProc> scoped_host_resolver_proc_;
127 };
128
129 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
130 MANUAL_OmniboxFocusLoadsInstant) {
131 set_browser(browser());
132
133 // Explicitly unfocus the omnibox.
134 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
135 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
136
137 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
138 EXPECT_FALSE(omnibox()->model()->has_focus());
139
140 // Delete any existing overlay.
141 instant()->overlay_.reset();
142 EXPECT_FALSE(instant()->GetOverlayContents());
143
144 // Refocus the omnibox. The InstantController should've preloaded Instant.
145 FocusOmniboxAndWaitForInstantExtendedSupport();
146 EXPECT_TRUE(OverlayIsGoogle());
147
148 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
149 EXPECT_TRUE(omnibox()->model()->has_focus());
150
151 // Check that the page supports Instant, but it isn't showing.
152 ASSERT_TRUE(instant()->overlay());
153 EXPECT_TRUE(instant()->overlay()->supports_instant());
154 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
155 EXPECT_TRUE(instant()->model()->mode().is_default());
156 }
157
158 // TODO: http://crbug.com/230940
159 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
160 DISABLED_BackspaceFromQueryToSameQueryAndSearch) {
161 set_browser(browser());
162 FocusOmniboxAndWaitForInstantExtendedSupport();
163 EXPECT_TRUE(OverlayIsGoogle());
164
165 // Type "face" and expect Google to set gray text for "book" to suggest
166 // [facebook], the query.
167 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("face"));
168 EXPECT_EQ(ASCIIToUTF16("face"), omnibox()->GetText());
169 EXPECT_EQ(ASCIIToUTF16("book"), GetGrayText());
170
171 // Backspace to the text "fac".
172 EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
173 EXPECT_EQ(ASCIIToUTF16("fac"), omnibox()->GetText());
174 EXPECT_EQ(ASCIIToUTF16("ebook"), GetGrayText());
175
176 // Press Enter. The page should show search results for [fac].
177 EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
178 instant()->GetOverlayContents(),
179 ASCIIToUTF16("fac - Google Search")));
180 }
181
182 // TODO: http://crbug.com/230940
183 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
184 DISABLED_BackspaceFromQueryToOtherQueryAndSearch) {
185 set_browser(browser());
186 FocusOmniboxAndWaitForInstantExtendedSupport();
187 EXPECT_TRUE(OverlayIsGoogle());
188
189 // Type "fan" and expect Google to set gray text to "dango" to suggest
190 // [fandango], the query.
191 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("fan"));
192 EXPECT_EQ(ASCIIToUTF16("fan"), omnibox()->GetText());
193 EXPECT_EQ(ASCIIToUTF16("dango"), GetGrayText());
194
195 // Backspace to the text "fa". Expect Google to set gray text for "cebook" to
196 // suggest [facebook], the query.
197 EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
198 EXPECT_EQ(ASCIIToUTF16("fa"), omnibox()->GetText());
199 EXPECT_EQ(ASCIIToUTF16("cebook"), GetGrayText());
200
201 // Press Enter. Instant should clear gray text and submit the query [fa].
202 EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
203 instant()->GetOverlayContents(),
204 ASCIIToUTF16("fa - Google Search")));
205 }
206
207 // TODO: http://crbug.com/230537
208 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
209 DISABLED_BackspaceFromUrlToNonSelectedUrlAndSearch) {
210 set_browser(browser());
211 FocusOmniboxAndWaitForInstantExtendedSupport();
212 EXPECT_TRUE(OverlayIsGoogle());
213
214 // Type "facebook.c" and expect Google to set blue text to "om" to suggest
215 // http://www.facebook.com/, the URL.
216 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("facebook.c"));
217 EXPECT_EQ(ASCIIToUTF16("facebook.com"), omnibox()->GetText());
218 EXPECT_EQ(ASCIIToUTF16("om"), GetBlueText());
219 bool selected = false;
220 EXPECT_TRUE(GetSelectionState(&selected));
221 EXPECT_TRUE(selected);
222
223 // Backspace to the text "facebook.c". Expect no suggestion text and no
224 // selected suggestion.
225 // Page won't actually show because it's showing "press enter to search".
226 EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
227 EXPECT_EQ(ASCIIToUTF16("facebook.c"), omnibox()->GetText());
228 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
229 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
230 EXPECT_TRUE(GetSelectionState(&selected));
231 EXPECT_FALSE(selected);
232
233 // Press Enter. Instant should submit the query "facebook.c".
234 EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
235 active_tab(), ASCIIToUTF16("facebook.c - Google Search")));
236 }
237
238 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
239 MANUAL_BackspaceFromUrlToUrlAndNavigate) {
240 set_browser(browser());
241 FocusOmniboxAndWaitForInstantExtendedSupport();
242 EXPECT_TRUE(OverlayIsGoogle());
243
244 // Type "facebook.com/" and expect Google to set blue text to "login.php" to
245 // suggest http://www.facebook.com/login.php, the URL.
246 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("facebook.com/"));
247 EXPECT_EQ(ASCIIToUTF16("facebook.com/login.php"), omnibox()->GetText());
248 EXPECT_EQ(ASCIIToUTF16("login.php"), GetBlueText());
249 bool selected = false;
250 EXPECT_TRUE(GetSelectionState(&selected));
251 EXPECT_TRUE(selected);
252
253 // Backspace to the text "facebook.com/". There should be no suggestion text,
254 // but the first suggestion should be selected.
255 EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
256 EXPECT_EQ(ASCIIToUTF16("facebook.com/"), omnibox()->GetText());
257 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
258 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
259 selected = false;
260 EXPECT_TRUE(GetSelectionState(&selected));
261 EXPECT_TRUE(selected);
262
263 // Press Enter. Instant should navigate to facebook.com.
264 PressEnterAndWaitForNavigation();
265 EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
266 }
267
268 // TODO: http://crbug.com/230537
269 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
270 DISABLED_BackspaceFromQueryToSelectedUrlAndNavigate) {
271 set_browser(browser());
272 FocusOmniboxAndWaitForInstantExtendedSupport();
273 EXPECT_TRUE(OverlayIsGoogle());
274
275 // Type "a.cop" and expect Google to set gray text to "land" to suggest the
276 // query [a.copland].
277 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("a.cop"));
278 EXPECT_EQ(ASCIIToUTF16("a.cop"), omnibox()->GetText());
279 EXPECT_EQ(ASCIIToUTF16("land"), GetGrayText());
280
281 // Backspace to the text "a.co". Expect no suggestion text, but the
282 // first suggestion should be selected URL "a.co".
283 EXPECT_TRUE(PressBackspaceAndWaitForSuggestions());
284 EXPECT_EQ(ASCIIToUTF16("a.co"), omnibox()->GetText());
285 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
286 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
287 bool selected = false;
288 EXPECT_TRUE(GetSelectionState(&selected));
289 EXPECT_TRUE(selected);
290
291 // Press Enter. Instant should navigate to a.co/.
292 PressEnterAndWaitForNavigation();
293 EXPECT_TRUE(GetActiveTabURL().DomainIs("amazon.com"));
294 }
295
296 // TODO: http://crbug.com/230491
297 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
298 DISABLED_BackspaceFromSelectedUrlToQueryAndSearch) {
299 set_browser(browser());
300 FocusOmniboxAndWaitForInstantExtendedSupport();
301 EXPECT_TRUE(OverlayIsGoogle());
302
303 // Type "e.co/" and expect the top suggestion to be the URL "e.co/".
304 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("e.co/"));
305 EXPECT_EQ(ASCIIToUTF16("e.co/"), omnibox()->GetText());
306 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
307 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
308 bool selected = false;
309 EXPECT_TRUE(GetSelectionState(&selected));
310 EXPECT_TRUE(selected);
311
312 // Backspace to the text "e.co". Expect Google to suggest the query [e.coli].
313 EXPECT_TRUE(PressBackspaceAndWaitForOverlayToShow());
314 EXPECT_EQ(ASCIIToUTF16("e.co"), omnibox()->GetText());
315 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
316 EXPECT_EQ(ASCIIToUTF16("li"), GetGrayText());
317 selected = true;
318 EXPECT_TRUE(GetSelectionState(&selected));
319 EXPECT_FALSE(selected);
320
321 // Press Enter. Instant should search for "e.co".
322 EXPECT_TRUE(PressEnterAndWaitForNavigationWithTitle(
323 instant()->GetOverlayContents(),
324 ASCIIToUTF16("e.co - Google Search")));
325 }
326
327 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_TypeURLAndPressEnter) {
328 set_browser(browser());
329 FocusOmniboxAndWaitForInstantExtendedSupport();
330 EXPECT_TRUE(OverlayIsGoogle());
331
332 // Type "www.facebook.com" and expect the top suggestion to be the URL
333 // facebook.com.
334 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("www.facebook.com"));
335 EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
336 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
337 bool selected = false;
338 EXPECT_TRUE(GetSelectionState(&selected));
339 EXPECT_TRUE(selected);
340
341 // Press Enter. Should navigate to facebook.com.
342 PressEnterAndWaitForNavigation();
343 EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
344 }
345
346 // TODO: http://crbug.com/232088
347 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
348 DISABLED_TypeAutocompletedURLAndPressEnter) {
349 set_browser(browser());
350 FocusOmniboxAndWaitForInstantExtendedSupport();
351 EXPECT_TRUE(OverlayIsGoogle());
352
353 // Type "www.facebook." and expect the top suggestion to be the URL
354 // www.facebook.com.
355 SetOmniboxTextAndWaitForSuggestion("www.facebook.");
356 EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
357 EXPECT_EQ(ASCIIToUTF16("com"), GetBlueText());
358 bool selected = false;
359 EXPECT_TRUE(GetSelectionState(&selected));
360 EXPECT_TRUE(selected);
361
362 // Press Enter. Should navigate to facebook.com.
363 PressEnterAndWaitForNavigation();
364 EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
365 }
366
367 // TODO: http://crbug.com/230537
368 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
369 DISABLED_PasteURLAndPressEnter) {
370 set_browser(browser());
371 FocusOmniboxAndWaitForInstantExtendedSupport();
372 EXPECT_TRUE(OverlayIsGoogle());
373
374 // Paste "www.facebook.com" and expect the top suggestion to be the URL
375 // facebook.com.
376 InstantTestModelObserver observer(
377 instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
378 omnibox()->OnBeforePossibleChange();
379 omnibox()->model()->on_paste();
380 SetOmniboxText("www.facebook.com");
381 omnibox()->OnAfterPossibleChange();
382 ASSERT_TRUE(observer.WaitForExpectedOverlayState());
383 EXPECT_EQ(ASCIIToUTF16("www.facebook.com"), omnibox()->GetText());
384 EXPECT_EQ(string16(), GetBlueText());
385 bool selected = false;
386 EXPECT_TRUE(GetSelectionState(&selected));
387 EXPECT_TRUE(selected);
388
389 // Press Enter. Should navigate to facebook.com.
390 PressEnterAndWaitForNavigation();
391 EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
392 }
393
394 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest, MANUAL_PasteAndGo) {
395 set_browser(browser());
396 FocusOmniboxAndWaitForInstantExtendedSupport();
397 EXPECT_TRUE(OverlayIsGoogle());
398
399 // "Paste and Go" with the text www.facebook.com.
400 content::WindowedNotificationObserver nav_observer(
401 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
402 content::NotificationService::AllSources());
403 omnibox()->model()->PasteAndGo(ASCIIToUTF16("www.facebook.com"));
404 nav_observer.Wait();
405 EXPECT_TRUE(GetActiveTabURL().DomainIs("facebook.com"));
406 }
407
408 IN_PROC_BROWSER_TEST_F(InstantExtendedManualTest,
409 MANUAL_TypeSearchAndPressControlEnter) {
410 set_browser(browser());
411 FocusOmniboxAndWaitForInstantExtendedSupport();
412 EXPECT_TRUE(OverlayIsGoogle());
413
414 // Type "example" and expect Google to suggest a query, i.e., no blue text.
415 SetOmniboxTextAndWaitForSuggestion("example");
416 EXPECT_EQ(ASCIIToUTF16("example"), omnibox()->GetText());
417 EXPECT_EQ(string16(), GetBlueText());
418
419 // Press ctrl+enter and expect to navigate to example.com.
420 content::WindowedNotificationObserver nav_observer(
421 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
422 content::NotificationService::AllSources());
423 omnibox()->model()->OnControlKeyChanged(true);
424 browser()->window()->GetLocationBar()->AcceptInput();
425 nav_observer.Wait();
426 // example.com redirects to iana.
427 EXPECT_TRUE(GetActiveTabURL().DomainIs("example.com") ||
428 GetActiveTabURL().DomainIs("iana.org"));
429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698