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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 EXPECT_EQ("hello", GetOmniboxText()); | 195 EXPECT_EQ("hello", GetOmniboxText()); |
190 | 196 |
191 SendDownArrow(); | 197 SendDownArrow(); |
192 EXPECT_EQ("result 1", GetOmniboxText()); | 198 EXPECT_EQ("result 1", GetOmniboxText()); |
193 SendDownArrow(); | 199 SendDownArrow(); |
194 EXPECT_EQ("result 2", GetOmniboxText()); | 200 EXPECT_EQ("result 2", GetOmniboxText()); |
195 SendUpArrow(); | 201 SendUpArrow(); |
196 EXPECT_EQ("result 1", GetOmniboxText()); | 202 EXPECT_EQ("result 1", GetOmniboxText()); |
197 SendUpArrow(); | 203 SendUpArrow(); |
198 EXPECT_EQ("hello", GetOmniboxText()); | 204 EXPECT_EQ("hello", GetOmniboxText()); |
| 205 |
| 206 // Ensure that the API's value is set correctly. |
| 207 std::string result; |
| 208 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), |
| 209 "window.chrome.searchBox.value", |
| 210 &result)); |
| 211 EXPECT_EQ("hello", result); |
| 212 |
| 213 EXPECT_TRUE(HasUserInputInProgress()); |
| 214 // TODO(beaudoin): Figure out why this fails. |
| 215 // EXPECT_FALSE(HasTemporaryText()); |
| 216 |
| 217 |
| 218 // Commit the search by pressing Enter. |
| 219 // TODO(sreeram): Enable this check once @mathp's CL lands: |
| 220 // https://codereview.chromium.org/12179025/ |
| 221 // browser()->window()->GetLocationBar()->AcceptInput(); |
| 222 // EXPECT_EQ("hello", GetOmniboxText()); |
| 223 } |
| 224 |
| 225 // This test simulates a search provider using the InstantExtended API to |
| 226 // navigate through the suggested results and hitting escape to get back to the |
| 227 // original user query. |
| 228 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { |
| 229 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
| 230 FocusOmniboxAndWaitForInstantSupport(); |
| 231 |
| 232 SetOmniboxTextAndWaitForInstantToShow("hello"); |
| 233 EXPECT_EQ("hello", GetOmniboxText()); |
| 234 |
| 235 SendDownArrow(); |
| 236 EXPECT_EQ("result 1", GetOmniboxText()); |
| 237 SendDownArrow(); |
| 238 EXPECT_EQ("result 2", GetOmniboxText()); |
| 239 SendEscape(); |
| 240 EXPECT_EQ("hello", GetOmniboxText()); |
| 241 |
| 242 // Ensure that the API's value is set correctly. |
| 243 std::string result; |
| 244 EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), |
| 245 "window.chrome.searchBox.value", |
| 246 &result)); |
| 247 EXPECT_EQ("hello", result); |
| 248 |
| 249 EXPECT_TRUE(HasUserInputInProgress()); |
| 250 EXPECT_FALSE(HasTemporaryText()); |
| 251 |
| 252 // Commit the search by pressing Enter. |
| 253 // TODO(sreeram): Enable this check once @mathp's CL lands: |
| 254 // https://codereview.chromium.org/12179025/ |
| 255 // browser()->window()->GetLocationBar()->AcceptInput(); |
| 256 // EXPECT_EQ("hello", GetOmniboxText()); |
199 } | 257 } |
200 | 258 |
201 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { | 259 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { |
202 // Setup Instant. | 260 // Setup Instant. |
203 ASSERT_NO_FATAL_FAILURE(SetupInstant()); | 261 ASSERT_NO_FATAL_FAILURE(SetupInstant()); |
204 FocusOmniboxAndWaitForInstantSupport(); | 262 FocusOmniboxAndWaitForInstantSupport(); |
205 | 263 |
206 // NTP contents should be preloaded. | 264 // NTP contents should be preloaded. |
207 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); | 265 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); |
208 content::WebContents* ntp_contents = instant()->ntp_->contents(); | 266 content::WebContents* ntp_contents = instant()->ntp_->contents(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 content::WebContents* active_tab = | 403 content::WebContents* active_tab = |
346 browser()->tab_strip_model()->GetActiveWebContents(); | 404 browser()->tab_strip_model()->GetActiveWebContents(); |
347 EXPECT_TRUE(instant_service->IsInstantProcess( | 405 EXPECT_TRUE(instant_service->IsInstantProcess( |
348 active_tab->GetRenderProcessHost()->GetID())); | 406 active_tab->GetRenderProcessHost()->GetID())); |
349 | 407 |
350 // Navigating elsewhere should not use the Instant render process. | 408 // Navigating elsewhere should not use the Instant render process. |
351 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); | 409 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
352 EXPECT_FALSE(instant_service->IsInstantProcess( | 410 EXPECT_FALSE(instant_service->IsInstantProcess( |
353 active_tab->GetRenderProcessHost()->GetID())); | 411 active_tab->GetRenderProcessHost()->GetID())); |
354 } | 412 } |
OLD | NEW |