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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 GetIntFromJS(contents, "mostVisitedItemsCount", | 111 GetIntFromJS(contents, "mostVisitedItemsCount", |
112 &most_visited_items_count_) && | 112 &most_visited_items_count_) && |
113 GetIntFromJS(contents, "firstMostVisitedItemId", | 113 GetIntFromJS(contents, "firstMostVisitedItemId", |
114 &first_most_visited_item_id_) && | 114 &first_most_visited_item_id_) && |
115 GetIntFromJS(contents, "onNativeSuggestionsCalls", | 115 GetIntFromJS(contents, "onNativeSuggestionsCalls", |
116 &on_native_suggestions_calls_) && | 116 &on_native_suggestions_calls_) && |
117 GetIntFromJS(contents, "onChangeCalls", | 117 GetIntFromJS(contents, "onChangeCalls", |
118 &on_change_calls_); | 118 &on_change_calls_); |
119 } | 119 } |
120 | 120 |
| 121 // A convenience function to explicitly blur the omnibox and focus |contents|. |
| 122 // TODO(msw|jered|sreeram): Fix test focus issues; see http://crbug.com/226189 |
| 123 void BlurOmniboxAndFocusContents(content::WebContents* contents) { |
| 124 omnibox()->model()->OnWillKillFocus(contents->GetView()->GetNativeView()); |
| 125 omnibox()->model()->OnKillFocus(); |
| 126 contents->GetView()->Focus(); |
| 127 EXPECT_FALSE(omnibox()->model()->has_focus()); |
| 128 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
| 129 } |
| 130 |
121 int on_most_visited_change_calls_; | 131 int on_most_visited_change_calls_; |
122 int most_visited_items_count_; | 132 int most_visited_items_count_; |
123 int first_most_visited_item_id_; | 133 int first_most_visited_item_id_; |
124 int on_native_suggestions_calls_; | 134 int on_native_suggestions_calls_; |
125 int on_change_calls_; | 135 int on_change_calls_; |
126 }; | 136 }; |
127 | 137 |
128 // Test class used to verify chrome-search: scheme and access policy from the | 138 // Test class used to verify chrome-search: scheme and access policy from the |
129 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it | 139 // Instant overlay. This is a subclass of |ExtensionBrowserTest| because it |
130 // loads a theme that provides a background image. | 140 // loads a theme that provides a background image. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 174 |
165 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { | 175 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { |
166 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 176 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
167 EXPECT_TRUE(instant()->extended_enabled_); | 177 EXPECT_TRUE(instant()->extended_enabled_); |
168 } | 178 } |
169 | 179 |
170 // Test that Instant is preloaded when the omnibox is focused. | 180 // Test that Instant is preloaded when the omnibox is focused. |
171 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { | 181 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { |
172 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 182 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
173 | 183 |
174 // Explicitly unfocus the omnibox. | 184 // Blur the omnibox and focus the active web contents. |
175 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 185 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
176 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 186 BlurOmniboxAndFocusContents( |
177 | 187 browser()->tab_strip_model()->GetActiveWebContents()); |
178 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | |
179 EXPECT_FALSE(omnibox()->model()->has_focus()); | |
180 | 188 |
181 // Delete any existing overlay. | 189 // Delete any existing overlay. |
182 instant()->overlay_.reset(); | 190 instant()->overlay_.reset(); |
183 EXPECT_FALSE(instant()->GetOverlayContents()); | 191 EXPECT_FALSE(instant()->GetOverlayContents()); |
184 | 192 |
185 // Refocus the omnibox. The InstantController should've preloaded Instant. | 193 // Refocus the omnibox. The InstantController should've preloaded Instant. |
186 FocusOmniboxAndWaitForInstantExtendedSupport(); | 194 FocusOmniboxAndWaitForInstantExtendedSupport(); |
187 | 195 |
188 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 196 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
189 EXPECT_TRUE(omnibox()->model()->has_focus()); | 197 EXPECT_TRUE(omnibox()->model()->has_focus()); |
190 | 198 |
191 content::WebContents* overlay = instant()->GetOverlayContents(); | 199 content::WebContents* overlay = instant()->GetOverlayContents(); |
192 EXPECT_TRUE(overlay); | 200 EXPECT_TRUE(overlay); |
193 | 201 |
194 // Check that the page supports Instant, but it isn't showing. | 202 // Check that the page supports Instant, but it isn't showing. |
195 EXPECT_TRUE(instant()->overlay_->supports_instant()); | 203 EXPECT_TRUE(instant()->overlay_->supports_instant()); |
196 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); | 204 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); |
197 EXPECT_TRUE(instant()->model()->mode().is_default()); | 205 EXPECT_TRUE(instant()->model()->mode().is_default()); |
198 | 206 |
199 // Adding a new tab shouldn't delete or recreate the overlay; otherwise, | 207 // Adding a new tab shouldn't delete or recreate the overlay; otherwise, |
200 // what's the point of preloading? | 208 // what's the point of preloading? |
201 AddBlankTabAndShow(browser()); | 209 AddBlankTabAndShow(browser()); |
202 EXPECT_EQ(overlay, instant()->GetOverlayContents()); | 210 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
203 | 211 |
204 // Unfocusing and refocusing the omnibox should also preserve the overlay. | 212 // Unfocusing and refocusing the omnibox should also preserve the overlay. |
205 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 213 BlurOmniboxAndFocusContents( |
206 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 214 browser()->tab_strip_model()->GetActiveWebContents()); |
207 | |
208 FocusOmnibox(); | 215 FocusOmnibox(); |
209 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); | 216 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); |
210 EXPECT_EQ(overlay, instant()->GetOverlayContents()); | 217 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
211 } | 218 } |
212 | 219 |
213 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { | 220 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { |
214 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 221 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
215 | 222 |
216 // Focus omnibox and confirm overlay isn't shown. | 223 // Focus omnibox and confirm overlay isn't shown. |
217 FocusOmniboxAndWaitForInstantExtendedSupport(); | 224 FocusOmniboxAndWaitForInstantExtendedSupport(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 content::WindowedNotificationObserver observer( | 367 content::WindowedNotificationObserver observer( |
361 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 368 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
362 content::NotificationService::AllSources()); | 369 content::NotificationService::AllSources()); |
363 | 370 |
364 // Do a search and commit it. | 371 // Do a search and commit it. |
365 SetOmniboxTextAndWaitForOverlayToShow("hello k"); | 372 SetOmniboxTextAndWaitForOverlayToShow("hello k"); |
366 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); | 373 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); |
367 browser()->window()->GetLocationBar()->AcceptInput(); | 374 browser()->window()->GetLocationBar()->AcceptInput(); |
368 observer.Wait(); | 375 observer.Wait(); |
369 | 376 |
370 // With a committed results page, do a search by unfocusing the omnibox and | 377 // With a committed results page, do a search by blurring the omnibox and |
371 // focusing the contents. | 378 // focusing the contents. Call handleOnChange before focusing the contents. |
372 SetOmniboxText("hello"); | 379 SetOmniboxText("hello"); |
373 // Calling handleOnChange manually to make sure it is called before the | |
374 // Focus() call below. | |
375 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), | 380 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), |
376 "suggestion = 'hello kitty';" | 381 "suggestion = 'hello kitty';" |
377 "handleOnChange();")); | 382 "handleOnChange();")); |
378 instant()->instant_tab()->contents()->GetView()->Focus(); | 383 BlurOmniboxAndFocusContents(instant()->instant_tab()->contents()); |
379 | 384 |
380 // Search term extraction should kick in with the autocompleted text. | 385 // Search term extraction should kick in with the autocompleted text. |
381 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); | 386 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); |
382 | 387 |
383 // Suggestion should be cleared at this point. | 388 // Suggestion should be cleared at this point. |
384 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText()); | 389 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText()); |
385 } | 390 } |
386 | 391 |
387 // Checks that a previous Navigation suggestion is not re-used when a search | 392 // Checks that a previous Navigation suggestion is not re-used when a search |
388 // suggestion comes in. Disabled on Mac because omnibox focus loss is not | 393 // suggestion comes in. Disabled on Mac because omnibox focus loss is not |
(...skipping 16 matching lines...) Expand all Loading... |
405 "behavior = 1;")); | 410 "behavior = 1;")); |
406 SetOmniboxTextAndWaitForOverlayToShow("exa"); | 411 SetOmniboxTextAndWaitForOverlayToShow("exa"); |
407 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); | 412 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); |
408 | 413 |
409 // Now send a search suggestion and see that Navigation suggestion is no | 414 // Now send a search suggestion and see that Navigation suggestion is no |
410 // longer kept. | 415 // longer kept. |
411 SetOmniboxText("exam"); | 416 SetOmniboxText("exam"); |
412 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" | 417 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" |
413 "behavior = 2;" | 418 "behavior = 2;" |
414 "handleOnChange();")); | 419 "handleOnChange();")); |
415 instant()->overlay()->contents()->GetView()->Focus(); | 420 BlurOmniboxAndFocusContents(instant()->overlay()->contents()); |
416 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); | 421 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); |
417 | 422 |
418 // TODO(jered): Remove this after fixing OnBlur(). | 423 // TODO(jered): Remove this after fixing OnBlur(). |
419 omnibox()->RevertAll(); | 424 omnibox()->RevertAll(); |
420 } | 425 } |
421 | 426 |
422 // This test simulates a search provider using the InstantExtended API to | 427 // This test simulates a search provider using the InstantExtended API to |
423 // navigate through the suggested results and back to the original user query. | 428 // navigate through the suggested results and back to the original user query. |
424 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { | 429 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { |
425 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 430 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 content::WebContents* active_tab = | 643 content::WebContents* active_tab = |
639 browser()->tab_strip_model()->GetActiveWebContents(); | 644 browser()->tab_strip_model()->GetActiveWebContents(); |
640 EXPECT_NE(ntp_url, active_tab->GetURL()); | 645 EXPECT_NE(ntp_url, active_tab->GetURL()); |
641 } | 646 } |
642 | 647 |
643 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { | 648 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) { |
644 // Setup Instant. | 649 // Setup Instant. |
645 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 650 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
646 FocusOmniboxAndWaitForInstantExtendedSupport(); | 651 FocusOmniboxAndWaitForInstantExtendedSupport(); |
647 | 652 |
648 // Explicitly unfocus the omnibox. | 653 // Explicitly blur the omnibox. |
649 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 654 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
650 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 655 BlurOmniboxAndFocusContents( |
651 EXPECT_FALSE(omnibox()->model()->has_focus()); | 656 browser()->tab_strip_model()->GetActiveWebContents()); |
652 | 657 |
653 // Open new tab. Preloaded NTP contents should have been used. | 658 // Open new tab. Preloaded NTP contents should have been used. |
654 ui_test_utils::NavigateToURLWithDisposition( | 659 ui_test_utils::NavigateToURLWithDisposition( |
655 browser(), | 660 browser(), |
656 GURL(chrome::kChromeUINewTabURL), | 661 GURL(chrome::kChromeUINewTabURL), |
657 NEW_FOREGROUND_TAB, | 662 NEW_FOREGROUND_TAB, |
658 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 663 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
659 | 664 |
660 // Omnibox should have focus. | 665 // Omnibox should have focus. |
661 EXPECT_TRUE(omnibox()->model()->has_focus()); | 666 EXPECT_TRUE(omnibox()->model()->has_focus()); |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 1434 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
1430 | 1435 |
1431 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL()); | 1436 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL()); |
1432 | 1437 |
1433 // The second argument says to use only the local overlay. | 1438 // The second argument says to use only the local overlay. |
1434 instant()->SetInstantEnabled(false, true); | 1439 instant()->SetInstantEnabled(false, true); |
1435 | 1440 |
1436 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 1441 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
1437 instant()->ntp_->contents()->GetURL()); | 1442 instant()->ntp_->contents()->GetURL()); |
1438 } | 1443 } |
OLD | NEW |