| 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. Disabled on Mac because omnibox focus loss is not |
| 389 // working correctly. http://crbug.com/178520 | 377 // working correctly. http://crbug.com/178520 |
| 390 #if defined(OS_MACOSX) | 378 #if defined(OS_MACOSX) |
| 391 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ | 379 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ |
| 392 DISABLED_NavigationSuggestionIsDiscardedUponSearchSuggestion | 380 DISABLED_NavigationSuggestionIsDiscardedUponSearchSuggestion |
| 393 #else | 381 #else |
| 394 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ | 382 #define MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion \ |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 content::WebContents* overlay = instant()->GetOverlayContents(); | 1336 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 1349 EXPECT_TRUE(UpdateSearchState(overlay)); | 1337 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 1350 EXPECT_EQ(0, on_native_suggestions_calls_); | 1338 EXPECT_EQ(0, on_native_suggestions_calls_); |
| 1351 | 1339 |
| 1352 SetOmniboxTextAndWaitForOverlayToShow("railroad"); | 1340 SetOmniboxTextAndWaitForOverlayToShow("railroad"); |
| 1353 | 1341 |
| 1354 EXPECT_EQ(overlay, instant()->GetOverlayContents()); | 1342 EXPECT_EQ(overlay, instant()->GetOverlayContents()); |
| 1355 EXPECT_TRUE(UpdateSearchState(overlay)); | 1343 EXPECT_TRUE(UpdateSearchState(overlay)); |
| 1356 EXPECT_EQ(1, on_native_suggestions_calls_); | 1344 EXPECT_EQ(1, on_native_suggestions_calls_); |
| 1357 } | 1345 } |
| OLD | NEW |