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

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

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

Powered by Google App Engine
This is Rietveld 408576698