OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
11 #include "chrome/browser/instant/instant_controller.h" | 11 #include "chrome/browser/instant/instant_controller.h" |
12 #include "chrome/browser/instant/instant_loader.h" | 12 #include "chrome/browser/instant/instant_loader.h" |
13 #include "chrome/browser/instant/instant_loader_manager.h" | 13 #include "chrome/browser/instant/instant_loader_manager.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
16 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 16 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
17 #include "chrome/browser/search_engines/template_url.h" | 17 #include "chrome/browser/search_engines/template_url.h" |
18 #include "chrome/browser/search_engines/template_url_model.h" | 18 #include "chrome/browser/search_engines/template_url_model.h" |
19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/omnibox/location_bar.h" | 21 #include "chrome/browser/ui/omnibox/location_bar.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
23 #include "chrome/common/chrome_switches.h" | |
24 #include "chrome/test/in_process_browser_test.h" | 23 #include "chrome/test/in_process_browser_test.h" |
25 #include "chrome/test/ui_test_utils.h" | 24 #include "chrome/test/ui_test_utils.h" |
26 | 25 |
27 #define EXPECT_STR_EQ(ascii, utf16) \ | 26 #define EXPECT_STR_EQ(ascii, utf16) \ |
28 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 27 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
29 | 28 |
30 class InstantTest : public InProcessBrowserTest { | 29 class InstantTest : public InProcessBrowserTest { |
31 public: | 30 public: |
32 InstantTest() | 31 InstantTest() |
33 : location_bar_(NULL), | 32 : location_bar_(NULL), |
34 preview_(NULL) { | 33 preview_(NULL) { |
35 set_show_window(true); | 34 set_show_window(true); |
36 EnableDOMAutomation(); | 35 EnableDOMAutomation(); |
37 } | 36 } |
38 | 37 |
| 38 void EnableInstant() { |
| 39 InstantController::Enable(browser()->profile()); |
| 40 } |
| 41 |
39 void SetupInstantProvider(const std::string& page) { | 42 void SetupInstantProvider(const std::string& page) { |
40 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel(); | 43 TemplateURLModel* model = browser()->profile()->GetTemplateURLModel(); |
41 ASSERT_TRUE(model); | 44 ASSERT_TRUE(model); |
42 | 45 |
43 if (!model->loaded()) { | 46 if (!model->loaded()) { |
44 model->Load(); | 47 model->Load(); |
45 ui_test_utils::WaitForNotification( | 48 ui_test_utils::WaitForNotification( |
46 NotificationType::TEMPLATE_URL_MODEL_LOADED); | 49 NotificationType::TEMPLATE_URL_MODEL_LOADED); |
47 } | 50 } |
48 | 51 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 266 } |
264 | 267 |
265 // Sends a message to the renderer and waits for the response to come back to | 268 // Sends a message to the renderer and waits for the response to come back to |
266 // the browser. | 269 // the browser. |
267 void WaitForMessageToBeProcessedByRenderer(TabContentsWrapper* tab) { | 270 void WaitForMessageToBeProcessedByRenderer(TabContentsWrapper* tab) { |
268 ASSERT_NO_FATAL_FAILURE( | 271 ASSERT_NO_FATAL_FAILURE( |
269 CheckBoolValueFromJavascript(true, "true", tab->tab_contents())); | 272 CheckBoolValueFromJavascript(true, "true", tab->tab_contents())); |
270 } | 273 } |
271 | 274 |
272 protected: | 275 protected: |
273 virtual void SetUpCommandLine(CommandLine* command_line) { | |
274 command_line->AppendSwitch(switches::kEnablePredictiveInstant); | |
275 } | |
276 | |
277 LocationBar* location_bar_; | 276 LocationBar* location_bar_; |
278 TabContents* preview_; | 277 TabContents* preview_; |
279 }; | 278 }; |
280 | 279 |
281 // TODO(tonyg): Add the following tests: | 280 // TODO(tonyg): Add the following tests: |
282 // - Test that the search box API is not populated for pages other than the | 281 // - Test that the search box API is not populated for pages other than the |
283 // default search provider. | 282 // default search provider. |
284 // - Test resize events. | 283 // - Test resize events. |
285 | 284 |
286 // Verify that the onchange event is dispatched upon typing in the box. | 285 // Verify that the onchange event is dispatched upon typing in the box. |
287 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { | 286 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
288 ASSERT_TRUE(test_server()->Start()); | 287 ASSERT_TRUE(test_server()->Start()); |
| 288 EnableInstant(); |
289 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 289 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
290 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 290 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
291 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 291 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
292 | 292 |
293 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 293 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
294 | 294 |
295 // Check that the value is reflected and onchange is called. | 295 // Check that the value is reflected and onchange is called. |
296 EXPECT_EQ("true 0 0 1 1 a false abc false 3 3", | 296 EXPECT_EQ("true 0 0 1 1 a false abc false 3 3", |
297 GetSearchStateAsString(preview_)); | 297 GetSearchStateAsString(preview_)); |
298 } | 298 } |
299 | 299 |
300 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { | 300 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsArrayOfStrings) { |
301 ASSERT_TRUE(test_server()->Start()); | 301 ASSERT_TRUE(test_server()->Start()); |
| 302 EnableInstant(); |
302 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 303 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
303 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 304 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
304 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 305 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
305 | 306 |
306 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']"); | 307 SetSuggestionsJavascriptArgument(preview_, "['abcde', 'unused']"); |
307 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 308 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
308 EXPECT_STR_EQ("abcde", GetSuggestion()); | 309 EXPECT_STR_EQ("abcde", GetSuggestion()); |
309 } | 310 } |
310 | 311 |
311 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyArray) { | 312 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyArray) { |
312 ASSERT_TRUE(test_server()->Start()); | 313 ASSERT_TRUE(test_server()->Start()); |
| 314 EnableInstant(); |
313 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 315 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
314 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 316 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
315 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 317 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
316 | 318 |
317 SetSuggestionsJavascriptArgument(preview_, "[]"); | 319 SetSuggestionsJavascriptArgument(preview_, "[]"); |
318 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 320 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
319 EXPECT_STR_EQ("", GetSuggestion()); | 321 EXPECT_STR_EQ("", GetSuggestion()); |
320 } | 322 } |
321 | 323 |
322 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsValidJson) { | 324 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsValidJson) { |
323 ASSERT_TRUE(test_server()->Start()); | 325 ASSERT_TRUE(test_server()->Start()); |
| 326 EnableInstant(); |
324 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 327 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
325 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 328 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
326 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 329 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
327 | 330 |
328 SetSuggestionsJavascriptArgument( | 331 SetSuggestionsJavascriptArgument( |
329 preview_, | 332 preview_, |
330 "{suggestions:[{value:'abcdefg'},{value:'unused'}]}"); | 333 "{suggestions:[{value:'abcdefg'},{value:'unused'}]}"); |
331 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 334 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
332 EXPECT_STR_EQ("abcdefg", GetSuggestion()); | 335 EXPECT_STR_EQ("abcdefg", GetSuggestion()); |
333 } | 336 } |
334 | 337 |
335 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsInvalidSuggestions) { | 338 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsInvalidSuggestions) { |
336 ASSERT_TRUE(test_server()->Start()); | 339 ASSERT_TRUE(test_server()->Start()); |
| 340 EnableInstant(); |
337 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 341 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
338 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 342 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
339 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 343 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
340 | 344 |
341 SetSuggestionsJavascriptArgument( | 345 SetSuggestionsJavascriptArgument( |
342 preview_, | 346 preview_, |
343 "{suggestions:{value:'abcdefg'}}"); | 347 "{suggestions:{value:'abcdefg'}}"); |
344 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 348 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
345 EXPECT_STR_EQ("", GetSuggestion()); | 349 EXPECT_STR_EQ("", GetSuggestion()); |
346 } | 350 } |
347 | 351 |
348 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyJson) { | 352 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptyJson) { |
349 ASSERT_TRUE(test_server()->Start()); | 353 ASSERT_TRUE(test_server()->Start()); |
| 354 EnableInstant(); |
350 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 355 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
351 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 356 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
352 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 357 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
353 | 358 |
354 SetSuggestionsJavascriptArgument(preview_, "{}"); | 359 SetSuggestionsJavascriptArgument(preview_, "{}"); |
355 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 360 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
356 EXPECT_STR_EQ("", GetSuggestion()); | 361 EXPECT_STR_EQ("", GetSuggestion()); |
357 } | 362 } |
358 | 363 |
359 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestions) { | 364 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestions) { |
360 ASSERT_TRUE(test_server()->Start()); | 365 ASSERT_TRUE(test_server()->Start()); |
| 366 EnableInstant(); |
361 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 367 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
362 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 368 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
363 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 369 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
364 | 370 |
365 SetSuggestionsJavascriptArgument(preview_, "{suggestions:[]}"); | 371 SetSuggestionsJavascriptArgument(preview_, "{suggestions:[]}"); |
366 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 372 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
367 EXPECT_STR_EQ("", GetSuggestion()); | 373 EXPECT_STR_EQ("", GetSuggestion()); |
368 } | 374 } |
369 | 375 |
370 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestion) { | 376 IN_PROC_BROWSER_TEST_F(InstantTest, SetSuggestionsEmptySuggestion) { |
371 ASSERT_TRUE(test_server()->Start()); | 377 ASSERT_TRUE(test_server()->Start()); |
| 378 EnableInstant(); |
372 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 379 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
373 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 380 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
374 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 381 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
375 | 382 |
376 SetSuggestionsJavascriptArgument(preview_, "{suggestions:[{}]}"); | 383 SetSuggestionsJavascriptArgument(preview_, "{suggestions:[{}]}"); |
377 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 384 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
378 EXPECT_STR_EQ("", GetSuggestion()); | 385 EXPECT_STR_EQ("", GetSuggestion()); |
379 } | 386 } |
380 | 387 |
381 // Verify instant preview is shown correctly for a non-search query. | 388 // Verify instant preview is shown correctly for a non-search query. |
382 IN_PROC_BROWSER_TEST_F(InstantTest, ShowPreviewNonSearch) { | 389 IN_PROC_BROWSER_TEST_F(InstantTest, ShowPreviewNonSearch) { |
383 ASSERT_TRUE(test_server()->Start()); | 390 ASSERT_TRUE(test_server()->Start()); |
| 391 EnableInstant(); |
384 GURL url(test_server()->GetURL("files/instant/empty.html")); | 392 GURL url(test_server()->GetURL("files/instant/empty.html")); |
385 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); | 393 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); |
386 // The preview should be active and showing. | 394 // The preview should be active and showing. |
387 ASSERT_TRUE(browser()->instant()->is_active()); | 395 ASSERT_TRUE(browser()->instant()->is_active()); |
388 ASSERT_TRUE(browser()->instant()->is_displayable()); | 396 ASSERT_TRUE(browser()->instant()->is_displayable()); |
389 ASSERT_TRUE(browser()->instant()->IsCurrent()); | 397 ASSERT_TRUE(browser()->instant()->IsCurrent()); |
390 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); | 398 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); |
391 RenderWidgetHostView* rwhv = | 399 RenderWidgetHostView* rwhv = |
392 browser()->instant()->GetPreviewContents()->tab_contents()-> | 400 browser()->instant()->GetPreviewContents()->tab_contents()-> |
393 GetRenderWidgetHostView(); | 401 GetRenderWidgetHostView(); |
394 ASSERT_TRUE(rwhv); | 402 ASSERT_TRUE(rwhv); |
395 ASSERT_TRUE(rwhv->IsShowing()); | 403 ASSERT_TRUE(rwhv->IsShowing()); |
396 } | 404 } |
397 | 405 |
398 // Transition from non-search to search and make sure everything is shown | 406 // Transition from non-search to search and make sure everything is shown |
399 // correctly. | 407 // correctly. |
400 IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearch) { | 408 IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearch) { |
401 ASSERT_TRUE(test_server()->Start()); | 409 ASSERT_TRUE(test_server()->Start()); |
| 410 EnableInstant(); |
402 GURL url(test_server()->GetURL("files/instant/empty.html")); | 411 GURL url(test_server()->GetURL("files/instant/empty.html")); |
403 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); | 412 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); |
404 // The preview should be active and showing. | 413 // The preview should be active and showing. |
405 ASSERT_TRUE(browser()->instant()->is_active()); | 414 ASSERT_TRUE(browser()->instant()->is_active()); |
406 ASSERT_TRUE(browser()->instant()->is_displayable()); | 415 ASSERT_TRUE(browser()->instant()->is_displayable()); |
407 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); | 416 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); |
408 ASSERT_TRUE(initial_tab); | 417 ASSERT_TRUE(initial_tab); |
409 RenderWidgetHostView* rwhv = | 418 RenderWidgetHostView* rwhv = |
410 initial_tab->tab_contents()->GetRenderWidgetHostView(); | 419 initial_tab->tab_contents()->GetRenderWidgetHostView(); |
411 ASSERT_TRUE(rwhv); | 420 ASSERT_TRUE(rwhv); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 // Showing as flaky on Mac | 481 // Showing as flaky on Mac |
473 // http://crbug.com/70860 | 482 // http://crbug.com/70860 |
474 #define MAYBE_SearchServerDoesntSupportInstant \ | 483 #define MAYBE_SearchServerDoesntSupportInstant \ |
475 DISABLED_SearchServerDoesntSupportInstant | 484 DISABLED_SearchServerDoesntSupportInstant |
476 #else | 485 #else |
477 #define MAYBE_SearchServerDoesntSupportInstant \ | 486 #define MAYBE_SearchServerDoesntSupportInstant \ |
478 SearchServerDoesntSupportInstant | 487 SearchServerDoesntSupportInstant |
479 #endif | 488 #endif |
480 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { | 489 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { |
481 ASSERT_TRUE(test_server()->Start()); | 490 ASSERT_TRUE(test_server()->Start()); |
| 491 EnableInstant(); |
482 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); | 492 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
483 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 493 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
484 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); | 494 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("a")); |
485 ASSERT_TRUE(browser()->instant()); | 495 ASSERT_TRUE(browser()->instant()); |
486 // Because we typed in a search string we should think we're showing instant | 496 // Because we typed in a search string we should think we're showing instant |
487 // results. | 497 // results. |
488 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); | 498 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); |
489 // But because we're waiting to determine if the page really supports instant | 499 // But because we're waiting to determine if the page really supports instant |
490 // we shouldn't be showing the preview. | 500 // we shouldn't be showing the preview. |
491 EXPECT_FALSE(browser()->instant()->is_displayable()); | 501 EXPECT_FALSE(browser()->instant()->is_displayable()); |
(...skipping 17 matching lines...) Expand all Loading... |
509 // http://crbug.com/70810 | 519 // http://crbug.com/70810 |
510 #define MAYBE_NonSearchToSearchDoesntSupportInstant \ | 520 #define MAYBE_NonSearchToSearchDoesntSupportInstant \ |
511 DISABLED_NonSearchToSearchDoesntSupportInstant | 521 DISABLED_NonSearchToSearchDoesntSupportInstant |
512 #else | 522 #else |
513 #define MAYBE_NonSearchToSearchDoesntSupportInstant \ | 523 #define MAYBE_NonSearchToSearchDoesntSupportInstant \ |
514 NonSearchToSearchDoesntSupportInstant | 524 NonSearchToSearchDoesntSupportInstant |
515 #endif | 525 #endif |
516 IN_PROC_BROWSER_TEST_F(InstantTest, | 526 IN_PROC_BROWSER_TEST_F(InstantTest, |
517 MAYBE_NonSearchToSearchDoesntSupportInstant) { | 527 MAYBE_NonSearchToSearchDoesntSupportInstant) { |
518 ASSERT_TRUE(test_server()->Start()); | 528 ASSERT_TRUE(test_server()->Start()); |
| 529 EnableInstant(); |
519 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); | 530 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
520 GURL url(test_server()->GetURL("files/instant/empty.html")); | 531 GURL url(test_server()->GetURL("files/instant/empty.html")); |
521 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); | 532 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); |
522 // The preview should be active and showing. | 533 // The preview should be active and showing. |
523 ASSERT_TRUE(browser()->instant()->is_displayable()); | 534 ASSERT_TRUE(browser()->instant()->is_displayable()); |
524 ASSERT_TRUE(browser()->instant()->is_active()); | 535 ASSERT_TRUE(browser()->instant()->is_active()); |
525 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); | 536 TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); |
526 ASSERT_TRUE(initial_tab); | 537 ASSERT_TRUE(initial_tab); |
527 RenderWidgetHostView* rwhv = | 538 RenderWidgetHostView* rwhv = |
528 initial_tab->tab_contents()->GetRenderWidgetHostView(); | 539 initial_tab->tab_contents()->GetRenderWidgetHostView(); |
(...skipping 17 matching lines...) Expand all Loading... |
546 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 557 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); |
547 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); | 558 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); |
548 EXPECT_FALSE(browser()->instant()->is_displayable()); | 559 EXPECT_FALSE(browser()->instant()->is_displayable()); |
549 // But because the omnibox is still open, instant should be active. | 560 // But because the omnibox is still open, instant should be active. |
550 ASSERT_TRUE(browser()->instant()->is_active()); | 561 ASSERT_TRUE(browser()->instant()->is_active()); |
551 } | 562 } |
552 | 563 |
553 // Verifies the page was told a non-zero height. | 564 // Verifies the page was told a non-zero height. |
554 IN_PROC_BROWSER_TEST_F(InstantTest, ValidHeight) { | 565 IN_PROC_BROWSER_TEST_F(InstantTest, ValidHeight) { |
555 ASSERT_TRUE(test_server()->Start()); | 566 ASSERT_TRUE(test_server()->Start()); |
| 567 EnableInstant(); |
556 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 568 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
557 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 569 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
558 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 570 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
559 | 571 |
560 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 572 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
561 | 573 |
562 int height; | 574 int height; |
563 | 575 |
564 // searchBox height is not yet set during initial load. | 576 // searchBox height is not yet set during initial load. |
565 ASSERT_TRUE(GetIntFromJavascript(preview_, | 577 ASSERT_TRUE(GetIntFromJavascript(preview_, |
566 "window.beforeLoadSearchBox.height", | 578 "window.beforeLoadSearchBox.height", |
567 &height)); | 579 &height)); |
568 EXPECT_EQ(0, height); | 580 EXPECT_EQ(0, height); |
569 | 581 |
570 // searchBox height is available by the time the page loads. | 582 // searchBox height is available by the time the page loads. |
571 ASSERT_TRUE(GetIntFromJavascript(preview_, | 583 ASSERT_TRUE(GetIntFromJavascript(preview_, |
572 "window.chrome.searchBox.height", | 584 "window.chrome.searchBox.height", |
573 &height)); | 585 &height)); |
574 EXPECT_GT(height, 0); | 586 EXPECT_GT(height, 0); |
575 } | 587 } |
576 | 588 |
577 // Verifies that if the server returns a 403 we don't show the preview and | 589 // Verifies that if the server returns a 403 we don't show the preview and |
578 // query the host again. | 590 // query the host again. |
579 IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { | 591 IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) { |
580 ASSERT_TRUE(test_server()->Start()); | 592 ASSERT_TRUE(test_server()->Start()); |
| 593 EnableInstant(); |
581 GURL url(test_server()->GetURL("files/instant/403.html")); | 594 GURL url(test_server()->GetURL("files/instant/403.html")); |
582 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 595 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
583 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 596 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
584 // The preview shouldn't be showing, but it should be loading. | 597 // The preview shouldn't be showing, but it should be loading. |
585 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); | 598 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); |
586 ASSERT_TRUE(browser()->instant()->is_active()); | 599 ASSERT_TRUE(browser()->instant()->is_active()); |
587 ASSERT_FALSE(browser()->instant()->is_displayable()); | 600 ASSERT_FALSE(browser()->instant()->is_displayable()); |
588 | 601 |
589 // When instant sees the 403, it should close the tab. | 602 // When instant sees the 403, it should close the tab. |
590 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 603 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); |
591 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 604 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
592 ASSERT_TRUE(browser()->instant()->is_active()); | 605 ASSERT_TRUE(browser()->instant()->is_active()); |
593 ASSERT_FALSE(browser()->instant()->is_displayable()); | 606 ASSERT_FALSE(browser()->instant()->is_displayable()); |
594 | 607 |
595 // Try loading another url on the server. Instant shouldn't create a new tab | 608 // Try loading another url on the server. Instant shouldn't create a new tab |
596 // as the server returned 403. | 609 // as the server returned 403. |
597 GURL url2(test_server()->GetURL("files/instant/empty.html")); | 610 GURL url2(test_server()->GetURL("files/instant/empty.html")); |
598 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); | 611 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); |
599 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 612 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
600 ASSERT_TRUE(browser()->instant()->is_active()); | 613 ASSERT_TRUE(browser()->instant()->is_active()); |
601 ASSERT_FALSE(browser()->instant()->is_displayable()); | 614 ASSERT_FALSE(browser()->instant()->is_displayable()); |
602 } | 615 } |
603 | 616 |
604 // Verify that the onsubmit event is dispatched upon pressing enter. | 617 // Verify that the onsubmit event is dispatched upon pressing enter. |
605 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { | 618 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
606 ASSERT_TRUE(test_server()->Start()); | 619 ASSERT_TRUE(test_server()->Start()); |
| 620 EnableInstant(); |
607 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 621 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
608 | 622 |
609 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 623 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
610 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 624 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
611 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 625 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
612 | 626 |
613 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 627 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
614 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); | 628 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); |
615 | 629 |
616 // Check that the preview contents have been committed. | 630 // Check that the preview contents have been committed. |
617 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 631 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
618 ASSERT_FALSE(browser()->instant()->is_active()); | 632 ASSERT_FALSE(browser()->instant()->is_active()); |
619 TabContents* contents = browser()->GetSelectedTabContents(); | 633 TabContents* contents = browser()->GetSelectedTabContents(); |
620 ASSERT_TRUE(contents); | 634 ASSERT_TRUE(contents); |
621 | 635 |
622 // Check that the value is reflected and onsubmit is called. | 636 // Check that the value is reflected and onsubmit is called. |
623 EXPECT_EQ("true 1 0 1 1 a false abc true 3 3", | 637 EXPECT_EQ("true 1 0 1 1 a false abc true 3 3", |
624 GetSearchStateAsString(preview_)); | 638 GetSearchStateAsString(preview_)); |
625 } | 639 } |
626 | 640 |
627 // Verify that the oncancel event is dispatched upon losing focus. | 641 // Verify that the oncancel event is dispatched upon losing focus. |
628 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { | 642 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
629 ASSERT_TRUE(test_server()->Start()); | 643 ASSERT_TRUE(test_server()->Start()); |
| 644 EnableInstant(); |
630 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 645 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
631 | 646 |
632 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 647 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
633 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 648 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
634 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 649 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
635 | 650 |
636 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 651 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
637 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), | 652 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), |
638 VIEW_ID_TAB_CONTAINER)); | 653 VIEW_ID_TAB_CONTAINER)); |
639 | 654 |
640 // Check that the preview contents have been committed. | 655 // Check that the preview contents have been committed. |
641 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 656 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
642 ASSERT_FALSE(browser()->instant()->is_active()); | 657 ASSERT_FALSE(browser()->instant()->is_active()); |
643 TabContents* contents = browser()->GetSelectedTabContents(); | 658 TabContents* contents = browser()->GetSelectedTabContents(); |
644 ASSERT_TRUE(contents); | 659 ASSERT_TRUE(contents); |
645 | 660 |
646 // Check that the value is reflected and oncancel is called. | 661 // Check that the value is reflected and oncancel is called. |
647 EXPECT_EQ("true 0 1 1 1 a false abc false 3 3", | 662 EXPECT_EQ("true 0 1 1 1 a false abc false 3 3", |
648 GetSearchStateAsString(preview_)); | 663 GetSearchStateAsString(preview_)); |
649 } | 664 } |
650 | 665 |
651 #if !defined(OS_MACOSX) | 666 #if !defined(OS_MACOSX) |
652 // Only passes on Mac. http://crbug.com/66850 | 667 // Only passes on Mac. http://crbug.com/66850 |
653 #define MAYBE_TabKey FAILS_TabKey | 668 #define MAYBE_TabKey FAILS_TabKey |
654 #else | 669 #else |
655 #define MAYBE_TabKey TabKey | 670 #define MAYBE_TabKey TabKey |
656 #endif | 671 #endif |
657 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { | 672 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) { |
658 ASSERT_TRUE(test_server()->Start()); | 673 ASSERT_TRUE(test_server()->Start()); |
| 674 EnableInstant(); |
659 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 675 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
660 | 676 |
661 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 677 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
662 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 678 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
663 ASSERT_NO_FATAL_FAILURE(SetupPreview()); | 679 ASSERT_NO_FATAL_FAILURE(SetupPreview()); |
664 | 680 |
665 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); | 681 ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc")); |
666 | 682 |
667 // Pressing tab to convert instant suggest into inline autocomplete. | 683 // Pressing tab to convert instant suggest into inline autocomplete. |
668 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 684 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
669 | 685 |
670 ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText()); | 686 ASSERT_EQ(ASCIIToUTF16("abcdef"), location_bar_->location_entry()->GetText()); |
671 | 687 |
672 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", | 688 EXPECT_EQ("true 0 0 2 2 a false abcdef false 6 6", |
673 GetSearchStateAsString(preview_)); | 689 GetSearchStateAsString(preview_)); |
674 | 690 |
675 // Pressing tab again to accept the current instant preview. | 691 // Pressing tab again to accept the current instant preview. |
676 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); | 692 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_TAB)); |
677 | 693 |
678 // Check that the preview contents have been committed. | 694 // Check that the preview contents have been committed. |
679 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 695 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
680 ASSERT_FALSE(browser()->instant()->is_active()); | 696 ASSERT_FALSE(browser()->instant()->is_active()); |
681 TabContents* contents = browser()->GetSelectedTabContents(); | 697 TabContents* contents = browser()->GetSelectedTabContents(); |
682 ASSERT_TRUE(contents); | 698 ASSERT_TRUE(contents); |
683 | 699 |
684 // Check that the value is reflected and onsubmit is called. | 700 // Check that the value is reflected and onsubmit is called. |
685 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6", | 701 EXPECT_EQ("true 1 0 2 2 a false abcdef true 6 6", |
686 GetSearchStateAsString(preview_)); | 702 GetSearchStateAsString(preview_)); |
687 } | 703 } |
OLD | NEW |