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