OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/instant/instant_commit_type.h" | 5 #include "chrome/browser/instant/instant_commit_type.h" |
6 #include "chrome/browser/instant/instant_ntp.h" | 6 #include "chrome/browser/instant/instant_ntp.h" |
7 #include "chrome/browser/instant/instant_overlay.h" | 7 #include "chrome/browser/instant/instant_overlay.h" |
8 #include "chrome/browser/instant/instant_service.h" | 8 #include "chrome/browser/instant/instant_service.h" |
9 #include "chrome/browser/instant/instant_service_factory.h" | 9 #include "chrome/browser/instant/instant_service_factory.h" |
10 #include "chrome/browser/instant/instant_test_utils.h" | 10 #include "chrome/browser/instant/instant_test_utils.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 omnibox()->model()->OnUpOrDownKeyPressed(1); | 47 omnibox()->model()->OnUpOrDownKeyPressed(1); |
48 // Wait for JavaScript to run the key handler by executing a blank script. | 48 // Wait for JavaScript to run the key handler by executing a blank script. |
49 EXPECT_TRUE(ExecuteScript(std::string())); | 49 EXPECT_TRUE(ExecuteScript(std::string())); |
50 } | 50 } |
51 | 51 |
52 void SendUpArrow() { | 52 void SendUpArrow() { |
53 omnibox()->model()->OnUpOrDownKeyPressed(-1); | 53 omnibox()->model()->OnUpOrDownKeyPressed(-1); |
54 // Wait for JavaScript to run the key handler by executing a blank script. | 54 // Wait for JavaScript to run the key handler by executing a blank script. |
55 EXPECT_TRUE(ExecuteScript(std::string())); | 55 EXPECT_TRUE(ExecuteScript(std::string())); |
56 } | 56 } |
| 57 |
| 58 void SendEscape() { |
| 59 omnibox()->model()->OnEscapeKeyPressed(); |
| 60 // Wait for JavaScript to run the key handler by executing a blank script. |
| 61 EXPECT_TRUE(ExecuteScript(std::string())); |
| 62 } |
57 }; | 63 }; |
58 | 64 |
59 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { | 65 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { |
60 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 66 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
61 EXPECT_TRUE(instant()->extended_enabled_); | 67 EXPECT_TRUE(instant()->extended_enabled_); |
62 } | 68 } |
63 | 69 |
64 // Test that Instant is preloaded when the omnibox is focused. | 70 // Test that Instant is preloaded when the omnibox is focused. |
65 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { | 71 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
66 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 72 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 EXPECT_EQ("hello", GetOmniboxText()); | 187 EXPECT_EQ("hello", GetOmniboxText()); |
182 | 188 |
183 SendDownArrow(); | 189 SendDownArrow(); |
184 EXPECT_EQ("result 1", GetOmniboxText()); | 190 EXPECT_EQ("result 1", GetOmniboxText()); |
185 SendDownArrow(); | 191 SendDownArrow(); |
186 EXPECT_EQ("result 2", GetOmniboxText()); | 192 EXPECT_EQ("result 2", GetOmniboxText()); |
187 SendUpArrow(); | 193 SendUpArrow(); |
188 EXPECT_EQ("result 1", GetOmniboxText()); | 194 EXPECT_EQ("result 1", GetOmniboxText()); |
189 SendUpArrow(); | 195 SendUpArrow(); |
190 EXPECT_EQ("hello", GetOmniboxText()); | 196 EXPECT_EQ("hello", GetOmniboxText()); |
| 197 |
| 198 // Ensure that the API's value is set correctly. |
| 199 std::string result; |
| 200 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), |
| 201 "window.chrome.searchBox.value", |
| 202 &result)); |
| 203 EXPECT_EQ("hello", result); |
| 204 |
| 205 EXPECT_TRUE(HasUserInputInProgress()); |
| 206 // TODO(beaudoin): Figure out why this fails. |
| 207 // EXPECT_FALSE(HasTemporaryText()); |
| 208 |
| 209 // Commit the search by pressing Enter. |
| 210 browser()->window()->GetLocationBar()->AcceptInput(); |
| 211 EXPECT_EQ("hello", GetOmniboxText()); |
| 212 } |
| 213 |
| 214 // This test simulates a search provider using the InstantExtended API to |
| 215 // navigate through the suggested results and hitting escape to get back to the |
| 216 // original user query. |
| 217 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { |
| 218 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 219 FocusOmniboxAndWaitForInstantSupport(); |
| 220 |
| 221 SetOmniboxTextAndWaitForInstantToShow("hello"); |
| 222 EXPECT_EQ("hello", GetOmniboxText()); |
| 223 |
| 224 SendDownArrow(); |
| 225 EXPECT_EQ("result 1", GetOmniboxText()); |
| 226 SendDownArrow(); |
| 227 EXPECT_EQ("result 2", GetOmniboxText()); |
| 228 SendEscape(); |
| 229 EXPECT_EQ("hello", GetOmniboxText()); |
| 230 |
| 231 // Ensure that the API's value is set correctly. |
| 232 std::string result; |
| 233 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), |
| 234 "window.chrome.searchBox.value", |
| 235 &result)); |
| 236 EXPECT_EQ("hello", result); |
| 237 |
| 238 EXPECT_TRUE(HasUserInputInProgress()); |
| 239 EXPECT_FALSE(HasTemporaryText()); |
| 240 |
| 241 // Commit the search by pressing Enter. |
| 242 browser()->window()->GetLocationBar()->AcceptInput(); |
| 243 EXPECT_EQ("hello", GetOmniboxText()); |
191 } | 244 } |
192 | 245 |
193 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { | 246 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { |
194 // Setup Instant. | 247 // Setup Instant. |
195 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 248 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
196 FocusOmniboxAndWaitForInstantSupport(); | 249 FocusOmniboxAndWaitForInstantSupport(); |
197 | 250 |
198 // NTP contents should be preloaded. | 251 // NTP contents should be preloaded. |
199 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 252 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
200 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 253 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 content::WebContents* active_tab = | 387 content::WebContents* active_tab = |
335 browser()->tab_strip_model()->GetActiveWebContents(); | 388 browser()->tab_strip_model()->GetActiveWebContents(); |
336 EXPECT_TRUE(instant_service->IsInstantProcess( | 389 EXPECT_TRUE(instant_service->IsInstantProcess( |
337 active_tab->GetRenderProcessHost()->GetID())); | 390 active_tab->GetRenderProcessHost()->GetID())); |
338 | 391 |
339 // Navigating elsewhere should not use the Instant render process. | 392 // Navigating elsewhere should not use the Instant render process. |
340 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 393 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
341 EXPECT_FALSE(instant_service->IsInstantProcess( | 394 EXPECT_FALSE(instant_service->IsInstantProcess( |
342 active_tab->GetRenderProcessHost()->GetID())); | 395 active_tab->GetRenderProcessHost()->GetID())); |
343 } | 396 } |
OLD | NEW |