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

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

Issue 8298005: Fixes bug in instant where we would end up incorrectly using the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (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.h" 8 #include "chrome/browser/autocomplete/autocomplete_edit.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/instant/instant_controller.h" 10 #include "chrome/browser/instant/instant_controller.h"
(...skipping 30 matching lines...) Expand all
41 #define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson 41 #define MAYBE_SetSuggestionsValidJson DISABLED_SetSuggestionsValidJson
42 #define MAYBE_SetSuggestionsInvalidSuggestions \ 42 #define MAYBE_SetSuggestionsInvalidSuggestions \
43 DISABLED_SetSuggestionsInvalidSuggestions 43 DISABLED_SetSuggestionsInvalidSuggestions
44 #define MAYBE_SetSuggestionsEmptyJson DISABLED_SetSuggestionsEmptyJson 44 #define MAYBE_SetSuggestionsEmptyJson DISABLED_SetSuggestionsEmptyJson
45 #define MAYBE_SetSuggestionsEmptySuggestions \ 45 #define MAYBE_SetSuggestionsEmptySuggestions \
46 DISABLED_SetSuggestionsEmptySuggestions 46 DISABLED_SetSuggestionsEmptySuggestions
47 #define MAYBE_SetSuggestionsEmptySuggestion \ 47 #define MAYBE_SetSuggestionsEmptySuggestion \
48 DISABLED_SetSuggestionsEmptySuggestion 48 DISABLED_SetSuggestionsEmptySuggestion
49 #define MAYBE_ShowPreviewNonSearch DISABLED_ShowPreviewNonSearch 49 #define MAYBE_ShowPreviewNonSearch DISABLED_ShowPreviewNonSearch
50 #define MAYBE_NonSearchToSearch DISABLED_NonSearchToSearch 50 #define MAYBE_NonSearchToSearch DISABLED_NonSearchToSearch
51 #define MAYBE_SearchToNonSearch DISABLED_SearchToNonSearch
51 #define MAYBE_ValidHeight DISABLED_ValidHeight 52 #define MAYBE_ValidHeight DISABLED_ValidHeight
52 #define MAYBE_OnSubmitEvent DISABLED_OnSubmitEvent 53 #define MAYBE_OnSubmitEvent DISABLED_OnSubmitEvent
53 #define MAYBE_OnCancelEvent DISABLED_OnCancelEvent 54 #define MAYBE_OnCancelEvent DISABLED_OnCancelEvent
54 #define MAYBE_InstantCompleteNever DISABLED_InstantCompleteNever 55 #define MAYBE_InstantCompleteNever DISABLED_InstantCompleteNever
55 #define MAYBE_InstantCompleteDelayed DISABLED_InstantCompleteDelayed 56 #define MAYBE_InstantCompleteDelayed DISABLED_InstantCompleteDelayed
56 #define MAYBE_DontCrashOnBlockedJS DISABLED_DontCrashOnBlockedJS 57 #define MAYBE_DontCrashOnBlockedJS DISABLED_DontCrashOnBlockedJS
57 #define MAYBE_DontPersistSearchbox DISABLED_DontPersistSearchbox 58 #define MAYBE_DontPersistSearchbox DISABLED_DontPersistSearchbox
58 #define MAYBE_PreloadsInstant DISABLED_PreloadsInstant 59 #define MAYBE_PreloadsInstant DISABLED_PreloadsInstant
59 #define MAYBE_ExperimentEnabled DISABLED_ExperimentEnabled 60 #define MAYBE_ExperimentEnabled DISABLED_ExperimentEnabled
60 #else 61 #else
61 #define MAYBE_OnChangeEvent OnChangeEvent 62 #define MAYBE_OnChangeEvent OnChangeEvent
62 #define MAYBE_SetSuggestionsArrayOfStrings SetSuggestionsArrayOfStrings 63 #define MAYBE_SetSuggestionsArrayOfStrings SetSuggestionsArrayOfStrings
63 #define MAYBE_SetSuggestionsEmptyArray SetSuggestionsEmptyArray 64 #define MAYBE_SetSuggestionsEmptyArray SetSuggestionsEmptyArray
64 #define MAYBE_SetSuggestionsValidJson SetSuggestionsValidJson 65 #define MAYBE_SetSuggestionsValidJson SetSuggestionsValidJson
65 #define MAYBE_SetSuggestionsInvalidSuggestions SetSuggestionsInvalidSuggestions 66 #define MAYBE_SetSuggestionsInvalidSuggestions SetSuggestionsInvalidSuggestions
66 #define MAYBE_SetSuggestionsEmptyJson SetSuggestionsEmptyJson 67 #define MAYBE_SetSuggestionsEmptyJson SetSuggestionsEmptyJson
67 #define MAYBE_SetSuggestionsEmptySuggestions SetSuggestionsEmptySuggestions 68 #define MAYBE_SetSuggestionsEmptySuggestions SetSuggestionsEmptySuggestions
68 #define MAYBE_SetSuggestionsEmptySuggestion SetSuggestionsEmptySuggestion 69 #define MAYBE_SetSuggestionsEmptySuggestion SetSuggestionsEmptySuggestion
69 #define MAYBE_ShowPreviewNonSearch ShowPreviewNonSearch 70 #define MAYBE_ShowPreviewNonSearch ShowPreviewNonSearch
70 #define MAYBE_NonSearchToSearch NonSearchToSearch 71 #define MAYBE_NonSearchToSearch NonSearchToSearch
72 #define MAYBE_SearchToNonSearch SearchToNonSearch
71 #define MAYBE_ValidHeight ValidHeight 73 #define MAYBE_ValidHeight ValidHeight
72 #define MAYBE_OnSubmitEvent OnSubmitEvent 74 #define MAYBE_OnSubmitEvent OnSubmitEvent
73 #define MAYBE_OnCancelEvent OnCancelEvent 75 #define MAYBE_OnCancelEvent OnCancelEvent
74 #define MAYBE_InstantCompleteNever InstantCompleteNever 76 #define MAYBE_InstantCompleteNever InstantCompleteNever
75 #define MAYBE_InstantCompleteDelayed InstantCompleteDelayed 77 #define MAYBE_InstantCompleteDelayed InstantCompleteDelayed
76 #define MAYBE_DontCrashOnBlockedJS DontCrashOnBlockedJS 78 #define MAYBE_DontCrashOnBlockedJS DontCrashOnBlockedJS
77 #define MAYBE_DontPersistSearchbox DontPersistSearchbox 79 #define MAYBE_DontPersistSearchbox DontPersistSearchbox
78 #define MAYBE_PreloadsInstant PreloadsInstant 80 #define MAYBE_PreloadsInstant PreloadsInstant
79 #define MAYBE_ExperimentEnabled ExperimentEnabled 81 #define MAYBE_ExperimentEnabled ExperimentEnabled
80 #endif 82 #endif
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ASSERT_TRUE(preview_); 167 ASSERT_TRUE(preview_);
166 ui_test_utils::WaitForNavigation(&preview_->controller()); 168 ui_test_utils::WaitForNavigation(&preview_->controller());
167 } 169 }
168 170
169 // Wait for instant to load and ensure it is in the state we expect. 171 // Wait for instant to load and ensure it is in the state we expect.
170 void SetupPreview() { 172 void SetupPreview() {
171 // Wait for the preview to navigate. 173 // Wait for the preview to navigate.
172 WaitForPreviewToNavigate(); 174 WaitForPreviewToNavigate();
173 175
174 ASSERT_FALSE(browser()->instant()->is_displayable()); 176 ASSERT_FALSE(browser()->instant()->is_displayable());
175 ASSERT_TRUE(browser()->instant()->is_active()); 177 ASSERT_TRUE(HasPreview());
176 178
177 // When the page loads, the initial searchBox values are set and only a 179 // When the page loads, the initial searchBox values are set and only a
178 // resize will have been sent. 180 // resize will have been sent.
179 ASSERT_EQ("true 0 0 0 true d false d false 1 1", 181 ASSERT_EQ("true 0 0 0 true d false d false 1 1",
180 GetSearchStateAsString(preview_, false)); 182 GetSearchStateAsString(preview_, false));
181 } 183 }
182 184
183 void SetLocationBarText(const std::string& text) { 185 void SetLocationBarText(const std::string& text) {
184 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 186 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
185 ui_test_utils::WindowedNotificationObserver controller_shown_observer( 187 ui_test_utils::WindowedNotificationObserver controller_shown_observer(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 bool GetBoolFromJavascript(TabContents* tab_contents, 238 bool GetBoolFromJavascript(TabContents* tab_contents,
237 const std::string& function, 239 const std::string& function,
238 bool* result) { 240 bool* result) {
239 std::string script = StringPrintf( 241 std::string script = StringPrintf(
240 "window.domAutomationController.send(%s)", function.c_str()); 242 "window.domAutomationController.send(%s)", function.c_str());
241 return ui_test_utils::ExecuteJavaScriptAndExtractBool( 243 return ui_test_utils::ExecuteJavaScriptAndExtractBool(
242 tab_contents->render_view_host(), 244 tab_contents->render_view_host(),
243 std::wstring(), UTF8ToWide(script), result); 245 std::wstring(), UTF8ToWide(script), result);
244 } 246 }
245 247
248 bool HasPreview() {
249 return browser()->instant()->GetPreviewContents() != NULL;
250 }
251
246 // Returns the state of the search box as a string. This consists of the 252 // Returns the state of the search box as a string. This consists of the
247 // following: 253 // following:
248 // window.chrome.sv 254 // window.chrome.sv
249 // window.onsubmitcalls 255 // window.onsubmitcalls
250 // window.oncancelcalls 256 // window.oncancelcalls
251 // window.onchangecalls 257 // window.onchangecalls
252 // 'true' if window.onresizecalls has been sent, otherwise false. 258 // 'true' if window.onresizecalls has been sent, otherwise false.
253 // window.beforeLoadSearchBox.value 259 // window.beforeLoadSearchBox.value
254 // window.beforeLoadSearchBox.verbatim 260 // window.beforeLoadSearchBox.verbatim
255 // window.chrome.searchBox.value 261 // window.chrome.searchBox.value
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 504 }
499 505
500 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ShowPreviewNonSearch) { 506 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ShowPreviewNonSearch) {
501 ASSERT_TRUE(test_server()->Start()); 507 ASSERT_TRUE(test_server()->Start());
502 EnableInstant(); 508 EnableInstant();
503 GURL url(test_server()->GetURL("files/instant/empty.html")); 509 GURL url(test_server()->GetURL("files/instant/empty.html"));
504 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 510 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
505 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); 511 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
506 512
507 // The preview should not be active or showing. 513 // The preview should not be active or showing.
508 ASSERT_FALSE(browser()->instant()->is_active()); 514 ASSERT_FALSE(HasPreview());
509 ASSERT_FALSE(browser()->instant()->is_displayable()); 515 ASSERT_FALSE(browser()->instant()->is_displayable());
510 ASSERT_FALSE(browser()->instant()->IsCurrent()); 516 ASSERT_FALSE(browser()->instant()->IsCurrent());
511 ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents()); 517 ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());
512 } 518 }
513 519
514 // Transition from non-search to search and make sure everything is shown 520 // Transition from non-search to search and make sure everything is shown
515 // correctly. 521 // correctly.
516 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearch) { 522 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NonSearchToSearch) {
517 ASSERT_TRUE(test_server()->Start()); 523 ASSERT_TRUE(test_server()->Start());
518 EnableInstant(); 524 EnableInstant();
519 GURL url(test_server()->GetURL("files/instant/empty.html")); 525 GURL url(test_server()->GetURL("files/instant/empty.html"));
520 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 526 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
521 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); 527 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
522 // The preview not should be active and not showing. 528 // The preview not should be active and not showing.
523 ASSERT_FALSE(browser()->instant()->is_active()); 529 ASSERT_FALSE(HasPreview());
524 ASSERT_FALSE(browser()->instant()->is_displayable()); 530 ASSERT_FALSE(browser()->instant()->is_displayable());
525 ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents()); 531 ASSERT_EQ(NULL, browser()->instant()->GetPreviewContents());
526 532
527 // Now type in some search text. 533 // Now type in some search text.
528 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 534 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
529 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def")); 535 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));
530 536
531 // Wait for the preview to navigate. 537 // Wait for the preview to navigate.
532 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate()); 538 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());
533 539
534 // The controller is still determining if the provider really supports 540 // The controller is still determining if the provider really supports
535 // instant. 541 // instant.
536 TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents(); 542 TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
537 ASSERT_TRUE(current_tab); 543 ASSERT_TRUE(current_tab);
538 544
539 // Instant should be active. 545 // Instant should be active.
540 EXPECT_TRUE(browser()->instant()->is_active()); 546 EXPECT_TRUE(HasPreview());
541 EXPECT_FALSE(browser()->instant()->is_displayable()); 547 EXPECT_FALSE(browser()->instant()->is_displayable());
542 548
543 // Because we're waiting on the page, instant isn't current. 549 // Because we're waiting on the page, instant isn't current.
544 ASSERT_FALSE(browser()->instant()->IsCurrent()); 550 ASSERT_FALSE(browser()->instant()->IsCurrent());
545 551
546 // Bounce a message to the renderer so that we know the instant has gotten a 552 // Bounce a message to the renderer so that we know the instant has gotten a
547 // response back from the renderer as to whether the page supports instant. 553 // response back from the renderer as to whether the page supports instant.
548 ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab)); 554 ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
549 555
550 // Reset the user text so that the page is told the text changed. We should be 556 // Reset the user text so that the page is told the text changed. We should be
551 // able to nuke this once 66104 is fixed. 557 // able to nuke this once 66104 is fixed.
552 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("defg")); 558 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("defg"));
553 559
554 // Wait for the renderer to process it. 560 // Wait for the renderer to process it.
555 ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab)); 561 ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
556 562
557 // We should have gotten a response back from the renderer that resulted in 563 // We should have gotten a response back from the renderer that resulted in
558 // committing. 564 // committing.
559 ASSERT_TRUE(browser()->instant()->is_active()); 565 ASSERT_TRUE(HasPreview());
560 ASSERT_TRUE(browser()->instant()->is_displayable()); 566 ASSERT_TRUE(browser()->instant()->is_displayable());
561 TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents(); 567 TabContentsWrapper* new_tab = browser()->instant()->GetPreviewContents();
562 ASSERT_TRUE(new_tab); 568 ASSERT_TRUE(new_tab);
563 RenderWidgetHostView* new_rwhv = 569 RenderWidgetHostView* new_rwhv =
564 new_tab->tab_contents()->GetRenderWidgetHostView(); 570 new_tab->tab_contents()->GetRenderWidgetHostView();
565 ASSERT_TRUE(new_rwhv); 571 ASSERT_TRUE(new_rwhv);
566 ASSERT_TRUE(new_rwhv->IsShowing()); 572 ASSERT_TRUE(new_rwhv->IsShowing());
567 } 573 }
568 574
575 // Transition from search to non-search and make sure instant isn't displayable.
576 // See bug http://crbug.com/100368 for details.
577 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchToNonSearch) {
578 ASSERT_TRUE(test_server()->Start());
579 EnableInstant();
580 GURL url(test_server()->GetURL("files/instant/empty.html"));
581 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
582
583 // Type in some search text.
584 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
585 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("def"));
586
587 // Load a non search url. Don't wait for the preview to navigate. It'll still
588 // end up loading in the background.
589 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
590
591 // Wait for the preview to navigate.
592 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate());
593
594 // Send onchange so that the page sends up suggestions.
595 TabContentsWrapper* current_tab = browser()->instant()->GetPreviewContents();
596 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
597 current_tab->tab_contents()->render_view_host(), std::wstring(),
598 L"window.chrome.searchBox.onchange();"));
599 ASSERT_NO_FATAL_FAILURE(WaitForMessageToBeProcessedByRenderer(current_tab));
600
601 // Instant should be active, but not displaying
602 EXPECT_TRUE(HasPreview());
603 EXPECT_FALSE(browser()->instant()->is_displayable());
604 }
605
569 // Makes sure that if the server doesn't support the instant API we don't show 606 // Makes sure that if the server doesn't support the instant API we don't show
570 // anything. 607 // anything.
571 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) { 608 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_SearchServerDoesntSupportInstant) {
572 ASSERT_TRUE(test_server()->Start()); 609 ASSERT_TRUE(test_server()->Start());
573 EnableInstant(); 610 EnableInstant();
574 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); 611 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
575 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 612 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
576 613
577 ui_test_utils::WindowedNotificationObserver tab_closed_observer( 614 ui_test_utils::WindowedNotificationObserver tab_closed_observer(
578 content::NOTIFICATION_TAB_CLOSED, 615 content::NOTIFICATION_TAB_CLOSED,
579 NotificationService::AllSources()); 616 NotificationService::AllSources());
580 617
581 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); 618 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
582 ASSERT_TRUE(browser()->instant()); 619 ASSERT_TRUE(browser()->instant());
583 // But because we're waiting to determine if the page really supports instant 620 // But because we're waiting to determine if the page really supports instant
584 // we shouldn't be showing the preview. 621 // we shouldn't be showing the preview.
585 EXPECT_FALSE(browser()->instant()->is_displayable()); 622 EXPECT_FALSE(browser()->instant()->is_displayable());
586 // But instant should still be active. 623 // But instant should still be active.
587 EXPECT_TRUE(browser()->instant()->is_active()); 624 EXPECT_TRUE(HasPreview());
588 625
589 // When the response comes back that the page doesn't support instant the tab 626 // When the response comes back that the page doesn't support instant the tab
590 // should be closed. 627 // should be closed.
591 tab_closed_observer.Wait(); 628 tab_closed_observer.Wait();
592 EXPECT_FALSE(browser()->instant()->is_displayable()); 629 EXPECT_FALSE(browser()->instant()->is_displayable());
593 EXPECT_TRUE(browser()->instant()->is_active()); 630 EXPECT_FALSE(HasPreview());
594 EXPECT_FALSE(browser()->instant()->IsCurrent()); 631 EXPECT_FALSE(browser()->instant()->IsCurrent());
595 } 632 }
596 633
597 // Verifies that Instant previews aren't shown for crash URLs. 634 // Verifies that Instant previews aren't shown for crash URLs.
598 IN_PROC_BROWSER_TEST_F(InstantTest, CrashUrlCancelsInstant) { 635 IN_PROC_BROWSER_TEST_F(InstantTest, CrashUrlCancelsInstant) {
599 ASSERT_TRUE(test_server()->Start()); 636 ASSERT_TRUE(test_server()->Start());
600 EnableInstant(); 637 EnableInstant();
601 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); 638 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
602 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 639 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
603 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("chrome://crash")); 640 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("chrome://crash"));
604 ASSERT_TRUE(browser()->instant()); 641 ASSERT_TRUE(browser()->instant());
605 EXPECT_FALSE(browser()->instant()->is_displayable()); 642 EXPECT_FALSE(browser()->instant()->is_displayable());
606 } 643 }
607 644
608 // Verifies transitioning from loading a non-search string to a search string 645 // Verifies transitioning from loading a non-search string to a search string
609 // with the provider not supporting instant works (meaning we don't display 646 // with the provider not supporting instant works (meaning we don't display
610 // anything). 647 // anything).
611 IN_PROC_BROWSER_TEST_F(InstantTest, 648 IN_PROC_BROWSER_TEST_F(InstantTest,
612 MAYBE_NonSearchToSearchDoesntSupportInstant) { 649 MAYBE_NonSearchToSearchDoesntSupportInstant) {
613 ASSERT_TRUE(test_server()->Start()); 650 ASSERT_TRUE(test_server()->Start());
614 EnableInstant(); 651 EnableInstant();
615 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); 652 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html"));
616 GURL url(test_server()->GetURL("files/instant/empty.html")); 653 GURL url(test_server()->GetURL("files/instant/empty.html"));
617 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); 654 ASSERT_NO_FATAL_FAILURE(FindLocationBar());
618 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); 655 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec()));
619 // The preview should not be showing or active. 656 // The preview should not be showing or active.
620 EXPECT_FALSE(browser()->instant()->is_displayable()); 657 EXPECT_FALSE(browser()->instant()->is_displayable());
621 EXPECT_FALSE(browser()->instant()->is_active()); 658 EXPECT_FALSE(HasPreview());
622 659
623 ui_test_utils::WindowedNotificationObserver tab_closed_observer( 660 ui_test_utils::WindowedNotificationObserver tab_closed_observer(
624 content::NOTIFICATION_TAB_CLOSED, 661 content::NOTIFICATION_TAB_CLOSED,
625 NotificationService::AllSources()); 662 NotificationService::AllSources());
626 663
627 // Now type in some search text. 664 // Now type in some search text.
628 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d")); 665 location_bar_->location_entry()->SetUserText(ASCIIToUTF16("d"));
629 666
630 // Instant should be active. 667 // Instant should be active.
631 ASSERT_TRUE(browser()->instant()->is_active()); 668 ASSERT_TRUE(HasPreview());
632 // Instant should not be current (it's still loading). 669 // Instant should not be current (it's still loading).
633 EXPECT_FALSE(browser()->instant()->IsCurrent()); 670 EXPECT_FALSE(browser()->instant()->IsCurrent());
634 671
635 // When the response comes back that the page doesn't support instant the tab 672 // When the response comes back that the page doesn't support instant the tab
636 // should be closed. 673 // should be closed.
637 tab_closed_observer.Wait(); 674 tab_closed_observer.Wait();
638 EXPECT_FALSE(browser()->instant()->is_displayable()); 675 EXPECT_FALSE(browser()->instant()->is_displayable());
639 // But because the omnibox is still open, instant should be active. 676 EXPECT_FALSE(HasPreview());
640 EXPECT_TRUE(browser()->instant()->is_active());
641 EXPECT_FALSE(browser()->instant()->is_displayable());
642 EXPECT_FALSE(browser()->instant()->IsCurrent()); 677 EXPECT_FALSE(browser()->instant()->IsCurrent());
643 EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents()); 678 EXPECT_EQ(NULL, browser()->instant()->GetPreviewContents());
644 } 679 }
645 680
646 // Verifies the page was told a non-zero height. 681 // Verifies the page was told a non-zero height.
647 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ValidHeight) { 682 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_ValidHeight) {
648 ASSERT_TRUE(test_server()->Start()); 683 ASSERT_TRUE(test_server()->Start());
649 EnableInstant(); 684 EnableInstant();
650 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); 685 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
651 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 686 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
(...skipping 24 matching lines...) Expand all
676 711
677 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 712 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
678 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 713 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
679 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 714 ASSERT_NO_FATAL_FAILURE(SetupPreview());
680 715
681 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def")); 716 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
682 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); 717 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));
683 718
684 // Check that the preview contents have been committed. 719 // Check that the preview contents have been committed.
685 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 720 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
686 ASSERT_FALSE(browser()->instant()->is_active()); 721 ASSERT_FALSE(HasPreview());
687 TabContents* contents = browser()->GetSelectedTabContents(); 722 TabContents* contents = browser()->GetSelectedTabContents();
688 ASSERT_TRUE(contents); 723 ASSERT_TRUE(contents);
689 724
690 // We should have two entries. One corresponding to the page the user was 725 // We should have two entries. One corresponding to the page the user was
691 // first on, and one for the search page. 726 // first on, and one for the search page.
692 ASSERT_EQ(2, contents->controller().entry_count()); 727 ASSERT_EQ(2, contents->controller().entry_count());
693 728
694 // Check that the value is reflected and onsubmit is called. 729 // Check that the value is reflected and onsubmit is called.
695 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", 730 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3",
696 GetSearchStateAsString(preview_, true)); 731 GetSearchStateAsString(preview_, true));
(...skipping 12 matching lines...) Expand all
709 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 744 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
710 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 745 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
711 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 746 ASSERT_NO_FATAL_FAILURE(SetupPreview());
712 747
713 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def")); 748 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
714 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), 749 ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
715 VIEW_ID_TAB_CONTAINER)); 750 VIEW_ID_TAB_CONTAINER));
716 751
717 // Check that the preview contents has been committed. 752 // Check that the preview contents has been committed.
718 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 753 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
719 ASSERT_FALSE(browser()->instant()->is_active()); 754 ASSERT_FALSE(HasPreview());
720 TabContents* contents = browser()->GetSelectedTabContents(); 755 TabContents* contents = browser()->GetSelectedTabContents();
721 ASSERT_TRUE(contents); 756 ASSERT_TRUE(contents);
722 757
723 // Check that the value is reflected and oncancel is called. 758 // Check that the value is reflected and oncancel is called.
724 EXPECT_EQ("true 0 1 1 true d false def false 3 3", 759 EXPECT_EQ("true 0 1 1 true d false def false 3 3",
725 GetSearchStateAsString(preview_, true)); 760 GetSearchStateAsString(preview_, true));
726 761
727 // Make sure the searchbox values were reset. 762 // Make sure the searchbox values were reset.
728 EXPECT_EQ("true 0 1 1 true d false false 0 0", 763 EXPECT_EQ("true 0 1 1 true d false false 0 0",
729 GetSearchStateAsString(preview_, false)); 764 GetSearchStateAsString(preview_, false));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 825
791 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 826 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
792 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); 827 ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
793 ASSERT_NO_FATAL_FAILURE(SetupPreview()); 828 ASSERT_NO_FATAL_FAILURE(SetupPreview());
794 829
795 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def")); 830 ASSERT_NO_FATAL_FAILURE(SetLocationBarText("def"));
796 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); 831 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN));
797 832
798 // Check that the preview contents have been committed. 833 // Check that the preview contents have been committed.
799 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); 834 ASSERT_FALSE(browser()->instant()->GetPreviewContents());
800 ASSERT_FALSE(browser()->instant()->is_active()); 835 ASSERT_FALSE(HasPreview());
801 836
802 TabContents* contents = browser()->GetSelectedTabContents(); 837 TabContents* contents = browser()->GetSelectedTabContents();
803 ASSERT_TRUE(contents); 838 ASSERT_TRUE(contents);
804 839
805 // Navigate to a new URL. This should reset the searchbox values. 840 // Navigate to a new URL. This should reset the searchbox values.
806 ui_test_utils::NavigateToURL( 841 ui_test_utils::NavigateToURL(
807 browser(), 842 browser(),
808 GURL(test_server()->GetURL("files/instant/empty.html"))); 843 GURL(test_server()->GetURL("files/instant/empty.html")));
809 bool result; 844 bool result;
810 ASSERT_TRUE(GetBoolFromJavascript( 845 ASSERT_TRUE(GetBoolFromJavascript(
(...skipping 26 matching lines...) Expand all
837 NotificationService::AllSources()); 872 NotificationService::AllSources());
838 873
839 // Focusing the omnibox should cause instant to be preloaded. 874 // Focusing the omnibox should cause instant to be preloaded.
840 FindLocationBar(); 875 FindLocationBar();
841 location_bar_->FocusLocation(false); 876 location_bar_->FocusLocation(false);
842 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); 877 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
843 EXPECT_TRUE(tab_contents); 878 EXPECT_TRUE(tab_contents);
844 879
845 instant_support_observer.Wait(); 880 instant_support_observer.Wait();
846 881
847 // However, instant should still not be active. 882 // Instant should have a preview, but not display it.
848 EXPECT_FALSE(browser()->instant()->is_active()); 883 EXPECT_TRUE(HasPreview());
849 EXPECT_FALSE(browser()->instant()->is_displayable()); 884 EXPECT_FALSE(browser()->instant()->is_displayable());
850 885
851 // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper. 886 // Adding a new tab shouldn't delete (or recreate) the TabContentsWrapper.
852 AddBlankTabAndShow(browser()); 887 AddBlankTabAndShow(browser());
853 EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents()); 888 EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());
854 889
855 // Doing a search should still use the same loader for the preview. 890 // Doing a search should still use the same loader for the preview.
856 SetLocationBarText("def"); 891 SetLocationBarText("def");
857 EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents()); 892 EXPECT_EQ(tab_contents, browser()->instant()->GetPreviewContents());
858 893
859 // Verify that the preview is in fact showing instant search. 894 // Verify that the preview is in fact showing instant search.
860 EXPECT_TRUE(browser()->instant()->is_active()); 895 EXPECT_TRUE(HasPreview());
861 EXPECT_TRUE(browser()->instant()->is_displayable()); 896 EXPECT_TRUE(browser()->instant()->is_displayable());
862 EXPECT_TRUE(browser()->instant()->IsCurrent()); 897 EXPECT_TRUE(browser()->instant()->IsCurrent());
863 } 898 }
864 899
865 // Tests the INSTANT experiment of the field trial. 900 // Tests the INSTANT experiment of the field trial.
866 class InstantFieldTrialInstantTest : public InstantTest { 901 class InstantFieldTrialInstantTest : public InstantTest {
867 public: 902 public:
868 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 903 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
869 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, 904 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
870 switches::kInstantFieldTrialInstant); 905 switches::kInstantFieldTrialInstant);
871 } 906 }
872 }; 907 };
873 908
874 // Tests that instant is active, even without calling EnableInstant(). 909 // Tests that instant is active, even without calling EnableInstant().
875 IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE_ExperimentEnabled) { 910 IN_PROC_BROWSER_TEST_F(InstantFieldTrialInstantTest, MAYBE_ExperimentEnabled) {
876 // Check that instant is enabled, despite not setting the preference. 911 // Check that instant is enabled, despite not setting the preference.
877 Profile* profile = browser()->profile(); 912 Profile* profile = browser()->profile();
878 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled)); 913 EXPECT_FALSE(profile->GetPrefs()->GetBoolean(prefs::kInstantEnabled));
879 EXPECT_TRUE(InstantController::IsEnabled(profile)); 914 EXPECT_TRUE(InstantController::IsEnabled(profile));
880 915
881 ASSERT_TRUE(test_server()->Start()); 916 ASSERT_TRUE(test_server()->Start());
882 SetupInstantProvider("search.html"); 917 SetupInstantProvider("search.html");
883 SetupLocationBar(); 918 SetupLocationBar();
884 SetupPreview(); 919 SetupPreview();
885 SetLocationBarText("def"); 920 SetLocationBarText("def");
886 921
887 // Check that instant is active and showing a preview. 922 // Check that instant is active and showing a preview.
888 EXPECT_TRUE(browser()->instant()->is_active()); 923 EXPECT_TRUE(HasPreview());
889 EXPECT_TRUE(browser()->instant()->is_displayable()); 924 EXPECT_TRUE(browser()->instant()->is_displayable());
890 EXPECT_TRUE(browser()->instant()->IsCurrent()); 925 EXPECT_TRUE(browser()->instant()->IsCurrent());
891 } 926 }
892 927
893 // Tests the HIDDEN experiment of the field trial. 928 // Tests the HIDDEN experiment of the field trial.
894 class InstantFieldTrialHiddenTest : public InstantTest { 929 class InstantFieldTrialHiddenTest : public InstantTest {
895 public: 930 public:
896 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 931 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
897 command_line->AppendSwitchASCII(switches::kInstantFieldTrial, 932 command_line->AppendSwitchASCII(switches::kInstantFieldTrial,
898 switches::kInstantFieldTrialHidden); 933 switches::kInstantFieldTrialHidden);
(...skipping 13 matching lines...) Expand all
912 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, 947 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED,
913 NotificationService::AllSources()); 948 NotificationService::AllSources());
914 SetupLocationBar(); 949 SetupLocationBar();
915 WaitForPreviewToNavigate(); 950 WaitForPreviewToNavigate();
916 instant_support_observer.Wait(); 951 instant_support_observer.Wait();
917 952
918 // Type into the omnibox, but don't press <Enter> yet. 953 // Type into the omnibox, but don't press <Enter> yet.
919 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def")); 954 location_bar_->location_entry()->SetUserText(UTF8ToUTF16("def"));
920 955
921 // Check that instant is active, but the preview is not showing. 956 // Check that instant is active, but the preview is not showing.
922 EXPECT_TRUE(browser()->instant()->is_active()); 957 EXPECT_TRUE(HasPreview());
923 EXPECT_FALSE(browser()->instant()->is_displayable()); 958 EXPECT_FALSE(browser()->instant()->is_displayable());
924 EXPECT_FALSE(browser()->instant()->IsCurrent()); 959 EXPECT_FALSE(browser()->instant()->IsCurrent());
925 960
926 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents(); 961 TabContentsWrapper* tab_contents = browser()->instant()->GetPreviewContents();
927 EXPECT_TRUE(tab_contents); 962 EXPECT_TRUE(tab_contents);
928 963
929 // Press <Enter> in the omnibox, causing the preview to be committed. 964 // Press <Enter> in the omnibox, causing the preview to be committed.
930 SendKey(ui::VKEY_RETURN); 965 SendKey(ui::VKEY_RETURN);
931 966
932 // The preview contents should now be the active tab contents. 967 // The preview contents should now be the active tab contents.
933 EXPECT_FALSE(browser()->instant()->GetPreviewContents()); 968 EXPECT_FALSE(browser()->instant()->GetPreviewContents());
934 EXPECT_FALSE(browser()->instant()->is_active()); 969 EXPECT_FALSE(HasPreview());
935 EXPECT_FALSE(browser()->instant()->is_displayable()); 970 EXPECT_FALSE(browser()->instant()->is_displayable());
936 EXPECT_FALSE(browser()->instant()->IsCurrent()); 971 EXPECT_FALSE(browser()->instant()->IsCurrent());
937 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper()); 972 EXPECT_EQ(tab_contents, browser()->GetSelectedTabContentsWrapper());
938 } 973 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/testing_automation_provider.cc ('k') | chrome/browser/instant/instant_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698