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

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

Powered by Google App Engine
This is Rietveld 408576698