Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/ui/search/instant_extended_browsertest.cc

Issue 12792013: Instant extended: Remove suggest commit on lost focus (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/search/instant_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"), GetGrayText()); 332 EXPECT_EQ(ASCIIToUTF16(" depp"), GetGrayText());
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"), GetGrayText());
340 // Suggestion should be cleared at this point.
341 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
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. 343 // 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, 344 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
354 MAYBE_OmniboxTextUponFocusedCommittedSERP) { 345 OmniboxTextUponFocusedCommittedSERP) {
355 // Setup Instant. 346 // Setup Instant.
356 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 347 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
357 FocusOmniboxAndWaitForInstantExtendedSupport(); 348 FocusOmniboxAndWaitForInstantExtendedSupport();
358 349
359 // Create an observer to wait for the instant tab to support Instant. 350 // Create an observer to wait for the instant tab to support Instant.
360 content::WindowedNotificationObserver observer( 351 content::WindowedNotificationObserver observer(
361 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 352 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
362 content::NotificationService::AllSources()); 353 content::NotificationService::AllSources());
363 354
364 // Do a search and commit it. 355 // Do a search and commit it.
365 SetOmniboxTextAndWaitForOverlayToShow("hello k"); 356 SetOmniboxTextAndWaitForOverlayToShow("hello k");
366 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); 357 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText());
367 browser()->window()->GetLocationBar()->AcceptInput(); 358 browser()->window()->GetLocationBar()->AcceptInput();
368 observer.Wait(); 359 observer.Wait();
369 360
370 // With a committed results page, do a search by unfocusing the omnibox and 361 // With a committed results page, do a search by unfocusing the omnibox and
371 // focusing the contents. 362 // focusing the contents.
372 SetOmniboxText("hello"); 363 SetOmniboxText("hello");
373 // Calling handleOnChange manually to make sure it is called before the 364 // Calling handleOnChange manually to make sure it is called before the
374 // Focus() call below. 365 // Focus() call below.
375 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(), 366 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(),
376 "suggestion = 'hello kitty';" 367 "suggestion = 'hello kitty';"
377 "handleOnChange();")); 368 "handleOnChange();"));
378 instant()->instant_tab()->contents()->GetView()->Focus(); 369 instant()->instant_tab()->contents()->GetView()->Focus();
379 370
380 // Search term extraction should kick in with the autocompleted text. 371 // Omnibox text and suggestion should not be changed.
381 EXPECT_EQ(ASCIIToUTF16("hello kitty"), omnibox()->GetText()); 372 EXPECT_EQ(ASCIIToUTF16("hello"), omnibox()->GetText());
382 373 EXPECT_EQ(ASCIIToUTF16(" kitty"), GetGrayText());
383 // Suggestion should be cleared at this point.
384 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
385 } 374 }
386 375
387 // Checks that a previous Navigation suggestion is not re-used when a search 376 // 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 377 // 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, 378 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
398 MAYBE_NavigationSuggestionIsDiscardedUponSearchSuggestion) { 379 NavigationSuggestionIsDiscardedUponSearchSuggestion) {
399 // Setup Instant. 380 // Setup Instant.
400 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 381 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
401 FocusOmniboxAndWaitForInstantExtendedSupport(); 382 FocusOmniboxAndWaitForInstantExtendedSupport();
402 383
403 // Tell the page to send a URL suggestion. 384 // Tell the page to send a URL suggestion.
404 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';" 385 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';"
405 "behavior = 1;")); 386 "behavior = 1;"));
406 SetOmniboxTextAndWaitForOverlayToShow("exa"); 387 SetOmniboxTextAndWaitForOverlayToShow("exa");
407 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText()); 388 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText());
408 389
409 // Now send a search suggestion and see that Navigation suggestion is no 390 // Now send a search suggestion and see that Navigation suggestion is no
410 // longer kept. 391 // longer kept.
392 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';"
393 "behavior = 2;"));
411 SetOmniboxText("exam"); 394 SetOmniboxText("exam");
412 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';" 395 // Wait for JavaScript to run handleOnChange by executing a blank script.
413 "behavior = 2;" 396 EXPECT_TRUE(ExecuteScript(std::string()));
414 "handleOnChange();")); 397
415 instant()->overlay()->contents()->GetView()->Focus(); 398 instant()->overlay()->contents()->GetView()->Focus();
416 EXPECT_EQ(ASCIIToUTF16("exams are great"), omnibox()->GetText()); 399 EXPECT_EQ(ASCIIToUTF16("exam"), omnibox()->GetText());
400 EXPECT_EQ(ASCIIToUTF16("s are great"), GetGrayText());
417 401
418 // TODO(jered): Remove this after fixing OnBlur(). 402 // TODO(jered): Remove this after fixing OnBlur().
419 omnibox()->RevertAll(); 403 omnibox()->RevertAll();
420 } 404 }
421 405
422 // This test simulates a search provider using the InstantExtended API to 406 // This test simulates a search provider using the InstantExtended API to
423 // navigate through the suggested results and back to the original user query. 407 // navigate through the suggested results and back to the original user query.
424 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { 408 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) {
425 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 409 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
426 FocusOmniboxAndWaitForInstantExtendedSupport(); 410 FocusOmniboxAndWaitForInstantExtendedSupport();
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1429 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1413 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1430 1414
1431 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL()); 1415 EXPECT_EQ(instant_url(), instant()->ntp_->contents()->GetURL());
1432 1416
1433 // The second argument says to use only the local overlay. 1417 // The second argument says to use only the local overlay.
1434 instant()->SetInstantEnabled(false, true); 1418 instant()->SetInstantEnabled(false, true);
1435 1419
1436 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), 1420 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl),
1437 instant()->ntp_->contents()->GetURL()); 1421 instant()->ntp_->contents()->GetURL());
1438 } 1422 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698