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