| OLD | NEW |
| 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 "base/prefs/pref_service.h" |
| 5 #include "chrome/browser/content_settings/host_content_settings_map.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 #include "chrome/browser/history/history_service_factory.h" | 7 #include "chrome/browser/history/history_service_factory.h" |
| 7 #include "chrome/browser/instant/instant_overlay.h" | 8 #include "chrome/browser/instant/instant_controller.h" |
| 9 #include "chrome/browser/instant/instant_loader.h" |
| 10 #include "chrome/browser/instant/instant_model.h" |
| 8 #include "chrome/browser/instant/instant_service.h" | 11 #include "chrome/browser/instant/instant_service.h" |
| 9 #include "chrome/browser/instant/instant_service_factory.h" | |
| 10 #include "chrome/browser/instant/instant_test_utils.h" | 12 #include "chrome/browser/instant/instant_test_utils.h" |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/task_manager/task_manager.h" | 15 #include "chrome/browser/task_manager/task_manager.h" |
| 15 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 16 #include "chrome/browser/ui/browser.h" | |
| 17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
| 18 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/omnibox/location_bar.h" |
| 20 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/interactive_test_utils.h" | 25 #include "chrome/test/base/interactive_test_utils.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | |
| 24 #include "content/public/browser/notification_service.h" | |
| 25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/test/browser_test_utils.h" |
| 27 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 29 | 31 |
| 30 class InstantTest : public InstantTestBase { | 32 class InstantTest : public InProcessBrowserTest, |
| 33 public InstantTestBase { |
| 31 protected: | 34 protected: |
| 32 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 35 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 33 ASSERT_TRUE(test_server()->Start()); | 36 ASSERT_TRUE(test_server()->Start()); |
| 34 instant_url_ = test_server()->GetURL("files/instant.html?"); | 37 set_instant_url(test_server()->GetURL("files/instant.html")); |
| 35 } | 38 } |
| 36 | 39 |
| 37 void FocusOmniboxAndWaitForInstantSupport() { | 40 virtual void SetUpOnMainThread() OVERRIDE { |
| 38 content::WindowedNotificationObserver observer( | 41 set_browser(browser()); |
| 39 chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED, | 42 } |
| 40 content::NotificationService::AllSources()); | 43 |
| 41 FocusOmnibox(); | 44 void SetupInstant() { |
| 42 observer.Wait(); | 45 TemplateURLData template_data; |
| 46 template_data.SetURL("http://does/not/exist?q={searchTerms}"); |
| 47 template_data.instant_url = instant_url().spec(); |
| 48 SetupDefaultSearchProvider(template_data); |
| 49 |
| 50 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); |
| 43 } | 51 } |
| 44 | 52 |
| 45 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { | 53 bool UpdateSearchState(content::WebContents* contents) WARN_UNUSED_RESULT { |
| 46 return GetIntFromJS(contents, "onvisibilitycalls", &onvisibilitycalls_) && | 54 return GetIntFromJS(contents, "onvisibilitycalls", &onvisibilitycalls_) && |
| 47 GetIntFromJS(contents, "onchangecalls", &onchangecalls_) && | 55 GetIntFromJS(contents, "onchangecalls", &onchangecalls_) && |
| 48 GetIntFromJS(contents, "onsubmitcalls", &onsubmitcalls_) && | 56 GetIntFromJS(contents, "onsubmitcalls", &onsubmitcalls_) && |
| 49 GetIntFromJS(contents, "oncancelcalls", &oncancelcalls_) && | 57 GetIntFromJS(contents, "oncancelcalls", &oncancelcalls_) && |
| 50 GetIntFromJS(contents, "onresizecalls", &onresizecalls_) && | 58 GetIntFromJS(contents, "onresizecalls", &onresizecalls_) && |
| 51 GetStringFromJS(contents, "value", &value_) && | 59 GetStringFromJS(contents, "value", &value_) && |
| 52 GetBoolFromJS(contents, "verbatim", &verbatim_) && | 60 GetBoolFromJS(contents, "verbatim", &verbatim_) && |
| 53 GetIntFromJS(contents, "height", &height_); | 61 GetIntFromJS(contents, "height", &height_); |
| 54 } | 62 } |
| 55 | 63 |
| 56 int onvisibilitycalls_; | 64 int onvisibilitycalls_; |
| 57 int onchangecalls_; | 65 int onchangecalls_; |
| 58 int onsubmitcalls_; | 66 int onsubmitcalls_; |
| 59 int oncancelcalls_; | 67 int oncancelcalls_; |
| 60 int onresizecalls_; | 68 int onresizecalls_; |
| 61 | 69 |
| 62 std::string value_; | 70 std::string value_; |
| 63 bool verbatim_; | 71 bool verbatim_; |
| 64 int height_; | 72 int height_; |
| 65 }; | 73 }; |
| 66 | 74 |
| 67 // Test that Instant is preloaded when the omnibox is focused. | 75 // Test that Instant is preloaded when the omnibox is focused. |
| 68 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { | 76 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { |
| 69 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | |
| 70 | |
| 71 // Explicitly unfocus the omnibox. | 77 // Explicitly unfocus the omnibox. |
| 72 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 78 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 73 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 79 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 74 | 80 |
| 75 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 81 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 76 EXPECT_FALSE(omnibox()->model()->has_focus()); | 82 EXPECT_FALSE(omnibox()->model()->has_focus()); |
| 77 | 83 |
| 78 // Delete any existing preview. | 84 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 79 instant()->overlay_.reset(); | 85 EXPECT_FALSE(service()->loader()->contents()); |
| 80 EXPECT_FALSE(instant()->GetPreviewContents()); | |
| 81 | 86 |
| 82 // Refocus the omnibox. The InstantController should've preloaded Instant. | 87 // Refocus the omnibox. The InstantLoader should preload an Instant page. |
| 83 FocusOmniboxAndWaitForInstantSupport(); | 88 FocusOmniboxAndWaitForInstantSupport(); |
| 84 | 89 |
| 85 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 90 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 86 EXPECT_TRUE(omnibox()->model()->has_focus()); | 91 EXPECT_TRUE(omnibox()->model()->has_focus()); |
| 87 | 92 |
| 88 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 93 content::WebContents* overlay = service()->loader()->contents(); |
| 89 EXPECT_TRUE(preview_tab); | 94 EXPECT_TRUE(overlay); |
| 90 | 95 |
| 91 // Check that the page supports Instant, but it isn't showing. | 96 // Check that the page supports Instant, but it isn't showing. |
| 92 EXPECT_TRUE(instant()->overlay_->supports_instant()); | 97 EXPECT_TRUE(service()->loader()->supports_instant()); |
| 93 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 98 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 94 EXPECT_TRUE(instant()->model()->mode().is_default()); | 99 EXPECT_FALSE(instant()->GetOverlayContents()); |
| 95 | 100 |
| 96 // Adding a new tab shouldn't delete or recreate the preview; otherwise, | 101 // Adding a new tab shouldn't delete or recreate the overlay; otherwise, |
| 97 // what's the point of preloading? | 102 // what's the point of preloading? |
| 98 AddBlankTabAndShow(browser()); | 103 AddBlankTabAndShow(browser()); |
| 99 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 104 EXPECT_EQ(overlay, service()->loader()->contents()); |
| 100 | 105 |
| 101 // Unfocusing and refocusing the omnibox should also preserve the preview. | 106 // Unfocusing and refocusing the omnibox should also preserve the overlay. |
| 102 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 107 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 103 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 108 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 104 | 109 |
| 105 FocusOmnibox(); | 110 FocusOmnibox(); |
| 106 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 111 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 107 | 112 |
| 108 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 113 EXPECT_EQ(overlay, service()->loader()->contents()); |
| 109 | 114 |
| 110 // Doing a search should also use the same preloaded page. | 115 // Doing a search should also use the same preloaded page. |
| 111 SetOmniboxTextAndWaitForInstantToShow("query"); | 116 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 112 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | 117 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 113 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 118 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| 114 } | 119 } |
| 115 | 120 |
| 116 // Flakes on Windows and Mac: http://crbug.com/170677 | |
| 117 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 118 #define MAYBE_OnChangeEvent DISABLED_OnChangeEvent | |
| 119 #else | |
| 120 #define MAYBE_OnChangeEvent OnChangeEvent | |
| 121 #endif | |
| 122 // Test that the onchange event is dispatched upon typing in the omnibox. | 121 // Test that the onchange event is dispatched upon typing in the omnibox. |
| 123 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { | 122 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
| 124 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 123 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 125 FocusOmniboxAndWaitForInstantSupport(); | 124 FocusOmniboxAndWaitForInstantSupport(); |
| 126 | 125 |
| 127 // Use the Instant page as the active tab, so we can exploit its visibility | 126 // Use the Instant page as the active tab, so we can exploit its visibility |
| 128 // handler to check visibility transitions. | 127 // handler to check visibility transitions. |
| 129 ui_test_utils::NavigateToURL(browser(), instant_url_); | 128 ui_test_utils::NavigateToURL(browser(), instant_url()); |
| 130 content::WebContents* active_tab = | 129 content::WebContents* active_tab = |
| 131 browser()->tab_strip_model()->GetActiveWebContents(); | 130 browser()->tab_strip_model()->GetActiveWebContents(); |
| 132 | 131 |
| 133 int active_tab_onvisibilitycalls = -1; | 132 int active_tab_onvisibilitycalls = -1; |
| 134 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", | 133 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
| 135 &active_tab_onvisibilitycalls)); | 134 &active_tab_onvisibilitycalls)); |
| 136 EXPECT_EQ(0, active_tab_onvisibilitycalls); | 135 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 137 | 136 |
| 138 // Typing "query" into the omnibox causes one or more onchange events. The | 137 // Typing "query" into the omnibox causes the first onchange event. The page |
| 139 // page suggested "query suggestion" is inline autocompleted into the omnibox, | 138 // suggested "query suggestion" is inline autocompleted into the omnibox, |
| 140 // causing another onchange event. | 139 // causing the second onchange event. |
| 141 SetOmniboxTextAndWaitForInstantToShow("query"); | 140 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 142 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 141 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
| 143 int min_onchangecalls = 2; | |
| 144 | 142 |
| 145 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 143 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
| 146 EXPECT_LE(min_onchangecalls, onchangecalls_); | 144 EXPECT_EQ(2, onchangecalls_); |
| 147 min_onchangecalls = onchangecalls_; | |
| 148 | 145 |
| 149 // Change the query and confirm more onchange events are sent. | 146 // Change the query and confirm that a third onchange event is sent. The |
| 147 // hardcoded "query suggestion" doesn't start with "search", so no inline |
| 148 // autocompletion or fourth onchange event happens. |
| 150 SetOmniboxText("search"); | 149 SetOmniboxText("search"); |
| 151 ++min_onchangecalls; | |
| 152 | 150 |
| 153 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 151 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
| 154 EXPECT_LE(min_onchangecalls, onchangecalls_); | 152 EXPECT_EQ(3, onchangecalls_); |
| 155 | 153 |
| 156 // The preview was shown once, and the active tab was never hidden. | 154 // The overlay was shown once, and the active tab was never hidden. |
| 157 EXPECT_EQ(1, onvisibilitycalls_); | 155 EXPECT_EQ(1, onvisibilitycalls_); |
| 158 active_tab_onvisibilitycalls = -1; | 156 active_tab_onvisibilitycalls = -1; |
| 159 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", | 157 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
| 160 &active_tab_onvisibilitycalls)); | 158 &active_tab_onvisibilitycalls)); |
| 161 EXPECT_EQ(0, active_tab_onvisibilitycalls); | 159 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 162 } | 160 } |
| 163 | 161 |
| 164 // Test that the onsubmit event is dispatched upon pressing Enter. | 162 // Test that the onsubmit event is dispatched upon pressing Enter. |
| 165 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { | 163 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
| 166 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 164 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 167 FocusOmniboxAndWaitForInstantSupport(); | 165 FocusOmniboxAndWaitForInstantSupport(); |
| 168 SetOmniboxTextAndWaitForInstantToShow("search"); | 166 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 169 | 167 |
| 170 // Stash a reference to the preview, so we can refer to it after commit. | 168 // Stash a reference to the overlay, so we can refer to it after commit. |
| 171 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 169 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 172 EXPECT_TRUE(preview_tab); | 170 EXPECT_TRUE(overlay); |
| 173 | 171 |
| 174 // The state of the searchbox before the commit. | 172 // The state of the searchbox before the commit. |
| 175 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 173 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 176 EXPECT_EQ("search", value_); | 174 EXPECT_EQ("search", value_); |
| 177 EXPECT_FALSE(verbatim_); | 175 EXPECT_FALSE(verbatim_); |
| 178 EXPECT_EQ(0, onsubmitcalls_); | 176 EXPECT_EQ(0, onsubmitcalls_); |
| 179 EXPECT_EQ(1, onvisibilitycalls_); | 177 EXPECT_EQ(1, onvisibilitycalls_); |
| 180 | 178 |
| 181 // Before the commit, the active tab is the NTP (i.e., not Instant). | 179 // Before the commit, the active tab is a blank page (i.e., not Instant). |
| 182 content::WebContents* active_tab = | 180 content::WebContents* active_tab = |
| 183 browser()->tab_strip_model()->GetActiveWebContents(); | 181 browser()->tab_strip_model()->GetActiveWebContents(); |
| 184 EXPECT_NE(preview_tab, active_tab); | 182 EXPECT_NE(overlay, active_tab); |
| 185 EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); | 183 EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); |
| 186 EXPECT_EQ(std::string(chrome::kAboutBlankURL), | 184 EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
| 187 omnibox()->model()->PermanentURL().spec()); | 185 omnibox()->model()->PermanentURL().spec()); |
| 188 | 186 |
| 189 // Commit the search by pressing Enter. | 187 // Commit the search by pressing Enter. |
| 190 browser()->window()->GetLocationBar()->AcceptInput(); | 188 browser()->window()->GetLocationBar()->AcceptInput(); |
| 191 | 189 |
| 192 // After the commit, Instant should not be showing. | 190 // After the commit, Instant should not be showing. |
| 193 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 191 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 194 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 195 | 192 |
| 196 // The old overlay is deleted and a new one is created. | 193 // Check that the current active tab is indeed what was once the overlay. |
| 197 EXPECT_TRUE(instant()->GetPreviewContents()); | 194 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 198 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); | |
| 199 | 195 |
| 200 // Check that the current active tab is indeed what was once the preview. | 196 // We should have two navigation entries, one for the blank page, and one for |
| 201 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); | 197 // the Instant search that was committed. |
| 202 | 198 EXPECT_EQ(2, overlay->GetController().GetEntryCount()); |
| 203 // We should have two navigation entries, one for the NTP, and one for the | |
| 204 // Instant search that was committed. | |
| 205 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); | |
| 206 | 199 |
| 207 // Check that the omnibox contains the Instant URL we loaded. | 200 // Check that the omnibox contains the Instant URL we loaded. |
| 208 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); | 201 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
| 209 | 202 |
| 210 // Check that the searchbox API values have been reset. | 203 // The page should've correctly received the committed query. |
| 211 std::string value; | 204 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 212 EXPECT_TRUE(GetStringFromJS(preview_tab, | |
| 213 "chrome.embeddedSearch.searchBox.value", &value)); | |
| 214 EXPECT_EQ("", value); | |
| 215 | |
| 216 // However, the page should've correctly received the committed query. | |
| 217 EXPECT_TRUE(UpdateSearchState(preview_tab)); | |
| 218 EXPECT_EQ("search", value_); | 205 EXPECT_EQ("search", value_); |
| 219 EXPECT_TRUE(verbatim_); | 206 EXPECT_TRUE(verbatim_); |
| 220 EXPECT_EQ(1, onsubmitcalls_); | 207 EXPECT_EQ(1, onsubmitcalls_); |
| 221 EXPECT_EQ(1, onvisibilitycalls_); | 208 EXPECT_EQ(1, onvisibilitycalls_); |
| 222 } | 209 } |
| 223 | 210 |
| 224 // Test that the oncancel event is dispatched upon clicking on the preview. | 211 // Test that the oncancel event is dispatched upon clicking on the overlay. |
| 225 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { | 212 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
| 226 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 213 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 227 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 214 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 228 FocusOmniboxAndWaitForInstantSupport(); | 215 FocusOmniboxAndWaitForInstantSupport(); |
| 229 SetOmniboxTextAndWaitForInstantToShow("search"); | 216 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 230 | 217 |
| 231 // Stash a reference to the preview, so we can refer to it after commit. | 218 // Stash a reference to the overlay, so we can refer to it after commit. |
| 232 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 219 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 233 EXPECT_TRUE(preview_tab); | 220 EXPECT_TRUE(overlay); |
| 234 | 221 |
| 235 // The state of the searchbox before the commit. | 222 // The state of the searchbox before the commit. |
| 236 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 223 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 237 EXPECT_EQ("search", value_); | 224 EXPECT_EQ("search", value_); |
| 238 EXPECT_FALSE(verbatim_); | 225 EXPECT_FALSE(verbatim_); |
| 239 EXPECT_EQ(0, oncancelcalls_); | 226 EXPECT_EQ(0, oncancelcalls_); |
| 240 EXPECT_EQ(1, onvisibilitycalls_); | 227 EXPECT_EQ(1, onvisibilitycalls_); |
| 241 | 228 |
| 242 // Before the commit, the active tab is the NTP (i.e., not Instant). | 229 // Before the commit, the active tab is a blank page (i.e., not Instant). |
| 243 content::WebContents* active_tab = | 230 content::WebContents* active_tab = |
| 244 browser()->tab_strip_model()->GetActiveWebContents(); | 231 browser()->tab_strip_model()->GetActiveWebContents(); |
| 245 EXPECT_NE(preview_tab, active_tab); | 232 EXPECT_NE(overlay, active_tab); |
| 246 EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); | 233 EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); |
| 247 EXPECT_EQ(std::string(chrome::kAboutBlankURL), | 234 EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
| 248 omnibox()->model()->PermanentURL().spec()); | 235 omnibox()->model()->PermanentURL().spec()); |
| 249 | 236 |
| 250 // Commit the search by clicking on the preview. | 237 // Commit the search by clicking on the overlay. |
| 251 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 238 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 252 | 239 |
| 253 // After the commit, Instant should not be showing. | 240 // After the commit, Instant should not be showing. |
| 254 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 241 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 255 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 256 | 242 |
| 257 // The old overlay is deleted and a new one is created. | 243 // Check that the current active tab is indeed what was once the overlay. |
| 258 EXPECT_TRUE(instant()->GetPreviewContents()); | 244 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 259 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); | |
| 260 | 245 |
| 261 // Check that the current active tab is indeed what was once the preview. | 246 // We should have two navigation entries, one for the blank page, and one for |
| 262 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); | 247 // the Instant search that was committed. |
| 263 | 248 EXPECT_EQ(2, overlay->GetController().GetEntryCount()); |
| 264 // We should have two navigation entries, one for the NTP, and one for the | |
| 265 // Instant search that was committed. | |
| 266 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); | |
| 267 | 249 |
| 268 // Check that the omnibox contains the Instant URL we loaded. | 250 // Check that the omnibox contains the Instant URL we loaded. |
| 269 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); | 251 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
| 270 | 252 |
| 271 // Check that the searchbox API values have been reset. | 253 // The page should've correctly received the committed query. |
| 272 std::string value; | 254 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 273 EXPECT_TRUE(GetStringFromJS(preview_tab, | |
| 274 "chrome.embeddedSearch.searchBox.value", &value)); | |
| 275 EXPECT_EQ("", value); | |
| 276 | |
| 277 // However, the page should've correctly received the committed query. | |
| 278 EXPECT_TRUE(UpdateSearchState(preview_tab)); | |
| 279 EXPECT_EQ("search", value_); | 255 EXPECT_EQ("search", value_); |
| 280 EXPECT_TRUE(verbatim_); | 256 EXPECT_TRUE(verbatim_); |
| 281 EXPECT_EQ(1, oncancelcalls_); | 257 EXPECT_EQ(1, oncancelcalls_); |
| 282 EXPECT_EQ(1, onvisibilitycalls_); | 258 EXPECT_EQ(1, onvisibilitycalls_); |
| 283 } | 259 } |
| 284 | 260 |
| 285 // Test that the onreisze event is dispatched upon typing in the omnibox. | 261 // Test that the onresize event is dispatched upon typing in the omnibox. |
| 286 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { | 262 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { |
| 287 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 263 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 264 FocusOmniboxAndWaitForInstantSupport(); |
| 265 content::WebContents* overlay = service()->loader()->contents(); |
| 288 | 266 |
| 289 FocusOmniboxAndWaitForInstantSupport(); | 267 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 290 | |
| 291 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 292 EXPECT_EQ(0, onresizecalls_); | 268 EXPECT_EQ(0, onresizecalls_); |
| 293 EXPECT_EQ(0, height_); | 269 EXPECT_EQ(0, height_); |
| 294 | 270 |
| 295 // Type a query into the omnibox. This should cause an onresize() event, with | 271 // Type a query into the omnibox. This should cause an onresize() event, with |
| 296 // a valid (non-zero) height. | 272 // a valid (non-zero) height. |
| 297 SetOmniboxTextAndWaitForInstantToShow("search"); | 273 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 274 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| 298 | 275 |
| 299 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 276 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 300 EXPECT_EQ(1, onresizecalls_); | 277 EXPECT_EQ(1, onresizecalls_); |
| 301 EXPECT_LT(0, height_); | 278 EXPECT_LT(0, height_); |
| 302 } | 279 } |
| 303 | 280 |
| 304 // Test that the INSTANT_COMPLETE_NOW behavior works as expected. | 281 // Test that the INSTANT_COMPLETE_NOW behavior works as expected. |
| 305 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { | 282 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { |
| 306 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 283 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 307 FocusOmniboxAndWaitForInstantSupport(); | 284 FocusOmniboxAndWaitForInstantSupport(); |
| 308 | 285 |
| 309 // Tell the JS to request the given behavior. | |
| 310 EXPECT_TRUE(ExecuteScript("behavior = 'now'")); | |
| 311 | |
| 312 // Type a query, causing the hardcoded "query suggestion" to be returned. | 286 // Type a query, causing the hardcoded "query suggestion" to be returned. |
| 313 SetOmniboxTextAndWaitForInstantToShow("query"); | 287 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 314 | 288 |
| 315 // Get what's showing in the omnibox, and what's highlighted. | 289 // Get what's showing in the omnibox, and what's highlighted. |
| 316 string16 text = omnibox()->GetText(); | 290 string16 text = omnibox()->GetText(); |
| 317 size_t start = 0, end = 0; | 291 size_t start = 0, end = 0; |
| 318 omnibox()->GetSelectionBounds(&start, &end); | 292 omnibox()->GetSelectionBounds(&start, &end); |
| 319 if (start > end) | 293 if (start > end) |
| 320 std::swap(start, end); | 294 std::swap(start, end); |
| 321 | 295 |
| 322 EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); | 296 EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); |
| 323 EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); | 297 EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); |
| 324 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 298 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
| 325 } | 299 } |
| 326 | 300 |
| 327 // Test that the INSTANT_COMPLETE_NEVER behavior works as expected. | |
| 328 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { | |
| 329 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | |
| 330 FocusOmniboxAndWaitForInstantSupport(); | |
| 331 | |
| 332 // Tell the JS to request the given behavior. | |
| 333 EXPECT_TRUE(ExecuteScript("behavior = 'never'")); | |
| 334 | |
| 335 // Type a query, causing the hardcoded "query suggestion" to be returned. | |
| 336 SetOmniboxTextAndWaitForInstantToShow("query"); | |
| 337 | |
| 338 // Get what's showing in the omnibox, and what's highlighted. | |
| 339 string16 text = omnibox()->GetText(); | |
| 340 size_t start = 0, end = 0; | |
| 341 omnibox()->GetSelectionBounds(&start, &end); | |
| 342 if (start > end) | |
| 343 std::swap(start, end); | |
| 344 | |
| 345 EXPECT_EQ(ASCIIToUTF16("query"), text); | |
| 346 EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start)); | |
| 347 EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion()); | |
| 348 } | |
| 349 | |
| 350 // Test that a valid suggestion is accepted. | 301 // Test that a valid suggestion is accepted. |
| 351 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { | 302 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { |
| 352 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 303 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 353 FocusOmniboxAndWaitForInstantSupport(); | 304 FocusOmniboxAndWaitForInstantSupport(); |
| 354 | 305 |
| 355 // Tell the JS to use the given suggestion. | 306 // Tell the JS to use the given suggestion. |
| 356 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); | 307 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 308 "suggestion = { suggestions: [ { value: 'query completion' } ] }")); |
| 357 | 309 |
| 358 // Type a query, causing "query completion" to be returned as the suggestion. | 310 // Type a query, causing "query completion" to be returned as the suggestion. |
| 359 SetOmniboxTextAndWaitForInstantToShow("query"); | 311 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 360 EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); | 312 EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); |
| 361 } | 313 } |
| 362 | 314 |
| 363 // Test that an invalid suggestion is rejected. | 315 // Test that an invalid suggestion is rejected. |
| 364 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { | 316 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { |
| 365 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 317 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 366 FocusOmniboxAndWaitForInstantSupport(); | 318 FocusOmniboxAndWaitForInstantSupport(); |
| 367 | 319 |
| 368 // Tell the JS to use an object in an invalid format. | 320 // Tell the JS to use an object in an invalid format. |
| 369 EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); | 321 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 322 "suggestion = { suggestions: { value: 'query completion' } }")); |
| 370 | 323 |
| 371 // Type a query, but expect no suggestion. | 324 // Type a query, but expect no suggestion. |
| 372 SetOmniboxTextAndWaitForInstantToShow("query"); | 325 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 373 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); | 326 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
| 374 } | 327 } |
| 375 | 328 |
| 376 // Test that various forms of empty suggestions are rejected. | 329 // Test that various forms of empty suggestions are rejected. |
| 377 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { | 330 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { |
| 378 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 331 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 332 |
| 379 FocusOmniboxAndWaitForInstantSupport(); | 333 FocusOmniboxAndWaitForInstantSupport(); |
| 380 | 334 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 381 EXPECT_TRUE(ExecuteScript("suggestion = {}")); | 335 "suggestion = {}")); |
| 382 SetOmniboxTextAndWaitForInstantToShow("query"); | 336 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 383 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); | 337 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
| 384 | 338 |
| 385 omnibox()->RevertAll(); | 339 omnibox()->RevertAll(); |
| 386 | 340 |
| 387 EXPECT_TRUE(ExecuteScript("suggestion = []")); | 341 FocusOmniboxAndWaitForInstantSupport(); |
| 388 SetOmniboxTextAndWaitForInstantToShow("query sugg"); | 342 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 343 "suggestion = []")); |
| 344 SetOmniboxTextAndWaitForOverlayToShow("query sugg"); |
| 389 EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); | 345 EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); |
| 390 | 346 |
| 391 omnibox()->RevertAll(); | 347 omnibox()->RevertAll(); |
| 392 | 348 |
| 393 EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); | 349 FocusOmniboxAndWaitForInstantSupport(); |
| 394 SetOmniboxTextAndWaitForInstantToShow("query suggest"); | 350 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 351 "suggestion = [{}]")); |
| 352 SetOmniboxTextAndWaitForOverlayToShow("query suggest"); |
| 395 EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); | 353 EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); |
| 396 } | 354 } |
| 397 | 355 |
| 398 // Test that Instant doesn't process URLs. | 356 // Test that Instant doesn't process URLs. |
| 399 IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { | 357 IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { |
| 400 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 358 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 401 FocusOmniboxAndWaitForInstantSupport(); | 359 FocusOmniboxAndWaitForInstantSupport(); |
| 402 | 360 |
| 403 // Note that we are not actually navigating to these URLs yet. We are just | 361 // Note that we are not actually navigating to these URLs yet. We are just |
| 404 // typing them into the omnibox (without pressing Enter) and checking that | 362 // typing them into the omnibox (without pressing Enter) and checking that |
| 405 // Instant doesn't try to process them. | 363 // Instant doesn't try to process them. |
| 406 SetOmniboxText(chrome::kChromeUICrashURL); | 364 SetOmniboxText(chrome::kChromeUICrashURL); |
| 407 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 365 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 408 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 409 | 366 |
| 410 SetOmniboxText(chrome::kChromeUIHangURL); | 367 SetOmniboxText(chrome::kChromeUIHangURL); |
| 411 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 368 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 412 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 413 | 369 |
| 414 SetOmniboxText(chrome::kChromeUIKillURL); | 370 SetOmniboxText(chrome::kChromeUIKillURL); |
| 415 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 371 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 416 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 417 | 372 |
| 418 // Make sure that the URLs were never sent to the preview page. | 373 EXPECT_FALSE(instant()->GetOverlayContents()); |
| 419 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 420 EXPECT_EQ("", value_); | |
| 421 } | 374 } |
| 422 | 375 |
| 423 // Test that Instant doesn't fire for intranet paths that look like searches. | 376 // Test that Instant doesn't fire for intranet paths that look like searches. |
| 424 // http://crbug.com/99836 | 377 // http://crbug.com/99836 |
| 425 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { | 378 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { |
| 426 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 379 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 427 | 380 |
| 428 // Navigate to a URL that looks like a search (when the scheme is stripped). | 381 // Navigate to a URL that looks like a search (when the scheme is stripped). |
| 429 // It's okay if the host is bogus or the navigation fails, since we only care | 382 // It's okay if the host is bogus or the navigation fails, since we only care |
| 430 // that Instant doesn't act on it. | 383 // that Instant doesn't act on it. |
| 431 ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); | 384 ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); |
| 432 EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); | 385 EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); |
| 433 | 386 |
| 434 EXPECT_TRUE(instant()->GetPreviewContents()); | 387 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 435 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 388 EXPECT_FALSE(instant()->GetOverlayContents()); |
| 436 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 437 } | 389 } |
| 438 | 390 |
| 439 // Test that transitions between searches and non-searches work as expected. | 391 // Test that transitions between searches and non-searches work as expected. |
| 440 IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { | 392 IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { |
| 441 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 393 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 442 FocusOmniboxAndWaitForInstantSupport(); | 394 FocusOmniboxAndWaitForInstantSupport(); |
| 443 | 395 |
| 444 // Type a search, and immediately a URL, without waiting for Instant to show. | 396 // Type a search, and immediately a URL, without waiting for Instant to show. |
| 445 // The page is told about the search. Though the page isn't told about the | 397 // This should cause the overlay to be discarded. |
| 446 // subsequent URL, it invalidates the search, so a blank query is sent in its | |
| 447 // place to indicate that the search is "out of date". | |
| 448 SetOmniboxText("query"); | 398 SetOmniboxText("query"); |
| 399 EXPECT_TRUE(instant()->GetOverlayContents()); |
| 400 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 401 |
| 449 SetOmniboxText("http://monstrous/nightmare"); | 402 SetOmniboxText("http://monstrous/nightmare"); |
| 450 int min_onchangecalls = 2; | 403 EXPECT_FALSE(instant()->GetOverlayContents()); |
| 451 | 404 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 452 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 453 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | |
| 454 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 455 EXPECT_EQ("", value_); | |
| 456 EXPECT_LE(min_onchangecalls, onchangecalls_); | |
| 457 min_onchangecalls = onchangecalls_; | |
| 458 | 405 |
| 459 // Type a search. Instant should show. | 406 // Type a search. Instant should show. |
| 460 SetOmniboxTextAndWaitForInstantToShow("search"); | 407 FocusOmniboxAndWaitForInstantSupport(); |
| 461 ++min_onchangecalls; | 408 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 409 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 462 | 410 |
| 463 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 411 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); |
| 464 EXPECT_TRUE(instant()->IsPreviewingSearchResults()); | |
| 465 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | |
| 466 EXPECT_EQ("search", value_); | 412 EXPECT_EQ("search", value_); |
| 467 EXPECT_LE(min_onchangecalls, onchangecalls_); | |
| 468 min_onchangecalls = onchangecalls_; | |
| 469 | 413 |
| 470 // Type another URL. The preview should be hidden. | 414 // Type another URL. The overlay should be hidden. |
| 471 SetOmniboxText("http://terrible/terror"); | 415 SetOmniboxText("http://terrible/terror"); |
| 472 ++min_onchangecalls; | 416 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 473 | |
| 474 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 475 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | |
| 476 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 477 EXPECT_EQ("", value_); | |
| 478 EXPECT_LE(min_onchangecalls, onchangecalls_); | |
| 479 min_onchangecalls = onchangecalls_; | |
| 480 | 417 |
| 481 // Type the same search as before. | 418 // Type the same search as before. |
| 482 SetOmniboxTextAndWaitForInstantToShow("search"); | 419 FocusOmniboxAndWaitForInstantSupport(); |
| 483 min_onchangecalls++; | 420 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 484 | 421 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 485 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 486 EXPECT_TRUE(instant()->IsPreviewingSearchResults()); | |
| 487 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | |
| 488 EXPECT_EQ("search", value_); | |
| 489 EXPECT_LE(min_onchangecalls, onchangecalls_); | |
| 490 min_onchangecalls = onchangecalls_; | |
| 491 | 422 |
| 492 // Revert the omnibox. | 423 // Revert the omnibox. |
| 493 omnibox()->RevertAll(); | 424 omnibox()->RevertAll(); |
| 494 min_onchangecalls++; | 425 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 495 | |
| 496 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | |
| 497 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | |
| 498 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 499 EXPECT_EQ("", value_); | |
| 500 EXPECT_LE(min_onchangecalls, onchangecalls_); | |
| 501 } | 426 } |
| 502 | 427 |
| 503 // Test that Instant can't be fooled into committing a URL. | 428 // Test that Instant can't be fooled into committing a URL. |
| 504 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { | 429 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { |
| 505 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 430 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 431 FocusOmniboxAndWaitForInstantSupport(); |
| 506 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 432 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 507 | 433 |
| 508 // Type a URL. The Instant preview shouldn't be showing. | 434 content::WebContents* overlay = service()->loader()->contents(); |
| 435 |
| 436 // Type a URL. The Instant overlay shouldn't be showing. |
| 509 SetOmniboxText("http://deadly/nadder"); | 437 SetOmniboxText("http://deadly/nadder"); |
| 510 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 438 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 511 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 512 | 439 |
| 513 // Unfocus and refocus the omnibox. | 440 // Unfocus and refocus the omnibox. |
| 514 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 441 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 515 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 442 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 516 FocusOmnibox(); | 443 FocusOmnibox(); |
| 517 | 444 |
| 518 content::WebContents* preview_tab = instant()->GetPreviewContents(); | |
| 519 EXPECT_TRUE(preview_tab); | |
| 520 | |
| 521 // The omnibox text hasn't changed, so Instant still shouldn't be showing. | 445 // The omnibox text hasn't changed, so Instant still shouldn't be showing. |
| 522 EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); | 446 EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); |
| 523 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 447 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 524 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 525 | 448 |
| 526 // Commit the URL. The omnibox should reflect the URL minus the scheme. | 449 // Commit the URL. The omnibox should reflect the URL minus the scheme. |
| 527 browser()->window()->GetLocationBar()->AcceptInput(); | 450 browser()->window()->GetLocationBar()->AcceptInput(); |
| 528 content::WebContents* active_tab = | 451 content::WebContents* active_tab = |
| 529 browser()->tab_strip_model()->GetActiveWebContents(); | 452 browser()->tab_strip_model()->GetActiveWebContents(); |
| 530 EXPECT_NE(preview_tab, active_tab); | 453 EXPECT_NE(overlay, active_tab); |
| 531 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); | 454 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); |
| 532 | 455 |
| 533 // Instant shouldn't have done anything. | 456 // Instant shouldn't have done anything. |
| 534 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 457 EXPECT_EQ(overlay, service()->loader()->contents()); |
| 535 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 458 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 536 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 537 } | 459 } |
| 538 | 460 |
| 539 // Test that Instant can't be fooled into committing a URL. | 461 // Test that Instant can't be fooled into committing a URL. |
| 540 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { | 462 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { |
| 541 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 463 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 542 FocusOmniboxAndWaitForInstantSupport(); | 464 FocusOmniboxAndWaitForInstantSupport(); |
| 543 | 465 |
| 544 // Type a query. This causes the preview to be shown. | 466 // Type a query. This causes the overlay to be shown. |
| 545 SetOmniboxTextAndWaitForInstantToShow("query"); | 467 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 546 | 468 |
| 547 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 469 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 548 EXPECT_TRUE(preview_tab); | |
| 549 | 470 |
| 550 // Type a URL. This causes the preview to be hidden. | 471 // Type a URL. This causes the overlay to be hidden. |
| 551 SetOmniboxText("http://hideous/zippleback"); | 472 SetOmniboxText("http://hideous/zippleback"); |
| 552 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 473 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 553 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 554 | 474 |
| 555 // Pretend the omnibox got focus. It already had focus, so we are just trying | 475 // Pretend the omnibox got focus. It already had focus, so we are just trying |
| 556 // to tickle a different code path. | 476 // to tickle a different code path. |
| 557 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, | 477 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE, |
| 558 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); | 478 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); |
| 559 | 479 |
| 560 // Commit the URL. As before, check that Instant wasn't committed. | 480 // Commit the URL. As before, check that Instant wasn't committed. |
| 561 browser()->window()->GetLocationBar()->AcceptInput(); | 481 browser()->window()->GetLocationBar()->AcceptInput(); |
| 562 content::WebContents* active_tab = | 482 content::WebContents* active_tab = |
| 563 browser()->tab_strip_model()->GetActiveWebContents(); | 483 browser()->tab_strip_model()->GetActiveWebContents(); |
| 564 EXPECT_NE(preview_tab, active_tab); | 484 EXPECT_NE(overlay, active_tab); |
| 565 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); | 485 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); |
| 566 | 486 |
| 567 // As before, Instant shouldn't have done anything. | 487 // As before, Instant shouldn't have done anything. |
| 568 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 488 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 569 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | |
| 570 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 571 } | 489 } |
| 572 | 490 |
| 573 // Test that a non-Instant search provider shows no previews. | 491 // Test that a non-Instant search provider shows no overlays. |
| 574 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { | 492 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { |
| 575 instant_url_ = test_server()->GetURL("files/empty.html"); | 493 set_instant_url(test_server()->GetURL("files/empty.html")); |
| 576 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 494 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 577 | 495 |
| 578 // Focus the omnibox. When the support determination response comes back, | 496 // Focus the omnibox. When the support determination response comes back, |
| 579 // Instant will destroy the non-Instant page, and attempt to recreate it. | 497 // Instant will destroy the non-Instant page. |
| 580 // We can know this happened by looking at the blacklist. | 498 FocusOmnibox(); |
| 581 EXPECT_EQ(0, instant()->blacklisted_urls_[instant_url_.spec()]); | 499 EXPECT_TRUE(service()->loader()->contents()); |
| 500 |
| 582 FocusOmniboxAndWaitForInstantSupport(); | 501 FocusOmniboxAndWaitForInstantSupport(); |
| 583 EXPECT_EQ(1, instant()->blacklisted_urls_[instant_url_.spec()]); | 502 EXPECT_FALSE(service()->loader()->contents()); |
| 584 } | 503 } |
| 585 | 504 |
| 586 // Test that the renderer doesn't crash if JavaScript is blocked. | 505 // Test that the renderer doesn't crash if JavaScript is blocked. |
| 587 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { | 506 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { |
| 588 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 507 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 589 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 508 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 590 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 509 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 591 | 510 |
| 592 // Wait for notification that the Instant API has been determined. As long as | 511 // Wait for notification that the Instant API has been determined. As long as |
| 593 // we get the notification we're good (the renderer didn't crash). | 512 // we get the notification we're good (the renderer didn't crash). |
| 594 FocusOmniboxAndWaitForInstantSupport(); | 513 FocusOmniboxAndWaitForInstantSupport(); |
| 514 EXPECT_FALSE(service()->loader()->contents()); |
| 595 } | 515 } |
| 596 | 516 |
| 597 // Test that the preview and active tab's visibility states are set correctly. | 517 // Test that the overlay and active tab's visibility states are set correctly. |
| 598 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { | 518 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { |
| 599 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 519 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 600 FocusOmniboxAndWaitForInstantSupport(); | 520 FocusOmniboxAndWaitForInstantSupport(); |
| 601 | 521 |
| 602 content::WebContents* active_tab = | 522 content::WebContents* active_tab = |
| 603 browser()->tab_strip_model()->GetActiveWebContents(); | 523 browser()->tab_strip_model()->GetActiveWebContents(); |
| 604 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 524 content::WebContents* overlay = service()->loader()->contents(); |
| 605 | 525 |
| 606 // Inititally, the active tab is showing; the preview is not. | 526 // Inititally, the active tab is showing; the overlay is not. |
| 607 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); | 527 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
| 608 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); | 528 EXPECT_TRUE(CheckVisibilityIs(overlay, false)); |
| 609 | 529 |
| 610 // Type a query and wait for Instant to show. | 530 // Type a query and wait for Instant to show. |
| 611 SetOmniboxTextAndWaitForInstantToShow("query"); | 531 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 612 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); | 532 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
| 613 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); | 533 EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
| 614 | 534 |
| 615 // Deleting the omnibox text should hide the preview. | 535 // Deleting the omnibox text should hide the overlay. |
| 616 SetOmniboxText(""); | 536 SetOmniboxText(""); |
| 617 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); | 537 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
| 618 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); | 538 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 619 | 539 |
| 620 // Typing a query should show the preview again. | 540 // Typing a query should show the overlay again. |
| 621 SetOmniboxTextAndWaitForInstantToShow("query"); | 541 FocusOmniboxAndWaitForInstantSupport(); |
| 542 overlay = service()->loader()->contents(); |
| 543 |
| 544 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 622 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); | 545 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
| 623 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); | 546 EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
| 624 | 547 |
| 625 // Commit the preview. | 548 // Commit the overlay. |
| 626 browser()->window()->GetLocationBar()->AcceptInput(); | 549 browser()->window()->GetLocationBar()->AcceptInput(); |
| 627 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); | 550 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 628 EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); | 551 EXPECT_TRUE(CheckVisibilityIs(overlay, true)); |
| 629 } | 552 } |
| 630 | 553 |
| 631 // Test that the task manager identifies Instant's preview tab correctly. | 554 // Test that the task manager identifies Instant's overlay tab correctly. |
| 632 IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { | 555 IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { |
| 633 // The browser starts with a new tab, so there's just one renderer initially. | 556 // The browser starts with a new tab, so there's just one renderer initially. |
| 634 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); | 557 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); |
| 635 task_manager->StartUpdating(); | 558 task_manager->StartUpdating(); |
| 636 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 559 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 637 | 560 |
| 638 string16 prefix = l10n_util::GetStringFUTF16( | 561 string16 prefix = l10n_util::GetStringFUTF16( |
| 639 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 562 IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, string16()); |
| 640 | 563 |
| 641 // There should be no Instant preview yet. | 564 // There should be no Instant overlay yet. |
| 642 for (int i = 0; i < task_manager->ResourceCount(); ++i) { | 565 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
| 643 string16 title = task_manager->GetResourceTitle(i); | 566 string16 title = task_manager->GetResourceTitle(i); |
| 644 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 567 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 645 } | 568 } |
| 646 | 569 |
| 647 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 570 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 648 FocusOmnibox(); | 571 FocusOmniboxAndWaitForInstantSupport(); |
| 572 content::WebContents* overlay = service()->loader()->contents(); |
| 649 | 573 |
| 650 // Now there should be two renderers, the second being the Instant preview. | 574 // Now there should be two renderers, the second being the Instant overlay. |
| 651 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 575 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 652 | 576 |
| 653 int instant_previews = 0; | 577 int instant_overlays = 0; |
| 654 for (int i = 0; i < task_manager->ResourceCount(); ++i) { | 578 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
| 655 string16 title = task_manager->GetResourceTitle(i); | 579 string16 title = task_manager->GetResourceTitle(i); |
| 656 if (StartsWith(title, prefix, true)) | 580 if (StartsWith(title, prefix, true)) |
| 657 ++instant_previews; | 581 ++instant_overlays; |
| 658 } | 582 } |
| 659 EXPECT_EQ(1, instant_previews); | 583 EXPECT_EQ(1, instant_overlays); |
| 584 |
| 585 // Type something into the omnibox. This causes the overlay to be shown and |
| 586 // another Instant page to be spun up in the background. |
| 587 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 588 |
| 589 // So now there are three renderers, two of which are Instant. |
| 590 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 591 |
| 592 instant_overlays = 0; |
| 593 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
| 594 string16 title = task_manager->GetResourceTitle(i); |
| 595 if (StartsWith(title, prefix, true)) |
| 596 ++instant_overlays; |
| 597 } |
| 598 EXPECT_EQ(2, instant_overlays); |
| 599 |
| 600 // Commit the overlay. It should now be considered a regular tab. |
| 601 browser()->window()->GetLocationBar()->AcceptInput(); |
| 602 |
| 603 // The task manager caches titles, so we need to force the cache to clear. |
| 604 task_manager->StopUpdating(); |
| 605 task_manager->StartUpdating(); |
| 606 |
| 607 int overlay_index = -1; |
| 608 instant_overlays = 0; |
| 609 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
| 610 string16 title = task_manager->GetResourceTitle(i); |
| 611 if (StartsWith(title, prefix, true)) |
| 612 ++instant_overlays; |
| 613 if (task_manager->GetResourceWebContents(i) == overlay) |
| 614 overlay_index = i; |
| 615 } |
| 616 EXPECT_EQ(1, instant_overlays); |
| 617 |
| 618 // We should've found the overlay (which is now a committed tab). |
| 619 EXPECT_LE(0, overlay_index); |
| 620 string16 title = task_manager->GetResourceTitle(overlay_index); |
| 621 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 660 } | 622 } |
| 661 | 623 |
| 662 void HistoryQueryDone(base::RunLoop* run_loop, | 624 void HistoryQueryDone(base::RunLoop* run_loop, |
| 663 bool* result, | 625 bool* result, |
| 664 HistoryService::Handle /* handle */, | 626 HistoryService::Handle /* handle */, |
| 665 bool success, | 627 bool success, |
| 666 const history::URLRow* /* urlrow */, | 628 const history::URLRow* /* urlrow */, |
| 667 history::VisitVector* /* visitvector */) { | 629 history::VisitVector* /* visitvector */) { |
| 668 *result = success; | 630 *result = success; |
| 669 run_loop->Quit(); | 631 run_loop->Quit(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 689 // |instant_url| is the URL Instant loads. |search_url| is the fake URL we | 651 // |instant_url| is the URL Instant loads. |search_url| is the fake URL we |
| 690 // enter into history for search terms extraction to work correctly. | 652 // enter into history for search terms extraction to work correctly. |
| 691 std::string search_url = template_url->url_ref().ReplaceSearchTerms( | 653 std::string search_url = template_url->url_ref().ReplaceSearchTerms( |
| 692 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); | 654 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); |
| 693 | 655 |
| 694 HistoryService* history = HistoryServiceFactory::GetForProfile( | 656 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 695 browser()->profile(), Profile::EXPLICIT_ACCESS); | 657 browser()->profile(), Profile::EXPLICIT_ACCESS); |
| 696 ui_test_utils::WaitForHistoryToLoad(history); | 658 ui_test_utils::WaitForHistoryToLoad(history); |
| 697 | 659 |
| 698 // Perform a search. | 660 // Perform a search. |
| 699 SetOmniboxTextAndWaitForInstantToShow("search"); | 661 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 700 | 662 |
| 701 // Commit the search. | 663 // Commit the search. |
| 702 browser()->window()->GetLocationBar()->AcceptInput(); | 664 browser()->window()->GetLocationBar()->AcceptInput(); |
| 703 | 665 |
| 704 bool found = false; | 666 bool found = false; |
| 705 CancelableRequestConsumer consumer; | 667 CancelableRequestConsumer consumer; |
| 706 | 668 |
| 707 // The fake search URL should be in history. | 669 // The fake search URL should be in history. |
| 708 base::RunLoop run_loop1; | 670 base::RunLoop run_loop1; |
| 709 history->QueryURL(GURL(search_url), false, &consumer, | 671 history->QueryURL(GURL(search_url), false, &consumer, |
| 710 base::Bind(&HistoryQueryDone, &run_loop1, &found)); | 672 base::Bind(&HistoryQueryDone, &run_loop1, &found)); |
| 711 run_loop1.Run(); | 673 run_loop1.Run(); |
| 712 EXPECT_TRUE(found); | 674 EXPECT_TRUE(found); |
| 713 | 675 |
| 714 // The Instant URL should not be in history. | 676 // The Instant URL should not be in history. |
| 715 base::RunLoop run_loop2; | 677 base::RunLoop run_loop2; |
| 716 history->QueryURL(instant_url_, false, &consumer, | 678 history->QueryURL(instant_url(), false, &consumer, |
| 717 base::Bind(&HistoryQueryDone, &run_loop2, &found)); | 679 base::Bind(&HistoryQueryDone, &run_loop2, &found)); |
| 718 run_loop2.Run(); | 680 run_loop2.Run(); |
| 719 EXPECT_FALSE(found); | 681 EXPECT_FALSE(found); |
| 720 | 682 |
| 721 // The search terms should have been extracted into history. | 683 // The search terms should have been extracted into history. |
| 722 base::RunLoop run_loop3; | 684 base::RunLoop run_loop3; |
| 723 std::vector<string16> queries; | 685 std::vector<string16> queries; |
| 724 history->GetMostRecentKeywordSearchTerms(template_url->id(), | 686 history->GetMostRecentKeywordSearchTerms(template_url->id(), |
| 725 ASCIIToUTF16("s"), 1, &consumer, | 687 ASCIIToUTF16("s"), 1, &consumer, |
| 726 base::Bind(&KeywordQueryDone, &run_loop3, &queries)); | 688 base::Bind(&KeywordQueryDone, &run_loop3, &queries)); |
| 727 run_loop3.Run(); | 689 run_loop3.Run(); |
| 728 ASSERT_TRUE(queries.size()); | 690 ASSERT_TRUE(queries.size()); |
| 729 EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); | 691 EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); |
| 730 } | 692 } |
| 731 | 693 |
| 732 // TODO(jered): Fix this test on Mac. It fails currently, but the behavior is | 694 // Test that creating a new window hides any currently showing Instant overlay. |
| 733 // actually closer to what we'd like. | 695 IN_PROC_BROWSER_TEST_F(InstantTest, NewWindowDismissesInstant) { |
| 734 #if defined(OS_MACOSX) | |
| 735 #define MAYBE_NewWindowDismissesInstant DISABLED_NewWindowDismissesInstant | |
| 736 #else | |
| 737 #define MAYBE_NewWindowDismissesInstant NewWindowDismissesInstant | |
| 738 #endif | |
| 739 // Test that creating a new window hides any currently showing Instant preview. | |
| 740 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) { | |
| 741 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 696 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 742 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 697 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 743 FocusOmniboxAndWaitForInstantSupport(); | 698 FocusOmniboxAndWaitForInstantSupport(); |
| 744 SetOmniboxTextAndWaitForInstantToShow("search"); | 699 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 745 | 700 |
| 746 Browser* previous_window = browser(); | 701 Browser* previous_window = browser(); |
| 747 EXPECT_TRUE(instant()->IsPreviewingSearchResults()); | 702 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 748 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); | |
| 749 | 703 |
| 750 InstantTestModelObserver observer(instant()->model(), | |
| 751 chrome::search::Mode::MODE_DEFAULT); | |
| 752 chrome::NewEmptyWindow(browser()->profile(), | 704 chrome::NewEmptyWindow(browser()->profile(), |
| 753 chrome::HOST_DESKTOP_TYPE_NATIVE); | 705 chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 754 observer.WaitUntilDesiredPreviewState(); | |
| 755 | 706 |
| 756 // Even though we just created a new Browser object (for the new window), the | 707 // Even though we just created a new Browser object (for the new window), the |
| 757 // browser() accessor should still give us the first window's Browser object. | 708 // browser() accessor should still give us the first window's Browser object. |
| 758 EXPECT_EQ(previous_window, browser()); | 709 EXPECT_EQ(previous_window, browser()); |
| 759 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 710 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 760 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 761 } | 711 } |
| 762 | 712 |
| 763 // Test that the Instant overlay is recreated when all these conditions are met: | 713 // Test that the Instant overlay is recreated when the stale page timer fires. |
| 764 // - The stale overlay timer has fired. | 714 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { |
| 765 // - The preview is not showing. | |
| 766 // - The omnibox doesn't have focus. | |
| 767 IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { | |
| 768 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 715 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 769 FocusOmniboxAndWaitForInstantSupport(); | 716 FocusOmniboxAndWaitForInstantSupport(); |
| 770 | 717 |
| 771 // The preview is refreshed only after all three conditions above are met. | 718 // The timer should be running, with a non-zero delay. |
| 772 SetOmniboxTextAndWaitForInstantToShow("query"); | 719 base::Timer* timer = &service()->loader()->stale_page_timer_; |
| 773 instant()->overlay_->is_stale_ = true; | 720 EXPECT_TRUE(service()->loader()->supports_instant()); |
| 774 instant()->ReloadOverlayIfStale(); | 721 EXPECT_TRUE(timer->IsRunning()); |
| 775 EXPECT_TRUE(instant()->overlay_->supports_instant()); | 722 EXPECT_LT(base::TimeDelta(), timer->GetCurrentDelay()); |
| 776 instant()->HideOverlay(); | |
| 777 EXPECT_TRUE(instant()->overlay_->supports_instant()); | |
| 778 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, | |
| 779 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); | |
| 780 EXPECT_FALSE(instant()->overlay_->supports_instant()); | |
| 781 | 723 |
| 782 // Try with a different ordering. | 724 // Restart the timer at zero delay, and wait for it to fire. |
| 783 SetOmniboxTextAndWaitForInstantToShow("query"); | 725 timer->Start(FROM_HERE, base::TimeDelta(), timer->user_task()); |
| 784 instant()->overlay_->is_stale_ = true; | 726 EXPECT_EQ(base::TimeDelta(), timer->GetCurrentDelay()); |
| 785 instant()->ReloadOverlayIfStale(); | 727 content::RunAllPendingInMessageLoop(); |
| 786 EXPECT_TRUE(instant()->overlay_->supports_instant()); | 728 |
| 787 instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, | 729 // The overlay was deleted and recreated, so its Instant support hasn't been |
| 788 OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); | 730 // determined yet. The timer would've been reset as usual. |
| 789 // TODO(sreeram): Currently, OmniboxLostFocus() calls HideOverlay(). When it | 731 EXPECT_FALSE(service()->loader()->supports_instant()); |
| 790 // stops hiding the preview eventually, uncomment these two lines: | 732 EXPECT_TRUE(timer->IsRunning()); |
| 791 // EXPECT_TRUE(instant()->overlay_->supports_instant()); | 733 EXPECT_LT(base::TimeDelta(), timer->GetCurrentDelay()); |
| 792 // instant()->HideOverlay(); | |
| 793 EXPECT_FALSE(instant()->overlay_->supports_instant()); | |
| 794 } | 734 } |
| 795 | 735 |
| 796 // Test that suggestions are case insensitive. http://crbug.com/150728 | 736 // Test that suggestions are case insensitive. http://crbug.com/150728 |
| 797 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { | 737 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveOne) { |
| 738 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 739 |
| 740 const std::string script = |
| 741 "suggestion = { suggestions: [ { value: 'INSTANT' } ] }"; |
| 742 |
| 743 const struct { |
| 744 const char* const user_text; |
| 745 const string16 omnibox_text; |
| 746 } kTestCases[] = { |
| 747 {"in", ASCIIToUTF16("instant")}, |
| 748 {"IN", ASCIIToUTF16("INSTANT")}, |
| 749 }; |
| 750 |
| 751 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 752 FocusOmniboxAndWaitForInstantSupport(); |
| 753 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 754 script)); |
| 755 SetOmniboxTextAndWaitForOverlayToShow(kTestCases[i].user_text); |
| 756 EXPECT_EQ(kTestCases[i].omnibox_text, omnibox()->GetText()); |
| 757 omnibox()->RevertAll(); |
| 758 } |
| 759 } |
| 760 |
| 761 // Test that suggestions are case insensitive. http://crbug.com/150728 |
| 762 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveTwo) { |
| 763 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 764 |
| 765 // U+0130 == LATIN CAPITAL LETTER I WITH DOT ABOVE |
| 766 const std::string script = |
| 767 "suggestion = { suggestions: [ { value: '\\u0130NSTANT' } ] }"; |
| 768 |
| 769 const struct { |
| 770 const std::string user_text; |
| 771 const string16 omnibox_text; |
| 772 } kTestCases[] = { |
| 773 {std::string("i"), WideToUTF16(L"i\u0307nstant")}, |
| 774 {std::string("I"), WideToUTF16(L"I\u0307nstant")}, |
| 775 {WideToUTF8(L"i\u0307"), WideToUTF16(L"i\u0307nstant")}, |
| 776 {WideToUTF8(L"I\u0307"), WideToUTF16(L"I\u0307nstant")}, |
| 777 {WideToUTF8(L"\u0130"), WideToUTF16(L"\u0130NSTANT")}, |
| 778 {std::string("in"), ASCIIToUTF16("in")}, |
| 779 {std::string("IN"), ASCIIToUTF16("IN")}, |
| 780 }; |
| 781 |
| 782 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { |
| 783 FocusOmniboxAndWaitForInstantSupport(); |
| 784 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 785 script)); |
| 786 SetOmniboxTextAndWaitForOverlayToShow(kTestCases[i].user_text); |
| 787 EXPECT_EQ(kTestCases[i].omnibox_text, omnibox()->GetText()); |
| 788 omnibox()->RevertAll(); |
| 789 } |
| 790 } |
| 791 |
| 792 // Test that suggestions are case insensitive. http://crbug.com/150728 |
| 793 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitiveThree) { |
| 798 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 794 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 799 FocusOmniboxAndWaitForInstantSupport(); | 795 FocusOmniboxAndWaitForInstantSupport(); |
| 800 | 796 |
| 801 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); | |
| 802 | |
| 803 SetOmniboxTextAndWaitForInstantToShow("in"); | |
| 804 EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText()); | |
| 805 | |
| 806 omnibox()->RevertAll(); | |
| 807 SetOmniboxTextAndWaitForInstantToShow("IN"); | |
| 808 EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText()); | |
| 809 | |
| 810 // U+0130 == LATIN CAPITAL LETTER I WITH DOT ABOVE | |
| 811 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u0130NSTANT' } ]")); | |
| 812 | |
| 813 omnibox()->RevertAll(); | |
| 814 SetOmniboxTextAndWaitForInstantToShow("i"); | |
| 815 EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); | |
| 816 | |
| 817 omnibox()->RevertAll(); | |
| 818 SetOmniboxTextAndWaitForInstantToShow("I"); | |
| 819 EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); | |
| 820 | |
| 821 omnibox()->RevertAll(); | |
| 822 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"i\u0307")); | |
| 823 EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); | |
| 824 | |
| 825 omnibox()->RevertAll(); | |
| 826 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"I\u0307")); | |
| 827 EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); | |
| 828 | |
| 829 omnibox()->RevertAll(); | |
| 830 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u0130")); | |
| 831 EXPECT_EQ(WideToUTF16(L"\u0130NSTANT"), omnibox()->GetText()); | |
| 832 | |
| 833 omnibox()->RevertAll(); | |
| 834 SetOmniboxTextAndWaitForInstantToShow("in"); | |
| 835 EXPECT_EQ(ASCIIToUTF16("in"), omnibox()->GetText()); | |
| 836 | |
| 837 omnibox()->RevertAll(); | |
| 838 SetOmniboxTextAndWaitForInstantToShow("IN"); | |
| 839 EXPECT_EQ(ASCIIToUTF16("IN"), omnibox()->GetText()); | |
| 840 | |
| 841 // Check that a d with a dot above and below it is completed regardless of | 797 // Check that a d with a dot above and below it is completed regardless of |
| 842 // how that is encoded. | 798 // how that is encoded. |
| 843 // U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW | 799 // U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW |
| 844 // U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE | 800 // U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE |
| 845 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]")); | 801 EXPECT_TRUE(content::ExecuteScript(service()->loader()->contents(), |
| 846 | 802 "suggestion = { suggestions: [ { value: '\\u1e0d\\u0307oh' } ] }")); |
| 847 omnibox()->RevertAll(); | 803 SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u1e0b\u0323")); |
| 848 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u1e0b\u0323")); | |
| 849 EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); | 804 EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); |
| 850 } | 805 } |
| 851 | 806 |
| 852 // Flakes on Windows and Mac: http://crbug.com/170677 | 807 // Test that the overlay can be committed onto a new tab. |
| 853 #if defined(OS_WIN) || defined(OS_MACOSX) | 808 IN_PROC_BROWSER_TEST_F(InstantTest, CommitInNewTab) { |
| 854 #define MAYBE_CommitInNewTab DISABLED_CommitInNewTab | |
| 855 #else | |
| 856 #define MAYBE_CommitInNewTab CommitInNewTab | |
| 857 #endif | |
| 858 // Test that the preview can be committed onto a new tab. | |
| 859 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { | |
| 860 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 809 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 861 FocusOmniboxAndWaitForInstantSupport(); | 810 FocusOmniboxAndWaitForInstantSupport(); |
| 862 | 811 |
| 863 // Use the Instant page as the active tab, so we can exploit its visibility | 812 // Use the Instant page as the active tab, so we can exploit its visibility |
| 864 // handler to check visibility transitions. | 813 // handler to check visibility transitions. |
| 865 ui_test_utils::NavigateToURL(browser(), instant_url_); | 814 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 815 ui_test_utils::NavigateToURL(browser(), instant_url()); |
| 866 content::WebContents* active_tab = | 816 content::WebContents* active_tab = |
| 867 browser()->tab_strip_model()->GetActiveWebContents(); | 817 browser()->tab_strip_model()->GetActiveWebContents(); |
| 868 | 818 |
| 869 int active_tab_onvisibilitycalls = -1; | 819 int active_tab_onvisibilitycalls = -1; |
| 870 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", | 820 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
| 871 &active_tab_onvisibilitycalls)); | 821 &active_tab_onvisibilitycalls)); |
| 872 EXPECT_EQ(0, active_tab_onvisibilitycalls); | 822 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 873 | 823 |
| 874 SetOmniboxTextAndWaitForInstantToShow("search"); | 824 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 875 | 825 |
| 876 // Stash a reference to the preview, so we can refer to it after commit. | 826 // Stash a reference to the overlay, so we can refer to it after commit. |
| 877 content::WebContents* preview_tab = instant()->GetPreviewContents(); | 827 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 878 EXPECT_TRUE(preview_tab); | 828 EXPECT_TRUE(overlay); |
| 879 | 829 |
| 880 // The state of the searchbox before the commit. | 830 // The state of the searchbox before the commit. |
| 881 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 831 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 882 EXPECT_EQ("search", value_); | 832 EXPECT_EQ("search", value_); |
| 883 EXPECT_FALSE(verbatim_); | 833 EXPECT_FALSE(verbatim_); |
| 884 EXPECT_EQ(0, onsubmitcalls_); | 834 EXPECT_EQ(0, onsubmitcalls_); |
| 885 EXPECT_EQ(1, onvisibilitycalls_); | 835 EXPECT_EQ(1, onvisibilitycalls_); |
| 886 | 836 |
| 887 // The state of the active tab before the commit. | 837 // The state of the active tab before the commit. |
| 888 EXPECT_NE(preview_tab, active_tab); | 838 EXPECT_NE(overlay, active_tab); |
| 889 EXPECT_EQ(2, active_tab->GetController().GetEntryCount()); | 839 EXPECT_EQ(2, active_tab->GetController().GetEntryCount()); |
| 890 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); | 840 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
| 891 active_tab_onvisibilitycalls = -1; | 841 active_tab_onvisibilitycalls = -1; |
| 892 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", | 842 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
| 893 &active_tab_onvisibilitycalls)); | 843 &active_tab_onvisibilitycalls)); |
| 894 EXPECT_EQ(0, active_tab_onvisibilitycalls); | 844 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 895 | 845 |
| 896 // Commit the search by pressing Alt-Enter. | 846 // Commit the search by pressing Alt-Enter. |
| 897 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); | 847 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
| 898 | 848 |
| 899 // After the commit, Instant should not be showing. | 849 // After the commit, Instant should not be showing. |
| 900 EXPECT_FALSE(instant()->IsPreviewingSearchResults()); | 850 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 901 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
| 902 | |
| 903 // The old overlay is deleted and a new one is created. | |
| 904 EXPECT_TRUE(instant()->GetPreviewContents()); | |
| 905 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); | |
| 906 | 851 |
| 907 // Check that we have two tabs and that the new active tab is indeed what was | 852 // Check that we have two tabs and that the new active tab is indeed what was |
| 908 // once the preview. The preview tab should have just one navigation entry, | 853 // once the overlay. The overlay tab should have just one navigation entry, |
| 909 // for the Instant search that was committed. | 854 // for the Instant search that was committed. |
| 910 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 855 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 911 EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); | 856 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 912 EXPECT_EQ(1, preview_tab->GetController().GetEntryCount()); | 857 EXPECT_EQ(1, overlay->GetController().GetEntryCount()); |
| 913 | 858 |
| 914 // Check that the omnibox contains the Instant URL we loaded. | 859 // Check that the omnibox contains the Instant URL we loaded. |
| 915 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); | 860 EXPECT_EQ(instant_url(), omnibox()->model()->PermanentURL()); |
| 916 | 861 |
| 917 // Check that the searchbox API values have been reset. | 862 // The page should've correctly received the committed query. |
| 918 std::string value; | 863 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 919 EXPECT_TRUE(GetStringFromJS(preview_tab, | |
| 920 "chrome.embeddedSearch.searchBox.value", &value)); | |
| 921 EXPECT_EQ("", value); | |
| 922 | |
| 923 // However, the page should've correctly received the committed query. | |
| 924 EXPECT_TRUE(UpdateSearchState(preview_tab)); | |
| 925 EXPECT_EQ("search", value_); | 864 EXPECT_EQ("search", value_); |
| 926 EXPECT_TRUE(verbatim_); | 865 EXPECT_TRUE(verbatim_); |
| 927 EXPECT_EQ(1, onsubmitcalls_); | 866 EXPECT_EQ(1, onsubmitcalls_); |
| 928 EXPECT_EQ(1, onvisibilitycalls_); | 867 EXPECT_EQ(1, onvisibilitycalls_); |
| 929 | 868 |
| 930 // The ex-active tab should've gotten a visibility change marking it hidden. | 869 // The ex-active tab should've gotten a visibility change marking it hidden. |
| 931 EXPECT_NE(active_tab, preview_tab); | 870 EXPECT_NE(overlay, active_tab); |
| 932 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", | 871 EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", |
| 933 &active_tab_onvisibilitycalls)); | 872 &active_tab_onvisibilitycalls)); |
| 934 EXPECT_EQ(1, active_tab_onvisibilitycalls); | 873 EXPECT_EQ(1, active_tab_onvisibilitycalls); |
| 935 } | 874 } |
| 936 | 875 |
| 937 // Test that suggestions are reusable. | 876 // Test that the Instant overlay is recreated if it gets destroyed. |
| 938 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { | 877 IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { |
| 939 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 878 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 879 |
| 880 // Get the overlay to show. |
| 881 FocusOmniboxAndWaitForInstantSupport(); |
| 882 SetOmniboxTextAndWaitForOverlayToShow("search"); |
| 883 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 884 |
| 885 InstantModel desired_model(service()); |
| 886 desired_model.SetOverlayState(NULL, 0, false); |
| 887 InstantTestModelObserver observer(instant(), &desired_model); |
| 888 |
| 889 // Kill the overlay's renderer. |
| 890 KillOverlayRenderView(); |
| 891 |
| 892 // Wait for the overlay to disappear. |
| 893 observer.WaitForDesiredOverlayState(); |
| 894 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
| 895 EXPECT_FALSE(instant()->GetOverlayContents()); |
| 896 |
| 897 // Tickle the loader into recreating an overlay. |
| 940 FocusOmniboxAndWaitForInstantSupport(); | 898 FocusOmniboxAndWaitForInstantSupport(); |
| 941 | 899 |
| 942 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];" | 900 // Continue typing. The overlay should show again, and set suggestions. |
| 943 "behavior = 'never';")); | 901 SetOmniboxTextAndWaitForOverlayToShow("query"); |
| 944 | 902 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); |
| 945 SetOmniboxTextAndWaitForInstantToShow("in"); | |
| 946 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); | |
| 947 | |
| 948 SetOmniboxText("ins"); | |
| 949 EXPECT_EQ(ASCIIToUTF16("tant"), omnibox()->GetInstantSuggestion()); | |
| 950 | |
| 951 SetOmniboxText("in"); | |
| 952 EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); | |
| 953 | |
| 954 SetOmniboxText("insane"); | |
| 955 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | |
| 956 } | |
| 957 | |
| 958 // Test that instant overlay is recreated if it gets destroyed. | |
| 959 IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { | |
| 960 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | |
| 961 FocusOmniboxAndWaitForInstantSupport(); | |
| 962 | |
| 963 // Type partial query, get suggestion to show. | |
| 964 SetOmniboxTextAndWaitForInstantToShow("q"); | |
| 965 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | |
| 966 | |
| 967 // Kill the instant renderer and wait for instant support again. | |
| 968 KillInstantRenderView(); | |
| 969 FocusOmniboxAndWaitForInstantSupport(); | |
| 970 | |
| 971 SetOmniboxTextAndWaitForInstantToShow("qu"); | |
| 972 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 903 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
| 973 } | 904 } |
| 974 | 905 |
| 975 IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) { | 906 IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) { |
| 976 // Prior to setup no render process is dedicated to Instant. | 907 // Prior to setup no render process is dedicated to Instant. |
| 977 InstantService* instant_service = | 908 EXPECT_EQ(0, service()->GetInstantProcessCount()); |
| 978 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 979 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 980 EXPECT_EQ(0, instant_service->GetInstantProcessCount()); | |
| 981 | 909 |
| 982 // Setup Instant. | 910 // Setup Instant. |
| 983 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 911 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 984 FocusOmniboxAndWaitForInstantSupport(); | 912 FocusOmniboxAndWaitForInstantSupport(); |
| 985 | 913 |
| 986 // Now there should be a registered Instant render process. | 914 // Now there should be a registered Instant render process. |
| 987 EXPECT_LT(0, instant_service->GetInstantProcessCount()); | 915 EXPECT_EQ(1, service()->GetInstantProcessCount()); |
| 988 | 916 |
| 989 // And the Instant preview should live inside it. | 917 // And the Instant overlay should live inside it. |
| 990 content::WebContents* preview = instant()->GetPreviewContents(); | 918 content::WebContents* overlay = service()->loader()->contents(); |
| 991 EXPECT_TRUE(instant_service->IsInstantProcess( | 919 EXPECT_TRUE( |
| 992 preview->GetRenderProcessHost()->GetID())); | 920 service()->IsInstantProcess(overlay->GetRenderProcessHost()->GetID())); |
| 993 | 921 |
| 994 // Search and commit the search by pressing Alt-Enter. | 922 // Search and commit the search by pressing Alt-Enter. |
| 995 SetOmniboxTextAndWaitForInstantToShow("tractor"); | 923 SetOmniboxTextAndWaitForOverlayToShow("tractor"); |
| 996 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); | 924 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
| 997 | 925 |
| 998 // The committed search results page should also live inside the | 926 // The committed results page should also live inside the Instant process. |
| 999 // Instant process. | |
| 1000 content::WebContents* active_tab = | 927 content::WebContents* active_tab = |
| 1001 browser()->tab_strip_model()->GetActiveWebContents(); | 928 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1002 EXPECT_TRUE(instant_service->IsInstantProcess( | 929 EXPECT_TRUE( |
| 1003 active_tab->GetRenderProcessHost()->GetID())); | 930 service()->IsInstantProcess(active_tab->GetRenderProcessHost()->GetID())); |
| 1004 | 931 |
| 1005 // Navigating away should change the process. | 932 // Navigating away should change the process. |
| 1006 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 933 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 1007 EXPECT_FALSE(instant_service->IsInstantProcess( | 934 EXPECT_FALSE( |
| 1008 active_tab->GetRenderProcessHost()->GetID())); | 935 service()->IsInstantProcess(active_tab->GetRenderProcessHost()->GetID())); |
| 1009 } | 936 } |
| OLD | NEW |