| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 // Set the text, and wait for suggestions to show up. | 327 // Set the text, and wait for suggestions to show up. |
| 328 SetOmniboxTextAndWaitForOverlayToShow("johnny"); | 328 SetOmniboxTextAndWaitForOverlayToShow("johnny"); |
| 329 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); | 329 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); |
| 330 | 330 |
| 331 // Test that the current suggestion is correctly set. | 331 // Test that the current suggestion is correctly set. |
| 332 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); | 332 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); |
| 333 | 333 |
| 334 // Commit the overlay by lost focus (e.g. clicking on the page). | 334 // Commit the overlay by lost focus (e.g. clicking on the page). |
| 335 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 335 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 336 | 336 |
| 337 // Search term extraction should kick in with the autocompleted text. | 337 // Omnibox text and suggestion should not be changed. |
| 338 EXPECT_EQ(ASCIIToUTF16("johnny depp"), omnibox()->GetText()); | 338 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); |
| 339 | 339 EXPECT_EQ(ASCIIToUTF16(" depp"), omnibox()->GetInstantSuggestion()); |
| 340 // Suggestion should be cleared at this point. | |
| 341 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | |
| 342 } | 340 } |
| 343 | 341 |
| 344 // Test that omnibox text is correctly set when clicking on committed SERP. | 342 // Test that omnibox text is correctly set when clicking on committed SERP. |
| 345 // Disabled on Mac because omnibox focus loss is not working correctly. | |
| 346 #if defined(OS_MACOSX) | |
| 347 #define MAYBE_OmniboxTextUponFocusedCommittedSERP \ | |
| 348 DISABLED_OmniboxTextUponFocusedCommittedSERP | |
| 349 #else | |
| 350 #define MAYBE_OmniboxTextUponFocusedCommittedSERP \ | |
| 351 OmniboxTextUponFocusedCommittedSERP | |
| 352 #endif | |
| 353 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 343 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 354 MAYBE_OmniboxTextUponFocusedCommittedSERP) { | 344 OmniboxTextUponFocusedCommittedSERP) { |
| 355 // Setup Instant. | 345 // Setup Instant. |
| 356 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 346 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 357 FocusOmniboxAndWaitForInstantExtendedSupport(); | 347 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 358 | 348 |
| 359 // Create an observer to wait for the instant tab to support Instant. | 349 // Create an observer to wait for the instant tab to support Instant. |
| 360 content::WindowedNotificationObserver observer( | 350 content::WindowedNotificationObserver observer( |
| 361 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 351 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 362 content::NotificationService::AllSources()); | 352 content::NotificationService::AllSources()); |
| 363 | 353 |
| 364 // Do a search and commit it. | 354 // Do a search and commit it. |
| 365 SetOmniboxTextAndWaitForOverlayToShow("hello k"); | 355 SetOmniboxTextAndWaitForOverlayToShow("hello k"); |
| 366 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); | 356 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); |
| 367 browser()->window()->GetLocationBar()->AcceptInput(); | 357 browser()->window()->GetLocationBar()->AcceptInput(); |
| 368 observer.Wait(); | 358 observer.Wait(); |
| 369 | 359 |
| 370 // With a committed results page, do a search by unfocusing the omnibox and | 360 // With a committed results page, do a search by unfocusing the omnibox and |
| 371 // focusing the contents. | 361 // focusing the contents. |
| 372 SetOmniboxText("hello"); | 362 SetOmniboxText("hello"); |
| 373 // Calling handleOnChange manually to make sure it is called before the | 363 // Calling handleOnChange manually to make sure it is called before the |
| 374 // Focus() call below. | 364 // Focus() call below. |
| 375 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), | 365 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), |
| 376 "suggestion = 'hello kitty';" | 366 "suggestion = 'hello kitty';" |
| 377 "handleOnChange();")); | 367 "handleOnChange();")); |
| 378 instant()->instant_tab()->contents()->GetView()->Focus(); | 368 instant()->instant_tab()->contents()->GetView()->Focus(); |
| 379 | 369 |
| 380 // Search term extraction should kick in with the autocompleted text. | 370 // Omnibox text and suggestion should not be changed. |
| 381 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); | 371 EXPECT_EQ(ASCIIToUTF16("hello"), omnibox()->GetText()); |
| 382 | 372 EXPECT_EQ(ASCIIToUTF16(" kitty"), omnibox()->GetInstantSuggestion()); |
| 383 // Suggestion should be cleared at this point. | |
| 384 EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); | |
| 385 } | 373 } |
| 386 | 374 |
| 387 // Checks that a previous Navigation suggestion is not re-used when a search | 375 // 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 | 376 // suggestion comes in. |
| 389 // working correctly. http://crbug.com/178520 | |
| 390 #if defined(OS_MACOSX) | |
| 391 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ | |
| 392 DISABLED_NavigationSuggestionIsDiscardedUponSearchSuggestion | |
| 393 #else | |
| 394 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ | |
| 395 NavigationSuggestionIsDiscardedUponSearchSuggestion | |
| 396 #endif | |
| 397 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 377 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 398 MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion) { | 378 NavigationSuggestionIsDiscardedUponSearchSuggestion) { |
| 399 // Setup Instant. | 379 // Setup Instant. |
| 400 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 380 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 401 FocusOmniboxAndWaitForInstantExtendedSupport(); | 381 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| 402 | 382 |
| 403 // Tell the page to send a URL suggestion. | 383 // Tell the page to send a URL suggestion. |
| 404 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';" | 384 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';" |
| 405 "behavior = 0;")); | 385 "behavior = 0;")); |
| 406 SetOmniboxTextAndWaitForOverlayToShow("exa"); | 386 SetOmniboxTextAndWaitForOverlayToShow("exa"); |
| 407 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); | 387 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); |
| 408 | 388 |
| 409 // Now send a search suggestion and see that Navigation suggestion is no | 389 // Now send a search suggestion and see that Navigation suggestion is no |
| 410 // longer kept. | 390 // longer kept. |
| 411 SetOmniboxText("exam"); | 391 SetOmniboxText("exam"); |
| 412 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" | 392 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" |
| 413 "behavior = 2;" | 393 "behavior = 2;" |
| 414 "handleOnChange();")); | 394 "handleOnChange();")); |
| 415 instant()->overlay()->contents()->GetView()->Focus(); | 395 instant()->overlay()->contents()->GetView()->Focus(); |
| 416 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); | 396 EXPECT_EQ(ASCIIToUTF16("exam"), omnibox()->GetText()); |
| 397 EXPECT_EQ(ASCIIToUTF16("s are great"), omnibox()->GetInstantSuggestion()); |
| 417 | 398 |
| 418 // TODO(jered): Remove this after fixing OnBlur(). | 399 // TODO(jered): Remove this after fixing OnBlur(). |
| 419 omnibox()->RevertAll(); | 400 omnibox()->RevertAll(); |
| 420 } | 401 } |
| 421 | 402 |
| 422 // This test simulates a search provider using the InstantExtended API to | 403 // This test simulates a search provider using the InstantExtended API to |
| 423 // navigate through the suggested results and back to the original user query. | 404 // navigate through the suggested results and back to the original user query. |
| 424 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { | 405 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { |
| 425 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 406 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 426 FocusOmniboxAndWaitForInstantExtendedSupport(); | 407 FocusOmniboxAndWaitForInstantExtendedSupport(); |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 content::WebContents* overlay = instant()->GetOverlayContents(); | 1329 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 1349 EXPECT_TRUE(UpdateSearchState(overlay)); | 1330 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 1350 EXPECT_EQ(0, on_native_suggestions_calls_); | 1331 EXPECT_EQ(0, on_native_suggestions_calls_); |
| 1351 | 1332 |
| 1352 SetOmniboxTextAndWaitForOverlayToShow("railroad"); | 1333 SetOmniboxTextAndWaitForOverlayToShow("railroad"); |
| 1353 | 1334 |
| 1354 EXPECT_EQ(overlay, instant()->GetOverlayContents()); | 1335 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| 1355 EXPECT_TRUE(UpdateSearchState(overlay)); | 1336 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 1356 EXPECT_EQ(1, on_native_suggestions_calls_); | 1337 EXPECT_EQ(1, on_native_suggestions_calls_); |
| 1357 } | 1338 } |
| OLD | NEW |