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

Side by Side Diff: chrome/browser/instant/instant_browsertest.cc

Issue 12520005: Move desktop-specific Instant bits to c/b/ui/search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/instant/OWNERS ('k') | chrome/browser/instant/instant_commit_type.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 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.
4
5 #include "chrome/browser/content_settings/host_content_settings_map.h"
6 #include "chrome/browser/history/history_service_factory.h"
7 #include "chrome/browser/instant/instant_overlay.h"
8 #include "chrome/browser/instant/instant_service.h"
9 #include "chrome/browser/instant/instant_service_factory.h"
10 #include "chrome/browser/instant/instant_test_utils.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search_engines/template_url_service.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/task_manager/task_manager.h"
15 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/host_desktop.h"
19 #include "chrome/browser/ui/omnibox/omnibox_view.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/url_constants.h"
22 #include "chrome/test/base/in_process_browser_test.h"
23 #include "chrome/test/base/interactive_test_utils.h"
24 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/web_contents.h"
27 #include "content/public/test/browser_test_utils.h"
28 #include "grit/generated_resources.h"
29 #include "ui/base/l10n/l10n_util.h"
30
31 class InstantTest : public InProcessBrowserTest, public InstantTestBase {
32 protected:
33 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
34 ASSERT_TRUE(test_server()->Start());
35 GURL instant_url = test_server()->GetURL("files/instant.html?");
36 InstantTestBase::Init(instant_url);
37 }
38
39 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
40 return GetIntFromJS(contents, "onvisibilitycalls", &onvisibilitycalls_) &&
41 GetIntFromJS(contents, "onchangecalls", &onchangecalls_) &&
42 GetIntFromJS(contents, "onsubmitcalls", &onsubmitcalls_) &&
43 GetIntFromJS(contents, "oncancelcalls", &oncancelcalls_) &&
44 GetIntFromJS(contents, "onresizecalls", &onresizecalls_) &&
45 GetStringFromJS(contents, "value", &value_) &&
46 GetBoolFromJS(contents, "verbatim", &verbatim_) &&
47 GetIntFromJS(contents, "height", &height_);
48 }
49
50 int onvisibilitycalls_;
51 int onchangecalls_;
52 int onsubmitcalls_;
53 int oncancelcalls_;
54 int onresizecalls_;
55
56 std::string value_;
57 bool verbatim_;
58 int height_;
59 };
60
61 // Test that Instant is preloaded when the omnibox is focused.
62 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) {
63 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
64
65 // Explicitly unfocus the omnibox.
66 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
67 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
68
69 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
70 EXPECT_FALSE(omnibox()->model()->has_focus());
71
72 // Delete any existing overlay.
73 instant()->overlay_.reset();
74 EXPECT_FALSE(instant()->GetOverlayContents());
75
76 // Refocus the omnibox. The InstantController should've preloaded Instant.
77 FocusOmniboxAndWaitForInstantSupport();
78
79 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
80 EXPECT_TRUE(omnibox()->model()->has_focus());
81
82 content::WebContents* overlay = instant()->GetOverlayContents();
83 EXPECT_TRUE(overlay);
84
85 // Check that the page supports Instant, but it isn't showing.
86 EXPECT_TRUE(instant()->overlay_->supports_instant());
87 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
88 EXPECT_TRUE(instant()->model()->mode().is_default());
89
90 // Adding a new tab shouldn't delete or recreate the overlay; otherwise,
91 // what's the point of preloading?
92 AddBlankTabAndShow(browser());
93 EXPECT_EQ(overlay, instant()->GetOverlayContents());
94
95 // Unfocusing and refocusing the omnibox should also preserve the overlay.
96 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
97 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
98
99 FocusOmnibox();
100 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
101
102 EXPECT_EQ(overlay, instant()->GetOverlayContents());
103
104 // Doing a search should also use the same preloaded page.
105 SetOmniboxTextAndWaitForOverlayToShow("query");
106 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
107 EXPECT_EQ(overlay, instant()->GetOverlayContents());
108 }
109
110 // Flakes on Windows and Mac: http://crbug.com/170677
111 #if defined(OS_WIN) || defined(OS_MACOSX)
112 #define MAYBE_OnChangeEvent DISABLED_OnChangeEvent
113 #else
114 #define MAYBE_OnChangeEvent OnChangeEvent
115 #endif
116 // Test that the onchange event is dispatched upon typing in the omnibox.
117 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) {
118 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
119 FocusOmniboxAndWaitForInstantSupport();
120
121 // Use the Instant page as the active tab, so we can exploit its visibility
122 // handler to check visibility transitions.
123 ui_test_utils::NavigateToURL(browser(), instant_url());
124 content::WebContents* active_tab =
125 browser()->tab_strip_model()->GetActiveWebContents();
126
127 int active_tab_onvisibilitycalls = -1;
128 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls",
129 &active_tab_onvisibilitycalls));
130 EXPECT_EQ(0, active_tab_onvisibilitycalls);
131
132 // Typing "query" into the omnibox causes one or more onchange events. The
133 // page suggested "query suggestion" is inline autocompleted into the omnibox,
134 // causing another onchange event.
135 SetOmniboxTextAndWaitForOverlayToShow("query");
136 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText());
137 int min_onchangecalls = 2;
138
139 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
140 EXPECT_LE(min_onchangecalls, onchangecalls_);
141 min_onchangecalls = onchangecalls_;
142
143 // Change the query and confirm more onchange events are sent.
144 SetOmniboxText("search");
145 ++min_onchangecalls;
146
147 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
148 EXPECT_LE(min_onchangecalls, onchangecalls_);
149
150 // The overlay was shown once, and the active tab was never hidden.
151 EXPECT_EQ(1, onvisibilitycalls_);
152 active_tab_onvisibilitycalls = -1;
153 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls",
154 &active_tab_onvisibilitycalls));
155 EXPECT_EQ(0, active_tab_onvisibilitycalls);
156 }
157
158 // Test that the onsubmit event is dispatched upon pressing Enter.
159 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) {
160 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
161 FocusOmniboxAndWaitForInstantSupport();
162 SetOmniboxTextAndWaitForOverlayToShow("search");
163
164 // Stash a reference to the overlay, so we can refer to it after commit.
165 content::WebContents* overlay = instant()->GetOverlayContents();
166 EXPECT_TRUE(overlay);
167
168 // The state of the searchbox before the commit.
169 EXPECT_TRUE(UpdateSearchState(overlay));
170 EXPECT_EQ("search", value_);
171 EXPECT_FALSE(verbatim_);
172 EXPECT_EQ(0, onsubmitcalls_);
173 EXPECT_EQ(1, onvisibilitycalls_);
174
175 // Before the commit, the active tab is the NTP (i.e., not Instant).
176 content::WebContents* active_tab =
177 browser()->tab_strip_model()->GetActiveWebContents();
178 EXPECT_NE(overlay, active_tab);
179 EXPECT_EQ(1, active_tab->GetController().GetEntryCount());
180 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
181 omnibox()->model()->PermanentURL().spec());
182
183 // Commit the search by pressing Enter.
184 browser()->window()->GetLocationBar()->AcceptInput();
185
186 // After the commit, Instant should not be showing.
187 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
188 EXPECT_TRUE(instant()->model()->mode().is_default());
189
190 // The old overlay is deleted and a new one is created.
191 EXPECT_TRUE(instant()->GetOverlayContents());
192 EXPECT_NE(instant()->GetOverlayContents(), overlay);
193
194 // Check that the current active tab is indeed what was once the overlay.
195 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents());
196
197 // We should have two navigation entries, one for the NTP, and one for the
198 // Instant search that was committed.
199 EXPECT_EQ(2, overlay->GetController().GetEntryCount());
200
201 // Check that the omnibox contains the Instant URL we loaded.
202 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL());
203
204 // Check that the searchbox API values have been reset.
205 std::string value;
206 EXPECT_TRUE(GetStringFromJS(overlay,
207 "chrome.embeddedSearch.searchBox.value", &value));
208 EXPECT_EQ("", value);
209
210 // However, the page should've correctly received the committed query.
211 EXPECT_TRUE(UpdateSearchState(overlay));
212 EXPECT_EQ("search", value_);
213 EXPECT_TRUE(verbatim_);
214 EXPECT_EQ(1, onsubmitcalls_);
215 EXPECT_EQ(1, onvisibilitycalls_);
216 }
217
218 // Test that the oncancel event is dispatched upon clicking on the overlay.
219 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) {
220 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
221 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
222 FocusOmniboxAndWaitForInstantSupport();
223 SetOmniboxTextAndWaitForOverlayToShow("search");
224
225 // Stash a reference to the overlay, so we can refer to it after commit.
226 content::WebContents* overlay = instant()->GetOverlayContents();
227 EXPECT_TRUE(overlay);
228
229 // The state of the searchbox before the commit.
230 EXPECT_TRUE(UpdateSearchState(overlay));
231 EXPECT_EQ("search", value_);
232 EXPECT_FALSE(verbatim_);
233 EXPECT_EQ(0, oncancelcalls_);
234 EXPECT_EQ(1, onvisibilitycalls_);
235
236 // Before the commit, the active tab is the NTP (i.e., not Instant).
237 content::WebContents* active_tab =
238 browser()->tab_strip_model()->GetActiveWebContents();
239 EXPECT_NE(overlay, active_tab);
240 EXPECT_EQ(1, active_tab->GetController().GetEntryCount());
241 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
242 omnibox()->model()->PermanentURL().spec());
243
244 // Commit the search by clicking on the overlay.
245 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
246
247 // After the commit, Instant should not be showing.
248 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
249 EXPECT_TRUE(instant()->model()->mode().is_default());
250
251 // The old overlay is deleted and a new one is created.
252 EXPECT_TRUE(instant()->GetOverlayContents());
253 EXPECT_NE(instant()->GetOverlayContents(), overlay);
254
255 // Check that the current active tab is indeed what was once the overlay.
256 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents());
257
258 // We should have two navigation entries, one for the NTP, and one for the
259 // Instant search that was committed.
260 EXPECT_EQ(2, overlay->GetController().GetEntryCount());
261
262 // Check that the omnibox contains the Instant URL we loaded.
263 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL());
264
265 // Check that the searchbox API values have been reset.
266 std::string value;
267 EXPECT_TRUE(GetStringFromJS(overlay,
268 "chrome.embeddedSearch.searchBox.value", &value));
269 EXPECT_EQ("", value);
270
271 // However, the page should've correctly received the committed query.
272 EXPECT_TRUE(UpdateSearchState(overlay));
273 EXPECT_EQ("search", value_);
274 EXPECT_TRUE(verbatim_);
275 EXPECT_EQ(1, oncancelcalls_);
276 EXPECT_EQ(1, onvisibilitycalls_);
277 }
278
279 // Test that the onreisze event is dispatched upon typing in the omnibox.
280 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) {
281 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
282
283 FocusOmniboxAndWaitForInstantSupport();
284
285 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
286 EXPECT_EQ(0, onresizecalls_);
287 EXPECT_EQ(0, height_);
288
289 // Type a query into the omnibox. This should cause an onresize() event, with
290 // a valid (non-zero) height.
291 SetOmniboxTextAndWaitForOverlayToShow("search");
292
293 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
294 EXPECT_EQ(1, onresizecalls_);
295 EXPECT_LT(0, height_);
296 }
297
298 // Test that the INSTANT_COMPLETE_NOW behavior works as expected.
299 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) {
300 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
301 FocusOmniboxAndWaitForInstantSupport();
302
303 // Tell the JS to request the given behavior.
304 EXPECT_TRUE(ExecuteScript("behavior = 'now'"));
305
306 // Type a query, causing the hardcoded "query suggestion" to be returned.
307 SetOmniboxTextAndWaitForOverlayToShow("query");
308
309 // Get what's showing in the omnibox, and what's highlighted.
310 string16 text = omnibox()->GetText();
311 size_t start = 0, end = 0;
312 omnibox()->GetSelectionBounds(&start, &end);
313 if (start > end)
314 std::swap(start, end);
315
316 EXPECT_EQ(ASCIIToUTF16("query suggestion"), text);
317 EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start));
318 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion());
319 }
320
321 // Test that the INSTANT_COMPLETE_NEVER behavior works as expected.
322 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) {
323 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
324 FocusOmniboxAndWaitForInstantSupport();
325
326 // Tell the JS to request the given behavior.
327 EXPECT_TRUE(ExecuteScript("behavior = 'never'"));
328
329 // Type a query, causing the hardcoded "query suggestion" to be returned.
330 SetOmniboxTextAndWaitForOverlayToShow("query");
331
332 // Get what's showing in the omnibox, and what's highlighted.
333 string16 text = omnibox()->GetText();
334 size_t start = 0, end = 0;
335 omnibox()->GetSelectionBounds(&start, &end);
336 if (start > end)
337 std::swap(start, end);
338
339 EXPECT_EQ(ASCIIToUTF16("query"), text);
340 EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start));
341 EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion());
342 }
343
344 // Test that a valid suggestion is accepted.
345 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) {
346 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
347 FocusOmniboxAndWaitForInstantSupport();
348
349 // Tell the JS to use the given suggestion.
350 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]"));
351
352 // Type a query, causing "query completion" to be returned as the suggestion.
353 SetOmniboxTextAndWaitForOverlayToShow("query");
354 EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText());
355 }
356
357 // Test that an invalid suggestion is rejected.
358 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) {
359 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
360 FocusOmniboxAndWaitForInstantSupport();
361
362 // Tell the JS to use an object in an invalid format.
363 EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }"));
364
365 // Type a query, but expect no suggestion.
366 SetOmniboxTextAndWaitForOverlayToShow("query");
367 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText());
368 }
369
370 // Test that various forms of empty suggestions are rejected.
371 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) {
372 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
373 FocusOmniboxAndWaitForInstantSupport();
374
375 EXPECT_TRUE(ExecuteScript("suggestion = {}"));
376 SetOmniboxTextAndWaitForOverlayToShow("query");
377 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText());
378
379 omnibox()->RevertAll();
380
381 EXPECT_TRUE(ExecuteScript("suggestion = []"));
382 SetOmniboxTextAndWaitForOverlayToShow("query sugg");
383 EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText());
384
385 omnibox()->RevertAll();
386
387 EXPECT_TRUE(ExecuteScript("suggestion = [{}]"));
388 SetOmniboxTextAndWaitForOverlayToShow("query suggest");
389 EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText());
390 }
391
392 // Tests that a previous search suggestion is not discarded if it's not stale.
393 IN_PROC_BROWSER_TEST_F(InstantTest, SearchSuggestionIsNotDiscarded) {
394 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
395 FocusOmniboxAndWaitForInstantSupport();
396
397 SetOmniboxTextAndWaitForOverlayToShow("query");
398 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText());
399 SetOmniboxText("query sugg");
400 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText());
401 }
402
403 // Test that Instant doesn't process URLs.
404 IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) {
405 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
406 FocusOmniboxAndWaitForInstantSupport();
407
408 // Note that we are not actually navigating to these URLs yet. We are just
409 // typing them into the omnibox (without pressing Enter) and checking that
410 // Instant doesn't try to process them.
411 SetOmniboxText(content::kChromeUICrashURL);
412 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
413 EXPECT_TRUE(instant()->model()->mode().is_default());
414
415 SetOmniboxText(content::kChromeUIHangURL);
416 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
417 EXPECT_TRUE(instant()->model()->mode().is_default());
418
419 SetOmniboxText(content::kChromeUIKillURL);
420 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
421 EXPECT_TRUE(instant()->model()->mode().is_default());
422
423 // Make sure that the URLs were never sent to the overlay page.
424 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
425 EXPECT_EQ("", value_);
426 }
427
428 // Test that Instant doesn't fire for intranet paths that look like searches.
429 // http://crbug.com/99836
430 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) {
431 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
432
433 // Navigate to a URL that looks like a search (when the scheme is stripped).
434 // It's okay if the host is bogus or the navigation fails, since we only care
435 // that Instant doesn't act on it.
436 ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga"));
437 EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText());
438
439 EXPECT_TRUE(instant()->GetOverlayContents());
440 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
441 EXPECT_TRUE(instant()->model()->mode().is_default());
442 }
443
444 // Test that transitions between searches and non-searches work as expected.
445 IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) {
446 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
447 FocusOmniboxAndWaitForInstantSupport();
448
449 // Type a search, and immediately a URL, without waiting for Instant to show.
450 // The page is told about the search. Though the page isn't told about the
451 // subsequent URL, it invalidates the search, so a blank query is sent in its
452 // place to indicate that the search is "out of date".
453 SetOmniboxText("query");
454 SetOmniboxText("http://monstrous/nightmare");
455 int min_onchangecalls = 2;
456
457 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
458 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
459 EXPECT_TRUE(instant()->model()->mode().is_default());
460 EXPECT_EQ("", value_);
461 EXPECT_LE(min_onchangecalls, onchangecalls_);
462 min_onchangecalls = onchangecalls_;
463
464 // Type a search. Instant should show.
465 SetOmniboxTextAndWaitForOverlayToShow("search");
466 ++min_onchangecalls;
467
468 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
469 EXPECT_TRUE(instant()->IsOverlayingSearchResults());
470 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
471 EXPECT_EQ("search", value_);
472 EXPECT_LE(min_onchangecalls, onchangecalls_);
473 min_onchangecalls = onchangecalls_;
474
475 // Type another URL. The overlay should be hidden.
476 SetOmniboxText("http://terrible/terror");
477 ++min_onchangecalls;
478
479 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
480 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
481 EXPECT_TRUE(instant()->model()->mode().is_default());
482 EXPECT_EQ("", value_);
483 EXPECT_LE(min_onchangecalls, onchangecalls_);
484 min_onchangecalls = onchangecalls_;
485
486 // Type the same search as before.
487 SetOmniboxTextAndWaitForOverlayToShow("search");
488 min_onchangecalls++;
489
490 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
491 EXPECT_TRUE(instant()->IsOverlayingSearchResults());
492 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
493 EXPECT_EQ("search", value_);
494 EXPECT_LE(min_onchangecalls, onchangecalls_);
495 min_onchangecalls = onchangecalls_;
496
497 // Revert the omnibox.
498 omnibox()->RevertAll();
499 min_onchangecalls++;
500
501 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
502 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
503 EXPECT_TRUE(instant()->model()->mode().is_default());
504 EXPECT_EQ("", value_);
505 EXPECT_LE(min_onchangecalls, onchangecalls_);
506 }
507
508 // Test that Instant can't be fooled into committing a URL.
509 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) {
510 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
511 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
512
513 // Type a URL. The Instant overlay shouldn't be showing.
514 SetOmniboxText("http://deadly/nadder");
515 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
516 EXPECT_TRUE(instant()->model()->mode().is_default());
517
518 // Unfocus and refocus the omnibox.
519 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
520 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
521 FocusOmnibox();
522
523 content::WebContents* overlay = instant()->GetOverlayContents();
524 EXPECT_TRUE(overlay);
525
526 // The omnibox text hasn't changed, so Instant still shouldn't be showing.
527 EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText());
528 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
529 EXPECT_TRUE(instant()->model()->mode().is_default());
530
531 // Commit the URL. The omnibox should reflect the URL minus the scheme.
532 browser()->window()->GetLocationBar()->AcceptInput();
533 content::WebContents* active_tab =
534 browser()->tab_strip_model()->GetActiveWebContents();
535 EXPECT_NE(overlay, active_tab);
536 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText());
537
538 // Instant shouldn't have done anything.
539 EXPECT_EQ(overlay, instant()->GetOverlayContents());
540 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
541 EXPECT_TRUE(instant()->model()->mode().is_default());
542 }
543
544 // Test that Instant can't be fooled into committing a URL.
545 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) {
546 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
547 FocusOmniboxAndWaitForInstantSupport();
548
549 // Type a query. This causes the overlay to be shown.
550 SetOmniboxTextAndWaitForOverlayToShow("query");
551
552 content::WebContents* overlay = instant()->GetOverlayContents();
553 EXPECT_TRUE(overlay);
554
555 // Type a URL. This causes the overlay to be hidden.
556 SetOmniboxText("http://hideous/zippleback");
557 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
558 EXPECT_TRUE(instant()->model()->mode().is_default());
559
560 // Pretend the omnibox got focus. It already had focus, so we are just trying
561 // to tickle a different code path.
562 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
563 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
564
565 // Commit the URL. As before, check that Instant wasn't committed.
566 browser()->window()->GetLocationBar()->AcceptInput();
567 content::WebContents* active_tab =
568 browser()->tab_strip_model()->GetActiveWebContents();
569 EXPECT_NE(overlay, active_tab);
570 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText());
571
572 // As before, Instant shouldn't have done anything.
573 EXPECT_EQ(overlay, instant()->GetOverlayContents());
574 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
575 EXPECT_TRUE(instant()->model()->mode().is_default());
576 }
577
578 // Test that a non-Instant search provider shows no overlays.
579 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) {
580 GURL instant_url = test_server()->GetURL("files/empty.html");
581 InstantTestBase::Init(instant_url);
582 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
583
584 // Focus the omnibox. When the support determination response comes back,
585 // Instant will destroy the non-Instant page, and attempt to recreate it.
586 // We can know this happened by looking at the blacklist.
587 EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url.spec()]);
588 FocusOmniboxAndWaitForInstantSupport();
589 EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url.spec()]);
590 }
591
592 // Test that the renderer doesn't crash if JavaScript is blocked.
593 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) {
594 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
596 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
597
598 // Wait for notification that the Instant API has been determined. As long as
599 // we get the notification we're good (the renderer didn't crash).
600 FocusOmniboxAndWaitForInstantSupport();
601 }
602
603 // Test that the overlay and active tab's visibility states are set correctly.
604 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) {
605 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
606 FocusOmniboxAndWaitForInstantSupport();
607
608 content::WebContents* active_tab =
609 browser()->tab_strip_model()->GetActiveWebContents();
610 content::WebContents* overlay = instant()->GetOverlayContents();
611
612 // Inititally, the active tab is showing; the overlay is not.
613 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
614 EXPECT_TRUE(CheckVisibilityIs(overlay, false));
615
616 // Type a query and wait for Instant to show.
617 SetOmniboxTextAndWaitForOverlayToShow("query");
618 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
619 EXPECT_TRUE(CheckVisibilityIs(overlay, true));
620
621 // Deleting the omnibox text should hide the overlay.
622 SetOmniboxText("");
623 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
624 EXPECT_TRUE(CheckVisibilityIs(overlay, false));
625
626 // Typing a query should show the overlay again.
627 SetOmniboxTextAndWaitForOverlayToShow("query");
628 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
629 EXPECT_TRUE(CheckVisibilityIs(overlay, true));
630
631 // Commit the overlay.
632 browser()->window()->GetLocationBar()->AcceptInput();
633 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents());
634 EXPECT_TRUE(CheckVisibilityIs(overlay, true));
635 }
636
637 // Test that the task manager identifies Instant's overlay correctly.
638 IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) {
639 // The browser starts with a new tab, so there's just one renderer initially.
640 TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
641 task_manager->StartUpdating();
642 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
643
644 string16 prefix = l10n_util::GetStringFUTF16(
645 IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, string16());
646
647 // There should be no Instant overlay yet.
648 for (int i = 0; i < task_manager->ResourceCount(); ++i) {
649 string16 title = task_manager->GetResourceTitle(i);
650 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix;
651 }
652
653 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
654 FocusOmnibox();
655
656 // Now there should be two renderers, the second being the Instant overlay.
657 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2);
658
659 int instant_overlays = 0;
660 for (int i = 0; i < task_manager->ResourceCount(); ++i) {
661 string16 title = task_manager->GetResourceTitle(i);
662 if (StartsWith(title, prefix, true))
663 ++instant_overlays;
664 }
665 EXPECT_EQ(1, instant_overlays);
666 }
667
668 void HistoryQueryDone(base::RunLoop* run_loop,
669 bool* result,
670 HistoryService::Handle /* handle */,
671 bool success,
672 const history::URLRow* /* urlrow */,
673 history::VisitVector* /* visitvector */) {
674 *result = success;
675 run_loop->Quit();
676 }
677
678 void KeywordQueryDone(base::RunLoop* run_loop,
679 std::vector<string16>* result,
680 HistoryService::Handle /* handle */,
681 std::vector<history::KeywordSearchTermVisit>* terms) {
682 for (size_t i = 0; i < terms->size(); ++i)
683 result->push_back((*terms)[i].term);
684 run_loop->Quit();
685 }
686
687 // Test that the Instant page load is not added to history.
688 IN_PROC_BROWSER_TEST_F(InstantTest, History) {
689 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
690 FocusOmniboxAndWaitForInstantSupport();
691
692 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile(
693 browser()->profile())->GetDefaultSearchProvider();
694
695 // |instant_url| is the URL Instant loads. |search_url| is the fake URL we
696 // enter into history for search terms extraction to work correctly.
697 std::string search_url = template_url->url_ref().ReplaceSearchTerms(
698 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search")));
699
700 HistoryService* history = HistoryServiceFactory::GetForProfile(
701 browser()->profile(), Profile::EXPLICIT_ACCESS);
702 ui_test_utils::WaitForHistoryToLoad(history);
703
704 // Perform a search.
705 SetOmniboxTextAndWaitForOverlayToShow("search");
706
707 // Commit the search.
708 browser()->window()->GetLocationBar()->AcceptInput();
709
710 bool found = false;
711 CancelableRequestConsumer consumer;
712
713 // The fake search URL should be in history.
714 base::RunLoop run_loop1;
715 history->QueryURL(GURL(search_url), false, &consumer,
716 base::Bind(&HistoryQueryDone, &run_loop1, &found));
717 run_loop1.Run();
718 EXPECT_TRUE(found);
719
720 // The Instant URL should not be in history.
721 base::RunLoop run_loop2;
722 history->QueryURL(instant_url(), false, &consumer,
723 base::Bind(&HistoryQueryDone, &run_loop2, &found));
724 run_loop2.Run();
725 EXPECT_FALSE(found);
726
727 // The search terms should have been extracted into history.
728 base::RunLoop run_loop3;
729 std::vector<string16> queries;
730 history->GetMostRecentKeywordSearchTerms(template_url->id(),
731 ASCIIToUTF16("s"), 1, &consumer,
732 base::Bind(&KeywordQueryDone, &run_loop3, &queries));
733 run_loop3.Run();
734 ASSERT_TRUE(queries.size());
735 EXPECT_EQ(ASCIIToUTF16("search"), queries[0]);
736 }
737
738 // TODO(jered): Fix this test on Mac. It fails currently, but the behavior is
739 // actually closer to what we'd like.
740 #if defined(OS_MACOSX)
741 #define MAYBE_NewWindowDismissesInstant DISABLED_NewWindowDismissesInstant
742 #else
743 #define MAYBE_NewWindowDismissesInstant NewWindowDismissesInstant
744 #endif
745 // Test that creating a new window hides any currently showing Instant overlay.
746 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) {
747 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
748 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
749 FocusOmniboxAndWaitForInstantSupport();
750 SetOmniboxTextAndWaitForOverlayToShow("search");
751
752 Browser* previous_window = browser();
753 EXPECT_TRUE(instant()->IsOverlayingSearchResults());
754 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
755
756 InstantTestModelObserver observer(instant()->model(),
757 chrome::search::Mode::MODE_DEFAULT);
758 chrome::NewEmptyWindow(browser()->profile(),
759 chrome::HOST_DESKTOP_TYPE_NATIVE);
760 observer.WaitForDesiredOverlayState();
761
762 // Even though we just created a new Browser object (for the new window), the
763 // browser() accessor should still give us the first window's Browser object.
764 EXPECT_EQ(previous_window, browser());
765 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
766 EXPECT_TRUE(instant()->model()->mode().is_default());
767 }
768
769 // Test that the Instant overlay is recreated when all these conditions are met:
770 // - The stale overlay timer has fired.
771 // - The overlay is not showing.
772 // - The omnibox doesn't have focus.
773 IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) {
774 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
775 FocusOmniboxAndWaitForInstantSupport();
776
777 // The overlay is refreshed only after all three conditions above are met.
778 SetOmniboxTextAndWaitForOverlayToShow("query");
779 instant()->overlay_->is_stale_ = true;
780 instant()->ReloadOverlayIfStale();
781 EXPECT_TRUE(instant()->overlay_->supports_instant());
782 instant()->HideOverlay();
783 EXPECT_TRUE(instant()->overlay_->supports_instant());
784 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
785 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
786 EXPECT_FALSE(instant()->overlay_->supports_instant());
787
788 // Try with a different ordering.
789 SetOmniboxTextAndWaitForOverlayToShow("query");
790 instant()->overlay_->is_stale_ = true;
791 instant()->ReloadOverlayIfStale();
792 EXPECT_TRUE(instant()->overlay_->supports_instant());
793 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
794 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL);
795 // TODO(sreeram): Currently, OmniboxLostFocus() calls HideOverlay(). When it
796 // stops hiding the overlay eventually, uncomment these two lines:
797 // EXPECT_TRUE(instant()->overlay_->supports_instant());
798 // instant()->HideOverlay();
799 EXPECT_FALSE(instant()->overlay_->supports_instant());
800 }
801
802 // Test that suggestions are case insensitive. http://crbug.com/150728
803 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) {
804 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
805 FocusOmniboxAndWaitForInstantSupport();
806
807 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]"));
808
809 SetOmniboxTextAndWaitForOverlayToShow("in");
810 EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText());
811
812 omnibox()->RevertAll();
813 SetOmniboxTextAndWaitForOverlayToShow("IN");
814 EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText());
815
816 // U+0130 == LATIN CAPITAL LETTER I WITH DOT ABOVE
817 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u0130NSTANT' } ]"));
818
819 omnibox()->RevertAll();
820 SetOmniboxTextAndWaitForOverlayToShow("i");
821 EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText());
822
823 omnibox()->RevertAll();
824 SetOmniboxTextAndWaitForOverlayToShow("I");
825 EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText());
826
827 omnibox()->RevertAll();
828 SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"i\u0307"));
829 EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText());
830
831 omnibox()->RevertAll();
832 SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"I\u0307"));
833 EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText());
834
835 omnibox()->RevertAll();
836 SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u0130"));
837 EXPECT_EQ(WideToUTF16(L"\u0130NSTANT"), omnibox()->GetText());
838
839 omnibox()->RevertAll();
840 SetOmniboxTextAndWaitForOverlayToShow("in");
841 EXPECT_EQ(ASCIIToUTF16("in"), omnibox()->GetText());
842
843 omnibox()->RevertAll();
844 SetOmniboxTextAndWaitForOverlayToShow("IN");
845 EXPECT_EQ(ASCIIToUTF16("IN"), omnibox()->GetText());
846
847 // Check that a d with a dot above and below it is completed regardless of
848 // how that is encoded.
849 // U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW
850 // U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE
851 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]"));
852
853 omnibox()->RevertAll();
854 SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u1e0b\u0323"));
855 EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText());
856 }
857
858 // Flakes on Windows and Mac: http://crbug.com/170677
859 #if defined(OS_WIN) || defined(OS_MACOSX)
860 #define MAYBE_CommitInNewTab DISABLED_CommitInNewTab
861 #else
862 #define MAYBE_CommitInNewTab CommitInNewTab
863 #endif
864 // Test that the overlay can be committed onto a new tab.
865 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) {
866 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
867 FocusOmniboxAndWaitForInstantSupport();
868
869 // Use the Instant page as the active tab, so we can exploit its visibility
870 // handler to check visibility transitions.
871 ui_test_utils::NavigateToURL(browser(), instant_url());
872 content::WebContents* active_tab =
873 browser()->tab_strip_model()->GetActiveWebContents();
874
875 int active_tab_onvisibilitycalls = -1;
876 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls",
877 &active_tab_onvisibilitycalls));
878 EXPECT_EQ(0, active_tab_onvisibilitycalls);
879
880 SetOmniboxTextAndWaitForOverlayToShow("search");
881
882 // Stash a reference to the overlay, so we can refer to it after commit.
883 content::WebContents* overlay = instant()->GetOverlayContents();
884 EXPECT_TRUE(overlay);
885
886 // The state of the searchbox before the commit.
887 EXPECT_TRUE(UpdateSearchState(overlay));
888 EXPECT_EQ("search", value_);
889 EXPECT_FALSE(verbatim_);
890 EXPECT_EQ(0, onsubmitcalls_);
891 EXPECT_EQ(1, onvisibilitycalls_);
892
893 // The state of the active tab before the commit.
894 EXPECT_NE(overlay, active_tab);
895 EXPECT_EQ(2, active_tab->GetController().GetEntryCount());
896 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL());
897 active_tab_onvisibilitycalls = -1;
898 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls",
899 &active_tab_onvisibilitycalls));
900 EXPECT_EQ(0, active_tab_onvisibilitycalls);
901
902 // Commit the search by pressing Alt-Enter.
903 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false);
904
905 // After the commit, Instant should not be showing.
906 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
907 EXPECT_TRUE(instant()->model()->mode().is_default());
908
909 // The old overlay is deleted and a new one is created.
910 EXPECT_TRUE(instant()->GetOverlayContents());
911 EXPECT_NE(instant()->GetOverlayContents(), overlay);
912
913 // Check that we have two tabs and that the new active tab is indeed what was
914 // once the overlay. The overlay should have just one navigation entry, for
915 // the Instant search that was committed.
916 EXPECT_EQ(2, browser()->tab_strip_model()->count());
917 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents());
918 EXPECT_EQ(1, overlay->GetController().GetEntryCount());
919
920 // Check that the omnibox contains the Instant URL we loaded.
921 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL());
922
923 // Check that the searchbox API values have been reset.
924 std::string value;
925 EXPECT_TRUE(GetStringFromJS(overlay,
926 "chrome.embeddedSearch.searchBox.value", &value));
927 EXPECT_EQ("", value);
928
929 // However, the page should've correctly received the committed query.
930 EXPECT_TRUE(UpdateSearchState(overlay));
931 EXPECT_EQ("search", value_);
932 EXPECT_TRUE(verbatim_);
933 EXPECT_EQ(1, onsubmitcalls_);
934 EXPECT_EQ(1, onvisibilitycalls_);
935
936 // The ex-active tab should've gotten a visibility change marking it hidden.
937 EXPECT_NE(active_tab, overlay);
938 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls",
939 &active_tab_onvisibilitycalls));
940 EXPECT_EQ(1, active_tab_onvisibilitycalls);
941 }
942
943 // Test that suggestions are reusable.
944 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) {
945 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
946 FocusOmniboxAndWaitForInstantSupport();
947
948 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];"
949 "behavior = 'never';"));
950
951 SetOmniboxTextAndWaitForOverlayToShow("in");
952 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion());
953
954 SetOmniboxText("ins");
955 EXPECT_EQ(ASCIIToUTF16("tant"), omnibox()->GetInstantSuggestion());
956
957 SetOmniboxText("in");
958 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion());
959
960 SetOmniboxText("insane");
961 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion());
962 }
963
964 // Test that the Instant overlay is recreated if it gets destroyed.
965 IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) {
966 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
967 FocusOmniboxAndWaitForInstantSupport();
968
969 // Type partial query, get suggestion to show.
970 SetOmniboxTextAndWaitForOverlayToShow("q");
971 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText());
972
973 // Kill the Instant renderer and wait for Instant support again.
974 KillInstantRenderView();
975 FocusOmniboxAndWaitForInstantSupport();
976
977 SetOmniboxTextAndWaitForOverlayToShow("qu");
978 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText());
979 }
980
981 IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) {
982 // Prior to setup no render process is dedicated to Instant.
983 InstantService* instant_service =
984 InstantServiceFactory::GetForProfile(browser()->profile());
985 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
986 EXPECT_EQ(0, instant_service->GetInstantProcessCount());
987
988 // Setup Instant.
989 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
990 FocusOmniboxAndWaitForInstantSupport();
991
992 // Now there should be a registered Instant render process.
993 EXPECT_LT(0, instant_service->GetInstantProcessCount());
994
995 // And the Instant overlay should live inside it.
996 content::WebContents* overlay = instant()->GetOverlayContents();
997 EXPECT_TRUE(instant_service->IsInstantProcess(
998 overlay->GetRenderProcessHost()->GetID()));
999
1000 // Search and commit the search by pressing Alt-Enter.
1001 SetOmniboxTextAndWaitForOverlayToShow("tractor");
1002 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false);
1003
1004 // The committed search results page should also live inside the
1005 // Instant process.
1006 content::WebContents* active_tab =
1007 browser()->tab_strip_model()->GetActiveWebContents();
1008 EXPECT_TRUE(instant_service->IsInstantProcess(
1009 active_tab->GetRenderProcessHost()->GetID()));
1010
1011 // Navigating away should change the process.
1012 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
1013 EXPECT_FALSE(instant_service->IsInstantProcess(
1014 active_tab->GetRenderProcessHost()->GetID()));
1015 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/OWNERS ('k') | chrome/browser/instant/instant_commit_type.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698