OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/stringprintf.h" | 5 #include "base/stringprintf.h" |
6 #include "chrome/browser/content_settings/host_content_settings_map.h" | 6 #include "chrome/browser/content_settings/host_content_settings_map.h" |
7 #include "chrome/browser/history/history_service_factory.h" | 7 #include "chrome/browser/history/history_service_factory.h" |
8 #include "chrome/browser/instant/instant_controller.h" | 8 #include "chrome/browser/instant/instant_controller.h" |
9 #include "chrome/browser/instant/instant_loader.h" | 9 #include "chrome/browser/instant/instant_loader.h" |
10 #include "chrome/browser/instant/instant_model.h" | 10 #include "chrome/browser/instant/instant_model.h" |
11 #include "chrome/browser/instant/instant_model_observer.h" | 11 #include "chrome/browser/instant/instant_model_observer.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "chrome/browser/task_manager/task_manager.h" | 15 #include "chrome/browser/task_manager/task_manager.h" |
16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 16 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/browser_instant_controller.h" | 18 #include "chrome/browser/ui/browser_instant_controller.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/omnibox/location_bar.h" | 21 #include "chrome/browser/ui/omnibox/location_bar.h" |
22 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 22 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
28 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
33 | 34 |
(...skipping 18 matching lines...) Expand all Loading... |
52 | 53 |
53 private: | 54 private: |
54 const InstantModel* const model_; | 55 const InstantModel* const model_; |
55 base::RunLoop run_loop_; | 56 base::RunLoop run_loop_; |
56 | 57 |
57 DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver); | 58 DISALLOW_COPY_AND_ASSIGN(InstantTestModelObserver); |
58 }; | 59 }; |
59 | 60 |
60 class InstantTest : public InProcessBrowserTest { | 61 class InstantTest : public InProcessBrowserTest { |
61 protected: | 62 protected: |
62 void SetupInstant(const std::string& page) { | 63 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
63 ASSERT_TRUE(test_server()->Start()); | 64 ASSERT_TRUE(test_server()->Start()); |
| 65 instant_url_ = test_server()->GetURL("files/instant.html"); |
| 66 } |
64 | 67 |
| 68 void SetupInstant() { |
65 TemplateURLService* service = | 69 TemplateURLService* service = |
66 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 70 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
67 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 71 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
68 | 72 |
69 TemplateURLData data; | 73 TemplateURLData data; |
70 data.SetURL("http://does/not/exist?q={searchTerms}"); | 74 data.SetURL("http://does/not/exist?q={searchTerms}"); |
71 data.instant_url = base::StringPrintf( | 75 data.instant_url = instant_url_.spec(); |
72 "http://%s:%d/files/%s", | |
73 test_server()->host_port_pair().host().c_str(), | |
74 test_server()->host_port_pair().port(), | |
75 page.c_str()); | |
76 | 76 |
77 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); | 77 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
78 service->Add(template_url); // Takes ownership of |template_url|. | 78 service->Add(template_url); // Takes ownership of |template_url|. |
79 service->SetDefaultSearchProvider(template_url); | 79 service->SetDefaultSearchProvider(template_url); |
80 | 80 |
81 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); | 81 browser()->profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, true); |
82 } | 82 } |
83 | 83 |
84 InstantController* instant() { | 84 InstantController* instant() { |
85 return browser()->instant_controller()->instant(); | 85 return browser()->instant_controller()->instant(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 bool GetStringFromJS(content::RenderViewHost* rvh, | 137 bool GetStringFromJS(content::RenderViewHost* rvh, |
138 const std::string& script, | 138 const std::string& script, |
139 std::string* result) WARN_UNUSED_RESULT { | 139 std::string* result) WARN_UNUSED_RESULT { |
140 return content::ExecuteJavaScriptAndExtractString( | 140 return content::ExecuteJavaScriptAndExtractString( |
141 rvh, std::wstring(), WrapScript(script), result); | 141 rvh, std::wstring(), WrapScript(script), result); |
142 } | 142 } |
143 | 143 |
144 bool UpdateSearchState(TabContents* tab) WARN_UNUSED_RESULT { | 144 bool UpdateSearchState(TabContents* tab) WARN_UNUSED_RESULT { |
145 content::RenderViewHost* rvh = tab->web_contents()->GetRenderViewHost(); | 145 content::RenderViewHost* rvh = tab->web_contents()->GetRenderViewHost(); |
146 return GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && | 146 return GetIntFromJS(rvh, "onvisibilitycalls", &onvisibilitycalls_) && |
| 147 GetIntFromJS(rvh, "onchangecalls", &onchangecalls_) && |
147 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && | 148 GetIntFromJS(rvh, "onsubmitcalls", &onsubmitcalls_) && |
148 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && | 149 GetIntFromJS(rvh, "oncancelcalls", &oncancelcalls_) && |
149 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && | 150 GetIntFromJS(rvh, "onresizecalls", &onresizecalls_) && |
150 GetIntFromJS(rvh, "onfocuscalls", &onfocuscalls_) && | 151 GetIntFromJS(rvh, "onfocuscalls", &onfocuscalls_) && |
151 GetIntFromJS(rvh, "onblurcalls", &onblurcalls_) && | 152 GetIntFromJS(rvh, "onblurcalls", &onblurcalls_) && |
152 GetStringFromJS(rvh, "value", &value_) && | 153 GetStringFromJS(rvh, "value", &value_) && |
153 GetBoolFromJS(rvh, "verbatim", &verbatim_) && | 154 GetBoolFromJS(rvh, "verbatim", &verbatim_) && |
154 GetIntFromJS(rvh, "height", &height_); | 155 GetIntFromJS(rvh, "height", &height_); |
155 } | 156 } |
156 | 157 |
157 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { | 158 bool ExecuteScript(const std::string& script) WARN_UNUSED_RESULT { |
158 return content::ExecuteJavaScript( | 159 return content::ExecuteJavaScript( |
159 instant()->GetPreviewContents()->web_contents()->GetRenderViewHost(), | 160 instant()->GetPreviewContents()->web_contents()->GetRenderViewHost(), |
160 std::wstring(), UTF8ToWide(script)); | 161 std::wstring(), UTF8ToWide(script)); |
161 } | 162 } |
162 | 163 |
163 bool CheckVisibilityIs(TabContents* tab, bool expected) WARN_UNUSED_RESULT { | 164 bool CheckVisibilityIs(TabContents* tab, bool expected) WARN_UNUSED_RESULT { |
164 bool actual = !expected; // Purposely start with a mis-match. | 165 bool actual = !expected; // Purposely start with a mis-match. |
165 // We can only use ASSERT_*() in a method that returns void, hence this | 166 // We can only use ASSERT_*() in a method that returns void, hence this |
166 // convoluted check. | 167 // convoluted check. |
167 return GetBoolFromJS(tab->web_contents()->GetRenderViewHost(), | 168 return GetBoolFromJS(tab->web_contents()->GetRenderViewHost(), |
168 "!document.webkitHidden", &actual) && | 169 "!document.webkitHidden", &actual) && |
169 actual == expected; | 170 actual == expected; |
170 } | 171 } |
171 | 172 |
| 173 GURL instant_url_; |
| 174 |
| 175 int onvisibilitycalls_; |
172 int onchangecalls_; | 176 int onchangecalls_; |
173 int onsubmitcalls_; | 177 int onsubmitcalls_; |
174 int oncancelcalls_; | 178 int oncancelcalls_; |
175 int onresizecalls_; | 179 int onresizecalls_; |
176 int onfocuscalls_; | 180 int onfocuscalls_; |
177 int onblurcalls_; | 181 int onblurcalls_; |
178 | 182 |
179 std::string value_; | 183 std::string value_; |
180 bool verbatim_; | 184 bool verbatim_; |
181 int height_; | 185 int height_; |
182 }; | 186 }; |
183 | 187 |
184 // Test that Instant is preloaded when the omnibox is focused. | 188 // Test that Instant is preloaded when the omnibox is focused. |
185 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { | 189 IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { |
186 // The omnibox gets focus before the test begins. At this time, there's no | 190 // The omnibox gets focus before the test begins. At this time, there's no |
187 // InstantController (which is only created in SetupInstant() below), so no | 191 // InstantController (which is only created in SetupInstant() below), so no |
188 // preloading has happened yet. | 192 // preloading has happened yet. |
189 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 193 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
190 EXPECT_FALSE(instant()->GetPreviewContents()); | 194 EXPECT_FALSE(instant()->GetPreviewContents()); |
191 | 195 |
192 // Explicitly unfocus the omnibox. | 196 // Explicitly unfocus the omnibox. |
193 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 197 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
194 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 198 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
195 | 199 |
196 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 200 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
197 EXPECT_FALSE(omnibox()->model()->has_focus()); | 201 EXPECT_FALSE(omnibox()->model()->has_focus()); |
198 | 202 |
199 // Refocus the omnibox. The InstantController should've preloaded Instant. | 203 // Refocus the omnibox. The InstantController should've preloaded Instant. |
(...skipping 25 matching lines...) Expand all Loading... |
225 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 229 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
226 | 230 |
227 // Doing a search should also use the same preloaded page. | 231 // Doing a search should also use the same preloaded page. |
228 SetOmniboxTextAndWaitForInstantToShow("query"); | 232 SetOmniboxTextAndWaitForInstantToShow("query"); |
229 EXPECT_TRUE(instant()->model()->is_ready()); | 233 EXPECT_TRUE(instant()->model()->is_ready()); |
230 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 234 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
231 } | 235 } |
232 | 236 |
233 // Test that the onchange event is dispatched upon typing in the omnibox. | 237 // Test that the onchange event is dispatched upon typing in the omnibox. |
234 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { | 238 IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) { |
235 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 239 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
236 FocusOmniboxAndWaitForInstantSupport(); | 240 |
| 241 // Use the Instant page as the active tab, so we can exploit its visibility |
| 242 // handler to check visibility transitions. |
| 243 ui_test_utils::NavigateToURL(browser(), instant_url_); |
| 244 content::RenderViewHost* active_rvh = |
| 245 chrome::GetActiveWebContents(browser())->GetRenderViewHost(); |
| 246 |
| 247 int active_tab_onvisibilitycalls = -1; |
| 248 EXPECT_TRUE(GetIntFromJS(active_rvh, "onvisibilitycalls", |
| 249 &active_tab_onvisibilitycalls)); |
| 250 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
237 | 251 |
238 // Typing "query" into the omnibox causes the first onchange event. | 252 // Typing "query" into the omnibox causes the first onchange event. |
| 253 FocusOmniboxAndWaitForInstantSupport(); |
239 SetOmniboxTextAndWaitForInstantToShow("query"); | 254 SetOmniboxTextAndWaitForInstantToShow("query"); |
240 | 255 |
241 // The page suggested "query suggestion" is inline autocompleted into the | 256 // The page suggested "query suggestion" is inline autocompleted into the |
242 // omnibox, causing the second onchange event. | 257 // omnibox, causing the second onchange event. |
243 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); | 258 EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); |
244 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 259 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
245 EXPECT_EQ(2, onchangecalls_); | 260 EXPECT_EQ(2, onchangecalls_); |
246 | 261 |
247 // Change the query and confirm that another onchange is sent. Since the new | 262 // Change the query and confirm that another onchange is sent. Since the new |
248 // query is not a prefix of the hardcoded "query suggestion", no inline | 263 // query is not a prefix of the hardcoded "query suggestion", no inline |
249 // autocompletion happens, and thus, no fourth onchange event. | 264 // autocompletion happens, and thus, no fourth onchange event. |
250 SetOmniboxText("search"); | 265 SetOmniboxText("search"); |
251 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 266 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
252 EXPECT_EQ(3, onchangecalls_); | 267 EXPECT_EQ(3, onchangecalls_); |
| 268 EXPECT_EQ(1, onvisibilitycalls_); |
| 269 |
| 270 active_tab_onvisibilitycalls = -1; |
| 271 EXPECT_TRUE(GetIntFromJS(active_rvh, "onvisibilitycalls", |
| 272 &active_tab_onvisibilitycalls)); |
| 273 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
253 } | 274 } |
254 | 275 |
255 // Test that the onsubmit event is dispatched upon pressing Enter. | 276 // Test that the onsubmit event is dispatched upon pressing Enter. |
256 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { | 277 IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { |
257 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 278 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
258 FocusOmniboxAndWaitForInstantSupport(); | 279 FocusOmniboxAndWaitForInstantSupport(); |
259 SetOmniboxTextAndWaitForInstantToShow("search"); | 280 SetOmniboxTextAndWaitForInstantToShow("search"); |
260 | 281 |
261 // Stash a reference to the preview, so we can refer to it after commit. | 282 // Stash a reference to the preview, so we can refer to it after commit. |
262 TabContents* preview_tab = instant()->GetPreviewContents(); | 283 TabContents* preview_tab = instant()->GetPreviewContents(); |
263 EXPECT_TRUE(preview_tab); | 284 EXPECT_TRUE(preview_tab); |
264 | 285 |
265 // The state of the searchbox before the commit. | 286 // The state of the searchbox before the commit. |
266 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 287 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
267 EXPECT_EQ("search", value_); | 288 EXPECT_EQ("search", value_); |
268 EXPECT_FALSE(verbatim_); | 289 EXPECT_FALSE(verbatim_); |
269 EXPECT_EQ(0, onsubmitcalls_); | 290 EXPECT_EQ(0, onsubmitcalls_); |
| 291 EXPECT_EQ(1, onvisibilitycalls_); |
270 | 292 |
271 // Before the commit, the active tab is the NTP (i.e., not Instant). | 293 // Before the commit, the active tab is the NTP (i.e., not Instant). |
272 TabContents* active_tab = chrome::GetActiveTabContents(browser()); | 294 TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
273 EXPECT_NE(preview_tab, active_tab); | 295 EXPECT_NE(preview_tab, active_tab); |
274 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); | 296 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); |
275 EXPECT_EQ(std::string(chrome::kAboutBlankURL), | 297 EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
276 omnibox()->model()->PermanentURL().spec()); | 298 omnibox()->model()->PermanentURL().spec()); |
277 | 299 |
278 // Commit the search by pressing Enter. | 300 // Commit the search by pressing Enter. |
279 browser()->window()->GetLocationBar()->AcceptInput(); | 301 browser()->window()->GetLocationBar()->AcceptInput(); |
280 | 302 |
281 // After the commit, Instant should not be showing. | 303 // After the commit, Instant should not be showing. |
282 EXPECT_FALSE(instant()->IsCurrent()); | 304 EXPECT_FALSE(instant()->IsCurrent()); |
283 EXPECT_FALSE(instant()->model()->is_ready()); | 305 EXPECT_FALSE(instant()->model()->is_ready()); |
284 | 306 |
285 // The old loader is deleted and a new one is created. | 307 // The old loader is deleted and a new one is created. |
286 EXPECT_TRUE(instant()->GetPreviewContents()); | 308 EXPECT_TRUE(instant()->GetPreviewContents()); |
287 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); | 309 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
288 | 310 |
289 // Check that the current active tab is indeed what was once the preview. | 311 // Check that the current active tab is indeed what was once the preview. |
290 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); | 312 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
291 | 313 |
292 // We should have two navigation entries, one for the NTP, and one for the | 314 // We should have two navigation entries, one for the NTP, and one for the |
293 // Instant search that was committed. | 315 // Instant search that was committed. |
294 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); | 316 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); |
295 | 317 |
296 // Check that the omnibox contains the Instant URL we loaded. | 318 // Check that the omnibox contains the Instant URL we loaded. |
297 std::string instant_url = TemplateURLServiceFactory::GetForProfile( | 319 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
298 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). | |
299 ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(string16())); | |
300 EXPECT_EQ(instant_url, omnibox()->model()->PermanentURL().spec()); | |
301 | 320 |
302 // Check that the searchbox API values have been reset. | 321 // Check that the searchbox API values have been reset. |
303 std::string value; | 322 std::string value; |
304 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), | 323 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), |
305 "chrome.searchBox.value", &value)); | 324 "chrome.searchBox.value", &value)); |
306 EXPECT_EQ("", value); | 325 EXPECT_EQ("", value); |
307 | 326 |
308 // However, the page should've correctly received the committed query. | 327 // However, the page should've correctly received the committed query. |
309 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 328 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
310 EXPECT_EQ("search", value_); | 329 EXPECT_EQ("search", value_); |
311 EXPECT_TRUE(verbatim_); | 330 EXPECT_TRUE(verbatim_); |
312 EXPECT_EQ(1, onsubmitcalls_); | 331 EXPECT_EQ(1, onsubmitcalls_); |
| 332 EXPECT_EQ(1, onvisibilitycalls_); |
313 } | 333 } |
314 | 334 |
315 // Test that the oncancel event is dispatched upon clicking on the preview. | 335 // Test that the oncancel event is dispatched upon clicking on the preview. |
316 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { | 336 IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { |
317 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 337 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
318 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 338 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 339 FocusOmniboxAndWaitForInstantSupport(); |
319 SetOmniboxTextAndWaitForInstantToShow("search"); | 340 SetOmniboxTextAndWaitForInstantToShow("search"); |
320 | 341 |
321 // Stash a reference to the preview, so we can refer to it after commit. | 342 // Stash a reference to the preview, so we can refer to it after commit. |
322 TabContents* preview_tab = instant()->GetPreviewContents(); | 343 TabContents* preview_tab = instant()->GetPreviewContents(); |
323 EXPECT_TRUE(preview_tab); | 344 EXPECT_TRUE(preview_tab); |
324 | 345 |
325 // The state of the searchbox before the commit. | 346 // The state of the searchbox before the commit. |
326 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 347 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
327 EXPECT_EQ("search", value_); | 348 EXPECT_EQ("search", value_); |
328 EXPECT_FALSE(verbatim_); | 349 EXPECT_FALSE(verbatim_); |
329 EXPECT_EQ(0, oncancelcalls_); | 350 EXPECT_EQ(0, oncancelcalls_); |
| 351 EXPECT_EQ(1, onvisibilitycalls_); |
330 | 352 |
331 // Before the commit, the active tab is the NTP (i.e., not Instant). | 353 // Before the commit, the active tab is the NTP (i.e., not Instant). |
332 TabContents* active_tab = chrome::GetActiveTabContents(browser()); | 354 TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
333 EXPECT_NE(preview_tab, active_tab); | 355 EXPECT_NE(preview_tab, active_tab); |
334 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); | 356 EXPECT_EQ(1, active_tab->web_contents()->GetController().GetEntryCount()); |
335 EXPECT_EQ(std::string(chrome::kAboutBlankURL), | 357 EXPECT_EQ(std::string(chrome::kAboutBlankURL), |
336 omnibox()->model()->PermanentURL().spec()); | 358 omnibox()->model()->PermanentURL().spec()); |
337 | 359 |
338 // Commit the search by clicking on the preview. | 360 // Commit the search by clicking on the preview. |
339 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 361 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
340 | 362 |
341 // After the commit, Instant should not be showing. | 363 // After the commit, Instant should not be showing. |
342 EXPECT_FALSE(instant()->IsCurrent()); | 364 EXPECT_FALSE(instant()->IsCurrent()); |
343 EXPECT_FALSE(instant()->model()->is_ready()); | 365 EXPECT_FALSE(instant()->model()->is_ready()); |
344 | 366 |
345 // The old loader is deleted and a new one is created. | 367 // The old loader is deleted and a new one is created. |
346 EXPECT_TRUE(instant()->GetPreviewContents()); | 368 EXPECT_TRUE(instant()->GetPreviewContents()); |
347 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); | 369 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
348 | 370 |
349 // Check that the current active tab is indeed what was once the preview. | 371 // Check that the current active tab is indeed what was once the preview. |
350 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); | 372 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
351 | 373 |
352 // We should have two navigation entries, one for the NTP, and one for the | 374 // We should have two navigation entries, one for the NTP, and one for the |
353 // Instant search that was committed. | 375 // Instant search that was committed. |
354 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); | 376 EXPECT_EQ(2, preview_tab->web_contents()->GetController().GetEntryCount()); |
355 | 377 |
356 // Check that the omnibox contains the Instant URL we loaded. | 378 // Check that the omnibox contains the Instant URL we loaded. |
357 std::string instant_url = TemplateURLServiceFactory::GetForProfile( | 379 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
358 browser()->profile())->GetDefaultSearchProvider()->instant_url_ref(). | |
359 ReplaceSearchTerms(TemplateURLRef::SearchTermsArgs(string16())); | |
360 EXPECT_EQ(instant_url, omnibox()->model()->PermanentURL().spec()); | |
361 | 380 |
362 // Check that the searchbox API values have been reset. | 381 // Check that the searchbox API values have been reset. |
363 std::string value; | 382 std::string value; |
364 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), | 383 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), |
365 "chrome.searchBox.value", &value)); | 384 "chrome.searchBox.value", &value)); |
366 EXPECT_EQ("", value); | 385 EXPECT_EQ("", value); |
367 | 386 |
368 // However, the page should've correctly received the committed query. | 387 // However, the page should've correctly received the committed query. |
369 EXPECT_TRUE(UpdateSearchState(preview_tab)); | 388 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
370 EXPECT_EQ("search", value_); | 389 EXPECT_EQ("search", value_); |
371 EXPECT_TRUE(verbatim_); | 390 EXPECT_TRUE(verbatim_); |
372 EXPECT_EQ(1, oncancelcalls_); | 391 EXPECT_EQ(1, oncancelcalls_); |
| 392 EXPECT_EQ(1, onvisibilitycalls_); |
373 } | 393 } |
374 | 394 |
375 // Test that the onreisze event is dispatched upon typing in the omnibox. | 395 // Test that the onreisze event is dispatched upon typing in the omnibox. |
376 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { | 396 IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { |
377 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 397 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
378 | 398 |
379 // This makes Instant load the preview, along with an initial onresize() (see | 399 // This makes Instant load the preview, along with an initial onresize() (see |
380 // SearchBoxExtension::PageSupportsInstant() for why). | 400 // SearchBoxExtension::PageSupportsInstant() for why). |
381 FocusOmniboxAndWaitForInstantSupport(); | 401 FocusOmniboxAndWaitForInstantSupport(); |
382 | 402 |
383 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 403 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
384 EXPECT_EQ(1, onresizecalls_); | 404 EXPECT_EQ(1, onresizecalls_); |
385 EXPECT_EQ(0, height_); | 405 EXPECT_EQ(0, height_); |
386 | 406 |
387 // Type a query into the omnibox. This should cause an onresize() event, with | 407 // Type a query into the omnibox. This should cause an onresize() event, with |
388 // a valid (non-zero) height. | 408 // a valid (non-zero) height. |
389 SetOmniboxTextAndWaitForInstantToShow("search"); | 409 SetOmniboxTextAndWaitForInstantToShow("search"); |
390 | 410 |
391 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 411 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
392 EXPECT_EQ(2, onresizecalls_); | 412 EXPECT_EQ(2, onresizecalls_); |
393 EXPECT_LT(0, height_); | 413 EXPECT_LT(0, height_); |
394 } | 414 } |
395 | 415 |
396 // Test that the searchbox isFocused property and focus and blur events work. | 416 // Test that the searchbox isFocused property and focus and blur events work. |
397 IN_PROC_BROWSER_TEST_F(InstantTest, Focus) { | 417 IN_PROC_BROWSER_TEST_F(InstantTest, Focus) { |
398 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 418 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
399 FocusOmniboxAndWaitForInstantSupport(); | 419 FocusOmniboxAndWaitForInstantSupport(); |
400 | 420 |
401 TabContents* preview_tab = instant()->GetPreviewContents(); | 421 content::RenderViewHost* preview_rvh = |
402 EXPECT_TRUE(preview_tab); | 422 instant()->GetPreviewContents()->web_contents()->GetRenderViewHost(); |
| 423 |
403 bool is_focused = false; | 424 bool is_focused = false; |
404 EXPECT_TRUE(GetBoolFromJS(preview_tab->web_contents()->GetRenderViewHost(), | 425 EXPECT_TRUE(GetBoolFromJS(preview_rvh, "chrome.searchBox.isFocused", |
405 "chrome.searchBox.isFocused", &is_focused)); | 426 &is_focused)); |
406 EXPECT_TRUE(is_focused); | 427 EXPECT_TRUE(is_focused); |
| 428 |
407 instant()->OnAutocompleteGotFocus(); | 429 instant()->OnAutocompleteGotFocus(); |
408 instant()->OnAutocompleteLostFocus(NULL); | 430 instant()->OnAutocompleteLostFocus(NULL); |
409 EXPECT_TRUE(GetBoolFromJS(preview_tab->web_contents()->GetRenderViewHost(), | 431 |
410 "chrome.searchBox.isFocused", &is_focused)); | 432 EXPECT_TRUE(GetBoolFromJS(preview_rvh, "chrome.searchBox.isFocused", |
| 433 &is_focused)); |
411 EXPECT_FALSE(is_focused); | 434 EXPECT_FALSE(is_focused); |
412 | 435 |
413 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 436 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
414 EXPECT_EQ(1, onfocuscalls_); | 437 EXPECT_EQ(1, onfocuscalls_); |
415 EXPECT_EQ(1, onblurcalls_); | 438 EXPECT_EQ(1, onblurcalls_); |
416 } | 439 } |
417 | 440 |
418 // Test that the INSTANT_COMPLETE_NOW behavior works as expected. | 441 // Test that the INSTANT_COMPLETE_NOW behavior works as expected. |
419 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { | 442 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { |
420 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 443 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
421 FocusOmniboxAndWaitForInstantSupport(); | 444 FocusOmniboxAndWaitForInstantSupport(); |
422 | 445 |
423 // Tell the JS to request the given behavior. | 446 // Tell the JS to request the given behavior. |
424 EXPECT_TRUE(ExecuteScript("behavior = 'now'")); | 447 EXPECT_TRUE(ExecuteScript("behavior = 'now'")); |
425 | 448 |
426 // Type a query, causing the hardcoded "query suggestion" to be returned. | 449 // Type a query, causing the hardcoded "query suggestion" to be returned. |
427 SetOmniboxTextAndWaitForInstantToShow("query"); | 450 SetOmniboxTextAndWaitForInstantToShow("query"); |
428 | 451 |
429 // Get what's showing in the omnibox, and what's highlighted. | 452 // Get what's showing in the omnibox, and what's highlighted. |
430 string16 text = omnibox()->GetText(); | 453 string16 text = omnibox()->GetText(); |
431 size_t start = 0, end = 0; | 454 size_t start = 0, end = 0; |
432 omnibox()->GetSelectionBounds(&start, &end); | 455 omnibox()->GetSelectionBounds(&start, &end); |
433 if (start > end) | 456 if (start > end) |
434 std::swap(start, end); | 457 std::swap(start, end); |
435 | 458 |
436 EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); | 459 EXPECT_EQ(ASCIIToUTF16("query suggestion"), text); |
437 EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); | 460 EXPECT_EQ(ASCIIToUTF16(" suggestion"), text.substr(start, end - start)); |
438 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | 461 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); |
439 } | 462 } |
440 | 463 |
441 // Test that the INSTANT_COMPLETE_NEVER behavior works as expected. | 464 // Test that the INSTANT_COMPLETE_NEVER behavior works as expected. |
442 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { | 465 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { |
443 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 466 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
444 FocusOmniboxAndWaitForInstantSupport(); | 467 FocusOmniboxAndWaitForInstantSupport(); |
445 | 468 |
446 // Tell the JS to request the given behavior. | 469 // Tell the JS to request the given behavior. |
447 EXPECT_TRUE(ExecuteScript("behavior = 'never'")); | 470 EXPECT_TRUE(ExecuteScript("behavior = 'never'")); |
448 | 471 |
449 // Type a query, causing the hardcoded "query suggestion" to be returned. | 472 // Type a query, causing the hardcoded "query suggestion" to be returned. |
450 SetOmniboxTextAndWaitForInstantToShow("query"); | 473 SetOmniboxTextAndWaitForInstantToShow("query"); |
451 | 474 |
452 // Get what's showing in the omnibox, and what's highlighted. | 475 // Get what's showing in the omnibox, and what's highlighted. |
453 string16 text = omnibox()->GetText(); | 476 string16 text = omnibox()->GetText(); |
454 size_t start = 0, end = 0; | 477 size_t start = 0, end = 0; |
455 omnibox()->GetSelectionBounds(&start, &end); | 478 omnibox()->GetSelectionBounds(&start, &end); |
456 if (start > end) | 479 if (start > end) |
457 std::swap(start, end); | 480 std::swap(start, end); |
458 | 481 |
459 EXPECT_EQ(ASCIIToUTF16("query"), text); | 482 EXPECT_EQ(ASCIIToUTF16("query"), text); |
460 EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start)); | 483 EXPECT_EQ(ASCIIToUTF16(""), text.substr(start, end - start)); |
461 EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion()); | 484 EXPECT_EQ(ASCIIToUTF16(" suggestion"), omnibox()->GetInstantSuggestion()); |
462 } | 485 } |
463 | 486 |
464 // Test that a valid suggestion is accepted. | 487 // Test that a valid suggestion is accepted. |
465 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { | 488 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { |
466 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 489 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
467 FocusOmniboxAndWaitForInstantSupport(); | 490 FocusOmniboxAndWaitForInstantSupport(); |
468 | 491 |
469 // Tell the JS to use the given suggestion. | 492 // Tell the JS to use the given suggestion. |
470 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); | 493 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); |
471 | 494 |
472 // Type a query, causing "query completion" to be returned as the suggestion. | 495 // Type a query, causing "query completion" to be returned as the suggestion. |
473 SetOmniboxTextAndWaitForInstantToShow("query"); | 496 SetOmniboxTextAndWaitForInstantToShow("query"); |
474 EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); | 497 EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); |
475 } | 498 } |
476 | 499 |
477 // Test that an invalid suggestion is rejected. | 500 // Test that an invalid suggestion is rejected. |
478 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { | 501 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { |
479 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 502 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
480 FocusOmniboxAndWaitForInstantSupport(); | 503 FocusOmniboxAndWaitForInstantSupport(); |
481 | 504 |
482 // Tell the JS to use an object in an invalid format. | 505 // Tell the JS to use an object in an invalid format. |
483 EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); | 506 EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); |
484 | 507 |
485 // Type a query, but expect no suggestion. | 508 // Type a query, but expect no suggestion. |
486 SetOmniboxTextAndWaitForInstantToShow("query"); | 509 SetOmniboxTextAndWaitForInstantToShow("query"); |
487 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); | 510 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
488 } | 511 } |
489 | 512 |
490 // Test that various forms of empty suggestions are rejected. | 513 // Test that various forms of empty suggestions are rejected. |
491 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { | 514 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { |
492 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 515 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
493 FocusOmniboxAndWaitForInstantSupport(); | 516 FocusOmniboxAndWaitForInstantSupport(); |
494 | 517 |
495 EXPECT_TRUE(ExecuteScript("suggestion = {}")); | 518 EXPECT_TRUE(ExecuteScript("suggestion = {}")); |
496 SetOmniboxTextAndWaitForInstantToShow("query"); | 519 SetOmniboxTextAndWaitForInstantToShow("query"); |
497 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); | 520 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); |
498 | 521 |
499 instant()->Hide(); | 522 instant()->Hide(); |
500 | 523 |
501 EXPECT_TRUE(ExecuteScript("suggestion = []")); | 524 EXPECT_TRUE(ExecuteScript("suggestion = []")); |
502 SetOmniboxTextAndWaitForInstantToShow("query sugg"); | 525 SetOmniboxTextAndWaitForInstantToShow("query sugg"); |
503 EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); | 526 EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); |
504 | 527 |
505 instant()->Hide(); | 528 instant()->Hide(); |
506 | 529 |
507 EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); | 530 EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); |
508 SetOmniboxTextAndWaitForInstantToShow("query suggest"); | 531 SetOmniboxTextAndWaitForInstantToShow("query suggest"); |
509 EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); | 532 EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); |
510 } | 533 } |
511 | 534 |
512 // Test that Instant doesn't process URLs. | 535 // Test that Instant doesn't process URLs. |
513 IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { | 536 IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { |
514 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 537 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
515 FocusOmniboxAndWaitForInstantSupport(); | 538 FocusOmniboxAndWaitForInstantSupport(); |
516 | 539 |
517 // Note that we are not actually navigating to these URLs yet. We are just | 540 // Note that we are not actually navigating to these URLs yet. We are just |
518 // typing them into the omnibox (without pressing Enter) and checking that | 541 // typing them into the omnibox (without pressing Enter) and checking that |
519 // Instant doesn't try to process them. | 542 // Instant doesn't try to process them. |
520 SetOmniboxText(chrome::kChromeUICrashURL); | 543 SetOmniboxText(chrome::kChromeUICrashURL); |
521 EXPECT_FALSE(instant()->IsCurrent()); | 544 EXPECT_FALSE(instant()->IsCurrent()); |
522 EXPECT_FALSE(instant()->model()->is_ready()); | 545 EXPECT_FALSE(instant()->model()->is_ready()); |
523 | 546 |
524 SetOmniboxText(chrome::kChromeUIHangURL); | 547 SetOmniboxText(chrome::kChromeUIHangURL); |
525 EXPECT_FALSE(instant()->IsCurrent()); | 548 EXPECT_FALSE(instant()->IsCurrent()); |
526 EXPECT_FALSE(instant()->model()->is_ready()); | 549 EXPECT_FALSE(instant()->model()->is_ready()); |
527 | 550 |
528 SetOmniboxText(chrome::kChromeUIKillURL); | 551 SetOmniboxText(chrome::kChromeUIKillURL); |
529 EXPECT_FALSE(instant()->IsCurrent()); | 552 EXPECT_FALSE(instant()->IsCurrent()); |
530 EXPECT_FALSE(instant()->model()->is_ready()); | 553 EXPECT_FALSE(instant()->model()->is_ready()); |
531 | 554 |
532 // Make sure that the URLs were never sent to the preview page. | 555 // Make sure that the URLs were never sent to the preview page. |
533 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 556 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
534 EXPECT_EQ(0, onchangecalls_); | 557 EXPECT_EQ(0, onchangecalls_); |
535 EXPECT_EQ("", value_); | 558 EXPECT_EQ("", value_); |
536 } | 559 } |
537 | 560 |
538 // Test that Instant doesn't fire for intranet paths that look like searches. | 561 // Test that Instant doesn't fire for intranet paths that look like searches. |
539 // http://crbug.com/99836 | 562 // http://crbug.com/99836 |
540 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { | 563 IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { |
541 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 564 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
542 | 565 |
543 // Navigate to a URL that looks like a search (when the scheme is stripped). | 566 // Navigate to a URL that looks like a search (when the scheme is stripped). |
544 // It's okay if the host is bogus or the navigation fails, since we only care | 567 // It's okay if the host is bogus or the navigation fails, since we only care |
545 // that Instant doesn't act on it. | 568 // that Instant doesn't act on it. |
546 ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); | 569 ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); |
547 EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); | 570 EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); |
548 EXPECT_FALSE(instant()->GetPreviewContents()); | 571 EXPECT_FALSE(instant()->GetPreviewContents()); |
549 } | 572 } |
550 | 573 |
551 // Test that transitions between searches and non-searches work as expected. | 574 // Test that transitions between searches and non-searches work as expected. |
552 IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { | 575 IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { |
553 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 576 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
554 FocusOmniboxAndWaitForInstantSupport(); | 577 FocusOmniboxAndWaitForInstantSupport(); |
555 | 578 |
556 // Type a search, and immediately a URL, without waiting for Instant to show. | 579 // Type a search, and immediately a URL, without waiting for Instant to show. |
557 SetOmniboxText("query"); | 580 SetOmniboxText("query"); |
558 SetOmniboxText("http://monstrous/nightmare"); | 581 SetOmniboxText("http://monstrous/nightmare"); |
559 | 582 |
560 // The page is told about the search. Though the page isn't told about the | 583 // The page is told about the search. Though the page isn't told about the |
561 // subsequent URL, it invalidates the search, so a blank query is sent in its | 584 // subsequent URL, it invalidates the search, so a blank query is sent in its |
562 // place to indicate that the search is "out of date". | 585 // place to indicate that the search is "out of date". |
563 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 586 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
(...skipping 30 matching lines...) Expand all Loading... |
594 omnibox()->RevertAll(); | 617 omnibox()->RevertAll(); |
595 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); | 618 EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); |
596 EXPECT_FALSE(instant()->IsCurrent()); | 619 EXPECT_FALSE(instant()->IsCurrent()); |
597 EXPECT_FALSE(instant()->model()->is_ready()); | 620 EXPECT_FALSE(instant()->model()->is_ready()); |
598 EXPECT_EQ(6, onchangecalls_); | 621 EXPECT_EQ(6, onchangecalls_); |
599 EXPECT_EQ("", value_); | 622 EXPECT_EQ("", value_); |
600 } | 623 } |
601 | 624 |
602 // Test that Instant can't be fooled into committing a URL. | 625 // Test that Instant can't be fooled into committing a URL. |
603 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { | 626 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { |
604 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 627 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
605 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 628 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
606 | 629 |
607 // Type a URL. The Instant preview shouldn't be showing. | 630 // Type a URL. The Instant preview shouldn't be showing. |
608 SetOmniboxText("http://deadly/nadder"); | 631 SetOmniboxText("http://deadly/nadder"); |
609 EXPECT_FALSE(instant()->IsCurrent()); | 632 EXPECT_FALSE(instant()->IsCurrent()); |
610 EXPECT_FALSE(instant()->model()->is_ready()); | 633 EXPECT_FALSE(instant()->model()->is_ready()); |
611 | 634 |
612 // Unfocus and refocus the omnibox. | 635 // Unfocus and refocus the omnibox. |
613 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 636 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
614 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 637 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
(...skipping 14 matching lines...) Expand all Loading... |
629 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); | 652 EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); |
630 | 653 |
631 // Instant shouldn't have done anything. | 654 // Instant shouldn't have done anything. |
632 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 655 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
633 EXPECT_FALSE(instant()->IsCurrent()); | 656 EXPECT_FALSE(instant()->IsCurrent()); |
634 EXPECT_FALSE(instant()->model()->is_ready()); | 657 EXPECT_FALSE(instant()->model()->is_ready()); |
635 } | 658 } |
636 | 659 |
637 // Test that Instant can't be fooled into committing a URL. | 660 // Test that Instant can't be fooled into committing a URL. |
638 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { | 661 IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { |
639 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 662 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
640 FocusOmniboxAndWaitForInstantSupport(); | 663 FocusOmniboxAndWaitForInstantSupport(); |
641 | 664 |
642 // Type a query. This causes the preview to be shown. | 665 // Type a query. This causes the preview to be shown. |
643 SetOmniboxTextAndWaitForInstantToShow("query"); | 666 SetOmniboxTextAndWaitForInstantToShow("query"); |
644 | 667 |
645 TabContents* preview_tab = instant()->GetPreviewContents(); | 668 TabContents* preview_tab = instant()->GetPreviewContents(); |
646 EXPECT_TRUE(preview_tab); | 669 EXPECT_TRUE(preview_tab); |
647 | 670 |
648 // Type a URL. This causes the preview to be hidden. | 671 // Type a URL. This causes the preview to be hidden. |
649 SetOmniboxText("http://hideous/zippleback"); | 672 SetOmniboxText("http://hideous/zippleback"); |
(...skipping 11 matching lines...) Expand all Loading... |
661 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); | 684 EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); |
662 | 685 |
663 // As before, Instant shouldn't have done anything. | 686 // As before, Instant shouldn't have done anything. |
664 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); | 687 EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); |
665 EXPECT_FALSE(instant()->IsCurrent()); | 688 EXPECT_FALSE(instant()->IsCurrent()); |
666 EXPECT_FALSE(instant()->model()->is_ready()); | 689 EXPECT_FALSE(instant()->model()->is_ready()); |
667 } | 690 } |
668 | 691 |
669 // Test that a non-Instant search provider shows no previews. | 692 // Test that a non-Instant search provider shows no previews. |
670 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { | 693 IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { |
671 ASSERT_NO_FATAL_FAILURE(SetupInstant("empty.html")); | 694 instant_url_ = test_server()->GetURL("files/empty.html"); |
| 695 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
672 | 696 |
673 // Focus the omnibox. When the support determination response comes back, | 697 // Focus the omnibox. When the support determination response comes back, |
674 // Instant will destroy the non-Instant page. | 698 // Instant will destroy the non-Instant page. |
675 FocusOmniboxAndWaitForInstantSupport(); | 699 FocusOmniboxAndWaitForInstantSupport(); |
676 EXPECT_FALSE(instant()->GetPreviewContents()); | 700 EXPECT_FALSE(instant()->GetPreviewContents()); |
677 } | 701 } |
678 | 702 |
679 // Test that the renderer doesn't crash if JavaScript is blocked. | 703 // Test that the renderer doesn't crash if JavaScript is blocked. |
680 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { | 704 IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { |
681 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 705 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
682 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 706 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
683 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 707 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
684 | 708 |
685 // Wait for notification that the Instant API has been determined. As long as | 709 // Wait for notification that the Instant API has been determined. As long as |
686 // we get the notification we're good (the renderer didn't crash). | 710 // we get the notification we're good (the renderer didn't crash). |
687 FocusOmniboxAndWaitForInstantSupport(); | 711 FocusOmniboxAndWaitForInstantSupport(); |
688 } | 712 } |
689 | 713 |
690 // Test that the preview and active tab's visibility states are set correctly. | 714 // Test that the preview and active tab's visibility states are set correctly. |
691 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { | 715 IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { |
692 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 716 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
693 FocusOmniboxAndWaitForInstantSupport(); | 717 FocusOmniboxAndWaitForInstantSupport(); |
694 | 718 |
695 TabContents* active_tab = chrome::GetActiveTabContents(browser()); | 719 TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
696 TabContents* preview_tab = instant()->GetPreviewContents(); | 720 TabContents* preview_tab = instant()->GetPreviewContents(); |
697 | 721 |
698 // Inititally, the active tab is showing; the preview is not. | 722 // Inititally, the active tab is showing; the preview is not. |
699 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); | 723 EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); |
700 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); | 724 EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); |
701 | 725 |
702 // Type a query and wait for Instant to show. | 726 // Type a query and wait for Instant to show. |
(...skipping 26 matching lines...) Expand all Loading... |
729 | 753 |
730 string16 prefix = l10n_util::GetStringFUTF16( | 754 string16 prefix = l10n_util::GetStringFUTF16( |
731 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 755 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
732 | 756 |
733 // There should be no Instant preview yet. | 757 // There should be no Instant preview yet. |
734 for (int i = 0; i < task_manager->ResourceCount(); ++i) { | 758 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
735 string16 title = task_manager->GetResourceTitle(i); | 759 string16 title = task_manager->GetResourceTitle(i); |
736 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 760 EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
737 } | 761 } |
738 | 762 |
739 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 763 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
740 FocusOmnibox(); | 764 FocusOmnibox(); |
741 | 765 |
742 // Now there should be two renderers, the second being the Instant preview. | 766 // Now there should be two renderers, the second being the Instant preview. |
743 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 767 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
744 | 768 |
745 int instant_previews = 0; | 769 int instant_previews = 0; |
746 for (int i = 0; i < task_manager->ResourceCount(); ++i) { | 770 for (int i = 0; i < task_manager->ResourceCount(); ++i) { |
747 string16 title = task_manager->GetResourceTitle(i); | 771 string16 title = task_manager->GetResourceTitle(i); |
748 if (StartsWith(title, prefix, true)) | 772 if (StartsWith(title, prefix, true)) |
749 ++instant_previews; | 773 ++instant_previews; |
(...skipping 15 matching lines...) Expand all Loading... |
765 std::vector<string16>* result, | 789 std::vector<string16>* result, |
766 HistoryService::Handle /* handle */, | 790 HistoryService::Handle /* handle */, |
767 std::vector<history::KeywordSearchTermVisit>* terms) { | 791 std::vector<history::KeywordSearchTermVisit>* terms) { |
768 for (size_t i = 0; i < terms->size(); ++i) | 792 for (size_t i = 0; i < terms->size(); ++i) |
769 result->push_back((*terms)[i].term); | 793 result->push_back((*terms)[i].term); |
770 run_loop->Quit(); | 794 run_loop->Quit(); |
771 } | 795 } |
772 | 796 |
773 // Test that the Instant page load is not added to history. | 797 // Test that the Instant page load is not added to history. |
774 IN_PROC_BROWSER_TEST_F(InstantTest, History) { | 798 IN_PROC_BROWSER_TEST_F(InstantTest, History) { |
775 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 799 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
776 FocusOmniboxAndWaitForInstantSupport(); | 800 FocusOmniboxAndWaitForInstantSupport(); |
777 | 801 |
778 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( | 802 const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
779 browser()->profile())->GetDefaultSearchProvider(); | 803 browser()->profile())->GetDefaultSearchProvider(); |
780 | 804 |
781 // |instant_url| is the URL Instant loads. |search_url| is the fake URL we | 805 // |instant_url| is the URL Instant loads. |search_url| is the fake URL we |
782 // enter into history for search terms extraction to work correctly. | 806 // enter into history for search terms extraction to work correctly. |
783 std::string search_url = template_url->url_ref().ReplaceSearchTerms( | 807 std::string search_url = template_url->url_ref().ReplaceSearchTerms( |
784 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); | 808 TemplateURLRef::SearchTermsArgs(ASCIIToUTF16("search"))); |
785 std::string instant_url = template_url->instant_url_ref().ReplaceSearchTerms( | |
786 TemplateURLRef::SearchTermsArgs(string16())); | |
787 | 809 |
788 HistoryService* history = HistoryServiceFactory::GetForProfile( | 810 HistoryService* history = HistoryServiceFactory::GetForProfile( |
789 browser()->profile(), Profile::EXPLICIT_ACCESS); | 811 browser()->profile(), Profile::EXPLICIT_ACCESS); |
790 ui_test_utils::WaitForHistoryToLoad(history); | 812 ui_test_utils::WaitForHistoryToLoad(history); |
791 | 813 |
792 // Perform a search. | 814 // Perform a search. |
793 SetOmniboxTextAndWaitForInstantToShow("search"); | 815 SetOmniboxTextAndWaitForInstantToShow("search"); |
794 EXPECT_EQ(instant_url, instant()->loader()->instant_url()); | 816 EXPECT_EQ(instant_url_.spec(), instant()->loader()->instant_url()); |
795 | 817 |
796 // Commit the search. | 818 // Commit the search. |
797 browser()->window()->GetLocationBar()->AcceptInput(); | 819 browser()->window()->GetLocationBar()->AcceptInput(); |
798 | 820 |
799 bool found = false; | 821 bool found = false; |
800 CancelableRequestConsumer consumer; | 822 CancelableRequestConsumer consumer; |
801 | 823 |
802 // The fake search URL should be in history. | 824 // The fake search URL should be in history. |
803 base::RunLoop run_loop1; | 825 base::RunLoop run_loop1; |
804 history->QueryURL(GURL(search_url), false, &consumer, | 826 history->QueryURL(GURL(search_url), false, &consumer, |
805 base::Bind(&HistoryQueryDone, &run_loop1, &found)); | 827 base::Bind(&HistoryQueryDone, &run_loop1, &found)); |
806 run_loop1.Run(); | 828 run_loop1.Run(); |
807 EXPECT_TRUE(found); | 829 EXPECT_TRUE(found); |
808 | 830 |
809 // The Instant URL should not be in history. | 831 // The Instant URL should not be in history. |
810 base::RunLoop run_loop2; | 832 base::RunLoop run_loop2; |
811 history->QueryURL(GURL(instant_url), false, &consumer, | 833 history->QueryURL(instant_url_, false, &consumer, |
812 base::Bind(&HistoryQueryDone, &run_loop2, &found)); | 834 base::Bind(&HistoryQueryDone, &run_loop2, &found)); |
813 run_loop2.Run(); | 835 run_loop2.Run(); |
814 EXPECT_FALSE(found); | 836 EXPECT_FALSE(found); |
815 | 837 |
816 // The search terms should have been extracted into history. | 838 // The search terms should have been extracted into history. |
817 base::RunLoop run_loop3; | 839 base::RunLoop run_loop3; |
818 std::vector<string16> queries; | 840 std::vector<string16> queries; |
819 history->GetMostRecentKeywordSearchTerms(template_url->id(), | 841 history->GetMostRecentKeywordSearchTerms(template_url->id(), |
820 ASCIIToUTF16("s"), 1, &consumer, | 842 ASCIIToUTF16("s"), 1, &consumer, |
821 base::Bind(&KeywordQueryDone, &run_loop3, &queries)); | 843 base::Bind(&KeywordQueryDone, &run_loop3, &queries)); |
822 run_loop3.Run(); | 844 run_loop3.Run(); |
823 ASSERT_TRUE(queries.size()); | 845 ASSERT_TRUE(queries.size()); |
824 EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); | 846 EXPECT_EQ(ASCIIToUTF16("search"), queries[0]); |
825 } | 847 } |
826 | 848 |
827 // Test that creating a new window hides any currently showing Instant preview. | 849 // Test that creating a new window hides any currently showing Instant preview. |
828 IN_PROC_BROWSER_TEST_F(InstantTest, NewWindowDismissesInstant) { | 850 IN_PROC_BROWSER_TEST_F(InstantTest, NewWindowDismissesInstant) { |
829 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 851 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
830 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 852 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 853 FocusOmniboxAndWaitForInstantSupport(); |
831 SetOmniboxTextAndWaitForInstantToShow("search"); | 854 SetOmniboxTextAndWaitForInstantToShow("search"); |
832 | 855 |
833 Browser* previous_window = browser(); | 856 Browser* previous_window = browser(); |
834 EXPECT_TRUE(instant()->IsCurrent()); | 857 EXPECT_TRUE(instant()->IsCurrent()); |
835 EXPECT_TRUE(instant()->model()->is_ready()); | 858 EXPECT_TRUE(instant()->model()->is_ready()); |
836 | 859 |
837 InstantTestModelObserver observer(instant()->model()); | 860 InstantTestModelObserver observer(instant()->model()); |
838 chrome::NewEmptyWindow(browser()->profile()); | 861 chrome::NewEmptyWindow(browser()->profile()); |
839 observer.WaitUntilDisplayStateChanged(); | 862 observer.WaitUntilDisplayStateChanged(); |
840 | 863 |
841 // Even though we just created a new Browser object (for the new window), the | 864 // Even though we just created a new Browser object (for the new window), the |
842 // browser() accessor should still give us the first window's Browser object. | 865 // browser() accessor should still give us the first window's Browser object. |
843 EXPECT_EQ(previous_window, browser()); | 866 EXPECT_EQ(previous_window, browser()); |
844 EXPECT_FALSE(instant()->IsCurrent()); | 867 EXPECT_FALSE(instant()->IsCurrent()); |
845 EXPECT_FALSE(instant()->model()->is_ready()); | 868 EXPECT_FALSE(instant()->model()->is_ready()); |
846 } | 869 } |
847 | 870 |
848 // Test that: | 871 // Test that: |
849 // - Instant loader is recreated on OnStaleLoader call when it is hidden. | 872 // - Instant loader is recreated on OnStaleLoader call when it is hidden. |
850 // - Instant loader is not recreated on OnStaleLoader call when it is visible. | 873 // - Instant loader is not recreated on OnStaleLoader call when it is visible. |
851 // - Instant loader is recreated when omnibox loses focus after the timer stops. | 874 // - Instant loader is recreated when omnibox loses focus after the timer stops. |
852 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { | 875 IN_PROC_BROWSER_TEST_F(InstantTest, InstantLoaderRefresh) { |
853 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 876 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
854 FocusOmniboxAndWaitForInstantSupport(); | 877 FocusOmniboxAndWaitForInstantSupport(); |
855 | 878 |
856 // Instant is not showing, so OnstaleLoader() should recreate the preview. | 879 // Instant is not showing, so OnstaleLoader() should recreate the preview. |
857 EXPECT_TRUE(instant()->loader()->supports_instant()); | 880 EXPECT_TRUE(instant()->loader()->supports_instant()); |
858 instant()->OnStaleLoader(); | 881 instant()->OnStaleLoader(); |
859 EXPECT_FALSE(instant()->loader()->supports_instant()); | 882 EXPECT_FALSE(instant()->loader()->supports_instant()); |
860 | 883 |
861 // Show Instant. | 884 // Show Instant. |
862 SetOmniboxTextAndWaitForInstantToShow("query"); | 885 SetOmniboxTextAndWaitForInstantToShow("query"); |
863 | 886 |
864 // Instant is showing, so OnStaleLoader() shouldn't kill the preview. | 887 // Instant is showing, so OnStaleLoader() shouldn't kill the preview. |
865 instant()->stale_loader_timer_.Stop(); | 888 instant()->stale_loader_timer_.Stop(); |
866 instant()->OnStaleLoader(); | 889 instant()->OnStaleLoader(); |
867 EXPECT_TRUE(instant()->model()->is_ready()); | 890 EXPECT_TRUE(instant()->model()->is_ready()); |
868 | 891 |
869 // The preview should be recreated once the omnibox loses focus. | 892 // The preview should be recreated once the omnibox loses focus. |
870 EXPECT_TRUE(instant()->loader()->supports_instant()); | 893 EXPECT_TRUE(instant()->loader()->supports_instant()); |
871 instant()->OnAutocompleteLostFocus(NULL); | 894 instant()->OnAutocompleteLostFocus(NULL); |
872 EXPECT_FALSE(instant()->loader()->supports_instant()); | 895 EXPECT_FALSE(instant()->loader()->supports_instant()); |
873 } | 896 } |
874 | 897 |
875 // Test that suggestions are case insensitive. http://crbug.com/150728 | 898 // Test that suggestions are case insensitive. http://crbug.com/150728 |
876 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { | 899 IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { |
877 ASSERT_NO_FATAL_FAILURE(SetupInstant("instant.html")); | 900 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
878 FocusOmniboxAndWaitForInstantSupport(); | 901 FocusOmniboxAndWaitForInstantSupport(); |
879 | 902 |
880 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); | 903 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); |
881 | 904 |
882 SetOmniboxTextAndWaitForInstantToShow("in"); | 905 SetOmniboxTextAndWaitForInstantToShow("in"); |
883 EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText()); | 906 EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText()); |
884 | 907 |
885 instant()->Hide(); | 908 instant()->Hide(); |
886 SetOmniboxTextAndWaitForInstantToShow("IN"); | 909 SetOmniboxTextAndWaitForInstantToShow("IN"); |
887 EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText()); | 910 EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 // Check that a d with a dot above and below it is completed regardless of | 943 // Check that a d with a dot above and below it is completed regardless of |
921 // how that is encoded. | 944 // how that is encoded. |
922 // U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW | 945 // U+1E0D = LATIN SMALL LETTER D WITH DOT BELOW |
923 // U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE | 946 // U+1E0B = LATIN SMALL LETTER D WITH DOT ABOVE |
924 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]")); | 947 EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]")); |
925 | 948 |
926 instant()->Hide(); | 949 instant()->Hide(); |
927 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u1e0b\u0323")); | 950 SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u1e0b\u0323")); |
928 EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); | 951 EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); |
929 } | 952 } |
| 953 |
| 954 // Test that the preview can be committed onto a new tab. |
| 955 IN_PROC_BROWSER_TEST_F(InstantTest, CommitInNewTab) { |
| 956 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 957 |
| 958 // Use the Instant page as the active tab, so we can exploit its visibility |
| 959 // handler to check visibility transitions. |
| 960 ui_test_utils::NavigateToURL(browser(), instant_url_); |
| 961 TabContents* active_tab = chrome::GetActiveTabContents(browser()); |
| 962 |
| 963 int active_tab_onvisibilitycalls = -1; |
| 964 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), |
| 965 "onvisibilitycalls", &active_tab_onvisibilitycalls)); |
| 966 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 967 |
| 968 FocusOmniboxAndWaitForInstantSupport(); |
| 969 SetOmniboxTextAndWaitForInstantToShow("search"); |
| 970 |
| 971 // Stash a reference to the preview, so we can refer to it after commit. |
| 972 TabContents* preview_tab = instant()->GetPreviewContents(); |
| 973 EXPECT_TRUE(preview_tab); |
| 974 |
| 975 // The state of the searchbox before the commit. |
| 976 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
| 977 EXPECT_EQ("search", value_); |
| 978 EXPECT_FALSE(verbatim_); |
| 979 EXPECT_EQ(0, onsubmitcalls_); |
| 980 EXPECT_EQ(1, onvisibilitycalls_); |
| 981 |
| 982 // The state of the active tab before the commit. |
| 983 EXPECT_NE(preview_tab, active_tab); |
| 984 EXPECT_EQ(2, active_tab->web_contents()->GetController().GetEntryCount()); |
| 985 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
| 986 active_tab_onvisibilitycalls = -1; |
| 987 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), |
| 988 "onvisibilitycalls", &active_tab_onvisibilitycalls)); |
| 989 EXPECT_EQ(0, active_tab_onvisibilitycalls); |
| 990 |
| 991 // Commit the search by pressing Alt-Enter. |
| 992 omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); |
| 993 |
| 994 // After the commit, Instant should not be showing. |
| 995 EXPECT_FALSE(instant()->IsCurrent()); |
| 996 EXPECT_FALSE(instant()->model()->is_ready()); |
| 997 |
| 998 // The old loader is deleted and a new one is created. |
| 999 EXPECT_TRUE(instant()->GetPreviewContents()); |
| 1000 EXPECT_NE(instant()->GetPreviewContents(), preview_tab); |
| 1001 |
| 1002 // Check that we have two tabs and that the new active tab is indeed what was |
| 1003 // once the preview. The preview tab should have just one navigation entry, |
| 1004 // for the Instant search that was committed. |
| 1005 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 1006 EXPECT_EQ(preview_tab, chrome::GetActiveTabContents(browser())); |
| 1007 EXPECT_EQ(1, preview_tab->web_contents()->GetController().GetEntryCount()); |
| 1008 |
| 1009 // Check that the omnibox contains the Instant URL we loaded. |
| 1010 EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); |
| 1011 |
| 1012 // Check that the searchbox API values have been reset. |
| 1013 std::string value; |
| 1014 EXPECT_TRUE(GetStringFromJS(preview_tab->web_contents()->GetRenderViewHost(), |
| 1015 "chrome.searchBox.value", &value)); |
| 1016 EXPECT_EQ("", value); |
| 1017 |
| 1018 // However, the page should've correctly received the committed query. |
| 1019 EXPECT_TRUE(UpdateSearchState(preview_tab)); |
| 1020 EXPECT_EQ("search", value_); |
| 1021 EXPECT_TRUE(verbatim_); |
| 1022 EXPECT_EQ(1, onsubmitcalls_); |
| 1023 EXPECT_EQ(1, onvisibilitycalls_); |
| 1024 |
| 1025 // The ex-active tab should've gotten a visibility change marking it hidden. |
| 1026 EXPECT_NE(active_tab, preview_tab); |
| 1027 EXPECT_TRUE(GetIntFromJS(active_tab->web_contents()->GetRenderViewHost(), |
| 1028 "onvisibilitycalls", &active_tab_onvisibilitycalls)); |
| 1029 EXPECT_EQ(1, active_tab_onvisibilitycalls); |
| 1030 } |
OLD | NEW |