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

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

Issue 17413017: InstantExtended: Don't create overlay. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_base.h" 9 #include "base/metrics/histogram_base.h"
10 #include "base/metrics/histogram_samples.h" 10 #include "base/metrics/histogram_samples.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); 288 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest);
289 }; 289 };
290 290
291 #if defined(HTML_INSTANT_EXTENDED_POPUP) 291 #if defined(HTML_INSTANT_EXTENDED_POPUP)
292 292
293 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { 293 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
294 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 294 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
295 EXPECT_TRUE(instant()->extended_enabled_); 295 EXPECT_TRUE(instant()->extended_enabled_);
296 } 296 }
297 297
298 // Test that Instant is preloaded when the omnibox is focused.
299 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
300 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
301
302 // Explicitly unfocus the omnibox.
303 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
304 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
305
306 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
307 EXPECT_FALSE(omnibox()->model()->has_focus());
308
309 // Delete any existing overlay.
310 instant()->overlay_.reset();
311 EXPECT_FALSE(instant()->GetOverlayContents());
312
313 // Refocus the omnibox. The InstantController should've preloaded Instant.
314 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
315
316 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
317 EXPECT_TRUE(omnibox()->model()->has_focus());
318
319 content::WebContents* overlay = instant()->GetOverlayContents();
320 EXPECT_TRUE(overlay);
321
322 // Check that the page supports Instant, but it isn't showing.
323 EXPECT_TRUE(instant()->overlay_->supports_instant());
324 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
325 EXPECT_TRUE(instant()->model()->mode().is_default());
326
327 // Adding a new tab shouldn't delete or recreate the overlay; otherwise,
328 // what's the point of preloading?
329 AddBlankTabAndShow(browser());
330 EXPECT_EQ(overlay, instant()->GetOverlayContents());
331
332 // Unfocusing and refocusing the omnibox should also preserve the overlay.
333 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
334 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
335
336 FocusOmnibox();
337 EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
338 EXPECT_EQ(overlay, instant()->GetOverlayContents());
339 }
340
341 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) {
342 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
343
344 // Focus omnibox and confirm overlay isn't shown.
345 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
346 content::WebContents* overlay = instant()->GetOverlayContents();
347 EXPECT_TRUE(overlay);
348 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
349 EXPECT_TRUE(instant()->model()->mode().is_default());
350
351 // Typing in the omnibox should show the overlay.
352 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
353 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
354 EXPECT_EQ(overlay, instant()->GetOverlayContents());
355 }
356
357 // Flaky on Linux Tests bot.
358 #if defined(OS_LINUX)
359 #define MAYBE_UsesOverlayIfTabNotReady DISABLED_UsesOverlayIfTabNotReady
360 #else
361 #define MAYBE_UsesOverlayIfTabNotReady UsesOverlayIfTabNotReady
362 #endif
363
364 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_UsesOverlayIfTabNotReady) {
365 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
366 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
367
368 // Open a new tab and navigate to instant URL. Start typing before InstantTab
369 // is properly hooked up. Should use the overlay.
370 ui_test_utils::NavigateToURLWithDisposition(
371 browser(),
372 instant_url(),
373 NEW_BACKGROUND_TAB,
374 ui_test_utils::BROWSER_TEST_NONE);
375 EXPECT_EQ(2, browser()->tab_strip_model()->count());
376 browser()->tab_strip_model()->ActivateTabAt(1, false);
377 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
378
379 // But Instant tab should still exist.
380 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab());
381 EXPECT_FALSE(instant()->UseTabForSuggestions());
382
383 // Wait for Instant Tab support if it still hasn't finished loading.
384 if (!instant()->instant_tab()->supports_instant()) {
385 content::WindowedNotificationObserver instant_tab_observer(
386 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
387 content::NotificationService::AllSources());
388 instant_tab_observer.Wait();
389 }
390
391 // Hide the overlay. Now, we should be using Instant tab for suggestions.
392 instant()->HideOverlay();
393 EXPECT_TRUE(instant()->UseTabForSuggestions());
394 }
395
396 // Flaky on Mac Tests bot. crbug.com/242415
397 #if defined(OS_MACOSX)
398 #define MAYBE_MiddleClickOnSuggestionOpensInNewTab DISABLED_MiddleClickOnSuggest ionOpensInNewTab
399 #else
400 #define MAYBE_MiddleClickOnSuggestionOpensInNewTab MiddleClickOnSuggestionOpensI nNewTab
401 #endif
402
403 // Test that middle clicking on a suggestion opens the result in a new tab.
404 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
405 MAYBE_MiddleClickOnSuggestionOpensInNewTab) {
406 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
407 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
408 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
409
410 EXPECT_EQ(1, browser()->tab_strip_model()->count());
411
412 // Typing in the omnibox should show the overlay.
413 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("http://www.example.com/"));
414
415 // Create an event listener that opens the top suggestion in a new tab.
416 EXPECT_TRUE(ExecuteScript(
417 "var rid = getApiHandle().nativeSuggestions[0].rid;"
418 "document.body.addEventListener('click', function() {"
419 "chrome.embeddedSearch.navigateContentWindow(rid, 2);"
420 "});"
421 ));
422
423 content::WindowedNotificationObserver observer(
424 chrome::NOTIFICATION_TAB_ADDED,
425 content::NotificationService::AllSources());
426
427 // Click to trigger the event listener.
428 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
429
430 // Wait for the new tab to be added.
431 observer.Wait();
432
433 // Check that the new tab URL is as expected.
434 content::WebContents* new_tab_contents =
435 browser()->tab_strip_model()->GetWebContentsAt(1);
436 EXPECT_EQ("http://www.example.com/", new_tab_contents->GetURL().spec());
437
438 // Check that there are now two tabs.
439 EXPECT_EQ(2, browser()->tab_strip_model()->count());
440 }
441
442 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
443 UnfocusingOmniboxDoesNotChangeSuggestions) {
444 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
445 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
446 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
447
448 // Get a committed tab to work with.
449 content::WebContents* instant_tab = instant()->GetOverlayContents();
450 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("committed"));
451 browser()->window()->GetLocationBar()->AcceptInput();
452
453 // Put focus back into the omnibox, type, and wait for some gray text.
454 EXPECT_TRUE(content::ExecuteScript(instant_tab,
455 "suggestion = 'santa claus';"));
456 SetOmniboxTextAndWaitForSuggestion("santa ");
457 EXPECT_EQ(ASCIIToUTF16("claus"), GetGrayText());
458 EXPECT_TRUE(content::ExecuteScript(instant_tab,
459 "onChangeCalls = onNativeSuggestionsCalls = 0;"));
460
461 // Now unfocus the omnibox.
462 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
463 EXPECT_TRUE(UpdateSearchState(instant_tab));
464 EXPECT_EQ(0, on_change_calls_);
465 EXPECT_EQ(0, on_native_suggestions_calls_);
466 }
467
468 // Test that omnibox text is correctly set when overlay is committed with Enter.
469 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponEnterCommit) {
470 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
471 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
472
473 // The page will autocomplete once we set the omnibox value.
474 EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';"));
475
476 // Set the text, and wait for suggestions to show up.
477 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("santa"));
478 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText());
479
480 // Test that the current suggestion is correctly set.
481 EXPECT_EQ(ASCIIToUTF16(" claus"), GetGrayText());
482
483 // Commit the search by pressing Enter.
484 browser()->window()->GetLocationBar()->AcceptInput();
485
486 // 'Enter' commits the query as it was typed.
487 EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText());
488
489 // Suggestion should be cleared at this point.
490 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
491 }
492
493 // Test that omnibox text is correctly set when committed with focus lost.
494 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxTextUponFocusLostCommit) {
495 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
496 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
497
498 // Set autocomplete text (grey text).
499 EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';"));
500
501 // Set the text, and wait for suggestions to show up.
502 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("johnny"));
503 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText());
504
505 // Test that the current suggestion is correctly set.
506 EXPECT_EQ(ASCIIToUTF16(" depp"), GetGrayText());
507
508 // Commit the overlay by lost focus (e.g. clicking on the page).
509 instant()->CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
510
511 // Omnibox text and suggestion should not be changed.
512 EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText());
513 EXPECT_EQ(ASCIIToUTF16(" depp"), GetGrayText());
514 }
515
516 // Test that omnibox text is correctly set when clicking on committed SERP.
517 // Disabled on Mac because omnibox focus loss is not working correctly.
518 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
519 OmniboxTextUponFocusedCommittedSERP) {
520 // Setup Instant.
521 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
522 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
523
524 // Create an observer to wait for the instant tab to support Instant.
525 content::WindowedNotificationObserver observer(
526 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
527 content::NotificationService::AllSources());
528
529 // Do a search and commit it.
530 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello k"));
531 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText());
532 browser()->window()->GetLocationBar()->AcceptInput();
533 observer.Wait();
534
535 // With a committed results page, do a search by unfocusing the omnibox and
536 // focusing the contents.
537 SetOmniboxText("hello");
538 // Calling handleOnChange manually to make sure it is called before the
539 // Focus() call below.
540 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(),
541 "suggestion = 'hello kitty';"
542 "handleOnChange();"));
543 instant()->instant_tab()->contents()->GetView()->Focus();
544
545 // Omnibox text and suggestion should not be changed.
546 EXPECT_EQ(ASCIIToUTF16("hello"), omnibox()->GetText());
547 EXPECT_EQ(ASCIIToUTF16(" kitty"), GetGrayText());
548 }
549
550 // Checks that a previous Navigation suggestion is not re-used when a search
551 // suggestion comes in.
552 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
553 NavigationSuggestionIsDiscardedUponSearchSuggestion) {
554 // Setup Instant.
555 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
556 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
557
558 // Tell the page to send a URL suggestion.
559 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';"
560 "behavior = 1;"));
561 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("exa"));
562 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText());
563
564 // Now send a search suggestion and see that Navigation suggestion is no
565 // longer kept.
566 EXPECT_TRUE(ExecuteScript("suggestion = 'exams are great';"
567 "behavior = 2;"));
568 SetOmniboxText("exam");
569 // Wait for JavaScript to run handleOnChange by executing a blank script.
570 EXPECT_TRUE(ExecuteScript(std::string()));
571
572 instant()->overlay()->contents()->GetView()->Focus();
573 EXPECT_EQ(ASCIIToUTF16("exam"), omnibox()->GetText());
574 EXPECT_EQ(ASCIIToUTF16("s are great"), GetGrayText());
575
576 // TODO(jered): Remove this after fixing OnBlur().
577 omnibox()->RevertAll();
578 }
579
580 // This test simulates a search provider using the InstantExtended API to
581 // navigate through the suggested results and back to the original user query.
582 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) {
583 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
584 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
585
586 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello"));
587 EXPECT_EQ("hello", GetOmniboxText());
588
589 SendDownArrow();
590 EXPECT_EQ("result 1", GetOmniboxText());
591 SendDownArrow();
592 EXPECT_EQ("result 2", GetOmniboxText());
593 SendUpArrow();
594 EXPECT_EQ("result 1", GetOmniboxText());
595 SendUpArrow();
596 EXPECT_EQ("hello", GetOmniboxText());
597
598 // Ensure that the API's value is set correctly.
599 std::string result;
600 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
601 "window.chrome.searchBox.value",
602 &result));
603 EXPECT_EQ("hello", result);
604
605 EXPECT_TRUE(HasUserInputInProgress());
606 // TODO(beaudoin): Figure out why this fails.
607 // EXPECT_FALSE(HasTemporaryText());
608
609 // Commit the search by pressing Enter.
610 browser()->window()->GetLocationBar()->AcceptInput();
611 EXPECT_EQ("hello", GetOmniboxText());
612 }
613
614 // Flaky on Linux Tests bot. See http://crbug.com/233090.
615 #if defined(OS_LINUX)
616 #define MAYBE_NavigateToURLSuggestionHitEnterAndLookForSubmit DISABLED_NavigateT oURLSuggestionHitEnterAndLookForSubmit
617 #else
618 #define MAYBE_NavigateToURLSuggestionHitEnterAndLookForSubmit NavigateToURLSugge stionHitEnterAndLookForSubmit
619 #endif
620
621 // This test simulates a search provider using the InstantExtended API to
622 // navigate through the suggested results and back to the original user query.
623 // If this test starts to flake, it may be that the second call to AcceptInput
624 // below causes instant()->instant_tab() to no longer be valid due to e.g. a
625 // navigation. In that case, see https://codereview.chromium.org/12895007/#msg28
626 // and onwards for possible alternatives.
627 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
628 MAYBE_NavigateToURLSuggestionHitEnterAndLookForSubmit) {
629 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
630 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
631
632 // Create an observer to wait for the instant tab to support Instant.
633 content::WindowedNotificationObserver observer(
634 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
635 content::NotificationService::AllSources());
636
637 // Do a search and commit it.
638 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello k"));
639 EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText());
640 browser()->window()->GetLocationBar()->AcceptInput();
641 observer.Wait();
642
643 SetOmniboxText("http");
644 EXPECT_EQ("http", GetOmniboxText());
645
646 SendDownArrow();
647 EXPECT_EQ("result 1", GetOmniboxText());
648 SendDownArrow();
649 EXPECT_EQ("result 2", GetOmniboxText());
650
651 // Set the next suggestion to be of type INSTANT_SUGGESTION_URL.
652 EXPECT_TRUE(content::ExecuteScript(instant()->instant_tab()->contents(),
653 "suggestionType = 1;"));
654 SendDownArrow();
655 EXPECT_EQ("http://www.google.com", GetOmniboxText());
656
657 EXPECT_TRUE(HasUserInputInProgress());
658
659 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents()));
660 // Note the commit count is initially 1 due to the AcceptInput() call above.
661 EXPECT_EQ(1, submit_count_);
662
663 std::string old_query_value(query_value_);
664
665 // Commit the search by pressing Enter.
666 browser()->window()->GetLocationBar()->AcceptInput();
667
668 // Make sure a submit message got sent.
669 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents()));
670 EXPECT_EQ(2, submit_count_);
671 EXPECT_EQ(old_query_value, query_value_);
672 }
673
674 // This test simulates a search provider using the InstantExtended API to
675 // navigate through the suggested results and hitting escape to get back to the
676 // original user query.
677 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) {
678 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
679 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
680
681 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello"));
682 EXPECT_EQ("hello", GetOmniboxText());
683
684 SendDownArrow();
685 EXPECT_EQ("result 1", GetOmniboxText());
686 SendDownArrow();
687 EXPECT_EQ("result 2", GetOmniboxText());
688 SendEscape();
689 EXPECT_EQ("hello", GetOmniboxText());
690
691 // Ensure that the API's value is set correctly.
692 std::string result;
693 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
694 "window.chrome.searchBox.value",
695 &result));
696 EXPECT_EQ("hello", result);
697
698 EXPECT_TRUE(HasUserInputInProgress());
699 EXPECT_FALSE(HasTemporaryText());
700
701 // Commit the search by pressing Enter.
702 browser()->window()->GetLocationBar()->AcceptInput();
703 EXPECT_EQ("hello", GetOmniboxText());
704 }
705
706 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PressEscapeWithBlueText) {
707 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
708 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
709
710 // Set blue text completion.
711 EXPECT_TRUE(ExecuteScript("suggestion = 'chimichanga.com';"
712 "behavior = 1;"));
713
714 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("chimi"));
715
716 EXPECT_EQ(ASCIIToUTF16("chimichanga.com"), omnibox()->GetText());
717 EXPECT_EQ(ASCIIToUTF16("changa.com"), GetBlueText());
718 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
719
720 EXPECT_TRUE(ExecuteScript("onChangeCalls = onNativeSuggestionsCalls = 0;"));
721
722 SendDownArrow();
723
724 EXPECT_EQ(ASCIIToUTF16("result 1"), omnibox()->GetText());
725 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
726 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
727
728 content::WindowedNotificationObserver observer(
729 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
730 content::NotificationService::AllSources());
731 SendEscape();
732 observer.Wait();
733
734 EXPECT_EQ(ASCIIToUTF16("chimichanga.com"), omnibox()->GetText());
735 EXPECT_EQ(ASCIIToUTF16("changa.com"), GetBlueText());
736 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
737
738 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
739 EXPECT_EQ(0, on_native_suggestions_calls_);
740 EXPECT_EQ(0, on_change_calls_);
741 }
742
743 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PressEscapeWithGrayText) {
744 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
745 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
746
747 // Set gray text completion.
748 EXPECT_TRUE(ExecuteScript("suggestion = 'cowabunga';"
749 "behavior = 2;"));
750
751 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("cowa"));
752
753 EXPECT_EQ(ASCIIToUTF16("cowa"), omnibox()->GetText());
754 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
755 EXPECT_EQ(ASCIIToUTF16("bunga"), GetGrayText());
756
757 EXPECT_TRUE(ExecuteScript("onChangeCalls = onNativeSuggestionsCalls = 0;"));
758
759 SendDownArrow();
760
761 EXPECT_EQ(ASCIIToUTF16("result 1"), omnibox()->GetText());
762 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
763 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
764
765 content::WindowedNotificationObserver observer(
766 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
767 content::NotificationService::AllSources());
768 SendEscape();
769 observer.Wait();
770
771 EXPECT_EQ(ASCIIToUTF16("cowa"), omnibox()->GetText());
772 EXPECT_EQ(ASCIIToUTF16(""), GetBlueText());
773 EXPECT_EQ(ASCIIToUTF16("bunga"), GetGrayText());
774
775 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
776 EXPECT_EQ(0, on_native_suggestions_calls_);
777 EXPECT_EQ(0, on_change_calls_);
778 }
779
780 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { 298 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
781 // Setup Instant. 299 // Setup Instant.
782 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 300 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
783 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 301 FocusOmniboxAndWaitForInstantNTPSupport();
784 302
785 // NTP contents should be preloaded. 303 // NTP contents should be preloaded.
786 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 304 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
787 content::WebContents* ntp_contents = instant()->ntp_->contents(); 305 content::WebContents* ntp_contents = instant()->ntp_->contents();
788 EXPECT_TRUE(ntp_contents); 306 EXPECT_TRUE(ntp_contents);
789 } 307 }
790 308
791 // Test that the local NTP is preloaded. 309 // Test that the local NTP is preloaded.
792 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsPreloaded) { 310 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsPreloaded) {
793 // Setup Instant. 311 // Setup Instant.
794 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 312 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
795 313
796 // The second argument says to use only the local overlay and NTP. 314 // The second argument says to use only the local overlay and NTP.
797 instant()->SetInstantEnabled(false, true); 315 instant()->SetInstantEnabled(false, true);
798 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 316 FocusOmniboxAndWaitForInstantNTPSupport();
799 317
800 // NTP contents should be preloaded. 318 // NTP contents should be preloaded.
801 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 319 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
802 content::WebContents* ntp_contents = instant()->ntp_->contents(); 320 content::WebContents* ntp_contents = instant()->ntp_->contents();
803 EXPECT_NE(static_cast<content::WebContents*>(NULL), ntp_contents); 321 EXPECT_NE(static_cast<content::WebContents*>(NULL), ntp_contents);
804 EXPECT_TRUE(instant()->ntp()->IsLocal()); 322 EXPECT_TRUE(instant()->ntp()->IsLocal());
805 } 323 }
806 324
807 // Test that the local NTP is not preloaded. 325 // Test that the local NTP is not preloaded.
808 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsNotPreloaded) { 326 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsNotPreloaded) {
809 // Setup Instant. 327 // Setup Instant.
810 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 328 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
811 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( 329 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
812 "InstantExtended/Group1 local_only:1 preload_local_only_ntp:0/")); 330 "InstantExtended/Group1 local_only:1 preload_local_only_ntp:0/"));
813 331
814 // The second argument says to use only the local overlay and NTP. 332 // The second argument says to use only the local overlay and NTP.
815 instant()->SetInstantEnabled(false, true); 333 instant()->SetInstantEnabled(false, true);
816 334
817 // NTP contents should not be preloaded. 335 // NTP contents should not be preloaded.
818 EXPECT_EQ(NULL, instant()->ntp()); 336 EXPECT_EQ(NULL, instant()->ntp());
819 } 337 }
820 338
821 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { 339 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
822 // Setup Instant. 340 // Setup Instant.
823 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 341 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
824 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 342 FocusOmniboxAndWaitForInstantNTPSupport();
825 343
826 // NTP contents should be preloaded. 344 // NTP contents should be preloaded.
827 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 345 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
828 content::WebContents* ntp_contents = instant()->ntp_->contents(); 346 content::WebContents* ntp_contents = instant()->ntp_->contents();
829 EXPECT_TRUE(ntp_contents); 347 EXPECT_TRUE(ntp_contents);
830 348
831 // Open new tab. Preloaded NTP contents should have been used. 349 // Open new tab. Preloaded NTP contents should have been used.
832 ui_test_utils::NavigateToURLWithDisposition( 350 ui_test_utils::NavigateToURLWithDisposition(
833 browser(), 351 browser(),
834 GURL(chrome::kChromeUINewTabURL), 352 GURL(chrome::kChromeUINewTabURL),
835 NEW_FOREGROUND_TAB, 353 NEW_FOREGROUND_TAB,
836 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 354 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
837 content::WebContents* active_tab = 355 content::WebContents* active_tab =
838 browser()->tab_strip_model()->GetActiveWebContents(); 356 browser()->tab_strip_model()->GetActiveWebContents();
839 EXPECT_EQ(ntp_contents, active_tab); 357 EXPECT_EQ(ntp_contents, active_tab);
840 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); 358 EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
841 } 359 }
842 360
843 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { 361 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
844 // Setup Instant. 362 // Setup Instant.
845 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 363 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
846 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 364 FocusOmniboxAndWaitForInstantNTPSupport();
847 365
848 // NTP contents should be preloaded. 366 // NTP contents should be preloaded.
849 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 367 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
850 content::WebContents* ntp_contents = instant()->ntp_->contents(); 368 content::WebContents* ntp_contents = instant()->ntp_->contents();
851 EXPECT_TRUE(ntp_contents); 369 EXPECT_TRUE(ntp_contents);
852 370
853 // Open new tab. Preloaded NTP contents should have been used. 371 // Open new tab. Preloaded NTP contents should have been used.
854 ui_test_utils::NavigateToURLWithDisposition( 372 ui_test_utils::NavigateToURLWithDisposition(
855 browser(), 373 browser(),
856 GURL(chrome::kChromeUINewTabURL), 374 GURL(chrome::kChromeUINewTabURL),
857 CURRENT_TAB, 375 CURRENT_TAB,
858 ui_test_utils::BROWSER_TEST_NONE); 376 ui_test_utils::BROWSER_TEST_NONE);
859 content::WebContents* active_tab = 377 content::WebContents* active_tab =
860 browser()->tab_strip_model()->GetActiveWebContents(); 378 browser()->tab_strip_model()->GetActiveWebContents();
861 EXPECT_EQ(ntp_contents, active_tab); 379 EXPECT_EQ(ntp_contents, active_tab);
862 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); 380 EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
863 } 381 }
864 382
865 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPForWrongProvider) { 383 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPForWrongProvider) {
866 // Setup Instant. 384 // Setup Instant.
867 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 385 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
868 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 386 FocusOmniboxAndWaitForInstantNTPSupport();
869 387
870 // NTP contents should be preloaded. 388 // NTP contents should be preloaded.
871 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 389 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
872 content::WebContents* ntp_contents = instant()->ntp_->contents(); 390 content::WebContents* ntp_contents = instant()->ntp_->contents();
873 EXPECT_TRUE(ntp_contents); 391 EXPECT_TRUE(ntp_contents);
874 GURL ntp_url = ntp_contents->GetURL(); 392 GURL ntp_url = ntp_contents->GetURL();
875 393
876 // Change providers. 394 // Change providers.
877 SetInstantURL("chrome://blank"); 395 SetInstantURL("chrome://blank");
878 396
879 // Open new tab. Preloaded NTP contents should have not been used. 397 // Open new tab. Preloaded NTP contents should have not been used.
880 ui_test_utils::NavigateToURLWithDisposition( 398 ui_test_utils::NavigateToURLWithDisposition(
881 browser(), 399 browser(),
882 GURL(chrome::kChromeUINewTabURL), 400 GURL(chrome::kChromeUINewTabURL),
883 NEW_FOREGROUND_TAB, 401 NEW_FOREGROUND_TAB,
884 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 402 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
885 content::WebContents* active_tab = 403 content::WebContents* active_tab =
886 browser()->tab_strip_model()->GetActiveWebContents(); 404 browser()->tab_strip_model()->GetActiveWebContents();
887 EXPECT_NE(ntp_url, active_tab->GetURL()); 405 EXPECT_NE(ntp_url, active_tab->GetURL());
888 } 406 }
889 407
890 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPRenderViewGone) { 408 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPRenderViewGone) {
891 // Setup Instant. 409 // Setup Instant.
892 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 410 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
893 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 411 FocusOmniboxAndWaitForInstantNTPSupport();
894 412
895 // NTP contents should be preloaded. 413 // NTP contents should be preloaded.
896 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 414 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
897 EXPECT_FALSE(instant()->ntp()->IsLocal()); 415 EXPECT_FALSE(instant()->ntp()->IsLocal());
898 416
899 // NTP not reloaded after being killed. 417 // NTP not reloaded after being killed.
900 instant()->InstantPageRenderViewGone(instant()->ntp()->contents()); 418 instant()->InstantPageRenderViewGone(instant()->ntp()->contents());
901 EXPECT_EQ(NULL, instant()->ntp()); 419 EXPECT_EQ(NULL, instant()->ntp());
902 420
903 // Open new tab. Should use local NTP. 421 // Open new tab. Should use local NTP.
904 ui_test_utils::NavigateToURLWithDisposition( 422 ui_test_utils::NavigateToURLWithDisposition(
905 browser(), 423 browser(),
906 GURL(chrome::kChromeUINewTabURL), 424 GURL(chrome::kChromeUINewTabURL),
907 NEW_FOREGROUND_TAB, 425 NEW_FOREGROUND_TAB,
908 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 426 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
909 content::WebContents* active_tab = 427 content::WebContents* active_tab =
910 browser()->tab_strip_model()->GetActiveWebContents(); 428 browser()->tab_strip_model()->GetActiveWebContents();
911 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 429 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
912 } 430 }
913 431
914 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { 432 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) {
915 // Setup Instant. 433 // Setup Instant.
916 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); 434 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
917 InstantTestBase::Init(instant_url); 435 InstantTestBase::Init(instant_url);
918 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 436 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
919 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 437 FocusOmniboxAndWaitForInstantNTPSupport();
920 438
921 // NTP contents should have fallen back to the local page. 439 // NTP contents should have fallen back to the local page.
922 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 440 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
923 EXPECT_TRUE(instant()->ntp()->IsLocal()); 441 EXPECT_TRUE(instant()->ntp()->IsLocal());
924 442
925 // Open new tab. Should use local NTP. 443 // Open new tab. Should use local NTP.
926 ui_test_utils::NavigateToURLWithDisposition( 444 ui_test_utils::NavigateToURLWithDisposition(
927 browser(), 445 browser(),
928 GURL(chrome::kChromeUINewTabURL), 446 GURL(chrome::kChromeUINewTabURL),
929 NEW_FOREGROUND_TAB, 447 NEW_FOREGROUND_TAB,
930 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 448 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
931 content::WebContents* active_tab = 449 content::WebContents* active_tab =
932 browser()->tab_strip_model()->GetActiveWebContents(); 450 browser()->tab_strip_model()->GetActiveWebContents();
933 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 451 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
934 } 452 }
935 453
936 // Flaky, http://crbug.com/240852 . 454 // Flaky, http://crbug.com/240852 .
937 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_OmniboxHasFocusOnNewTab) { 455 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_OmniboxHasFocusOnNewTab) {
938 // Setup Instant. 456 // Setup Instant.
939 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 457 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
940 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 458 FocusOmniboxAndWaitForInstantNTPSupport();
941 459
942 // Explicitly unfocus the omnibox. 460 // Explicitly unfocus the omnibox.
943 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 461 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
944 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 462 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
945 EXPECT_FALSE(omnibox()->model()->has_focus()); 463 EXPECT_FALSE(omnibox()->model()->has_focus());
946 464
947 // Open new tab. Preloaded NTP contents should have been used. 465 // Open new tab. Preloaded NTP contents should have been used.
948 ui_test_utils::NavigateToURLWithDisposition( 466 ui_test_utils::NavigateToURLWithDisposition(
949 browser(), 467 browser(),
950 GURL(chrome::kChromeUINewTabURL), 468 GURL(chrome::kChromeUINewTabURL),
951 NEW_FOREGROUND_TAB, 469 NEW_FOREGROUND_TAB,
952 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 470 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
953 471
954 // Omnibox should have focus. 472 // Omnibox should have focus.
955 EXPECT_TRUE(omnibox()->model()->has_focus()); 473 EXPECT_TRUE(omnibox()->model()->has_focus());
956 } 474 }
957 475
958 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { 476 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
959 // Setup Instant. 477 // Setup Instant.
960 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 478 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
961 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 479 FocusOmniboxAndWaitForInstantNTPSupport();
962 480
963 // Open new tab. Preloaded NTP contents should have been used. 481 // Open new tab. Preloaded NTP contents should have been used.
964 ui_test_utils::NavigateToURLWithDisposition( 482 ui_test_utils::NavigateToURLWithDisposition(
965 browser(), 483 browser(),
966 GURL(chrome::kChromeUINewTabURL), 484 GURL(chrome::kChromeUINewTabURL),
967 NEW_FOREGROUND_TAB, 485 NEW_FOREGROUND_TAB,
968 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 486 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
969 487
970 // Omnibox should be empty. 488 // Omnibox should be empty.
971 EXPECT_TRUE(omnibox()->GetText().empty()); 489 EXPECT_TRUE(omnibox()->GetText().empty());
972 } 490 }
973 491
974 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) { 492 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) {
975 // Setup Instant. 493 // Setup Instant.
976 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 494 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
977 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 495 FocusOmniboxAndWaitForInstantNTPSupport();
978 496
979 // Open new tab. Preloaded NTP contents should have been used. 497 // Open new tab. Preloaded NTP contents should have been used.
980 ui_test_utils::NavigateToURLWithDisposition( 498 ui_test_utils::NavigateToURLWithDisposition(
981 browser(), 499 browser(),
982 GURL(chrome::kChromeUINewTabURL), 500 GURL(chrome::kChromeUINewTabURL),
983 NEW_FOREGROUND_TAB, 501 NEW_FOREGROUND_TAB,
984 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 502 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
985 503
986 // No favicon should be shown. 504 // No favicon should be shown.
987 content::WebContents* active_tab = 505 content::WebContents* active_tab =
988 browser()->tab_strip_model()->GetActiveWebContents(); 506 browser()->tab_strip_model()->GetActiveWebContents();
989 FaviconTabHelper* favicon_tab_helper = 507 FaviconTabHelper* favicon_tab_helper =
990 FaviconTabHelper::FromWebContents(active_tab); 508 FaviconTabHelper::FromWebContents(active_tab);
991 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); 509 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon());
992 510
993 // Favicon should be shown off the NTP. 511 // Favicon should be shown off the NTP.
994 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 512 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
995 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 513 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
996 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); 514 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab);
997 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); 515 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon());
998 } 516 }
999 517
1000 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
1001 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1002
1003 // Focus omnibox and confirm overlay isn't shown.
1004 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1005 content::WebContents* overlay = instant()->GetOverlayContents();
1006 EXPECT_TRUE(overlay);
1007 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1008 EXPECT_TRUE(instant()->model()->mode().is_default());
1009
1010 // Navigate to the NTP. Should use preloaded contents.
1011 ui_test_utils::NavigateToURLWithDisposition(
1012 browser(),
1013 GURL(chrome::kChromeUINewTabURL),
1014 CURRENT_TAB,
1015 ui_test_utils::BROWSER_TEST_NONE);
1016
1017 // Typing in the omnibox should not show the overlay.
1018 SetOmniboxText("query");
1019 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1020 EXPECT_TRUE(instant()->model()->mode().is_default());
1021 }
1022
1023 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { 518 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
1024 // Prior to setup, Instant has an overlay with a failed "google.com" load in 519 // Prior to setup, Instant has an ntp with a failed "google.com" load in
1025 // it, which is rendered in the dedicated Instant renderer process. 520 // it, which is rendered in the dedicated Instant renderer process.
1026 // 521 //
1027 // TODO(sreeram): Fix this up when we stop doing crazy things on init. 522 // TODO(sreeram): Fix this up when we stop doing crazy things on init.
1028 InstantService* instant_service = 523 InstantService* instant_service =
1029 InstantServiceFactory::GetForProfile(browser()->profile()); 524 InstantServiceFactory::GetForProfile(browser()->profile());
1030 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 525 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
1031 #if !defined(OS_MACOSX) 526 #if !defined(OS_MACOSX)
1032 // The failed "google.com" load is deleted, which sometimes leads to the 527 // The failed "google.com" load is deleted, which sometimes leads to the
1033 // process shutting down on Mac. 528 // process shutting down on Mac.
1034 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 529 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
1035 #endif 530 #endif
1036 531
1037 // Setup Instant. 532 // Setup Instant.
1038 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 533 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1039 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 534 FocusOmniboxAndWaitForInstantNTPSupport();
1040 535
1041 // The registered Instant render process should still exist. 536 // The registered Instant render process should still exist.
1042 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 537 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
1043 538 // And the Instant ntp should live inside it.
1044 // And the Instant overlay and ntp should live inside it.
1045 content::WebContents* overlay = instant()->GetOverlayContents();
1046 EXPECT_TRUE(instant_service->IsInstantProcess(
1047 overlay->GetRenderProcessHost()->GetID()));
1048 content::WebContents* ntp_contents = instant()->ntp_->contents(); 539 content::WebContents* ntp_contents = instant()->ntp_->contents();
1049 EXPECT_TRUE(instant_service->IsInstantProcess( 540 EXPECT_TRUE(instant_service->IsInstantProcess(
1050 ntp_contents->GetRenderProcessHost()->GetID())); 541 ntp_contents->GetRenderProcessHost()->GetID()));
1051 542
1052 // Navigating to the NTP should use the Instant render process. 543 // Navigating to the NTP should use the Instant render process.
1053 ui_test_utils::NavigateToURLWithDisposition( 544 ui_test_utils::NavigateToURLWithDisposition(
1054 browser(), 545 browser(),
1055 GURL(chrome::kChromeUINewTabURL), 546 GURL(chrome::kChromeUINewTabURL),
1056 CURRENT_TAB, 547 CURRENT_TAB,
1057 ui_test_utils::BROWSER_TEST_NONE); 548 ui_test_utils::BROWSER_TEST_NONE);
1058 content::WebContents* active_tab = 549 content::WebContents* active_tab =
1059 browser()->tab_strip_model()->GetActiveWebContents(); 550 browser()->tab_strip_model()->GetActiveWebContents();
1060 EXPECT_TRUE(instant_service->IsInstantProcess( 551 EXPECT_TRUE(instant_service->IsInstantProcess(
1061 active_tab->GetRenderProcessHost()->GetID())); 552 active_tab->GetRenderProcessHost()->GetID()));
1062 553
1063 // Navigating elsewhere should not use the Instant render process. 554 // Navigating elsewhere should not use the Instant render process.
1064 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 555 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
1065 EXPECT_FALSE(instant_service->IsInstantProcess( 556 EXPECT_FALSE(instant_service->IsInstantProcess(
1066 active_tab->GetRenderProcessHost()->GetID())); 557 active_tab->GetRenderProcessHost()->GetID()));
1067 } 558 }
1068 559
1069 // Test that a search query will not be displayed for navsuggest queries. 560 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) {
1070 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1071 SearchQueryNotDisplayedForNavsuggest) {
1072 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1073
1074 // The second argument indicates to use only the local overlay and NTP.
1075 instant()->SetInstantEnabled(true, true);
1076
1077 // Focus omnibox and confirm overlay isn't shown.
1078 FocusOmniboxAndWaitForInstantOverlaySupport();
1079
1080 // Typing in the omnibox should show the overlay.
1081 SetOmniboxText("face");
1082
1083 content::WebContents* overlay = instant()->GetOverlayContents();
1084
1085 // Add a navsuggest suggestion.
1086 instant()->SetSuggestions(
1087 overlay,
1088 std::vector<InstantSuggestion>(
1089 1,
1090 InstantSuggestion(ASCIIToUTF16("http://facemash.com/"),
1091 INSTANT_COMPLETE_NOW,
1092 INSTANT_SUGGESTION_URL,
1093 ASCIIToUTF16("face"),
1094 kNoMatchIndex)));
1095
1096 while (!omnibox()->model()->autocomplete_controller()->done()) {
1097 content::WindowedNotificationObserver autocomplete_observer(
1098 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
1099 content::NotificationService::AllSources());
1100 autocomplete_observer.Wait();
1101 }
1102
1103 EXPECT_TRUE(ExecuteScript(
1104 "var sorted = chrome.embeddedSearch.searchBox.nativeSuggestions.sort("
1105 "function (a,b) {"
1106 "return b.rankingData.relevance - a.rankingData.relevance;"
1107 "});"));
1108
1109 int suggestions_count = -1;
1110 EXPECT_TRUE(GetIntFromJS(
1111 overlay, "sorted.length", &suggestions_count));
1112 ASSERT_GT(suggestions_count, 0);
1113
1114 std::string type;
1115 EXPECT_TRUE(
1116 GetStringFromJS(overlay, "sorted[0].type", &type));
1117 ASSERT_EQ("navsuggest", type);
1118
1119 bool is_search;
1120 EXPECT_TRUE(GetBoolFromJS(
1121 overlay, "!!sorted[0].is_search", &is_search));
1122 EXPECT_FALSE(is_search);
1123 }
1124
1125 // Verification of fix for BUG=176365. Ensure that each Instant WebContents in
1126 // a tab uses a new BrowsingInstance, to avoid conflicts in the
1127 // NavigationController.
1128 // Flaky: http://crbug.com/177516
1129 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) {
1130 // Setup Instant.
1131 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1132 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1133
1134 // Check that the uncommited ntp page and uncommited overlay have unrelated
1135 // site instances.
1136 // TODO(sreeram): |ntp_| is going away, so this check can be removed in the
1137 // future.
1138 content::WebContents* overlay = instant()->GetOverlayContents();
1139 content::WebContents* ntp_contents = instant()->ntp_->contents();
1140 EXPECT_FALSE(overlay->GetSiteInstance()->IsRelatedSiteInstance(
1141 ntp_contents->GetSiteInstance()));
1142
1143 // Type a query and hit enter to get a results page. The overlay becomes the
1144 // active tab.
1145 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello"));
1146 EXPECT_EQ("hello", GetOmniboxText());
1147 browser()->window()->GetLocationBar()->AcceptInput();
1148 content::WebContents* first_active_tab =
1149 browser()->tab_strip_model()->GetActiveWebContents();
1150 EXPECT_EQ(first_active_tab, overlay);
1151 scoped_refptr<content::SiteInstance> first_site_instance =
1152 first_active_tab->GetSiteInstance();
1153 EXPECT_FALSE(first_site_instance->IsRelatedSiteInstance(
1154 ntp_contents->GetSiteInstance()));
1155
1156 // Navigating elsewhere gets us off of the commited page. The next
1157 // query will give us a new |overlay| which we will then commit.
1158 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
1159
1160 // Show and commit the new overlay.
1161 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("hello again"));
1162 EXPECT_EQ("hello again", GetOmniboxText());
1163 browser()->window()->GetLocationBar()->AcceptInput();
1164 content::WebContents* second_active_tab =
1165 browser()->tab_strip_model()->GetActiveWebContents();
1166 EXPECT_NE(first_active_tab, second_active_tab);
1167 scoped_refptr<content::SiteInstance> second_site_instance =
1168 second_active_tab->GetSiteInstance();
1169 EXPECT_NE(first_site_instance, second_site_instance);
1170 EXPECT_FALSE(
1171 first_site_instance->IsRelatedSiteInstance(second_site_instance.get()));
1172 }
1173
1174 // Tests that suggestions are sanity checked.
1175 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) {
1176 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1177 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1178
1179 // Do not set gray text that is not a suffix of the query.
1180 EXPECT_TRUE(ExecuteScript("suggestion = 'potato';"
1181 "behavior = 2;"));
1182 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1183 EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText());
1184 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
1185
1186 omnibox()->RevertAll();
1187
1188 // Do not set blue text that is not a valid URL completion.
1189 EXPECT_TRUE(ExecuteScript("suggestion = 'this is not a url!';"
1190 "behavior = 1;"));
1191 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("this is"));
1192 EXPECT_EQ(ASCIIToUTF16("this is"), omnibox()->GetText());
1193 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
1194
1195 omnibox()->RevertAll();
1196
1197 // Do not set gray text when blue text is already set.
1198 // First set up some blue text completion.
1199 EXPECT_TRUE(ExecuteScript("suggestion = 'www.example.com';"
1200 "behavior = 1;"));
1201 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("http://www.ex"));
1202 EXPECT_EQ(ASCIIToUTF16("http://www.example.com"), omnibox()->GetText());
1203 EXPECT_EQ(ASCIIToUTF16("ample.com"), GetBlueText());
1204
1205 // Now try to set gray text for the same query.
1206 EXPECT_TRUE(ExecuteScript("suggestion = 'www.example.com rocks';"
1207 "behavior = 2;"));
1208 SetOmniboxText("http://www.ex");
1209 EXPECT_EQ(ASCIIToUTF16("http://www.example.com"), omnibox()->GetText());
1210 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
1211
1212 omnibox()->RevertAll();
1213
1214 // Ignore an out-of-date blue text suggestion. (Simulates a laggy
1215 // SetSuggestion IPC by directly calling into InstantController.)
1216 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("http://www.example.com/"));
1217 instant()->SetSuggestions(
1218 instant()->overlay()->contents(),
1219 std::vector<InstantSuggestion>(
1220 1,
1221 InstantSuggestion(ASCIIToUTF16("www.exa"),
1222 INSTANT_COMPLETE_NOW,
1223 INSTANT_SUGGESTION_URL,
1224 ASCIIToUTF16("www.exa"),
1225 kNoMatchIndex)));
1226 EXPECT_EQ(
1227 "http://www.example.com/",
1228 omnibox()->model()->result().default_match()->destination_url.spec());
1229
1230 omnibox()->RevertAll();
1231
1232 // TODO(samarth): uncomment after fixing crbug.com/191656.
1233 // Use an out-of-date blue text suggestion, if the text typed by the user is
1234 // contained in the suggestion.
1235 // ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("ex"));
1236 // instant()->SetSuggestions(
1237 // instant()->overlay()->contents(),
1238 // std::vector<InstantSuggestion>(
1239 // 1,
1240 // InstantSuggestion(ASCIIToUTF16("www.example.com"),
1241 // INSTANT_COMPLETE_NOW,
1242 // INSTANT_SUGGESTION_URL,
1243 // ASCIIToUTF16("e"))));
1244 // EXPECT_EQ(
1245 // "http://www.example.com/",
1246 // omnibox()->model()->result().default_match()->destination_url.spec());
1247
1248 // omnibox()->RevertAll();
1249
1250 // When asked to suggest blue text in verbatim mode, suggest the exact
1251 // omnibox text rather than using the supplied suggestion text.
1252 EXPECT_TRUE(ExecuteScript("suggestion = 'www.example.com/q';"
1253 "behavior = 1;"));
1254 SetOmniboxText("www.example.com/q");
1255 omnibox()->OnBeforePossibleChange();
1256 SetOmniboxText("www.example.com/");
1257 omnibox()->OnAfterPossibleChange();
1258 EXPECT_EQ(ASCIIToUTF16("www.example.com/"), omnibox()->GetText());
1259 }
1260
1261 // Tests that a previous navigation suggestion is not discarded if it's not
1262 // stale.
1263 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1264 NavigationSuggestionIsNotDiscarded) {
1265 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1266 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1267
1268 // Tell the page to send a URL suggestion.
1269 EXPECT_TRUE(ExecuteScript("suggestion = 'http://www.example.com';"
1270 "behavior = 1;"));
1271 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("exa"));
1272 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText());
1273 SetOmniboxText("exam");
1274 EXPECT_EQ(ASCIIToUTF16("example.com"), omnibox()->GetText());
1275
1276 // TODO(jered): Remove this after fixing OnBlur().
1277 omnibox()->RevertAll();
1278 }
1279
1280 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) {
1281 content::WindowedNotificationObserver observer( 561 content::WindowedNotificationObserver observer(
1282 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 562 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1283 content::NotificationService::AllSources()); 563 content::NotificationService::AllSources());
1284 // Initialize Instant. 564 // Initialize Instant.
1285 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 565 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1286 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 566 FocusOmniboxAndWaitForInstantNTPSupport();
1287 567
1288 // Get a handle to the NTP and the current state of the JS. 568 // Get a handle to the NTP and the current state of the JS.
1289 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 569 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
1290 content::WebContents* overlay = instant()->ntp_->contents(); 570 content::WebContents* ntp = instant()->ntp_->contents();
1291 EXPECT_TRUE(overlay); 571 EXPECT_TRUE(ntp);
1292 EXPECT_TRUE(UpdateSearchState(overlay)); 572 EXPECT_TRUE(UpdateSearchState(ntp));
1293 573
1294 // Wait for most visited data to be ready, if necessary. 574 // Wait for most visited data to be ready, if necessary.
1295 if (on_most_visited_change_calls_ == 0) { 575 if (on_most_visited_change_calls_ == 0) {
1296 observer.Wait(); 576 observer.Wait();
1297 EXPECT_TRUE(UpdateSearchState(overlay)); 577 EXPECT_TRUE(UpdateSearchState(ntp));
1298 } 578 }
1299 579
1300 EXPECT_EQ(1, on_most_visited_change_calls_); 580 EXPECT_EQ(1, on_most_visited_change_calls_);
1301 581
1302 // Make sure we have at least two Most Visited Items and save that number. 582 // Make sure we have at least two Most Visited Items and save that number.
1303 // TODO(pedrosimonetti): For now, we're relying on the fact that the Top 583 // TODO(pedrosimonetti): For now, we're relying on the fact that the Top
1304 // Sites will have at lease two items in it. The correct approach would be 584 // Sites will have at lease two items in it. The correct approach would be
1305 // adding those items to the Top Sites manually before starting the test. 585 // adding those items to the Top Sites manually before starting the test.
1306 EXPECT_GT(most_visited_items_count_, 1); 586 EXPECT_GT(most_visited_items_count_, 1);
1307 int old_most_visited_items_count = most_visited_items_count_; 587 int old_most_visited_items_count = most_visited_items_count_;
1308 588
1309 // Delete the fist Most Visited Item. 589 // Delete the fist Most Visited Item.
1310 int rid = first_most_visited_item_id_; 590 int rid = first_most_visited_item_id_;
1311 std::ostringstream stream; 591 std::ostringstream stream;
1312 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 592 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
1313 EXPECT_TRUE(ExecuteScript(stream.str())); 593 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str()));
1314 observer.Wait(); 594 observer.Wait();
1315 595
1316 // Update Most Visited state. 596 // Update Most Visited state.
1317 EXPECT_TRUE(UpdateSearchState(overlay)); 597 EXPECT_TRUE(UpdateSearchState(ntp));
1318 598
1319 // Make sure we have one less item in there. 599 // Make sure we have one less item in there.
1320 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 1); 600 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 1);
1321 601
1322 // Undo the deletion of the fist Most Visited Item. 602 // Undo the deletion of the fist Most Visited Item.
1323 stream.str(std::string()); 603 stream.str(std::string());
1324 stream << "newTabPageHandle.undoMostVisitedDeletion(" << rid << ");"; 604 stream << "newTabPageHandle.undoMostVisitedDeletion(" << rid << ");";
1325 EXPECT_TRUE(ExecuteScript(stream.str())); 605 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str()));
1326 observer.Wait(); 606 observer.Wait();
1327 607
1328 // Update Most Visited state. 608 // Update Most Visited state.
1329 EXPECT_TRUE(UpdateSearchState(overlay)); 609 EXPECT_TRUE(UpdateSearchState(ntp));
1330 610
1331 // Make sure we have the same number of items as before. 611 // Make sure we have the same number of items as before.
1332 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); 612 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count);
1333 613
1334 // Delete the fist Most Visited Item. 614 // Delete the fist Most Visited Item.
1335 rid = first_most_visited_item_id_; 615 rid = first_most_visited_item_id_;
1336 stream.str(std::string()); 616 stream.str(std::string());
1337 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 617 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
1338 EXPECT_TRUE(ExecuteScript(stream.str())); 618 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str()));
1339 observer.Wait(); 619 observer.Wait();
1340 620
1341 // Update Most Visited state. 621 // Update Most Visited state.
1342 EXPECT_TRUE(UpdateSearchState(overlay)); 622 EXPECT_TRUE(UpdateSearchState(ntp));
1343 623
1344 // Delete the second Most Visited Item. 624 // Delete the second Most Visited Item.
1345 rid = first_most_visited_item_id_; 625 rid = first_most_visited_item_id_;
1346 stream.str(std::string()); 626 stream.str(std::string());
1347 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 627 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
1348 EXPECT_TRUE(ExecuteScript(stream.str())); 628 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str()));
1349 observer.Wait(); 629 observer.Wait();
1350 630
1351 // Update Most Visited state. 631 // Update Most Visited state.
1352 EXPECT_TRUE(UpdateSearchState(overlay)); 632 EXPECT_TRUE(UpdateSearchState(ntp));
1353 633
1354 // Make sure we have two less items in there. 634 // Make sure we have two less items in there.
1355 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 2); 635 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 2);
1356 636
1357 // Delete the second Most Visited Item. 637 // Delete the second Most Visited Item.
1358 stream.str(std::string()); 638 stream.str(std::string());
1359 stream << "newTabPageHandle.undoAllMostVisitedDeletions();"; 639 stream << "newTabPageHandle.undoAllMostVisitedDeletions();";
1360 EXPECT_TRUE(ExecuteScript(stream.str())); 640 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str()));
1361 observer.Wait(); 641 observer.Wait();
1362 642
1363 // Update Most Visited state. 643 // Update Most Visited state.
1364 EXPECT_TRUE(UpdateSearchState(overlay)); 644 EXPECT_TRUE(UpdateSearchState(ntp));
1365 645
1366 // Make sure we have the same number of items as before. 646 // Make sure we have the same number of items as before.
1367 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); 647 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count);
1368 } 648 }
1369 649
1370 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { 650 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) {
1371 InstallThemeSource(); 651 InstallThemeSource();
1372 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); 652 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
1373 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 653 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1374 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 654 FocusOmniboxAndWaitForInstantNTPSupport();
1375 655
1376 // The "Instant" New Tab should have access to chrome-search: scheme but not 656 // The "Instant" New Tab should have access to chrome-search: scheme but not
1377 // chrome: scheme. 657 // chrome: scheme.
1378 ui_test_utils::NavigateToURLWithDisposition( 658 ui_test_utils::NavigateToURLWithDisposition(
1379 browser(), 659 browser(),
1380 GURL(chrome::kChromeUINewTabURL), 660 GURL(chrome::kChromeUINewTabURL),
1381 NEW_FOREGROUND_TAB, 661 NEW_FOREGROUND_TAB,
1382 ui_test_utils::BROWSER_TEST_NONE); 662 ui_test_utils::BROWSER_TEST_NONE);
1383 663
1384 content::RenderViewHost* rvh = 664 content::RenderViewHost* rvh =
(...skipping 12 matching lines...) Expand all
1397 // TODO(dhollowa): Fix flakes. http://crbug.com/179930. 677 // TODO(dhollowa): Fix flakes. http://crbug.com/179930.
1398 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) { 678 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) {
1399 // Create a favicon. 679 // Create a favicon.
1400 history::TopSites* top_sites = browser()->profile()->GetTopSites(); 680 history::TopSites* top_sites = browser()->profile()->GetTopSites();
1401 GURL url("http://www.google.com/foo.html"); 681 GURL url("http://www.google.com/foo.html");
1402 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); 682 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE));
1403 ThumbnailScore high_score(0.0, true, true, base::Time::Now()); 683 ThumbnailScore high_score(0.0, true, true, base::Time::Now());
1404 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); 684 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score));
1405 685
1406 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 686 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1407 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 687 FocusOmniboxAndWaitForInstantNTPSupport();
1408 688
1409 // The "Instant" New Tab should have access to chrome-search: scheme but not 689 // The "Instant" New Tab should have access to chrome-search: scheme but not
1410 // chrome: scheme. 690 // chrome: scheme.
1411 ui_test_utils::NavigateToURLWithDisposition( 691 ui_test_utils::NavigateToURLWithDisposition(
1412 browser(), 692 browser(),
1413 GURL(chrome::kChromeUINewTabURL), 693 GURL(chrome::kChromeUINewTabURL),
1414 NEW_FOREGROUND_TAB, 694 NEW_FOREGROUND_TAB,
1415 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 695 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1416 696
1417 content::RenderViewHost* rvh = 697 content::RenderViewHost* rvh =
1418 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); 698 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost();
1419 699
1420 // Get the favicons. 700 // Get the favicons.
1421 const std::string chrome_favicon_url( 701 const std::string chrome_favicon_url(
1422 "chrome://favicon/largest/http://www.google.com/foo.html"); 702 "chrome://favicon/largest/http://www.google.com/foo.html");
1423 const std::string search_favicon_url( 703 const std::string search_favicon_url(
1424 "chrome-search://favicon/largest/http://www.google.com/foo.html"); 704 "chrome-search://favicon/largest/http://www.google.com/foo.html");
1425 bool loaded = false; 705 bool loaded = false;
1426 ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded)); 706 ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded));
1427 EXPECT_FALSE(loaded) << chrome_favicon_url; 707 EXPECT_FALSE(loaded) << chrome_favicon_url;
1428 ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded)); 708 ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded));
1429 EXPECT_TRUE(loaded) << search_favicon_url; 709 EXPECT_TRUE(loaded) << search_favicon_url;
1430 } 710 }
1431 711
712 // Only implemented in Views and Mac currently: http://crbug.com/164723
713 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
714 #define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin
715 #else
716 #define MAYBE_HomeButtonAffectsMargin DISABLED_HomeButtonAffectsMargin
717 #endif
718
719 // Check that toggling the state of the home button changes the start-edge
720 // margin and width.
721 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) {
722 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
723 FocusOmniboxAndWaitForInstantNTPSupport();
724
725 // Get the current value of the start-edge margin and width.
726 int start_margin;
727 int width;
728 content::WebContents* ntp = instant()->ntp_->contents();
729 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.startMargin", &start_margin));
730 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.width", &width));
731
732 // Toggle the home button visibility pref.
733 PrefService* profile_prefs = browser()->profile()->GetPrefs();
734 bool show_home = profile_prefs->GetBoolean(prefs::kShowHomeButton);
735 profile_prefs->SetBoolean(prefs::kShowHomeButton, !show_home);
736
737 // Make sure the margin and width changed.
738 int new_start_margin;
739 int new_width;
740 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.startMargin",
741 &new_start_margin));
742 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.width", &new_width));
743 EXPECT_NE(start_margin, new_start_margin);
744 EXPECT_NE(width, new_width);
745 EXPECT_EQ(new_width - width, start_margin - new_start_margin);
746 }
747
1432 // WebUIBindings should never be enabled on ANY Instant web contents. 748 // WebUIBindings should never be enabled on ANY Instant web contents.
1433 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnNTP) { 749 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnNTP) {
1434 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 750 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1435 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 751 FocusOmniboxAndWaitForInstantNTPSupport();
1436 752
1437 ui_test_utils::NavigateToURLWithDisposition( 753 ui_test_utils::NavigateToURLWithDisposition(
1438 browser(), 754 browser(),
1439 GURL(chrome::kChromeUINewTabURL), 755 GURL(chrome::kChromeUINewTabURL),
1440 NEW_FOREGROUND_TAB, 756 NEW_FOREGROUND_TAB,
1441 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 757 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1442 const content::WebContents* tab = 758 const content::WebContents* tab =
1443 browser()->tab_strip_model()->GetActiveWebContents(); 759 browser()->tab_strip_model()->GetActiveWebContents();
1444 760
1445 // Instant-provided NTP should not have any bindings enabled. 761 // Instant-provided NTP should not have any bindings enabled.
1446 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); 762 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings());
1447 } 763 }
1448 764
1449 // WebUIBindings should never be enabled on ANY Instant web contents. 765 // WebUIBindings should never be enabled on ANY Instant web contents.
1450 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnPreview) {
1451 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1452 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1453
1454 // Typing in the omnibox shows the overlay.
1455 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1456 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
1457 content::WebContents* preview = instant()->GetOverlayContents();
1458 ASSERT_NE(static_cast<content::WebContents*>(NULL), preview);
1459
1460 // Instant preview should not have any bindings enabled.
1461 EXPECT_EQ(0, preview->GetRenderViewHost()->GetEnabledBindings());
1462 }
1463
1464 // WebUIBindings should never be enabled on ANY Instant web contents.
1465 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnResults) { 766 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnResults) {
1466 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 767 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1467 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 768 FocusOmniboxAndWaitForInstantNTPSupport();
1468 769
1469 // Typing in the omnibox shows the overlay. 770 // Type a query and press enter to get results.
1470 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query")); 771 SetOmniboxText("query");
1471 content::WebContents* preview = instant()->GetOverlayContents();
1472 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
1473 // Commit the search by pressing Enter. 772 // Commit the search by pressing Enter.
1474 browser()->window()->GetLocationBar()->AcceptInput(); 773 browser()->window()->GetLocationBar()->AcceptInput();
1475 EXPECT_TRUE(instant()->model()->mode().is_default()); 774 EXPECT_TRUE(instant()->model()->mode().is_default());
1476 const content::WebContents* tab = 775 const content::WebContents* tab =
1477 browser()->tab_strip_model()->GetActiveWebContents(); 776 browser()->tab_strip_model()->GetActiveWebContents();
1478 EXPECT_EQ(preview, tab);
1479 777
1480 // The commited Instant page should not have any bindings enabled. 778 // The commited Instant page should not have any bindings enabled.
1481 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); 779 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings());
1482 } 780 }
1483 781
1484 // Only implemented in Views and Mac currently: http://crbug.com/164723
1485 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
1486 #define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin
1487 #else
1488 #define MAYBE_HomeButtonAffectsMargin DISABLED_HomeButtonAffectsMargin
1489 #endif
1490 // Check that toggling the state of the home button changes the start-edge
1491 // margin and width.
1492 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) {
1493 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1494 FocusOmniboxAndWaitForInstantOverlaySupport();
1495
1496 // Get the current value of the start-edge margin and width.
1497 int start_margin;
1498 int width;
1499 content::WebContents* overlay = instant()->GetOverlayContents();
1500 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin",
1501 &start_margin));
1502 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &width));
1503
1504 // Toggle the home button visibility pref.
1505 PrefService* profile_prefs = browser()->profile()->GetPrefs();
1506 bool show_home = profile_prefs->GetBoolean(prefs::kShowHomeButton);
1507 profile_prefs->SetBoolean(prefs::kShowHomeButton, !show_home);
1508
1509 // Make sure the margin and width changed.
1510 int new_start_margin;
1511 int new_width;
1512 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin",
1513 &new_start_margin));
1514 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &new_width));
1515 EXPECT_NE(start_margin, new_start_margin);
1516 EXPECT_NE(width, new_width);
1517 EXPECT_EQ(new_width - width, start_margin - new_start_margin);
1518 }
1519
1520 // Commit does not happen on Mac: http://crbug.com/178520
1521 #if defined(OS_MACOSX)
1522 #define MAYBE_CommitWhenFocusLostInFullHeight \
1523 DISABLED_CommitWhenFocusLostInFullHeight
1524 #else
1525 #define MAYBE_CommitWhenFocusLostInFullHeight CommitWhenFocusLostInFullHeight
1526 #endif
1527 // Test that the overlay is committed when the omnibox loses focus when it is
1528 // shown at 100% height.
1529 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1530 MAYBE_CommitWhenFocusLostInFullHeight) {
1531 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1532
1533 // Focus omnibox and confirm overlay isn't shown.
1534 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1535 content::WebContents* overlay = instant()->GetOverlayContents();
1536 EXPECT_TRUE(overlay);
1537 EXPECT_TRUE(instant()->model()->mode().is_default());
1538 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1539
1540 // Typing in the omnibox should show the overlay.
1541 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1542 EXPECT_TRUE(instant()->IsOverlayingSearchResults());
1543 EXPECT_EQ(overlay, instant()->GetOverlayContents());
1544
1545 // Explicitly unfocus the omnibox without triggering a click. Note that this
1546 // doesn't actually change the focus state of the omnibox, only what the
1547 // Instant controller sees it as.
1548 omnibox()->model()->OnWillKillFocus(NULL);
1549 omnibox()->model()->OnKillFocus();
1550
1551 // Confirm that the overlay has been committed.
1552 content::WebContents* active_tab =
1553 browser()->tab_strip_model()->GetActiveWebContents();
1554 EXPECT_EQ(overlay, active_tab);
1555 }
1556
1557 #if defined(OS_MACOSX)
1558 // http://crbug.com/227076
1559 #define MAYBE_CommitWhenShownInFullHeightWithoutFocus \
1560 DISABLED_CommitWhenShownInFullHeightWithoutFocus
1561 #else
1562 #define MAYBE_CommitWhenShownInFullHeightWithoutFocus \
1563 CommitWhenShownInFullHeightWithoutFocus
1564 #endif
1565
1566 // Test that the overlay is committed when shown at 100% height without focus
1567 // in the omnibox.
1568 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1569 MAYBE_CommitWhenShownInFullHeightWithoutFocus) {
1570 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1571
1572 // Focus omnibox and confirm overlay isn't shown.
1573 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1574 content::WebContents* overlay = instant()->GetOverlayContents();
1575 EXPECT_TRUE(overlay);
1576 EXPECT_TRUE(instant()->model()->mode().is_default());
1577 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1578
1579 // Create an observer to wait for the commit.
1580 content::WindowedNotificationObserver commit_observer(
1581 chrome::NOTIFICATION_INSTANT_COMMITTED,
1582 content::NotificationService::AllSources());
1583
1584 // Create an observer to wait for the autocomplete.
1585 content::WindowedNotificationObserver autocomplete_observer(
1586 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
1587 content::NotificationService::AllSources());
1588
1589 // Typing in the omnibox should show the overlay. Don't wait for the overlay
1590 // to show however.
1591 SetOmniboxText("query");
1592
1593 autocomplete_observer.Wait();
1594
1595 // Explicitly unfocus the omnibox without triggering a click. Note that this
1596 // doesn't actually change the focus state of the omnibox, only what the
1597 // Instant controller sees it as.
1598 omnibox()->model()->OnWillKillFocus(NULL);
1599 omnibox()->model()->OnKillFocus();
1600
1601 // Wait for the overlay to show.
1602 commit_observer.Wait();
1603
1604 // Confirm that the overlay has been committed.
1605 content::WebContents* active_tab =
1606 browser()->tab_strip_model()->GetActiveWebContents();
1607 EXPECT_EQ(overlay, active_tab);
1608 }
1609
1610 // Test that a transient entry is set properly when the overlay is committed
1611 // without a navigation.
1612 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, TransientEntrySet) {
1613 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1614
1615 // Focus omnibox and confirm overlay isn't shown.
1616 FocusOmniboxAndWaitForInstantOverlaySupport();
1617 content::WebContents* overlay = instant()->GetOverlayContents();
1618 EXPECT_TRUE(overlay);
1619 EXPECT_TRUE(instant()->model()->mode().is_default());
1620 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1621
1622 // Commit the overlay without triggering a navigation.
1623 content::WindowedNotificationObserver observer(
1624 chrome::NOTIFICATION_INSTANT_COMMITTED,
1625 content::NotificationService::AllSources());
1626 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1627 browser()->window()->GetLocationBar()->AcceptInput();
1628 observer.Wait();
1629
1630 // Confirm that the overlay has been committed.
1631 content::WebContents* active_tab =
1632 browser()->tab_strip_model()->GetActiveWebContents();
1633 EXPECT_EQ(overlay, active_tab);
1634
1635 // The page hasn't navigated so there should be a transient entry with the
1636 // same URL but different page ID as the last committed entry.
1637 const content::NavigationEntry* transient_entry =
1638 active_tab->GetController().GetTransientEntry();
1639 const content::NavigationEntry* committed_entry =
1640 active_tab->GetController().GetLastCommittedEntry();
1641 EXPECT_EQ(transient_entry->GetURL(), committed_entry->GetURL());
1642 EXPECT_NE(transient_entry->GetPageID(), committed_entry->GetPageID());
1643 }
1644
1645 // Test that the a transient entry is cleared when the overlay is committed
1646 // with a navigation.
1647 // TODO(samarth) : this test fails, http://crbug.com/181070.
1648 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_TransientEntryRemoved) {
1649 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1650
1651 // Focus omnibox and confirm overlay isn't shown.
1652 FocusOmniboxAndWaitForInstantOverlaySupport();
1653 content::WebContents* overlay = instant()->GetOverlayContents();
1654 EXPECT_TRUE(overlay);
1655 EXPECT_TRUE(instant()->model()->mode().is_default());
1656 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
1657
1658 // Create an observer to wait for the commit.
1659 content::WindowedNotificationObserver observer(
1660 chrome::NOTIFICATION_INSTANT_COMMITTED,
1661 content::NotificationService::AllSources());
1662
1663 // Trigger a navigation on commit.
1664 EXPECT_TRUE(ExecuteScript(
1665 "getApiHandle().oncancel = function() {"
1666 " location.replace(location.href + '#q=query');"
1667 "};"
1668 ));
1669
1670 // Commit the overlay.
1671 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1672 browser()->window()->GetLocationBar()->AcceptInput();
1673 observer.Wait();
1674
1675 // Confirm that the overlay has been committed.
1676 content::WebContents* active_tab =
1677 browser()->tab_strip_model()->GetActiveWebContents();
1678 EXPECT_EQ(overlay, active_tab);
1679
1680 // The page has navigated so there should be no transient entry.
1681 const content::NavigationEntry* transient_entry =
1682 active_tab->GetController().GetTransientEntry();
1683 EXPECT_EQ(NULL, transient_entry);
1684
1685 // The last committed entry should be the URL the page navigated to.
1686 const content::NavigationEntry* committed_entry =
1687 active_tab->GetController().GetLastCommittedEntry();
1688 EXPECT_TRUE(EndsWith(committed_entry->GetURL().spec(), "#q=query", true));
1689 }
1690
1691 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, RestrictedURLReading) {
1692 std::string search_query;
1693 bool is_undefined;
1694 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1695 FocusOmniboxAndWaitForInstantOverlaySupport();
1696
1697 // Verify we can read out something ok.
1698 const char kOKQuery[] = "santa";
1699 SetOmniboxText(kOKQuery);
1700 EXPECT_EQ(ASCIIToUTF16(kOKQuery), omnibox()->GetText());
1701 // Must always assert the value is defined before trying to read it, as trying
1702 // to read undefined values causes the test to hang.
1703 EXPECT_TRUE(GetBoolFromJS(instant()->GetOverlayContents(),
1704 "apiHandle.value === undefined",
1705 &is_undefined));
1706 ASSERT_FALSE(is_undefined);
1707 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
1708 "apiHandle.value",
1709 &search_query));
1710 EXPECT_EQ(kOKQuery, search_query);
1711
1712 // Verify we can't read out something that should be restricted, like a https
1713 // url with a path.
1714 const char kHTTPSUrlWithPath[] = "https://www.example.com/foobar";
1715 SetOmniboxText(kHTTPSUrlWithPath);
1716 EXPECT_EQ(ASCIIToUTF16(kHTTPSUrlWithPath), omnibox()->GetText());
1717 EXPECT_TRUE(GetBoolFromJS(instant()->GetOverlayContents(),
1718 "apiHandle.value === undefined",
1719 &is_undefined));
1720 EXPECT_TRUE(is_undefined);
1721 }
1722
1723 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, RestrictedItemReadback) {
1724 // Initialize Instant.
1725 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1726 FocusOmniboxAndWaitForInstantOverlaySupport();
1727
1728 // Get a handle to the NTP and the current state of the JS.
1729 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
1730 content::WebContents* preview_tab = instant()->ntp()->contents();
1731 EXPECT_TRUE(preview_tab);
1732
1733 // Manufacture a few autocomplete results and get them down to the page.
1734 std::vector<InstantAutocompleteResult> autocomplete_results;
1735 for (int i = 0; i < 3; ++i) {
1736 std::string description(base::StringPrintf("Test Description %d", i));
1737 std::string url(base::StringPrintf("http://www.testurl%d.com", i));
1738
1739 InstantAutocompleteResult res;
1740 res.provider = ASCIIToUTF16(AutocompleteProvider::TypeToString(
1741 AutocompleteProvider::TYPE_BUILTIN));
1742 res.type = AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1743 res.description = ASCIIToUTF16(description);
1744 res.destination_url = ASCIIToUTF16(url);
1745 res.transition = content::PAGE_TRANSITION_TYPED;
1746 res.relevance = 42 + i;
1747
1748 autocomplete_results.push_back(res);
1749 }
1750 instant()->overlay()->SendAutocompleteResults(autocomplete_results);
1751
1752 // Apparently, one needs to access nativeSuggestions before
1753 // apiHandle.setRestrictedValue can work.
1754 EXPECT_TRUE(ExecuteScript("var foo = apiHandle.nativeSuggestions;"));
1755
1756 const char kQueryString[] = "Hippos go berzerk!";
1757
1758 // First set the query text to a non restricted value and ensure it can be
1759 // read back.
1760 std::ostringstream stream;
1761 stream << "apiHandle.setValue('" << kQueryString << "');";
1762 EXPECT_TRUE(ExecuteScript(stream.str()));
1763
1764 std::string query_string;
1765 bool is_undefined;
1766 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
1767 "apiHandle.value",
1768 &query_string));
1769 EXPECT_EQ(kQueryString, query_string);
1770
1771 // Set the query text to the first restricted autocomplete item.
1772 int rid = 1;
1773 stream.str(std::string());
1774 stream << "apiHandle.setRestrictedValue(" << rid << ");";
1775 EXPECT_TRUE(ExecuteScript(stream.str()));
1776
1777 // Expect that we now receive undefined when reading the value back.
1778 EXPECT_TRUE(GetBoolFromJS(
1779 instant()->GetOverlayContents(),
1780 "apiHandle.value === undefined",
1781 &is_undefined));
1782 EXPECT_TRUE(is_undefined);
1783
1784 // Now set the query text to a non restricted value and ensure that the
1785 // visibility has been reset and the string can again be read back.
1786 stream.str(std::string());
1787 stream << "apiHandle.setValue('" << kQueryString << "');";
1788 EXPECT_TRUE(ExecuteScript(stream.str()));
1789
1790 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
1791 "apiHandle.value",
1792 &query_string));
1793 EXPECT_EQ(kQueryString, query_string);
1794 }
1795
1796 // Test that autocomplete results are sent to the page only when all the
1797 // providers are done.
1798 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AutocompleteProvidersDone) {
1799 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1800 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1801
1802 content::WebContents* overlay = instant()->GetOverlayContents();
1803 EXPECT_TRUE(UpdateSearchState(overlay));
1804 EXPECT_EQ(0, on_native_suggestions_calls_);
1805
1806 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("railroad"));
1807
1808 EXPECT_EQ(overlay, instant()->GetOverlayContents());
1809 EXPECT_TRUE(UpdateSearchState(overlay));
1810 EXPECT_EQ(1, on_native_suggestions_calls_);
1811 }
1812
1813 // Test that the Bookmark provider is enabled, and returns results. 782 // Test that the Bookmark provider is enabled, and returns results.
1814 // TODO(sreeram): Convert this to a unit test. 783 // TODO(sreeram): Convert this to a unit test.
1815 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_HasBookmarkProvider) { 784 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_HasBookmarkProvider) {
1816 // No need to setup Instant. 785 // No need to setup Instant.
1817 set_browser(browser()); 786 set_browser(browser());
1818 787
1819 BookmarkModel* bookmark_model = 788 BookmarkModel* bookmark_model =
1820 BookmarkModelFactory::GetForProfile(browser()->profile()); 789 BookmarkModelFactory::GetForProfile(browser()->profile());
1821 ASSERT_TRUE(bookmark_model); 790 ASSERT_TRUE(bookmark_model);
1822 ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model); 791 ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model);
1823 bookmark_utils::AddIfNotBookmarked(bookmark_model, GURL("http://angeline/"), 792 bookmark_utils::AddIfNotBookmarked(bookmark_model, GURL("http://angeline/"),
1824 ASCIIToUTF16("angeline")); 793 ASCIIToUTF16("angeline"));
1825 794
1826 SetOmniboxText("angeline"); 795 SetOmniboxText("angeline");
1827 796
1828 bool found_bookmark_match = false; 797 bool found_bookmark_match = false;
1829 798
1830 const AutocompleteResult& result = omnibox()->model()->result(); 799 const AutocompleteResult& result = omnibox()->model()->result();
1831 for (AutocompleteResult::const_iterator iter = result.begin(); 800 for (AutocompleteResult::const_iterator iter = result.begin();
1832 !found_bookmark_match && iter != result.end(); ++iter) { 801 !found_bookmark_match && iter != result.end(); ++iter) {
1833 found_bookmark_match = iter->type == AutocompleteMatchType::BOOKMARK_TITLE; 802 found_bookmark_match = iter->type == AutocompleteMatchType::BOOKMARK_TITLE;
1834 } 803 }
1835 804
1836 EXPECT_TRUE(found_bookmark_match); 805 EXPECT_TRUE(found_bookmark_match);
1837 } 806 }
1838 807
1839 // Test that the omnibox's temporary text is reset when the popup is closed. 808 // Test that hitting Esc to clear the omnibox works. http://crbug.com/231744.
1840 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, TemporaryTextResetWhenPopupClosed) { 809 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_EscapeClearsOmnibox) {
1841 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 810 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1842 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 811 FocusOmniboxAndWaitForInstantNTPSupport();
1843 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1844
1845 // Show the overlay and arrow-down to a suggestion (this sets temporary text).
1846 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("juju"));
1847 SendDownArrow();
1848
1849 EXPECT_TRUE(HasTemporaryText());
1850 EXPECT_EQ("result 1", GetOmniboxText());
1851
1852 // Click outside the omnibox (but not on the overlay), to make the omnibox
1853 // lose focus. Close the popup explicitly, to workaround test/toolkit issues.
1854 ui_test_utils::ClickOnView(browser(), VIEW_ID_TOOLBAR);
1855 omnibox()->CloseOmniboxPopup();
1856
1857 // The temporary text should've been accepted as the user text.
1858 EXPECT_FALSE(HasTemporaryText());
1859 EXPECT_EQ("result 1", GetOmniboxText());
1860
1861 // Now refocus the omnibox and hit Escape. This shouldn't crash.
1862 FocusOmnibox();
1863 SendEscape();
1864
1865 // The omnibox should've reverted to the underlying permanent URL.
1866 EXPECT_FALSE(HasTemporaryText());
1867 EXPECT_EQ(std::string(content::kAboutBlankURL), GetOmniboxText());
1868 }
1869
1870 // Test that autocomplete results aren't sent when the popup is closed.
1871 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1872 NoAutocompleteResultsWhenPopupClosed) {
1873 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1874 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1875 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1876
1877 // Show the overlay and arrow-down to a suggestion (this sets temporary text).
1878 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("thangam"));
1879 SendDownArrow();
1880 EXPECT_TRUE(HasTemporaryText());
1881
1882 EXPECT_TRUE(ExecuteScript("onChangeCalls = onNativeSuggestionsCalls = 0;"));
1883
1884 content::WebContents* overlay = instant()->GetOverlayContents();
1885 EXPECT_TRUE(UpdateSearchState(overlay));
1886 EXPECT_EQ(0, on_change_calls_);
1887 EXPECT_EQ(0, on_native_suggestions_calls_);
1888
1889 // Click outside the omnibox (but not on the overlay), to make the omnibox
1890 // lose focus. Close the popup explicitly, to workaround test/toolkit issues.
1891 ui_test_utils::ClickOnView(browser(), VIEW_ID_TOOLBAR);
1892 omnibox()->CloseOmniboxPopup();
1893 EXPECT_FALSE(HasTemporaryText());
1894
1895 EXPECT_EQ(overlay, instant()->GetOverlayContents());
1896 EXPECT_TRUE(UpdateSearchState(overlay));
1897 EXPECT_EQ(0, on_change_calls_);
1898 EXPECT_EQ(0, on_native_suggestions_calls_);
1899 }
1900
1901 // Test that suggestions are not accepted when unexpected.
1902 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DeniesUnexpectedSuggestions) {
1903 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1904 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1905 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("chip"));
1906 SendDownArrow();
1907
1908 EXPECT_EQ("result 1", GetOmniboxText());
1909 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
1910
1911 // Make the page send an unexpected suggestion.
1912 EXPECT_TRUE(ExecuteScript("suggestion = 'chippies';"
1913 "handleOnChange();"));
1914
1915 // Verify that the suggestion is ignored.
1916 EXPECT_EQ("result 1", GetOmniboxText());
1917 EXPECT_EQ(ASCIIToUTF16(""), GetGrayText());
1918 }
1919
1920 // Test that autocomplete results are cleared when the query is cleared.
1921 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EmptyAutocompleteResults) {
1922 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1923 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1924
1925 // Type a URL, so that there's at least one autocomplete result (a "URL what
1926 // you typed" match).
1927 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("http://upsamina/"));
1928
1929 content::WebContents* overlay = instant()->GetOverlayContents();
1930
1931 int num_autocomplete_results = 0;
1932 EXPECT_TRUE(GetIntFromJS(
1933 overlay,
1934 "chrome.embeddedSearch.searchBox.nativeSuggestions.length",
1935 &num_autocomplete_results));
1936 EXPECT_LT(0, num_autocomplete_results);
1937
1938 // Erase the query in the omnibox.
1939 SetOmniboxText("");
1940
1941 EXPECT_TRUE(GetIntFromJS(
1942 overlay,
1943 "chrome.embeddedSearch.searchBox.nativeSuggestions.length",
1944 &num_autocomplete_results));
1945 EXPECT_EQ(0, num_autocomplete_results);
1946 }
1947
1948 // Test that hitting Esc to clear the omnibox works. http://crbug.com/231744.
1949 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EscapeClearsOmnibox) {
1950 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1951 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1952 812
1953 // Navigate to the Instant NTP, and wait for it to be recognized. 813 // Navigate to the Instant NTP, and wait for it to be recognized.
1954 content::WindowedNotificationObserver instant_tab_observer( 814 content::WindowedNotificationObserver instant_tab_observer(
1955 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 815 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1956 content::NotificationService::AllSources()); 816 content::NotificationService::AllSources());
1957 ui_test_utils::NavigateToURLWithDisposition( 817 ui_test_utils::NavigateToURLWithDisposition(
1958 browser(), 818 browser(),
1959 GURL(chrome::kChromeUINewTabURL), 819 GURL(chrome::kChromeUINewTabURL),
1960 NEW_FOREGROUND_TAB, 820 NEW_FOREGROUND_TAB,
1961 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 821 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
(...skipping 18 matching lines...) Expand all
1980 &query)); 840 &query));
1981 EXPECT_EQ("", query); 841 EXPECT_EQ("", query);
1982 EXPECT_EQ("", GetOmniboxText()); 842 EXPECT_EQ("", GetOmniboxText());
1983 843
1984 EXPECT_TRUE(UpdateSearchState(contents)); 844 EXPECT_TRUE(UpdateSearchState(contents));
1985 EXPECT_LT(0, on_change_calls_); 845 EXPECT_LT(0, on_change_calls_);
1986 EXPECT_EQ(0, submit_count_); 846 EXPECT_EQ(0, submit_count_);
1987 EXPECT_LT(0, on_esc_key_press_event_calls_); 847 EXPECT_LT(0, on_esc_key_press_event_calls_);
1988 } 848 }
1989 849
1990 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiRespondsToFocusChange) {
1991 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1992 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1993 EXPECT_FALSE(is_focused_);
1994 EXPECT_EQ(0, on_focus_changed_calls_);
1995
1996 // Focus the omnibox.
1997 FocusOmniboxAndWaitForInstantOverlaySupport();
1998 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
1999 EXPECT_TRUE(is_focused_);
2000 EXPECT_EQ(1, on_focus_changed_calls_);
2001
2002 // Now unfocus the omnibox.
2003 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
2004 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2005 EXPECT_FALSE(is_focused_);
2006 EXPECT_EQ(2, on_focus_changed_calls_);
2007
2008 // Focus the omnibox again.
2009 // The first focus may have worked only due to initial-state anomalies.
2010 FocusOmnibox();
2011 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2012 EXPECT_TRUE(is_focused_);
2013 EXPECT_EQ(3, on_focus_changed_calls_);
2014 }
2015
2016 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusApiIgnoresRedundantFocus) {
2017 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2018 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
2019 EXPECT_FALSE(is_focused_);
2020 EXPECT_EQ(0, on_focus_changed_calls_);
2021
2022 // Focus the Omnibox.
2023 FocusOmniboxAndWaitForInstantOverlaySupport();
2024 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2025 EXPECT_TRUE(is_focused_);
2026 EXPECT_EQ(1, on_focus_changed_calls_);
2027
2028 // When we focus the omnibox again, nothing should change.
2029 FocusOmnibox();
2030 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2031 EXPECT_TRUE(is_focused_);
2032 EXPECT_EQ(1, on_focus_changed_calls_);
2033
2034 // Now unfocus the omnibox.
2035 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
2036 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2037 EXPECT_FALSE(is_focused_);
2038 EXPECT_EQ(2, on_focus_changed_calls_);
2039
2040 // When we unfocus again, nothing should change.
2041 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
2042 ASSERT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2043 EXPECT_FALSE(is_focused_);
2044 EXPECT_EQ(2, on_focus_changed_calls_);
2045 }
2046
2047 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { 850 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
2048 InstantService* instant_service = 851 InstantService* instant_service =
2049 InstantServiceFactory::GetForProfile(browser()->profile()); 852 InstantServiceFactory::GetForProfile(browser()->profile());
2050 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 853 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
2051 854
2052 // Setup Instant. 855 // Setup Instant.
2053 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 856 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2054 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 857 FocusOmniboxAndWaitForInstantNTPSupport();
2055 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 858 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
2056 859
2057 // Navigating to the NTP should use the Instant render process. 860 // Navigating to the NTP should use the Instant render process.
2058 ui_test_utils::NavigateToURLWithDisposition( 861 ui_test_utils::NavigateToURLWithDisposition(
2059 browser(), 862 browser(),
2060 GURL(chrome::kChromeUINewTabURL), 863 GURL(chrome::kChromeUINewTabURL),
2061 CURRENT_TAB, 864 CURRENT_TAB,
2062 ui_test_utils::BROWSER_TEST_NONE); 865 ui_test_utils::BROWSER_TEST_NONE);
2063 content::WebContents* ntp_contents = 866 content::WebContents* ntp_contents =
2064 browser()->tab_strip_model()->GetActiveWebContents(); 867 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 observer.Wait(); 900 observer.Wait();
2098 901
2099 // |ntp_contents| should not use the Instant render process. 902 // |ntp_contents| should not use the Instant render process.
2100 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); 903 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents));
2101 EXPECT_FALSE(instant_service->IsInstantProcess( 904 EXPECT_FALSE(instant_service->IsInstantProcess(
2102 ntp_contents->GetRenderProcessHost()->GetID())); 905 ntp_contents->GetRenderProcessHost()->GetID()));
2103 // Make sure the URL remains the same. 906 // Make sure the URL remains the same.
2104 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); 907 EXPECT_EQ(ntp_url, ntp_contents->GetURL());
2105 } 908 }
2106 909
2107 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayRenderViewGone) {
2108 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2109 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2110 EXPECT_NE(static_cast<content::WebContents*>(NULL),
2111 instant()->GetOverlayContents());
2112
2113 // Overlay is not reloaded after being killed.
2114 EXPECT_FALSE(instant()->overlay()->IsLocal());
2115 instant()->InstantPageRenderViewGone(instant()->GetOverlayContents());
2116 EXPECT_EQ(NULL, instant()->GetOverlayContents());
2117
2118 // The local overlay is used on the next Update().
2119 SetOmniboxText("query");
2120 EXPECT_TRUE(instant()->overlay()->IsLocal());
2121
2122 // Switched back to the remote overlay when omnibox loses and regains focus.
2123 instant()->HideOverlay();
2124 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus();
2125 FocusOmnibox();
2126 EXPECT_FALSE(instant()->overlay()->IsLocal());
2127 }
2128
2129 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlayDoesntSupportInstant) {
2130 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
2131 InstantTestBase::Init(instant_url);
2132 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2133
2134 // Focus the omnibox. When the support determination response comes back,
2135 // Instant will destroy the non-Instant page and fall back to the local page.
2136 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2137 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2138 EXPECT_TRUE(instant()->overlay()->IsLocal());
2139
2140 // The local overlay is used on the next Update().
2141 SetOmniboxText("query");
2142 EXPECT_TRUE(instant()->overlay()->IsLocal());
2143
2144 // Switched back to the remote overlay when omnibox loses and regains focus.
2145 instant()->HideOverlay();
2146 browser()->tab_strip_model()->GetActiveWebContents()->GetView()->Focus();
2147 FocusOmnibox();
2148 EXPECT_FALSE(instant()->overlay()->IsLocal());
2149
2150 // Overlay falls back to local again after determining support.
2151 FocusOmniboxAndWaitForInstantOverlaySupport();
2152 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2153 EXPECT_TRUE(instant()->overlay()->IsLocal());
2154 }
2155
2156 // Test that if Instant alters the input from URL to search, it's respected.
2157 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromURLToSearch) {
2158 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2159 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2160
2161 content::WebContents* overlay = instant()->GetOverlayContents();
2162 EXPECT_TRUE(ExecuteScript("suggestions = ['mcqueen.com'];"));
2163
2164 SetOmniboxTextAndWaitForOverlayToShow("lightning");
2165 EXPECT_EQ("lightning", GetOmniboxText());
2166
2167 SendDownArrow();
2168 EXPECT_EQ("mcqueen.com", GetOmniboxText());
2169
2170 // Press Enter.
2171 browser()->window()->GetLocationBar()->AcceptInput();
2172
2173 // Confirm that the Instant overlay was committed.
2174 EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents());
2175 }
2176
2177 // Test that if Instant alters the input from search to URL, it's respected.
2178 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputChangedFromSearchToURL) {
2179 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2180 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2181
2182 content::WebContents* overlay = instant()->GetOverlayContents();
2183 EXPECT_TRUE(ExecuteScript("suggestionType = 1;")); // INSTANT_SUGGESTION_URL
2184
2185 SetOmniboxTextAndWaitForOverlayToShow("mack.com");
2186 EXPECT_EQ("mack.com", GetOmniboxText());
2187
2188 SendDownArrow();
2189 EXPECT_EQ("result 1", GetOmniboxText());
2190
2191 // Press Enter.
2192 browser()->window()->GetLocationBar()->AcceptInput();
2193
2194 // Confirm that the Instant overlay was NOT committed.
2195 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents());
2196 }
2197
2198 // Test that renderer initiated navigations to an instant URL from a non 910 // Test that renderer initiated navigations to an instant URL from a non
2199 // Instant page do not end up in an Instant process if they are bounced to the 911 // Instant page do not end up in an Instant process if they are bounced to the
2200 // browser. 912 // browser.
2201 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 913 IN_PROC_BROWSER_TEST_F(
2202 RendererInitiatedNavigationNotInInstantProcess) { 914 InstantExtendedTest,
915 DISABLED_RendererInitiatedNavigationNotInInstantProcess) {
2203 InstantService* instant_service = 916 InstantService* instant_service =
2204 InstantServiceFactory::GetForProfile(browser()->profile()); 917 InstantServiceFactory::GetForProfile(browser()->profile());
2205 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 918 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
2206 919
2207 // Setup Instant. 920 // Setup Instant.
2208 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 921 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2209 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 922 FocusOmniboxAndWaitForInstantNTPSupport();
2210 923
2211 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 924 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
2212 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 925 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2213 926
2214 // Don't use https server for the non instant URL so that the browser uses 927 // Don't use https server for the non instant URL so that the browser uses
2215 // different RenderViews. 928 // different RenderViews.
2216 GURL non_instant_url = test_server()->GetURL("files/simple.html"); 929 GURL non_instant_url = test_server()->GetURL("files/simple.html");
2217 ui_test_utils::NavigateToURLWithDisposition( 930 ui_test_utils::NavigateToURLWithDisposition(
2218 browser(), 931 browser(),
2219 non_instant_url, 932 non_instant_url,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 // Test that renderer initiated navigations to an Instant URL from an 977 // Test that renderer initiated navigations to an Instant URL from an
2265 // Instant process end up in an Instant process. 978 // Instant process end up in an Instant process.
2266 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 979 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2267 RendererInitiatedNavigationInInstantProcess) { 980 RendererInitiatedNavigationInInstantProcess) {
2268 InstantService* instant_service = 981 InstantService* instant_service =
2269 InstantServiceFactory::GetForProfile(browser()->profile()); 982 InstantServiceFactory::GetForProfile(browser()->profile());
2270 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 983 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
2271 984
2272 // Setup Instant. 985 // Setup Instant.
2273 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 986 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2274 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 987 FocusOmniboxAndWaitForInstantNTPSupport();
2275 988
2276 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 989 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
2277 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 990 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2278 991
2279 ui_test_utils::NavigateToURLWithDisposition( 992 ui_test_utils::NavigateToURLWithDisposition(
2280 browser(), 993 browser(),
2281 instant_url(), 994 instant_url(),
2282 CURRENT_TAB, 995 CURRENT_TAB,
2283 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 996 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
2284 content::WebContents* contents = 997 content::WebContents* contents =
(...skipping 17 matching lines...) Expand all
2302 contents, "document.getElementById('toClick').click();")); 1015 contents, "document.getElementById('toClick').click();"));
2303 observer.Wait(); 1016 observer.Wait();
2304 1017
2305 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 1018 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2306 contents = browser()->tab_strip_model()->GetActiveWebContents(); 1019 contents = browser()->tab_strip_model()->GetActiveWebContents();
2307 EXPECT_TRUE(instant_service->IsInstantProcess( 1020 EXPECT_TRUE(instant_service->IsInstantProcess(
2308 contents->GetRenderProcessHost()->GetID())); 1021 contents->GetRenderProcessHost()->GetID()));
2309 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); 1022 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL());
2310 } 1023 }
2311 1024
2312 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchProviderDoesntRun) {
2313 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2314 FocusOmniboxAndWaitForInstantOverlaySupport();
2315
2316 // Add "query" to history.
2317 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000));
2318 BlockUntilHistoryProcessesPendingRequests();
2319
2320 SetOmniboxText("quer");
2321
2322 // Should get only SWYT from SearchProvider.
2323 EXPECT_EQ(1, CountSearchProviderSuggestions());
2324 }
2325
2326 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchProviderRunsForLocalOnly) {
2327 // Force local-only Instant.
2328 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2329 instant()->SetInstantEnabled(true, true);
2330 FocusOmniboxAndWaitForInstantOverlaySupport();
2331
2332 // Add "query" to history.
2333 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000));
2334 BlockUntilHistoryProcessesPendingRequests();
2335
2336 SetOmniboxText("quer");
2337
2338 // Should get 2 suggestions from SearchProvider:
2339 // - SWYT for "quer"
2340 // - Search history suggestion for "query"
2341 EXPECT_EQ(2, CountSearchProviderSuggestions());
2342 }
2343
2344 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchProviderRunsForFallback) {
2345 // Use an Instant URL that won't support Instant.
2346 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
2347 InstantTestBase::Init(instant_url);
2348 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2349 FocusOmniboxAndWaitForInstantOverlaySupport();
2350 // Should fallback to the local overlay.
2351 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2352 EXPECT_TRUE(instant()->overlay()->IsLocal());
2353
2354 // Add "query" to history and wait for Instant support.
2355 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("query"), 10000));
2356 BlockUntilHistoryProcessesPendingRequests();
2357
2358 SetOmniboxText("quer");
2359
2360 // Should get 2 suggestions from SearchProvider:
2361 // - SWYT for "quer"
2362 // - Search history suggestion for "query"
2363 EXPECT_EQ(2, CountSearchProviderSuggestions());
2364 }
2365
2366 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchProviderForLocalNTP) {
2367 // Force local-only Instant.
2368 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2369 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2370 instant()->SetInstantEnabled(true, true);
2371
2372 // Add "google" to history.
2373 ASSERT_TRUE(AddSearchToHistory(ASCIIToUTF16("google"), 10000));
2374 BlockUntilHistoryProcessesPendingRequests();
2375
2376 // Create an observer to wait for the autocomplete.
2377 content::WindowedNotificationObserver autocomplete_observer(
2378 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
2379 content::NotificationService::AllSources());
2380
2381 SetOmniboxText("http://www.example.com");
2382
2383 autocomplete_observer.Wait();
2384 ASSERT_TRUE(omnibox()->model()->autocomplete_controller()->
2385 search_provider()->IsNonInstantSearchDone());
2386 }
2387
2388 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlaySendsSearchWhatYouTyped) {
2389 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2390 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2391
2392 // This input could be interpreted either as an URL or a query based on the
2393 // relative ranking of search-what-you-typed or url-what-you-typed.
2394 content::WindowedNotificationObserver autocomplete_observer(
2395 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
2396 content::NotificationService::AllSources());
2397 SetOmniboxText("define:foo");
2398 autocomplete_observer.Wait();
2399
2400 // In this case, we should treat [define:foo] as a query, so
2401 // search-what-you-typed should be the top suggestion.
2402 EXPECT_TRUE(ExecuteScript(
2403 "var sorted = chrome.embeddedSearch.searchBox.nativeSuggestions.sort("
2404 "function (a,b) {"
2405 "return b.rankingData.relevance - a.rankingData.relevance;"
2406 "});"));
2407 std::string type;
2408 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(),
2409 "sorted[0].type", &type));
2410 ASSERT_EQ("search-what-you-typed", type);
2411 }
2412
2413 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2414 OverlayDoesNotEchoSearchProviderNavsuggest) {
2415 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2416 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2417
2418 // Show the overlay so suggestions are allowed.
2419 SetOmniboxTextAndWaitForOverlayToShow("www.");
2420 content::WebContents* overlay = instant()->GetOverlayContents();
2421
2422 // Set a URL suggestion and wait for SearchProvider to echo it.
2423 content::WindowedNotificationObserver autocomplete_observer(
2424 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS,
2425 content::NotificationService::AllSources());
2426 instant()->SetSuggestions(
2427 overlay,
2428 std::vector<InstantSuggestion>(
2429 1,
2430 InstantSuggestion(ASCIIToUTF16("http://www.example.com/"),
2431 INSTANT_COMPLETE_NOW,
2432 INSTANT_SUGGESTION_URL,
2433 ASCIIToUTF16("www."),
2434 kNoMatchIndex)));
2435 autocomplete_observer.Wait();
2436
2437 // Check that SearchProvider set a NAVSUGGEST match.
2438 bool have_navsuggest_match = false;
2439 SearchProvider* search_provider =
2440 omnibox()->model()->autocomplete_controller()->search_provider();
2441 for (ACMatches::const_iterator match = search_provider->matches().begin();
2442 match != search_provider->matches().end(); ++match) {
2443 if (match->type == AutocompleteMatchType::NAVSUGGEST) {
2444 have_navsuggest_match = true;
2445 break;
2446 }
2447 }
2448 ASSERT_TRUE(have_navsuggest_match);
2449
2450 // Check that InstantController did not send the NAVSUGGEST match.
2451 bool sent_navsuggest_match = true;
2452 EXPECT_TRUE(GetBoolFromJS(overlay,
2453 "chrome.embeddedSearch.searchBox.nativeSuggestions.some("
2454 "function (s) {"
2455 "return s.type == 'navsuggest';"
2456 "})", &sent_navsuggest_match));
2457 EXPECT_FALSE(sent_navsuggest_match);
2458 }
2459
2460 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { 1025 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) {
2461 // Get a committed Instant tab, which will be in the Instant process and thus 1026 // Get a committed Instant tab, which will be in the Instant process and thus
2462 // support chrome::GetSearchTerms(). 1027 // support chrome::GetSearchTerms().
2463 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1028 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2464 FocusOmniboxAndWaitForInstantOverlaySupport(); 1029 FocusOmnibox();
2465 1030
2466 // Create an observer to wait for the instant tab to support Instant. 1031 // Create an observer to wait for the instant tab to support Instant.
2467 content::WindowedNotificationObserver observer( 1032 content::WindowedNotificationObserver observer(
2468 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1033 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2469 content::NotificationService::AllSources()); 1034 content::NotificationService::AllSources());
2470 1035
2471 // Do a search and commit it. 1036 // Do a search and commit it.
2472 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo")); 1037 SetOmniboxText("foo");
2473 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 1038 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
2474 browser()->window()->GetLocationBar()->AcceptInput(); 1039 browser()->window()->GetLocationBar()->AcceptInput();
2475 observer.Wait(); 1040 observer.Wait();
2476 1041
2477 // Set URL-like search terms for the instant tab. 1042 // Set URL-like search terms for the instant tab.
2478 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 1043 content::WebContents* instant_tab = instant()->instant_tab()->contents();
2479 content::NavigationEntry* visible_entry = 1044 content::NavigationEntry* visible_entry =
2480 instant_tab->GetController().GetVisibleEntry(); 1045 instant_tab->GetController().GetVisibleEntry();
2481 visible_entry->SetExtraData(sessions::kSearchTermsKey, 1046 visible_entry->SetExtraData(sessions::kSearchTermsKey,
2482 ASCIIToUTF16("http://example.com")); 1047 ASCIIToUTF16("http://example.com"));
2483 SetOmniboxText("http://example.com"); 1048 SetOmniboxText("http://example.com");
2484 omnibox()->model()->SetInputInProgress(false); 1049 omnibox()->model()->SetInputInProgress(false);
2485 omnibox()->CloseOmniboxPopup(); 1050 omnibox()->CloseOmniboxPopup();
2486 1051
2487 // Accept the omnibox input. 1052 // Accept the omnibox input.
2488 EXPECT_FALSE(omnibox()->model()->user_input_in_progress()); 1053 EXPECT_FALSE(omnibox()->model()->user_input_in_progress());
2489 EXPECT_TRUE( 1054 EXPECT_TRUE(
2490 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms()); 1055 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms());
2491 GURL instant_tab_url = instant_tab->GetURL(); 1056 GURL instant_tab_url = instant_tab->GetURL();
2492 browser()->window()->GetLocationBar()->AcceptInput(); 1057 browser()->window()->GetLocationBar()->AcceptInput();
2493 EXPECT_EQ(instant_tab_url, instant_tab->GetURL()); 1058 EXPECT_EQ(instant_tab_url, instant_tab->GetURL());
2494 } 1059 }
2495 1060
2496 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS) { 1061 // TODO(jered): Figure out why this test flakes and fix it.
1062 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1063 DISABLED_AcceptingJSSearchDoesNotRunJS) {
2497 // Get a committed Instant tab, which will be in the Instant process and thus 1064 // Get a committed Instant tab, which will be in the Instant process and thus
2498 // support chrome::GetSearchTerms(). 1065 // support chrome::GetSearchTerms().
2499 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1066 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2500 FocusOmniboxAndWaitForInstantOverlaySupport(); 1067 FocusOmnibox();
2501 1068
2502 // Create an observer to wait for the instant tab to support Instant. 1069 // Create an observer to wait for the instant tab to support Instant.
2503 content::WindowedNotificationObserver observer( 1070 content::WindowedNotificationObserver observer(
2504 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1071 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2505 content::NotificationService::AllSources()); 1072 content::NotificationService::AllSources());
2506 1073
2507 // Do a search and commit it. 1074 // Do a search and commit it.
2508 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo")); 1075 SetOmniboxText("foo");
2509 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 1076 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
2510 browser()->window()->GetLocationBar()->AcceptInput(); 1077 browser()->window()->GetLocationBar()->AcceptInput();
2511 observer.Wait(); 1078 observer.Wait();
2512 1079
2513 // Set URL-like search terms for the instant tab. 1080 // Set URL-like search terms for the instant tab.
2514 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 1081 content::WebContents* instant_tab = instant()->instant_tab()->contents();
2515 content::NavigationEntry* visible_entry = 1082 content::NavigationEntry* visible_entry =
2516 instant_tab->GetController().GetVisibleEntry(); 1083 instant_tab->GetController().GetVisibleEntry();
2517 const char kEvilJS[] = "javascript:document.title='evil';1;"; 1084 const char kEvilJS[] = "javascript:document.title='evil';1;";
2518 visible_entry->SetExtraData(sessions::kSearchTermsKey, ASCIIToUTF16(kEvilJS)); 1085 visible_entry->SetExtraData(sessions::kSearchTermsKey, ASCIIToUTF16(kEvilJS));
2519 SetOmniboxText(kEvilJS); 1086 SetOmniboxText(kEvilJS);
2520 omnibox()->model()->SetInputInProgress(false); 1087 omnibox()->model()->SetInputInProgress(false);
2521 omnibox()->CloseOmniboxPopup(); 1088 omnibox()->CloseOmniboxPopup();
2522 1089
2523 // Accept the omnibox input. 1090 // Accept the omnibox input.
2524 EXPECT_FALSE(omnibox()->model()->user_input_in_progress()); 1091 EXPECT_FALSE(omnibox()->model()->user_input_in_progress());
2525 EXPECT_TRUE( 1092 EXPECT_TRUE(
2526 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms()); 1093 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms());
2527 browser()->window()->GetLocationBar()->AcceptInput(); 1094 browser()->window()->GetLocationBar()->AcceptInput();
2528 // Force some Javascript to run in the renderer so the inline javascript: 1095 // Force some Javascript to run in the renderer so the inline javascript:
2529 // would be forced to run if it's going to. 1096 // would be forced to run if it's going to.
2530 EXPECT_TRUE(content::ExecuteScript(instant_tab, "1;")); 1097 EXPECT_TRUE(content::ExecuteScript(instant_tab, "1;"));
2531 EXPECT_NE(ASCIIToUTF16("evil"), instant_tab->GetTitle()); 1098 EXPECT_NE(ASCIIToUTF16("evil"), instant_tab->GetTitle());
2532 } 1099 }
2533 1100
2534 // Flaky on mac: http://crbug.com/242164 1101 IN_PROC_BROWSER_TEST_F(
2535 #if defined(OS_MACOSX) 1102 InstantExtendedTest,
2536 #define MAYBE_ReloadSearchAfterBackReloadsCorrectQuery DISABLED_ReloadSearchAfte rBackReloadsCorrectQuery 1103 DISABLED_ReloadSearchAfterBackReloadsCorrectQuery) {
2537 #else
2538 #define MAYBE_ReloadSearchAfterBackReloadsCorrectQuery ReloadSearchAfterBackRelo adsCorrectQuery
2539 #endif
2540
2541 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2542 MAYBE_ReloadSearchAfterBackReloadsCorrectQuery) {
2543 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1104 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2544 FocusOmniboxAndWaitForInstantOverlaySupport(); 1105 FocusOmnibox();
2545 1106
2546 // Create an observer to wait for the instant tab to support Instant. 1107 // Create an observer to wait for the instant tab to support Instant.
2547 content::WindowedNotificationObserver observer( 1108 content::WindowedNotificationObserver observer(
2548 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1109 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2549 content::NotificationService::AllSources()); 1110 content::NotificationService::AllSources());
2550 1111
2551 // Search for [foo]. 1112 // Search for [foo].
2552 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo")); 1113 SetOmniboxText("foo");
2553 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 1114 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
2554 browser()->window()->GetLocationBar()->AcceptInput(); 1115 browser()->window()->GetLocationBar()->AcceptInput();
2555 observer.Wait(); 1116 observer.Wait();
2556 1117
2557 // Search again for [bar]. 1118 // Search again for [bar].
2558 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 1119 content::WebContents* instant_tab = instant()->instant_tab()->contents();
2559 EXPECT_TRUE(content::ExecuteScript(instant_tab, 1120 EXPECT_TRUE(content::ExecuteScript(instant_tab,
2560 "suggestion = 'bart';")); 1121 "suggestion = 'bart';"));
2561 SetOmniboxTextAndWaitForSuggestion("bar"); 1122 SetOmniboxTextAndWaitForSuggestion("bar");
2562 EXPECT_EQ(ASCIIToUTF16("t"), GetGrayText());
2563 1123
2564 // Accept the new query and wait for the page to navigate. 1124 // Accept the new query and wait for the page to navigate.
2565 content::WindowedNotificationObserver nav_observer( 1125 content::WindowedNotificationObserver nav_observer(
2566 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 1126 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
2567 content::NotificationService::AllSources()); 1127 content::NotificationService::AllSources());
2568 browser()->window()->GetLocationBar()->AcceptInput(); 1128 browser()->window()->GetLocationBar()->AcceptInput();
2569 nav_observer.Wait(); 1129 nav_observer.Wait();
2570 1130
2571 // Press back button and reload. 1131 // Press back button and reload.
2572 content::WindowedNotificationObserver back_observer( 1132 content::WindowedNotificationObserver back_observer(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 browser(), 1164 browser(),
2605 GURL(chrome::kChromeUINewTabURL), 1165 GURL(chrome::kChromeUINewTabURL),
2606 NEW_WINDOW, 1166 NEW_WINDOW,
2607 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 1167 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
2608 1168
2609 const BrowserList* native_browser_list = BrowserList::GetInstance( 1169 const BrowserList* native_browser_list = BrowserList::GetInstance(
2610 chrome::HOST_DESKTOP_TYPE_NATIVE); 1170 chrome::HOST_DESKTOP_TYPE_NATIVE);
2611 ASSERT_EQ(2u, native_browser_list->size()); 1171 ASSERT_EQ(2u, native_browser_list->size());
2612 set_browser(native_browser_list->get(1)); 1172 set_browser(native_browser_list->get(1));
2613 1173
2614 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1174 FocusOmniboxAndWaitForInstantNTPSupport();
2615 1175
2616 // Also make sure our instant_tab_ is loaded. 1176 // Also make sure our instant_tab_ is loaded.
2617 if (!instant()->instant_tab_) { 1177 if (!instant()->instant_tab_) {
2618 content::WindowedNotificationObserver instant_tab_observer( 1178 content::WindowedNotificationObserver instant_tab_observer(
2619 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1179 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2620 content::NotificationService::AllSources()); 1180 content::NotificationService::AllSources());
2621 instant_tab_observer.Wait(); 1181 instant_tab_observer.Wait();
2622 } 1182 }
2623 1183
2624 // NTP contents should be preloaded. 1184 // NTP contents should be preloaded.
2625 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 1185 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
2626 EXPECT_TRUE(instant()->ntp()->IsLocal()); 1186 EXPECT_TRUE(instant()->ntp()->IsLocal());
2627 1187
2628 // Overlay contents should be preloaded.
2629 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2630 EXPECT_TRUE(instant()->overlay()->IsLocal());
2631
2632 // Instant tab contents should be preloaded. 1188 // Instant tab contents should be preloaded.
2633 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); 1189 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab());
2634 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); 1190 EXPECT_TRUE(instant()->instant_tab()->IsLocal());
2635 } 1191 }
2636 1192
2637 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2638 PageVisibilityEventOnCommit) {
2639 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2640 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2641
2642 // Set the text, and wait for suggestions to show up.
2643 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("search"));
2644
2645 content::WebContents* overlay = instant()->GetOverlayContents();
2646
2647 // Before commiting, verify visibility calls.
2648 int on_visibility_calls = -1;
2649 EXPECT_TRUE(GetIntFromJS(overlay, "onvisibilitycalls", &on_visibility_calls));
2650 EXPECT_EQ(1, on_visibility_calls);
2651
2652 // Commit the search by pressing Enter.
2653 browser()->window()->GetLocationBar()->AcceptInput();
2654
2655 // After commiting, verify visibility calls.
2656 on_visibility_calls = -1;
2657 EXPECT_TRUE(GetIntFromJS(overlay, "onvisibilitycalls", &on_visibility_calls));
2658 EXPECT_EQ(1, on_visibility_calls);
2659 }
2660
2661 // Test that if the LogDropdownShown() call records a histogram value.
2662 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LogDropdownShown) {
2663 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2664 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2665 int64 histogramValue = GetHistogramCount("Instant.TimeToFirstShowFromWeb");
2666 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("a"));
2667 EXPECT_EQ(histogramValue + 1,
2668 GetHistogramCount("Instant.TimeToFirstShowFromWeb"));
2669 }
2670
2671 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, TaskManagerPrefix) {
2672 TaskManagerModel* task_manager = TaskManager::GetInstance()->model();
2673 task_manager->StartUpdating();
2674
2675 // There should be three renderers, the second being the Instant overlay,
2676 // and the third being the preloaded NTP.
2677 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3);
2678
2679 string16 prefix = l10n_util::GetStringFUTF16(
2680 IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, string16());
2681
2682 int instant_overlays = 0;
2683 for (int i = 0; i < task_manager->ResourceCount(); ++i) {
2684 string16 title = task_manager->GetResourceTitle(i);
2685 if (StartsWith(title, prefix, true))
2686 ++instant_overlays;
2687 }
2688 EXPECT_EQ(2, instant_overlays);
2689 }
2690
2691 // Broken on mac: http://crbug.com/247448 1193 // Broken on mac: http://crbug.com/247448
2692 #if defined(OS_MACOSX) 1194 #if defined(OS_MACOSX)
2693 #define MAYBE_KeyboardTogglesVoiceSearch DISABLED_KeyboardTogglesVoiceSearch 1195 #define MAYBE_KeyboardTogglesVoiceSearch DISABLED_KeyboardTogglesVoiceSearch
2694 #else 1196 #else
2695 #define MAYBE_KeyboardTogglesVoiceSearch KeyboardTogglesVoiceSearch 1197 #define MAYBE_KeyboardTogglesVoiceSearch KeyboardTogglesVoiceSearch
2696 #endif 1198 #endif
2697 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_KeyboardTogglesVoiceSearch) { 1199 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_KeyboardTogglesVoiceSearch) {
2698 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1200 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2699 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1201 FocusOmniboxAndWaitForInstantNTPSupport();
2700
2701 // Test that toggle is not fired when no tab is open.
2702 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD,
2703 true, true, false, false));
2704 EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents()));
2705 EXPECT_EQ(0, on_toggle_voice_search_calls_);
2706 1202
2707 // Open new tab and test that toggle is fired. 1203 // Open new tab and test that toggle is fired.
2708 ui_test_utils::NavigateToURLWithDisposition( 1204 ui_test_utils::NavigateToURLWithDisposition(
2709 browser(), 1205 browser(),
2710 GURL(chrome::kChromeUINewTabURL), 1206 GURL(chrome::kChromeUINewTabURL),
2711 NEW_FOREGROUND_TAB, 1207 CURRENT_TAB,
2712 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1208 ui_test_utils::BROWSER_TEST_NONE);
1209 content::WebContents* active_tab =
1210 browser()->tab_strip_model()->GetActiveWebContents();
2713 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD, 1211 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD,
2714 true, true, false, false)); 1212 true, true, false, false));
2715 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); 1213 EXPECT_TRUE(UpdateSearchState(active_tab));
2716 EXPECT_EQ(1, on_toggle_voice_search_calls_); 1214 EXPECT_EQ(1, on_toggle_voice_search_calls_);
2717 } 1215 }
2718 1216
2719 // Test to verify that the omnibox search query is updated on browser 1217 // Test to verify that the omnibox search query is updated on browser
2720 // back/forward button press events. 1218 // back/forward button press events.
2721 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnNavigation) { 1219 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnNavigation) {
2722 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1220 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2723 1221
2724 // Focus omnibox and confirm overlay isn't shown. 1222 // Focus omnibox.
2725 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1223 FocusOmniboxAndWaitForInstantNTPSupport();
2726 content::WebContents* overlay = instant()->GetOverlayContents(); 1224 SetOmniboxText("flowers");
2727 EXPECT_TRUE(overlay);
2728 EXPECT_TRUE(instant()->model()->mode().is_default());
2729 EXPECT_FALSE(instant()->IsOverlayingSearchResults());
2730
2731 // Typing in the omnibox should show the overlay.
2732 SetOmniboxTextAndWaitForOverlayToShow("flowers");
2733 EXPECT_TRUE(instant()->IsOverlayingSearchResults());
2734 EXPECT_EQ(overlay, instant()->GetOverlayContents());
2735 1225
2736 // Commit the search by pressing 'Enter'. 1226 // Commit the search by pressing 'Enter'.
2737 PressEnterAndWaitForNavigation(); 1227 PressEnterAndWaitForNavigation();
2738 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); 1228 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText());
2739 1229
2740 // Typing in the new search query in omnibox. 1230 // Typing in the new search query in omnibox.
2741 SetOmniboxText("cattles"); 1231 SetOmniboxText("cattles");
2742 // Commit the search by pressing 'Enter'. 1232 // Commit the search by pressing 'Enter'.
2743 PressEnterAndWaitForNavigation(); 1233 PressEnterAndWaitForNavigation();
2744 // 'Enter' commits the query as it was typed. This creates a navigation entry 1234 // 'Enter' commits the query as it was typed. This creates a navigation entry
(...skipping 15 matching lines...) Expand all
2760 FocusOmnibox(); 1250 FocusOmnibox();
2761 PressEnterAndWaitForNavigation(); 1251 PressEnterAndWaitForNavigation();
2762 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); 1252 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText());
2763 } 1253 }
2764 1254
2765 #endif // HTML_INSTANT_EXTENDED_POPUP 1255 #endif // HTML_INSTANT_EXTENDED_POPUP
2766 1256
2767 #if !defined(HTML_INSTANT_EXTENDED_POPUP) 1257 #if !defined(HTML_INSTANT_EXTENDED_POPUP)
2768 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { 1258 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) {
2769 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1259 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2770 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1260 FocusOmniboxAndWaitForInstantNTPSupport();
2771 1261
2772 content::WindowedNotificationObserver observer( 1262 content::WindowedNotificationObserver observer(
2773 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1263 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2774 content::NotificationService::AllSources()); 1264 content::NotificationService::AllSources());
2775 SetOmniboxText("flowers"); 1265 SetOmniboxText("flowers");
2776 PressEnterAndWaitForNavigation(); 1266 PressEnterAndWaitForNavigation();
2777 observer.Wait(); 1267 observer.Wait();
2778 1268
2779 // Just did a regular search. 1269 // Just did a regular search.
2780 content::WebContents* active_tab = 1270 content::WebContents* active_tab =
2781 browser()->tab_strip_model()->GetActiveWebContents(); 1271 browser()->tab_strip_model()->GetActiveWebContents();
2782 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); 1272 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers"));
2783 ASSERT_TRUE(UpdateSearchState(active_tab)); 1273 ASSERT_TRUE(UpdateSearchState(active_tab));
2784 ASSERT_EQ(0, submit_count_); 1274 ASSERT_EQ(0, submit_count_);
2785 1275
2786 SetOmniboxText("puppies"); 1276 SetOmniboxText("puppies");
2787 PressEnterAndWaitForNavigation(); 1277 PressEnterAndWaitForNavigation();
2788 1278
2789 // Should have reused the tab and sent an onsubmit message. 1279 // Should have reused the tab and sent an onsubmit message.
2790 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1280 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
2791 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); 1281 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies"));
2792 ASSERT_TRUE(UpdateSearchState(active_tab)); 1282 ASSERT_TRUE(UpdateSearchState(active_tab));
2793 EXPECT_EQ(1, submit_count_); 1283 EXPECT_EQ(1, submit_count_);
2794 } 1284 }
2795 1285
2796 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 1286 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2797 SearchDoesntReuseInstantTabWithoutSupport) { 1287 SearchDoesntReuseInstantTabWithoutSupport) {
2798 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1288 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2799 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1289 FocusOmniboxAndWaitForInstantNTPSupport();
2800 1290
2801 // Don't wait for the navigation to complete. 1291 // Don't wait for the navigation to complete.
2802 SetOmniboxText("flowers"); 1292 SetOmniboxText("flowers");
2803 browser()->window()->GetLocationBar()->AcceptInput(); 1293 browser()->window()->GetLocationBar()->AcceptInput();
2804 1294
2805 SetOmniboxText("puppies"); 1295 SetOmniboxText("puppies");
2806 browser()->window()->GetLocationBar()->AcceptInput(); 1296 browser()->window()->GetLocationBar()->AcceptInput();
2807 1297
2808 // Should not have reused the tab. 1298 // Should not have reused the tab.
2809 ASSERT_THAT( 1299 ASSERT_THAT(
2810 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), 1300 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
2811 HasSubstr("q=puppies")); 1301 HasSubstr("q=puppies"));
2812 } 1302 }
2813 1303
2814 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 1304 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2815 TypedSearchURLDoesntReuseInstantTab) { 1305 TypedSearchURLDoesntReuseInstantTab) {
2816 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1306 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2817 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1307 FocusOmniboxAndWaitForInstantNTPSupport();
2818 1308
2819 // Create an observer to wait for the instant tab to support Instant. 1309 // Create an observer to wait for the instant tab to support Instant.
2820 content::WindowedNotificationObserver observer_1( 1310 content::WindowedNotificationObserver observer_1(
2821 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1311 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2822 content::NotificationService::AllSources()); 1312 content::NotificationService::AllSources());
2823 SetOmniboxText("flowers"); 1313 SetOmniboxText("flowers");
2824 PressEnterAndWaitForNavigation(); 1314 PressEnterAndWaitForNavigation();
2825 observer_1.Wait(); 1315 observer_1.Wait();
2826 1316
2827 // Just did a regular search. 1317 // Just did a regular search.
(...skipping 11 matching lines...) Expand all
2839 PressEnterAndWaitForNavigation(); 1329 PressEnterAndWaitForNavigation();
2840 observer_2.Wait(); 1330 observer_2.Wait();
2841 1331
2842 // Should not have reused the tab. 1332 // Should not have reused the tab.
2843 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1333 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
2844 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); 1334 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies"));
2845 } 1335 }
2846 1336
2847 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { 1337 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) {
2848 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1338 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2849 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1339 FocusOmniboxAndWaitForInstantNTPSupport();
2850 1340
2851 // Create an observer to wait for the instant tab to support Instant. 1341 // Create an observer to wait for the instant tab to support Instant.
2852 content::WindowedNotificationObserver observer( 1342 content::WindowedNotificationObserver observer(
2853 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1343 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
2854 content::NotificationService::AllSources()); 1344 content::NotificationService::AllSources());
2855 1345
2856 SetOmniboxText("flowers"); 1346 SetOmniboxText("flowers");
2857 browser()->window()->GetLocationBar()->AcceptInput(); 1347 browser()->window()->GetLocationBar()->AcceptInput();
2858 observer.Wait(); 1348 observer.Wait();
2859 1349
2860 const std::string& url = 1350 const std::string& url =
2861 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(); 1351 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec();
2862 // Make sure we actually used search_url, not instant_url. 1352 // Make sure we actually used search_url, not instant_url.
2863 ASSERT_THAT(url, HasSubstr("&is_search")); 1353 ASSERT_THAT(url, HasSubstr("&is_search"));
2864 EXPECT_THAT(url, HasSubstr("&es_sm=")); 1354 EXPECT_THAT(url, HasSubstr("&es_sm="));
2865 } 1355 }
2866 1356
2867 #endif // if !defined(HTML_INSTANT_EXTENDED_POPUP) 1357 #endif // if !defined(HTML_INSTANT_EXTENDED_POPUP)
2868 1358
2869 // Test to verify that switching tabs should not dispatch onmostvisitedchanged 1359 // Test to verify that switching tabs should not dispatch onmostvisitedchanged
2870 // events. 1360 // events.
2871 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { 1361 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) {
2872 // Initialize Instant. 1362 // Initialize Instant.
2873 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1363 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2874 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); 1364 FocusOmniboxAndWaitForInstantNTPSupport();
2875 1365
2876 // Open new tab. Preloaded NTP contents should have been used. 1366 // Open new tab. Preloaded NTP contents should have been used.
2877 ui_test_utils::NavigateToURLWithDisposition( 1367 ui_test_utils::NavigateToURLWithDisposition(
2878 browser(), 1368 browser(),
2879 GURL(chrome::kChromeUINewTabURL), 1369 GURL(chrome::kChromeUINewTabURL),
2880 NEW_FOREGROUND_TAB, 1370 NEW_FOREGROUND_TAB,
2881 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1371 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
2882 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 1372 EXPECT_EQ(2, browser()->tab_strip_model()->count());
2883 1373
2884 // Make sure new tab received the onmostvisitedchanged event once. 1374 // Make sure new tab received the onmostvisitedchanged event once.
2885 content::WebContents* active_tab = 1375 content::WebContents* active_tab =
2886 browser()->tab_strip_model()->GetActiveWebContents(); 1376 browser()->tab_strip_model()->GetActiveWebContents();
2887 EXPECT_TRUE(UpdateSearchState(active_tab)); 1377 EXPECT_TRUE(UpdateSearchState(active_tab));
2888 EXPECT_EQ(2, on_most_visited_change_calls_); 1378 EXPECT_EQ(2, on_most_visited_change_calls_);
2889 1379
2890 // Activate the previous tab. 1380 // Activate the previous tab.
2891 browser()->tab_strip_model()->ActivateTabAt(0, false); 1381 browser()->tab_strip_model()->ActivateTabAt(0, false);
2892 1382
2893 // Switch back to new tab. 1383 // Switch back to new tab.
2894 browser()->tab_strip_model()->ActivateTabAt(1, false); 1384 browser()->tab_strip_model()->ActivateTabAt(1, false);
2895 1385
2896 // Confirm that new tab got no onmostvisitedchanged event. 1386 // Confirm that new tab got no onmostvisitedchanged event.
2897 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1387 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
2898 EXPECT_TRUE(UpdateSearchState(active_tab)); 1388 EXPECT_TRUE(UpdateSearchState(active_tab));
2899 EXPECT_EQ(2, on_most_visited_change_calls_); 1389 EXPECT_EQ(2, on_most_visited_change_calls_);
2900 } 1390 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_controller.cc ('k') | chrome/browser/ui/search/instant_extended_manual_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698