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

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

Powered by Google App Engine
This is Rietveld 408576698