Index: chrome/browser/instant/instant_browsertest.cc |
=================================================================== |
--- chrome/browser/instant/instant_browsertest.cc (revision 68817) |
+++ chrome/browser/instant/instant_browsertest.cc (working copy) |
@@ -13,6 +13,7 @@ |
#include "chrome/browser/location_bar.h" |
#include "chrome/browser/profile.h" |
#include "chrome/browser/renderer_host/render_view_host.h" |
+#include "chrome/browser/renderer_host/render_widget_host_view.h" |
#include "chrome/browser/search_engines/template_url.h" |
#include "chrome/browser/search_engines/template_url_model.h" |
#include "chrome/browser/tab_contents/tab_contents.h" |
@@ -59,10 +60,16 @@ |
model->SetDefaultSearchProvider(template_url); |
} |
+ virtual void FindLocationBar() { |
+ if (location_bar_) |
+ return; |
+ location_bar_ = browser()->window()->GetLocationBar(); |
+ ASSERT_TRUE(location_bar_); |
+ } |
+ |
// Type a character to get instant to trigger. |
void SetupLocationBar() { |
- location_bar_ = browser()->window()->GetLocationBar(); |
- ASSERT_TRUE(location_bar_); |
+ FindLocationBar(); |
location_bar_->location_entry()->SetUserText(L"a"); |
} |
@@ -96,7 +103,7 @@ |
} |
void SetLocationBarText(const std::wstring& text) { |
- ASSERT_TRUE(location_bar_); |
+ ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
location_bar_->location_entry()->SetUserText(text); |
ui_test_utils::WaitForNotification( |
NotificationType::INSTANT_CONTROLLER_SHOWN); |
@@ -179,6 +186,63 @@ |
1, "window.onchangecalls", preview_)); |
} |
+// Makes sure that if the server doesn't support the instant API we don't show |
+// anything. |
+IN_PROC_BROWSER_TEST_F(InstantTest, SearchServerDoesntSupportInstant) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
+ ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
+ location_bar_->location_entry()->SetUserText(L"a"); |
+ ASSERT_TRUE(browser()->instant()); |
+ // Because we typed in a search string we should think we're showing instant |
+ // results. |
+ EXPECT_TRUE(browser()->instant()->IsShowingInstant()); |
+ // But because we're waiting to determine if the page really supports instant |
+ // we shouldn't be showing the preview. |
+ EXPECT_FALSE(browser()->instant()->is_active()); |
+ |
+ // When the response comes back that the page doesn't support instant the tab |
+ // should be closed. |
+ ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); |
+ EXPECT_FALSE(browser()->instant()->IsShowingInstant()); |
+ EXPECT_FALSE(browser()->instant()->is_active()); |
+} |
+ |
+// Verifies transitioning from loading a non-search string to a search string |
+// with the provider not supporting instant works (meaning we don't display |
+// anything). |
+IN_PROC_BROWSER_TEST_F(InstantTest, NonSearchToSearchDoesntSupportInstant) { |
+ ASSERT_TRUE(test_server()->Start()); |
+ ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("empty.html")); |
+ GURL url(test_server()->GetURL("files/instant/empty.html")); |
+ ASSERT_NO_FATAL_FAILURE(SetLocationBarText(UTF8ToWide(url.spec()))); |
+ // The preview should be active and showing. |
+ ASSERT_TRUE(browser()->instant()->is_active()); |
+ TabContentsWrapper* initial_tab = browser()->instant()->GetPreviewContents(); |
+ ASSERT_TRUE(initial_tab); |
+ RenderWidgetHostView* rwhv = |
+ initial_tab->tab_contents()->GetRenderWidgetHostView(); |
+ ASSERT_TRUE(rwhv); |
+ ASSERT_TRUE(rwhv->IsShowing()); |
+ |
+ // Now type in some search text. |
+ location_bar_->location_entry()->SetUserText(L"a"); |
+ |
+ // Instant should still be live. |
+ ASSERT_TRUE(browser()->instant()->is_active()); |
+ // Because we typed in a search string we should think we're showing instant |
+ // results. |
+ EXPECT_TRUE(browser()->instant()->MightSupportInstant()); |
+ // Instant should not be current (it's still loading). |
+ EXPECT_FALSE(browser()->instant()->IsCurrent()); |
+ |
+ // When the response comes back that the page doesn't support instant the tab |
+ // should be closed. |
+ ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); |
+ EXPECT_FALSE(browser()->instant()->IsShowingInstant()); |
+ EXPECT_FALSE(browser()->instant()->is_active()); |
+} |
+ |
// Verify that the onsubmit event is dispatched upon pressing enter. |
// TODO(sky): Disabled, http://crbug.com/62940. |
IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) { |