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

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

Issue 11421079: Persist the Instant API to committed search result pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Kittens live! Created 8 years 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_loader.h" 7 #include "chrome/browser/instant/instant_loader.h"
8 #include "chrome/browser/instant/instant_model_observer.h" 8 #include "chrome/browser/instant/instant_model_observer.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/task_manager/task_manager.h" 12 #include "chrome/browser/task_manager/task_manager.h"
13 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" 13 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
14 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_instant_controller.h" 15 #include "chrome/browser/ui/browser_instant_controller.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/omnibox/location_bar.h" 18 #include "chrome/browser/ui/omnibox/location_bar.h"
19 #include "chrome/browser/ui/omnibox/omnibox_view.h" 19 #include "chrome/browser/ui/omnibox/omnibox_view.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/in_process_browser_test.h" 23 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
29 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
30 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 WrapScript(script), result); 136 WrapScript(script), result);
138 } 137 }
139 138
140 bool GetStringFromJS(content::RenderViewHost* rvh, 139 bool GetStringFromJS(content::RenderViewHost* rvh,
141 const std::string& script, 140 const std::string& script,
142 std::string* result) WARN_UNUSED_RESULT { 141 std::string* result) WARN_UNUSED_RESULT {
143 return content::ExecuteJavaScriptAndExtractString( 142 return content::ExecuteJavaScriptAndExtractString(
144 rvh, std::wstring(), WrapScript(script), result); 143 rvh, std::wstring(), WrapScript(script), result);
145 } 144 }
146 145
147 bool UpdateSearchState(TabContents* tab) WARN_UNUSED_RESULT { 146 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT {
148 content::RenderViewHost* rvh = tab->web_contents()->GetRenderViewHost(); 147 content::RenderViewHost* rvh = contents->GetRenderViewHost();
149 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && 148 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) &&
150 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && 149 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) &&
151 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && 150 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) &&
152 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && 151 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) &&
153 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && 152 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) &&
154 GetStringFromJS(rvh, "value", &value_) && 153 GetStringFromJS(rvh, "value", &value_) &&
155 GetBoolFromJS(rvh, "verbatim", &verbatim_) && 154 GetBoolFromJS(rvh, "verbatim", &verbatim_) &&
156 GetIntFromJS(rvh, "height", &height_); 155 GetIntFromJS(rvh, "height", &height_);
157 } 156 }
158 157
159 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { 158 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT {
160 return content::ExecuteJavaScript( 159 return content::ExecuteJavaScript(
161 instant()->GetPreviewContents()->web_contents()->GetRenderViewHost(), 160 instant()->GetPreviewContents()->GetRenderViewHost(), std::wstring(),
162 std::wstring(), UTF8ToWide(script)); 161 UTF8ToWide(script));
163 } 162 }
164 163
165 bool CheckVisibilityIs(TabContents* tab, bool expected) WARN_UNUSED_RESULT { 164 bool CheckVisibilityIs(content::WebContents* contents,
165 bool expected) WARN_UNUSED_RESULT {
166 bool actual = !expected; // Purposely start with a mis-match. 166 bool actual = !expected; // Purposely start with a mis-match.
167 // We can only use ASSERT_*() in a method that returns void, hence this 167 // We can only use ASSERT_*() in a method that returns void, hence this
168 // convoluted check. 168 // convoluted check.
169 return GetBoolFromJS(tab->web_contents()->GetRenderViewHost(), 169 return GetBoolFromJS(contents->GetRenderViewHost(),
170 "!document.webkitHidden", &actual) && 170 "!document.webkitHidden", &actual) &&
171 actual == expected; 171 actual == expected;
172 } 172 }
173 173
174 GURL instant_url_; 174 GURL instant_url_;
175 175
176 int onvisibilitycalls_; 176 int onvisibilitycalls_;
177 int onchangecalls_; 177 int onchangecalls_;
178 int onsubmitcalls_; 178 int onsubmitcalls_;
179 int oncancelcalls_; 179 int oncancelcalls_;
180 int onresizecalls_; 180 int onresizecalls_;
181 181
182 std::string value_; 182 std::string value_;
183 bool verbatim_; 183 bool verbatim_;
184 int height_; 184 int height_;
185 }; 185 };
186 186
187 // Test that Instant is preloaded when the omnibox is focused. 187 // Test that Instant is preloaded when the omnibox is focused.
188 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { 188 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) {
189 // The omnibox gets focus before the test begins. At this time, there's no
190 // InstantController (which is only created in SetupInstant() below), so no
191 // preloading has happened yet.
192 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 189 ASSERT_NO_FATAL_FAILURE(SetupInstant());
193 EXPECT_FALSE(instant()->GetPreviewContents());
194 190
195 // Explicitly unfocus the omnibox. 191 // Explicitly unfocus the omnibox.
196 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 192 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
197 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 193 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
198 194
199 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 195 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
200 EXPECT_FALSE(omnibox()->model()->has_focus()); 196 EXPECT_FALSE(omnibox()->model()->has_focus());
201 197
198 // Delete any existing preview.
199 instant()->loader_.reset();
200 EXPECT_FALSE(instant()->GetPreviewContents());
201
202 // Refocus the omnibox. The InstantController should've preloaded Instant. 202 // Refocus the omnibox. The InstantController should've preloaded Instant.
203 FocusOmniboxAndWaitForInstantSupport(); 203 FocusOmniboxAndWaitForInstantSupport();
204 204
205 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 205 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
206 EXPECT_TRUE(omnibox()->model()->has_focus()); 206 EXPECT_TRUE(omnibox()->model()->has_focus());
207 207
208 TabContents* preview_tab = instant()->GetPreviewContents(); 208 content::WebContents* preview_tab = instant()->GetPreviewContents();
209 EXPECT_TRUE(preview_tab); 209 EXPECT_TRUE(preview_tab);
210 210
211 // Check that the page supports Instant, but it isn't showing. 211 // Check that the page supports Instant, but it isn't showing.
212 EXPECT_TRUE(instant()->loader()->supports_instant()); 212 EXPECT_TRUE(instant()->loader_->supports_instant());
213 EXPECT_FALSE(instant()->IsCurrent()); 213 EXPECT_FALSE(instant()->IsCurrent());
214 EXPECT_TRUE(instant()->model()->mode().is_default()); 214 EXPECT_TRUE(instant()->model()->mode().is_default());
215 215
216 // Adding a new tab shouldn't delete or recreate the TabContents; otherwise, 216 // Adding a new tab shouldn't delete or recreate the preview; otherwise,
217 // what's the point of preloading? 217 // what's the point of preloading?
218 AddBlankTabAndShow(browser()); 218 AddBlankTabAndShow(browser());
219 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 219 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
220 220
221 // Unfocusing and refocusing the omnibox should also preserve the preview. 221 // Unfocusing and refocusing the omnibox should also preserve the preview.
222 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 222 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
223 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 223 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
224 224
225 FocusOmnibox(); 225 FocusOmnibox();
226 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 226 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 EXPECT_EQ(0, active_tab_onvisibilitycalls); 275 EXPECT_EQ(0, active_tab_onvisibilitycalls);
276 } 276 }
277 277
278 // Test that the onsubmit event is dispatched upon pressing Enter. 278 // Test that the onsubmit event is dispatched upon pressing Enter.
279 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { 279 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) {
280 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 280 ASSERT_NO_FATAL_FAILURE(SetupInstant());
281 FocusOmniboxAndWaitForInstantSupport(); 281 FocusOmniboxAndWaitForInstantSupport();
282 SetOmniboxTextAndWaitForInstantToShow("search"); 282 SetOmniboxTextAndWaitForInstantToShow("search");
283 283
284 // Stash a reference to the preview, so we can refer to it after commit. 284 // Stash a reference to the preview, so we can refer to it after commit.
285 TabContents* preview_tab = instant()->GetPreviewContents(); 285 content::WebContents* preview_tab = instant()->GetPreviewContents();
286 EXPECT_TRUE(preview_tab); 286 EXPECT_TRUE(preview_tab);
287 287
288 // The state of the searchbox before the commit. 288 // The state of the searchbox before the commit.
289 EXPECT_TRUE(UpdateSearchState(preview_tab)); 289 EXPECT_TRUE(UpdateSearchState(preview_tab));
290 EXPECT_EQ("search", value_); 290 EXPECT_EQ("search", value_);
291 EXPECT_FALSE(verbatim_); 291 EXPECT_FALSE(verbatim_);
292 EXPECT_EQ(0, onsubmitcalls_); 292 EXPECT_EQ(0, onsubmitcalls_);
293 EXPECT_EQ(1, onvisibilitycalls_); 293 EXPECT_EQ(1, onvisibilitycalls_);
294 294
295 // Before the commit, the active tab is the NTP (i.e., not Instant). 295 // Before the commit, the active tab is the NTP (i.e., not Instant).
296 TabContents* active_tab = 296 content::WebContents* active_tab =
297 browser()->tab_strip_model()->GetActiveTabContents(); 297 browser()->tab_strip_model()->GetActiveWebContents();
298 EXPECT_NE(preview_tab, active_tab); 298 EXPECT_NE(preview_tab, active_tab);
299 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); 299 EXPECT_EQ(1, active_tab->GetController().GetEntryCount());
300 EXPECT_EQ(std::string(chrome::kAboutBlankURL), 300 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
301 omnibox()->model()->PermanentURL().spec()); 301 omnibox()->model()->PermanentURL().spec());
302 302
303 // Commit the search by pressing Enter. 303 // Commit the search by pressing Enter.
304 browser()->window()->GetLocationBar()->AcceptInput(); 304 browser()->window()->GetLocationBar()->AcceptInput();
305 305
306 // After the commit, Instant should not be showing. 306 // After the commit, Instant should not be showing.
307 EXPECT_FALSE(instant()->IsCurrent()); 307 EXPECT_FALSE(instant()->IsCurrent());
308 EXPECT_TRUE(instant()->model()->mode().is_default()); 308 EXPECT_TRUE(instant()->model()->mode().is_default());
309 309
310 // The old loader is deleted and a new one is created. 310 // The old loader is deleted and a new one is created.
311 EXPECT_TRUE(instant()->GetPreviewContents()); 311 EXPECT_TRUE(instant()->GetPreviewContents());
312 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); 312 EXPECT_NE(instant()->GetPreviewContents(), preview_tab);
313 313
314 // Check that the current active tab is indeed what was once the preview. 314 // Check that the current active tab is indeed what was once the preview.
315 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveTabContents()); 315 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents());
316 316
317 // We should have two navigation entries, one for the NTP, and one for the 317 // We should have two navigation entries, one for the NTP, and one for the
318 // Instant search that was committed. 318 // Instant search that was committed.
319 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); 319 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount());
320 320
321 // Check that the omnibox contains the Instant URL we loaded. 321 // Check that the omnibox contains the Instant URL we loaded.
322 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); 322 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL());
323 323
324 // Check that the searchbox API values have been reset. 324 // Check that the searchbox API values have been reset.
325 std::string value; 325 std::string value;
326 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), 326 EXPECT_TRUE(GetStringFromJS(preview_tab->GetRenderViewHost(),
327 "chrome.searchBox.value", &value)); 327 "chrome.searchBox.value", &value));
328 EXPECT_EQ("", value); 328 EXPECT_EQ("", value);
329 329
330 // However, the page should've correctly received the committed query. 330 // However, the page should've correctly received the committed query.
331 EXPECT_TRUE(UpdateSearchState(preview_tab)); 331 EXPECT_TRUE(UpdateSearchState(preview_tab));
332 EXPECT_EQ("search", value_); 332 EXPECT_EQ("search", value_);
333 EXPECT_TRUE(verbatim_); 333 EXPECT_TRUE(verbatim_);
334 EXPECT_EQ(1, onsubmitcalls_); 334 EXPECT_EQ(1, onsubmitcalls_);
335 EXPECT_EQ(1, onvisibilitycalls_); 335 EXPECT_EQ(1, onvisibilitycalls_);
336 } 336 }
337 337
338 // Test that the oncancel event is dispatched upon clicking on the preview. 338 // Test that the oncancel event is dispatched upon clicking on the preview.
339 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { 339 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) {
340 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 340 ASSERT_NO_FATAL_FAILURE(SetupInstant());
341 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 341 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
342 FocusOmniboxAndWaitForInstantSupport(); 342 FocusOmniboxAndWaitForInstantSupport();
343 SetOmniboxTextAndWaitForInstantToShow("search"); 343 SetOmniboxTextAndWaitForInstantToShow("search");
344 344
345 // Stash a reference to the preview, so we can refer to it after commit. 345 // Stash a reference to the preview, so we can refer to it after commit.
346 TabContents* preview_tab = instant()->GetPreviewContents(); 346 content::WebContents* preview_tab = instant()->GetPreviewContents();
347 EXPECT_TRUE(preview_tab); 347 EXPECT_TRUE(preview_tab);
348 348
349 // The state of the searchbox before the commit. 349 // The state of the searchbox before the commit.
350 EXPECT_TRUE(UpdateSearchState(preview_tab)); 350 EXPECT_TRUE(UpdateSearchState(preview_tab));
351 EXPECT_EQ("search", value_); 351 EXPECT_EQ("search", value_);
352 EXPECT_FALSE(verbatim_); 352 EXPECT_FALSE(verbatim_);
353 EXPECT_EQ(0, oncancelcalls_); 353 EXPECT_EQ(0, oncancelcalls_);
354 EXPECT_EQ(1, onvisibilitycalls_); 354 EXPECT_EQ(1, onvisibilitycalls_);
355 355
356 // Before the commit, the active tab is the NTP (i.e., not Instant). 356 // Before the commit, the active tab is the NTP (i.e., not Instant).
357 TabContents* active_tab = 357 content::WebContents* active_tab =
358 browser()->tab_strip_model()->GetActiveTabContents(); 358 browser()->tab_strip_model()->GetActiveWebContents();
359 EXPECT_NE(preview_tab, active_tab); 359 EXPECT_NE(preview_tab, active_tab);
360 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); 360 EXPECT_EQ(1, active_tab->GetController().GetEntryCount());
361 EXPECT_EQ(std::string(chrome::kAboutBlankURL), 361 EXPECT_EQ(std::string(chrome::kAboutBlankURL),
362 omnibox()->model()->PermanentURL().spec()); 362 omnibox()->model()->PermanentURL().spec());
363 363
364 // Commit the search by clicking on the preview. 364 // Commit the search by clicking on the preview.
365 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 365 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
366 366
367 // After the commit, Instant should not be showing. 367 // After the commit, Instant should not be showing.
368 EXPECT_FALSE(instant()->IsCurrent()); 368 EXPECT_FALSE(instant()->IsCurrent());
369 EXPECT_TRUE(instant()->model()->mode().is_default()); 369 EXPECT_TRUE(instant()->model()->mode().is_default());
370 370
371 // The old loader is deleted and a new one is created. 371 // The old loader is deleted and a new one is created.
372 EXPECT_TRUE(instant()->GetPreviewContents()); 372 EXPECT_TRUE(instant()->GetPreviewContents());
373 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); 373 EXPECT_NE(instant()->GetPreviewContents(), preview_tab);
374 374
375 // Check that the current active tab is indeed what was once the preview. 375 // Check that the current active tab is indeed what was once the preview.
376 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveTabContents()); 376 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents());
377 377
378 // We should have two navigation entries, one for the NTP, and one for the 378 // We should have two navigation entries, one for the NTP, and one for the
379 // Instant search that was committed. 379 // Instant search that was committed.
380 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); 380 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount());
381 381
382 // Check that the omnibox contains the Instant URL we loaded. 382 // Check that the omnibox contains the Instant URL we loaded.
383 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); 383 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL());
384 384
385 // Check that the searchbox API values have been reset. 385 // Check that the searchbox API values have been reset.
386 std::string value; 386 std::string value;
387 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), 387 EXPECT_TRUE(GetStringFromJS(preview_tab->GetRenderViewHost(),
388 "chrome.searchBox.value", &value)); 388 "chrome.searchBox.value", &value));
389 EXPECT_EQ("", value); 389 EXPECT_EQ("", value);
390 390
391 // However, the page should've correctly received the committed query. 391 // However, the page should've correctly received the committed query.
392 EXPECT_TRUE(UpdateSearchState(preview_tab)); 392 EXPECT_TRUE(UpdateSearchState(preview_tab));
393 EXPECT_EQ("search", value_); 393 EXPECT_EQ("search", value_);
394 EXPECT_TRUE(verbatim_); 394 EXPECT_TRUE(verbatim_);
395 EXPECT_EQ(1, oncancelcalls_); 395 EXPECT_EQ(1, oncancelcalls_);
396 EXPECT_EQ(1, onvisibilitycalls_); 396 EXPECT_EQ(1, onvisibilitycalls_);
397 } 397 }
398 398
399 // Test that the onreisze event is dispatched upon typing in the omnibox. 399 // Test that the onreisze event is dispatched upon typing in the omnibox.
400 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { 400 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) {
401 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 401 ASSERT_NO_FATAL_FAILURE(SetupInstant());
402 402
403 // This makes Instant load the preview, along with an initial onresize() (see
404 // SearchBoxExtension::PageSupportsInstant() for why).
405 FocusOmniboxAndWaitForInstantSupport(); 403 FocusOmniboxAndWaitForInstantSupport();
406 404
407 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); 405 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents()));
408 EXPECT_EQ(1, onresizecalls_); 406 EXPECT_EQ(0, onresizecalls_);
409 EXPECT_EQ(0, height_); 407 EXPECT_EQ(0, height_);
410 408
411 // Type a query into the omnibox. This should cause an onresize() event, with 409 // Type a query into the omnibox. This should cause an onresize() event, with
412 // a valid (non-zero) height. 410 // a valid (non-zero) height.
413 SetOmniboxTextAndWaitForInstantToShow("search"); 411 SetOmniboxTextAndWaitForInstantToShow("search");
414 412
415 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); 413 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents()));
416 EXPECT_EQ(2, onresizecalls_); 414 EXPECT_EQ(1, onresizecalls_);
417 EXPECT_LT(0, height_); 415 EXPECT_LT(0, height_);
418 } 416 }
419 417
420 // Test that the INSTANT_COMPLETE_NOW behavior works as expected. 418 // Test that the INSTANT_COMPLETE_NOW behavior works as expected.
421 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { 419 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) {
422 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 420 ASSERT_NO_FATAL_FAILURE(SetupInstant());
423 FocusOmniboxAndWaitForInstantSupport(); 421 FocusOmniboxAndWaitForInstantSupport();
424 422
425 // Tell the JS to request the given behavior. 423 // Tell the JS to request the given behavior.
426 EXPECT_TRUE(ExecuteScript("behavior = 'now'")); 424 EXPECT_TRUE(ExecuteScript("behavior = 'now'"));
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // Type a URL. The Instant preview shouldn't be showing. 623 // Type a URL. The Instant preview shouldn't be showing.
626 SetOmniboxText("http://deadly/nadder"); 624 SetOmniboxText("http://deadly/nadder");
627 EXPECT_FALSE(instant()->IsCurrent()); 625 EXPECT_FALSE(instant()->IsCurrent());
628 EXPECT_TRUE(instant()->model()->mode().is_default()); 626 EXPECT_TRUE(instant()->model()->mode().is_default());
629 627
630 // Unfocus and refocus the omnibox. 628 // Unfocus and refocus the omnibox.
631 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 629 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
632 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); 630 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
633 FocusOmnibox(); 631 FocusOmnibox();
634 632
635 TabContents* preview_tab = instant()->GetPreviewContents(); 633 content::WebContents* preview_tab = instant()->GetPreviewContents();
636 EXPECT_TRUE(preview_tab); 634 EXPECT_TRUE(preview_tab);
637 635
638 // The omnibox text hasn't changed, so Instant still shouldn't be showing. 636 // The omnibox text hasn't changed, so Instant still shouldn't be showing.
639 EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); 637 EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText());
640 EXPECT_FALSE(instant()->IsCurrent()); 638 EXPECT_FALSE(instant()->IsCurrent());
641 EXPECT_TRUE(instant()->model()->mode().is_default()); 639 EXPECT_TRUE(instant()->model()->mode().is_default());
642 640
643 // Commit the URL. The omnibox should reflect the URL minus the scheme. 641 // Commit the URL. The omnibox should reflect the URL minus the scheme.
644 browser()->window()->GetLocationBar()->AcceptInput(); 642 browser()->window()->GetLocationBar()->AcceptInput();
645 TabContents* active_tab = 643 content::WebContents* active_tab =
646 browser()->tab_strip_model()->GetActiveTabContents(); 644 browser()->tab_strip_model()->GetActiveWebContents();
647 EXPECT_NE(preview_tab, active_tab); 645 EXPECT_NE(preview_tab, active_tab);
648 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); 646 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText());
649 647
650 // Instant shouldn't have done anything. 648 // Instant shouldn't have done anything.
651 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 649 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
652 EXPECT_FALSE(instant()->IsCurrent()); 650 EXPECT_FALSE(instant()->IsCurrent());
653 EXPECT_TRUE(instant()->model()->mode().is_default()); 651 EXPECT_TRUE(instant()->model()->mode().is_default());
654 } 652 }
655 653
656 // Test that Instant can't be fooled into committing a URL. 654 // Test that Instant can't be fooled into committing a URL.
657 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { 655 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) {
658 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 656 ASSERT_NO_FATAL_FAILURE(SetupInstant());
659 FocusOmniboxAndWaitForInstantSupport(); 657 FocusOmniboxAndWaitForInstantSupport();
660 658
661 // Type a query. This causes the preview to be shown. 659 // Type a query. This causes the preview to be shown.
662 SetOmniboxTextAndWaitForInstantToShow("query"); 660 SetOmniboxTextAndWaitForInstantToShow("query");
663 661
664 TabContents* preview_tab = instant()->GetPreviewContents(); 662 content::WebContents* preview_tab = instant()->GetPreviewContents();
665 EXPECT_TRUE(preview_tab); 663 EXPECT_TRUE(preview_tab);
666 664
667 // Type a URL. This causes the preview to be hidden. 665 // Type a URL. This causes the preview to be hidden.
668 SetOmniboxText("http://hideous/zippleback"); 666 SetOmniboxText("http://hideous/zippleback");
669 EXPECT_FALSE(instant()->IsCurrent()); 667 EXPECT_FALSE(instant()->IsCurrent());
670 EXPECT_TRUE(instant()->model()->mode().is_default()); 668 EXPECT_TRUE(instant()->model()->mode().is_default());
671 669
672 // Pretend the omnibox got focus. It already had focus, so we are just trying 670 // Pretend the omnibox got focus. It already had focus, so we are just trying
673 // to tickle a different code path. 671 // to tickle a different code path.
674 instant()->OmniboxGotFocus(); 672 instant()->OmniboxGotFocus();
675 673
676 // Commit the URL. As before, check that Instant wasn't committed. 674 // Commit the URL. As before, check that Instant wasn't committed.
677 browser()->window()->GetLocationBar()->AcceptInput(); 675 browser()->window()->GetLocationBar()->AcceptInput();
678 TabContents* active_tab = 676 content::WebContents* active_tab =
679 browser()->tab_strip_model()->GetActiveTabContents(); 677 browser()->tab_strip_model()->GetActiveWebContents();
680 EXPECT_NE(preview_tab, active_tab); 678 EXPECT_NE(preview_tab, active_tab);
681 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); 679 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText());
682 680
683 // As before, Instant shouldn't have done anything. 681 // As before, Instant shouldn't have done anything.
684 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); 682 EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
685 EXPECT_FALSE(instant()->IsCurrent()); 683 EXPECT_FALSE(instant()->IsCurrent());
686 EXPECT_TRUE(instant()->model()->mode().is_default()); 684 EXPECT_TRUE(instant()->model()->mode().is_default());
687 } 685 }
688 686
689 // Test that a non-Instant search provider shows no previews. 687 // Test that a non-Instant search provider shows no previews.
690 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { 688 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) {
691 instant_url_ = test_server()->GetURL("files/empty.html"); 689 instant_url_ = test_server()->GetURL("files/empty.html");
692 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 690 ASSERT_NO_FATAL_FAILURE(SetupInstant());
693 691
694 // Focus the omnibox. When the support determination response comes back, 692 // Focus the omnibox. When the support determination response comes back,
695 // Instant will destroy the non-Instant page. 693 // Instant will destroy the non-Instant page, and attempt to recreate it.
694 // We can know this happened by looking at the blacklist.
695 EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url_.spec()]);
696 FocusOmniboxAndWaitForInstantSupport(); 696 FocusOmniboxAndWaitForInstantSupport();
697 EXPECT_FALSE(instant()->GetPreviewContents()); 697 EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url_.spec()]);
698 } 698 }
699 699
700 // Test that the renderer doesn't crash if JavaScript is blocked. 700 // Test that the renderer doesn't crash if JavaScript is blocked.
701 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { 701 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) {
702 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 702 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
703 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 703 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
704 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 704 ASSERT_NO_FATAL_FAILURE(SetupInstant());
705 705
706 // Wait for notification that the Instant API has been determined. As long as 706 // Wait for notification that the Instant API has been determined. As long as
707 // we get the notification we're good (the renderer didn't crash). 707 // we get the notification we're good (the renderer didn't crash).
708 FocusOmniboxAndWaitForInstantSupport(); 708 FocusOmniboxAndWaitForInstantSupport();
709 } 709 }
710 710
711 // Test that the preview and active tab's visibility states are set correctly. 711 // Test that the preview and active tab's visibility states are set correctly.
712 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { 712 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) {
713 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 713 ASSERT_NO_FATAL_FAILURE(SetupInstant());
714 FocusOmniboxAndWaitForInstantSupport(); 714 FocusOmniboxAndWaitForInstantSupport();
715 715
716 TabContents* active_tab = 716 content::WebContents* active_tab =
717 browser()->tab_strip_model()->GetActiveTabContents(); 717 browser()->tab_strip_model()->GetActiveWebContents();
718 TabContents* preview_tab = instant()->GetPreviewContents(); 718 content::WebContents* preview_tab = instant()->GetPreviewContents();
719 719
720 // Inititally, the active tab is showing; the preview is not. 720 // Inititally, the active tab is showing; the preview is not.
721 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); 721 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
722 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); 722 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false));
723 723
724 // Type a query and wait for Instant to show. 724 // Type a query and wait for Instant to show.
725 SetOmniboxTextAndWaitForInstantToShow("query"); 725 SetOmniboxTextAndWaitForInstantToShow("query");
726 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); 726 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
727 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); 727 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true));
728 728
729 // Deleting the omnibox text should hide the preview. 729 // Deleting the omnibox text should hide the preview.
730 SetOmniboxText(""); 730 SetOmniboxText("");
731 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); 731 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
732 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); 732 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false));
733 733
734 // Typing a query should show the preview again. 734 // Typing a query should show the preview again.
735 SetOmniboxTextAndWaitForInstantToShow("query"); 735 SetOmniboxTextAndWaitForInstantToShow("query");
736 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); 736 EXPECT_TRUE(CheckVisibilityIs(active_tab, true));
737 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); 737 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true));
738 738
739 // Commit the preview. 739 // Commit the preview.
740 browser()->window()->GetLocationBar()->AcceptInput(); 740 browser()->window()->GetLocationBar()->AcceptInput();
741 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveTabContents()); 741 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents());
742 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); 742 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true));
743 } 743 }
744 744
745 // Test that the task manager identifies Instant's preview tab correctly. 745 // Test that the task manager identifies Instant's preview tab correctly.
746 IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { 746 IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) {
747 // The browser starts with a new tab, so there's just one renderer initially. 747 // The browser starts with a new tab, so there's just one renderer initially.
748 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); 748 TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
749 task_manager->StartUpdating(); 749 task_manager->StartUpdating();
750 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 750 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1);
751 751
(...skipping 16 matching lines...) Expand all
768 for (int i = 0; i < task_manager->ResourceCount(); ++i) { 768 for (int i = 0; i < task_manager->ResourceCount(); ++i) {
769 string16 title = task_manager->GetResourceTitle(i); 769 string16 title = task_manager->GetResourceTitle(i);
770 if (StartsWith(title, prefix, true)) 770 if (StartsWith(title, prefix, true))
771 ++instant_previews; 771 ++instant_previews;
772 } 772 }
773 EXPECT_EQ(1, instant_previews); 773 EXPECT_EQ(1, instant_previews);
774 } 774 }
775 775
776 void HistoryQueryDone(base::RunLoop* run_loop, 776 void HistoryQueryDone(base::RunLoop* run_loop,
777 bool* result, 777 bool* result,
778 HistoryService::Handle /* handle */, 778 HistoryService::Handle /* handle */,
779 bool success, 779 bool success,
780 const history::URLRow* /* urlrow */, 780 const history::URLRow* /* urlrow */,
781 history::VisitVector* /* visitvector */) { 781 history::VisitVector* /* visitvector */) {
782 *result = success; 782 *result = success;
783 run_loop->Quit(); 783 run_loop->Quit();
784 } 784 }
785 785
786 void KeywordQueryDone(base::RunLoop* run_loop, 786 void KeywordQueryDone(base::RunLoop* run_loop,
787 std::vector<string16>* result, 787 std::vector<string16>* result,
788 HistoryService::Handle /* handle */, 788 HistoryService::Handle /* handle */,
789 std::vector<history::KeywordSearchTermVisit>* terms) { 789 std::vector<history::KeywordSearchTermVisit>* terms) {
790 for (size_t i = 0; i < terms->size(); ++i) 790 for (size_t i = 0; i < terms->size(); ++i)
791 result->push_back((*terms)[i].term); 791 result->push_back((*terms)[i].term);
(...skipping 12 matching lines...) Expand all
804 // enter into history for search terms extraction to work correctly. 804 // enter into history for search terms extraction to work correctly.
805 std::string search_url = template_url->url_ref().ReplaceSearchTerms( 805 std::string search_url = template_url->url_ref().ReplaceSearchTerms(
806 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); 806 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search")));
807 807
808 HistoryService* history = HistoryServiceFactory::GetForProfile( 808 HistoryService* history = HistoryServiceFactory::GetForProfile(
809 browser()->profile(), Profile::EXPLICIT_ACCESS); 809 browser()->profile(), Profile::EXPLICIT_ACCESS);
810 ui_test_utils::WaitForHistoryToLoad(history); 810 ui_test_utils::WaitForHistoryToLoad(history);
811 811
812 // Perform a search. 812 // Perform a search.
813 SetOmniboxTextAndWaitForInstantToShow("search"); 813 SetOmniboxTextAndWaitForInstantToShow("search");
814 EXPECT_EQ(instant_url_.spec(), instant()->loader()->instant_url());
815 814
816 // Commit the search. 815 // Commit the search.
817 browser()->window()->GetLocationBar()->AcceptInput(); 816 browser()->window()->GetLocationBar()->AcceptInput();
818 817
819 bool found = false; 818 bool found = false;
820 CancelableRequestConsumer consumer; 819 CancelableRequestConsumer consumer;
821 820
822 // The fake search URL should be in history. 821 // The fake search URL should be in history.
823 base::RunLoop run_loop1; 822 base::RunLoop run_loop1;
824 history->QueryURL(GURL(search_url), false, &consumer, 823 history->QueryURL(GURL(search_url), false, &consumer,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 // - The preview is not showing. 878 // - The preview is not showing.
880 // - The omnibox doesn't have focus. 879 // - The omnibox doesn't have focus.
881 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { 880 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) {
882 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 881 ASSERT_NO_FATAL_FAILURE(SetupInstant());
883 FocusOmniboxAndWaitForInstantSupport(); 882 FocusOmniboxAndWaitForInstantSupport();
884 883
885 // The preview is refreshed only after all three conditions above are met. 884 // The preview is refreshed only after all three conditions above are met.
886 SetOmniboxTextAndWaitForInstantToShow("query"); 885 SetOmniboxTextAndWaitForInstantToShow("query");
887 instant()->stale_loader_timer_.Stop(); 886 instant()->stale_loader_timer_.Stop();
888 instant()->OnStaleLoader(); 887 instant()->OnStaleLoader();
889 EXPECT_TRUE(instant()->loader()->supports_instant()); 888 EXPECT_TRUE(instant()->loader_->supports_instant());
890 instant()->Hide(true); 889 instant()->Hide();
891 EXPECT_TRUE(instant()->loader()->supports_instant()); 890 EXPECT_TRUE(instant()->loader_->supports_instant());
892 instant()->OmniboxLostFocus(NULL); 891 instant()->OmniboxLostFocus(NULL);
893 EXPECT_FALSE(instant()->loader()->supports_instant()); 892 EXPECT_FALSE(instant()->loader_->supports_instant());
894 893
895 // Try with a different ordering. 894 // Try with a different ordering.
896 SetOmniboxTextAndWaitForInstantToShow("query"); 895 SetOmniboxTextAndWaitForInstantToShow("query");
897 instant()->stale_loader_timer_.Stop(); 896 instant()->stale_loader_timer_.Stop();
898 instant()->OnStaleLoader(); 897 instant()->OnStaleLoader();
899 EXPECT_TRUE(instant()->loader()->supports_instant()); 898 EXPECT_TRUE(instant()->loader_->supports_instant());
900 instant()->OmniboxLostFocus(NULL); 899 instant()->OmniboxLostFocus(NULL);
901 // TODO(sreeram): Currently, OmniboxLostFocus() calls Hide(). Eventually, 900 // TODO(sreeram): Currently, OmniboxLostFocus() calls Hide(). Eventually,
902 // when it stops hiding the preview, uncomment these two lines below: 901 // when it stops hiding the preview, uncomment these two lines below:
903 // EXPECT_TRUE(instant()->loader()->supports_instant()); 902 // EXPECT_TRUE(instant()->loader_->supports_instant());
904 // instant()->Hide(true); 903 // instant()->Hide();
905 EXPECT_FALSE(instant()->loader()->supports_instant()); 904 EXPECT_FALSE(instant()->loader_->supports_instant());
906 } 905 }
907 906
908 // Test that suggestions are case insensitive. http://crbug.com/150728 907 // Test that suggestions are case insensitive. http://crbug.com/150728
909 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { 908 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) {
910 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 909 ASSERT_NO_FATAL_FAILURE(SetupInstant());
911 FocusOmniboxAndWaitForInstantSupport(); 910 FocusOmniboxAndWaitForInstantSupport();
912 911
913 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); 912 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]"));
914 913
915 SetOmniboxTextAndWaitForInstantToShow("in"); 914 SetOmniboxTextAndWaitForInstantToShow("in");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 } 961 }
963 962
964 // Test that the preview can be committed onto a new tab. 963 // Test that the preview can be committed onto a new tab.
965 IN_PROC_BROWSER_TEST_F(InstantTest, CommitInNewTab) { 964 IN_PROC_BROWSER_TEST_F(InstantTest, CommitInNewTab) {
966 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 965 ASSERT_NO_FATAL_FAILURE(SetupInstant());
967 FocusOmniboxAndWaitForInstantSupport(); 966 FocusOmniboxAndWaitForInstantSupport();
968 967
969 // Use the Instant page as the active tab, so we can exploit its visibility 968 // Use the Instant page as the active tab, so we can exploit its visibility
970 // handler to check visibility transitions. 969 // handler to check visibility transitions.
971 ui_test_utils::NavigateToURL(browser(), instant_url_); 970 ui_test_utils::NavigateToURL(browser(), instant_url_);
972 TabContents* active_tab = 971 content::WebContents* active_tab =
973 browser()->tab_strip_model()->GetActiveTabContents(); 972 browser()->tab_strip_model()->GetActiveWebContents();
974 973
975 int active_tab_onvisibilitycalls = -1; 974 int active_tab_onvisibilitycalls = -1;
976 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), 975 EXPECT_TRUE(GetIntFromJS(active_tab->GetRenderViewHost(), "onvisibilitycalls",
977 "onvisibilitycalls", &active_tab_onvisibilitycalls)); 976 &active_tab_onvisibilitycalls));
978 EXPECT_EQ(0, active_tab_onvisibilitycalls); 977 EXPECT_EQ(0, active_tab_onvisibilitycalls);
979 978
980 SetOmniboxTextAndWaitForInstantToShow("search"); 979 SetOmniboxTextAndWaitForInstantToShow("search");
981 980
982 // Stash a reference to the preview, so we can refer to it after commit. 981 // Stash a reference to the preview, so we can refer to it after commit.
983 TabContents* preview_tab = instant()->GetPreviewContents(); 982 content::WebContents* preview_tab = instant()->GetPreviewContents();
984 EXPECT_TRUE(preview_tab); 983 EXPECT_TRUE(preview_tab);
985 984
986 // The state of the searchbox before the commit. 985 // The state of the searchbox before the commit.
987 EXPECT_TRUE(UpdateSearchState(preview_tab)); 986 EXPECT_TRUE(UpdateSearchState(preview_tab));
988 EXPECT_EQ("search", value_); 987 EXPECT_EQ("search", value_);
989 EXPECT_FALSE(verbatim_); 988 EXPECT_FALSE(verbatim_);
990 EXPECT_EQ(0, onsubmitcalls_); 989 EXPECT_EQ(0, onsubmitcalls_);
991 EXPECT_EQ(1, onvisibilitycalls_); 990 EXPECT_EQ(1, onvisibilitycalls_);
992 991
993 // The state of the active tab before the commit. 992 // The state of the active tab before the commit.
994 EXPECT_NE(preview_tab, active_tab); 993 EXPECT_NE(preview_tab, active_tab);
995 EXPECT_EQ(2, active_tab->web_contents()->GetController().GetEntryCount()); 994 EXPECT_EQ(2, active_tab->GetController().GetEntryCount());
996 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); 995 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL());
997 active_tab_onvisibilitycalls = -1; 996 active_tab_onvisibilitycalls = -1;
998 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), 997 EXPECT_TRUE(GetIntFromJS(active_tab->GetRenderViewHost(), "onvisibilitycalls",
999 "onvisibilitycalls", &active_tab_onvisibilitycalls)); 998 &active_tab_onvisibilitycalls));
1000 EXPECT_EQ(0, active_tab_onvisibilitycalls); 999 EXPECT_EQ(0, active_tab_onvisibilitycalls);
1001 1000
1002 // Commit the search by pressing Alt-Enter. 1001 // Commit the search by pressing Alt-Enter.
1003 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); 1002 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false);
1004 1003
1005 // After the commit, Instant should not be showing. 1004 // After the commit, Instant should not be showing.
1006 EXPECT_FALSE(instant()->IsCurrent()); 1005 EXPECT_FALSE(instant()->IsCurrent());
1007 EXPECT_TRUE(instant()->model()->mode().is_default()); 1006 EXPECT_TRUE(instant()->model()->mode().is_default());
1008 1007
1009 // The old loader is deleted and a new one is created. 1008 // The old loader is deleted and a new one is created.
1010 EXPECT_TRUE(instant()->GetPreviewContents()); 1009 EXPECT_TRUE(instant()->GetPreviewContents());
1011 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); 1010 EXPECT_NE(instant()->GetPreviewContents(), preview_tab);
1012 1011
1013 // Check that we have two tabs and that the new active tab is indeed what was 1012 // Check that we have two tabs and that the new active tab is indeed what was
1014 // once the preview. The preview tab should have just one navigation entry, 1013 // once the preview. The preview tab should have just one navigation entry,
1015 // for the Instant search that was committed. 1014 // for the Instant search that was committed.
1016 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1015 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1017 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveTabContents()); 1016 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents());
1018 EXPECT_EQ(1, preview_tab->web_contents()->GetController().GetEntryCount()); 1017 EXPECT_EQ(1, preview_tab->GetController().GetEntryCount());
1019 1018
1020 // Check that the omnibox contains the Instant URL we loaded. 1019 // Check that the omnibox contains the Instant URL we loaded.
1021 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); 1020 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL());
1022 1021
1023 // Check that the searchbox API values have been reset. 1022 // Check that the searchbox API values have been reset.
1024 std::string value; 1023 std::string value;
1025 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), 1024 EXPECT_TRUE(GetStringFromJS(preview_tab->GetRenderViewHost(),
1026 "chrome.searchBox.value", &value)); 1025 "chrome.searchBox.value", &value));
1027 EXPECT_EQ("", value); 1026 EXPECT_EQ("", value);
1028 1027
1029 // However, the page should've correctly received the committed query. 1028 // However, the page should've correctly received the committed query.
1030 EXPECT_TRUE(UpdateSearchState(preview_tab)); 1029 EXPECT_TRUE(UpdateSearchState(preview_tab));
1031 EXPECT_EQ("search", value_); 1030 EXPECT_EQ("search", value_);
1032 EXPECT_TRUE(verbatim_); 1031 EXPECT_TRUE(verbatim_);
1033 EXPECT_EQ(1, onsubmitcalls_); 1032 EXPECT_EQ(1, onsubmitcalls_);
1034 EXPECT_EQ(1, onvisibilitycalls_); 1033 EXPECT_EQ(1, onvisibilitycalls_);
1035 1034
1036 // The ex-active tab should've gotten a visibility change marking it hidden. 1035 // The ex-active tab should've gotten a visibility change marking it hidden.
1037 EXPECT_NE(active_tab, preview_tab); 1036 EXPECT_NE(active_tab, preview_tab);
1038 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), 1037 EXPECT_TRUE(GetIntFromJS(active_tab->GetRenderViewHost(), "onvisibilitycalls",
1039 "onvisibilitycalls", &active_tab_onvisibilitycalls)); 1038 &active_tab_onvisibilitycalls));
1040 EXPECT_EQ(1, active_tab_onvisibilitycalls); 1039 EXPECT_EQ(1, active_tab_onvisibilitycalls);
1041 } 1040 }
1042 1041
1043 // Test that suggestions are reusable. 1042 // Test that suggestions are reusable.
1044 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { 1043 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) {
1045 ASSERT_NO_FATAL_FAILURE(SetupInstant()); 1044 ASSERT_NO_FATAL_FAILURE(SetupInstant());
1046 FocusOmniboxAndWaitForInstantSupport(); 1045 FocusOmniboxAndWaitForInstantSupport();
1047 1046
1048 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];" 1047 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];"
1049 "behavior = 'never';")); 1048 "behavior = 'never';"));
1050 1049
1051 SetOmniboxTextAndWaitForInstantToShow("in"); 1050 SetOmniboxTextAndWaitForInstantToShow("in");
1052 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); 1051 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion());
1053 1052
1054 SetOmniboxText("ins"); 1053 SetOmniboxText("ins");
1055 EXPECT_EQ(ASCIIToUTF16("tant"), omnibox()->GetInstantSuggestion()); 1054 EXPECT_EQ(ASCIIToUTF16("tant"), omnibox()->GetInstantSuggestion());
1056 1055
1057 SetOmniboxText("in"); 1056 SetOmniboxText("in");
1058 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); 1057 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion());
1059 1058
1060 SetOmniboxText("insane"); 1059 SetOmniboxText("insane");
1061 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); 1060 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion());
1062 } 1061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698