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

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

Issue 17444007: Revert 207790 "InstantExtended: Don't create overlay, again." (Closed) Base URL: svn://svn.chromium.org/chrome/
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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 ThemeServiceFactory::GetThemeForProfile( 281 ThemeServiceFactory::GetThemeForProfile(
282 ExtensionBrowserTest::browser()->profile()); 282 ExtensionBrowserTest::browser()->profile());
283 ASSERT_NE(static_cast<extensions::Extension*>(NULL), theme); 283 ASSERT_NE(static_cast<extensions::Extension*>(NULL), theme);
284 ASSERT_EQ(theme->name(), theme_name); 284 ASSERT_EQ(theme->name(), theme_name);
285 } 285 }
286 286
287 private: 287 private:
288 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest); 288 DISALLOW_COPY_AND_ASSIGN(InstantPolicyTest);
289 }; 289 };
290 290
291 #if defined(HTML_INSTANT_EXTENDED_POPUP)
292
291 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) { 293 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
292 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 294 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
293 EXPECT_TRUE(instant()->extended_enabled_); 295 EXPECT_TRUE(instant()->extended_enabled_);
294 } 296 }
295 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
296 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) { 780 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
297 // Setup Instant. 781 // Setup Instant.
298 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 782 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
299 FocusOmniboxAndWaitForInstantNTPSupport(); 783 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
300 784
301 // NTP contents should be preloaded. 785 // NTP contents should be preloaded.
302 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 786 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
303 content::WebContents* ntp_contents = instant()->ntp_->contents(); 787 content::WebContents* ntp_contents = instant()->ntp_->contents();
304 EXPECT_TRUE(ntp_contents); 788 EXPECT_TRUE(ntp_contents);
305 } 789 }
306 790
307 // Test that the local NTP is preloaded. 791 // Test that the local NTP is preloaded.
308 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsPreloaded) { 792 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsPreloaded) {
309 // Setup Instant. 793 // Setup Instant.
310 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 794 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
311 795
312 // The second argument says to use only the local overlay and NTP. 796 // The second argument says to use only the local overlay and NTP.
313 instant()->SetInstantEnabled(false, true); 797 instant()->SetInstantEnabled(false, true);
314 FocusOmniboxAndWaitForInstantNTPSupport(); 798 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
315 799
316 // NTP contents should be preloaded. 800 // NTP contents should be preloaded.
317 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 801 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
318 content::WebContents* ntp_contents = instant()->ntp_->contents(); 802 content::WebContents* ntp_contents = instant()->ntp_->contents();
319 EXPECT_NE(static_cast<content::WebContents*>(NULL), ntp_contents); 803 EXPECT_NE(static_cast<content::WebContents*>(NULL), ntp_contents);
320 EXPECT_TRUE(instant()->ntp()->IsLocal()); 804 EXPECT_TRUE(instant()->ntp()->IsLocal());
321 } 805 }
322 806
323 // Test that the local NTP is not preloaded. 807 // Test that the local NTP is not preloaded.
324 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsNotPreloaded) { 808 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LocalOnlyNTPIsNotPreloaded) {
325 // Setup Instant. 809 // Setup Instant.
326 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 810 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
327 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( 811 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString(
328 "InstantExtended/Group1 local_only:1 preload_local_only_ntp:0/")); 812 "InstantExtended/Group1 local_only:1 preload_local_only_ntp:0/"));
329 813
330 // The second argument says to use only the local overlay and NTP. 814 // The second argument says to use only the local overlay and NTP.
331 instant()->SetInstantEnabled(false, true); 815 instant()->SetInstantEnabled(false, true);
332 816
333 // NTP contents should not be preloaded. 817 // NTP contents should not be preloaded.
334 EXPECT_EQ(NULL, instant()->ntp()); 818 EXPECT_EQ(NULL, instant()->ntp());
335 } 819 }
336 820
337 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) { 821 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
338 // Setup Instant. 822 // Setup Instant.
339 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 823 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
340 FocusOmniboxAndWaitForInstantNTPSupport(); 824 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
341 825
342 // NTP contents should be preloaded. 826 // NTP contents should be preloaded.
343 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 827 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
344 content::WebContents* ntp_contents = instant()->ntp_->contents(); 828 content::WebContents* ntp_contents = instant()->ntp_->contents();
345 EXPECT_TRUE(ntp_contents); 829 EXPECT_TRUE(ntp_contents);
346 830
347 // Open new tab. Preloaded NTP contents should have been used. 831 // Open new tab. Preloaded NTP contents should have been used.
348 ui_test_utils::NavigateToURLWithDisposition( 832 ui_test_utils::NavigateToURLWithDisposition(
349 browser(), 833 browser(),
350 GURL(chrome::kChromeUINewTabURL), 834 GURL(chrome::kChromeUINewTabURL),
351 NEW_FOREGROUND_TAB, 835 NEW_FOREGROUND_TAB,
352 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 836 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
353 content::WebContents* active_tab = 837 content::WebContents* active_tab =
354 browser()->tab_strip_model()->GetActiveWebContents(); 838 browser()->tab_strip_model()->GetActiveWebContents();
355 EXPECT_EQ(ntp_contents, active_tab); 839 EXPECT_EQ(ntp_contents, active_tab);
356 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); 840 EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
357 } 841 }
358 842
359 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) { 843 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
360 // Setup Instant. 844 // Setup Instant.
361 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 845 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
362 FocusOmniboxAndWaitForInstantNTPSupport(); 846 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
363 847
364 // NTP contents should be preloaded. 848 // NTP contents should be preloaded.
365 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 849 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
366 content::WebContents* ntp_contents = instant()->ntp_->contents(); 850 content::WebContents* ntp_contents = instant()->ntp_->contents();
367 EXPECT_TRUE(ntp_contents); 851 EXPECT_TRUE(ntp_contents);
368 852
369 // Open new tab. Preloaded NTP contents should have been used. 853 // Open new tab. Preloaded NTP contents should have been used.
370 ui_test_utils::NavigateToURLWithDisposition( 854 ui_test_utils::NavigateToURLWithDisposition(
371 browser(), 855 browser(),
372 GURL(chrome::kChromeUINewTabURL), 856 GURL(chrome::kChromeUINewTabURL),
373 CURRENT_TAB, 857 CURRENT_TAB,
374 ui_test_utils::BROWSER_TEST_NONE); 858 ui_test_utils::BROWSER_TEST_NONE);
375 content::WebContents* active_tab = 859 content::WebContents* active_tab =
376 browser()->tab_strip_model()->GetActiveWebContents(); 860 browser()->tab_strip_model()->GetActiveWebContents();
377 EXPECT_EQ(ntp_contents, active_tab); 861 EXPECT_EQ(ntp_contents, active_tab);
378 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); 862 EXPECT_TRUE(chrome::IsInstantNTP(active_tab));
379 } 863 }
380 864
381 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPForWrongProvider) { 865 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPForWrongProvider) {
382 // Setup Instant. 866 // Setup Instant.
383 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 867 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
384 FocusOmniboxAndWaitForInstantNTPSupport(); 868 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
385 869
386 // NTP contents should be preloaded. 870 // NTP contents should be preloaded.
387 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 871 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
388 content::WebContents* ntp_contents = instant()->ntp_->contents(); 872 content::WebContents* ntp_contents = instant()->ntp_->contents();
389 EXPECT_TRUE(ntp_contents); 873 EXPECT_TRUE(ntp_contents);
390 GURL ntp_url = ntp_contents->GetURL(); 874 GURL ntp_url = ntp_contents->GetURL();
391 875
392 // Change providers. 876 // Change providers.
393 SetInstantURL("chrome://blank"); 877 SetInstantURL("chrome://blank");
394 878
395 // Open new tab. Preloaded NTP contents should have not been used. 879 // Open new tab. Preloaded NTP contents should have not been used.
396 ui_test_utils::NavigateToURLWithDisposition( 880 ui_test_utils::NavigateToURLWithDisposition(
397 browser(), 881 browser(),
398 GURL(chrome::kChromeUINewTabURL), 882 GURL(chrome::kChromeUINewTabURL),
399 NEW_FOREGROUND_TAB, 883 NEW_FOREGROUND_TAB,
400 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 884 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
401 content::WebContents* active_tab = 885 content::WebContents* active_tab =
402 browser()->tab_strip_model()->GetActiveWebContents(); 886 browser()->tab_strip_model()->GetActiveWebContents();
403 EXPECT_NE(ntp_url, active_tab->GetURL()); 887 EXPECT_NE(ntp_url, active_tab->GetURL());
404 } 888 }
405 889
406 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPRenderViewGone) { 890 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPRenderViewGone) {
407 // Setup Instant. 891 // Setup Instant.
408 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 892 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
409 FocusOmniboxAndWaitForInstantNTPSupport(); 893 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
410 894
411 // NTP contents should be preloaded. 895 // NTP contents should be preloaded.
412 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 896 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
413 EXPECT_FALSE(instant()->ntp()->IsLocal()); 897 EXPECT_FALSE(instant()->ntp()->IsLocal());
414 898
415 // NTP not reloaded after being killed. 899 // NTP not reloaded after being killed.
416 instant()->InstantPageRenderViewGone(instant()->ntp()->contents()); 900 instant()->InstantPageRenderViewGone(instant()->ntp()->contents());
417 EXPECT_EQ(NULL, instant()->ntp()); 901 EXPECT_EQ(NULL, instant()->ntp());
418 902
419 // Open new tab. Should use local NTP. 903 // Open new tab. Should use local NTP.
420 ui_test_utils::NavigateToURLWithDisposition( 904 ui_test_utils::NavigateToURLWithDisposition(
421 browser(), 905 browser(),
422 GURL(chrome::kChromeUINewTabURL), 906 GURL(chrome::kChromeUINewTabURL),
423 NEW_FOREGROUND_TAB, 907 NEW_FOREGROUND_TAB,
424 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 908 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
425 content::WebContents* active_tab = 909 content::WebContents* active_tab =
426 browser()->tab_strip_model()->GetActiveWebContents(); 910 browser()->tab_strip_model()->GetActiveWebContents();
427 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 911 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
428 } 912 }
429 913
430 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) { 914 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPDoesntSupportInstant) {
431 // Setup Instant. 915 // Setup Instant.
432 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1"); 916 GURL instant_url = test_server()->GetURL("files/empty.html?strk=1");
433 InstantTestBase::Init(instant_url); 917 InstantTestBase::Init(instant_url);
434 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 918 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
435 FocusOmniboxAndWaitForInstantNTPSupport(); 919 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
436 920
437 // NTP contents should have fallen back to the local page. 921 // NTP contents should have fallen back to the local page.
438 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 922 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
439 EXPECT_TRUE(instant()->ntp()->IsLocal()); 923 EXPECT_TRUE(instant()->ntp()->IsLocal());
440 924
441 // Open new tab. Should use local NTP. 925 // Open new tab. Should use local NTP.
442 ui_test_utils::NavigateToURLWithDisposition( 926 ui_test_utils::NavigateToURLWithDisposition(
443 browser(), 927 browser(),
444 GURL(chrome::kChromeUINewTabURL), 928 GURL(chrome::kChromeUINewTabURL),
445 NEW_FOREGROUND_TAB, 929 NEW_FOREGROUND_TAB,
446 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 930 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
447 content::WebContents* active_tab = 931 content::WebContents* active_tab =
448 browser()->tab_strip_model()->GetActiveWebContents(); 932 browser()->tab_strip_model()->GetActiveWebContents();
449 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec()); 933 EXPECT_EQ(instant()->GetLocalInstantURL(), active_tab->GetURL().spec());
450 } 934 }
451 935
452 // Flaky, http://crbug.com/240852 . 936 // Flaky, http://crbug.com/240852 .
453 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_OmniboxHasFocusOnNewTab) { 937 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_OmniboxHasFocusOnNewTab) {
454 // Setup Instant. 938 // Setup Instant.
455 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 939 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
456 FocusOmniboxAndWaitForInstantNTPSupport(); 940 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
457 941
458 // Explicitly unfocus the omnibox. 942 // Explicitly unfocus the omnibox.
459 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 943 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
460 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 944 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
461 EXPECT_FALSE(omnibox()->model()->has_focus()); 945 EXPECT_FALSE(omnibox()->model()->has_focus());
462 946
463 // Open new tab. Preloaded NTP contents should have been used. 947 // Open new tab. Preloaded NTP contents should have been used.
464 ui_test_utils::NavigateToURLWithDisposition( 948 ui_test_utils::NavigateToURLWithDisposition(
465 browser(), 949 browser(),
466 GURL(chrome::kChromeUINewTabURL), 950 GURL(chrome::kChromeUINewTabURL),
467 NEW_FOREGROUND_TAB, 951 NEW_FOREGROUND_TAB,
468 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 952 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
469 953
470 // Omnibox should have focus. 954 // Omnibox should have focus.
471 EXPECT_TRUE(omnibox()->model()->has_focus()); 955 EXPECT_TRUE(omnibox()->model()->has_focus());
472 } 956 }
473 957
474 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) { 958 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
475 // Setup Instant. 959 // Setup Instant.
476 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 960 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
477 FocusOmniboxAndWaitForInstantNTPSupport(); 961 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
478 962
479 // Open new tab. Preloaded NTP contents should have been used. 963 // Open new tab. Preloaded NTP contents should have been used.
480 ui_test_utils::NavigateToURLWithDisposition( 964 ui_test_utils::NavigateToURLWithDisposition(
481 browser(), 965 browser(),
482 GURL(chrome::kChromeUINewTabURL), 966 GURL(chrome::kChromeUINewTabURL),
483 NEW_FOREGROUND_TAB, 967 NEW_FOREGROUND_TAB,
484 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 968 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
485 969
486 // Omnibox should be empty. 970 // Omnibox should be empty.
487 EXPECT_TRUE(omnibox()->GetText().empty()); 971 EXPECT_TRUE(omnibox()->GetText().empty());
488 } 972 }
489 973
490 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) { 974 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoFaviconOnNewTabPage) {
491 // Setup Instant. 975 // Setup Instant.
492 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 976 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
493 FocusOmniboxAndWaitForInstantNTPSupport(); 977 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
494 978
495 // Open new tab. Preloaded NTP contents should have been used. 979 // Open new tab. Preloaded NTP contents should have been used.
496 ui_test_utils::NavigateToURLWithDisposition( 980 ui_test_utils::NavigateToURLWithDisposition(
497 browser(), 981 browser(),
498 GURL(chrome::kChromeUINewTabURL), 982 GURL(chrome::kChromeUINewTabURL),
499 NEW_FOREGROUND_TAB, 983 NEW_FOREGROUND_TAB,
500 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 984 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
501 985
502 // No favicon should be shown. 986 // No favicon should be shown.
503 content::WebContents* active_tab = 987 content::WebContents* active_tab =
504 browser()->tab_strip_model()->GetActiveWebContents(); 988 browser()->tab_strip_model()->GetActiveWebContents();
505 FaviconTabHelper* favicon_tab_helper = 989 FaviconTabHelper* favicon_tab_helper =
506 FaviconTabHelper::FromWebContents(active_tab); 990 FaviconTabHelper::FromWebContents(active_tab);
507 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon()); 991 EXPECT_FALSE(favicon_tab_helper->ShouldDisplayFavicon());
508 992
509 // Favicon should be shown off the NTP. 993 // Favicon should be shown off the NTP.
510 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 994 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
511 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 995 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
512 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab); 996 favicon_tab_helper = FaviconTabHelper::FromWebContents(active_tab);
513 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon()); 997 EXPECT_TRUE(favicon_tab_helper->ShouldDisplayFavicon());
514 } 998 }
515 999
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
516 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { 1023 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
517 // Prior to setup, Instant has an ntp with a failed "google.com" load in 1024 // Prior to setup, Instant has an overlay with a failed "google.com" load in
518 // it, which is rendered in the dedicated Instant renderer process. 1025 // it, which is rendered in the dedicated Instant renderer process.
519 // 1026 //
520 // TODO(sreeram): Fix this up when we stop doing crazy things on init. 1027 // TODO(sreeram): Fix this up when we stop doing crazy things on init.
521 InstantService* instant_service = 1028 InstantService* instant_service =
522 InstantServiceFactory::GetForProfile(browser()->profile()); 1029 InstantServiceFactory::GetForProfile(browser()->profile());
523 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 1030 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
524 #if !defined(OS_MACOSX) 1031 #if !defined(OS_MACOSX)
525 // The failed "google.com" load is deleted, which sometimes leads to the 1032 // The failed "google.com" load is deleted, which sometimes leads to the
526 // process shutting down on Mac. 1033 // process shutting down on Mac.
527 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 1034 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
528 #endif 1035 #endif
529 1036
530 // Setup Instant. 1037 // Setup Instant.
531 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1038 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
532 FocusOmniboxAndWaitForInstantNTPSupport(); 1039 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
533 1040
534 // The registered Instant render process should still exist. 1041 // The registered Instant render process should still exist.
535 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 1042 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
536 // And the Instant ntp should live inside it. 1043
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()));
537 content::WebContents* ntp_contents = instant()->ntp_->contents(); 1048 content::WebContents* ntp_contents = instant()->ntp_->contents();
538 EXPECT_TRUE(instant_service->IsInstantProcess( 1049 EXPECT_TRUE(instant_service->IsInstantProcess(
539 ntp_contents->GetRenderProcessHost()->GetID())); 1050 ntp_contents->GetRenderProcessHost()->GetID()));
540 1051
541 // Navigating to the NTP should use the Instant render process. 1052 // Navigating to the NTP should use the Instant render process.
542 ui_test_utils::NavigateToURLWithDisposition( 1053 ui_test_utils::NavigateToURLWithDisposition(
543 browser(), 1054 browser(),
544 GURL(chrome::kChromeUINewTabURL), 1055 GURL(chrome::kChromeUINewTabURL),
545 CURRENT_TAB, 1056 CURRENT_TAB,
546 ui_test_utils::BROWSER_TEST_NONE); 1057 ui_test_utils::BROWSER_TEST_NONE);
547 content::WebContents* active_tab = 1058 content::WebContents* active_tab =
548 browser()->tab_strip_model()->GetActiveWebContents(); 1059 browser()->tab_strip_model()->GetActiveWebContents();
549 EXPECT_TRUE(instant_service->IsInstantProcess( 1060 EXPECT_TRUE(instant_service->IsInstantProcess(
550 active_tab->GetRenderProcessHost()->GetID())); 1061 active_tab->GetRenderProcessHost()->GetID()));
551 1062
552 // Navigating elsewhere should not use the Instant render process. 1063 // Navigating elsewhere should not use the Instant render process.
553 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); 1064 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
554 EXPECT_FALSE(instant_service->IsInstantProcess( 1065 EXPECT_FALSE(instant_service->IsInstantProcess(
555 active_tab->GetRenderProcessHost()->GetID())); 1066 active_tab->GetRenderProcessHost()->GetID()));
556 } 1067 }
557 1068
558 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_MostVisited) { 1069 // Test that a search query will not be displayed for navsuggest queries.
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) {
559 content::WindowedNotificationObserver observer( 1281 content::WindowedNotificationObserver observer(
560 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1282 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
561 content::NotificationService::AllSources()); 1283 content::NotificationService::AllSources());
562 // Initialize Instant. 1284 // Initialize Instant.
563 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1285 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
564 FocusOmniboxAndWaitForInstantNTPSupport(); 1286 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
565 1287
566 // Get a handle to the NTP and the current state of the JS. 1288 // Get a handle to the NTP and the current state of the JS.
567 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 1289 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
568 content::WebContents* ntp = instant()->ntp_->contents(); 1290 content::WebContents* overlay = instant()->ntp_->contents();
569 EXPECT_TRUE(ntp); 1291 EXPECT_TRUE(overlay);
570 EXPECT_TRUE(UpdateSearchState(ntp)); 1292 EXPECT_TRUE(UpdateSearchState(overlay));
571 1293
572 // Wait for most visited data to be ready, if necessary. 1294 // Wait for most visited data to be ready, if necessary.
573 if (on_most_visited_change_calls_ == 0) { 1295 if (on_most_visited_change_calls_ == 0) {
574 observer.Wait(); 1296 observer.Wait();
575 EXPECT_TRUE(UpdateSearchState(ntp)); 1297 EXPECT_TRUE(UpdateSearchState(overlay));
576 } 1298 }
577 1299
578 EXPECT_EQ(1, on_most_visited_change_calls_); 1300 EXPECT_EQ(1, on_most_visited_change_calls_);
579 1301
580 // Make sure we have at least two Most Visited Items and save that number. 1302 // Make sure we have at least two Most Visited Items and save that number.
581 // TODO(pedrosimonetti): For now, we're relying on the fact that the Top 1303 // TODO(pedrosimonetti): For now, we're relying on the fact that the Top
582 // Sites will have at lease two items in it. The correct approach would be 1304 // Sites will have at lease two items in it. The correct approach would be
583 // adding those items to the Top Sites manually before starting the test. 1305 // adding those items to the Top Sites manually before starting the test.
584 EXPECT_GT(most_visited_items_count_, 1); 1306 EXPECT_GT(most_visited_items_count_, 1);
585 int old_most_visited_items_count = most_visited_items_count_; 1307 int old_most_visited_items_count = most_visited_items_count_;
586 1308
587 // Delete the fist Most Visited Item. 1309 // Delete the fist Most Visited Item.
588 int rid = first_most_visited_item_id_; 1310 int rid = first_most_visited_item_id_;
589 std::ostringstream stream; 1311 std::ostringstream stream;
590 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 1312 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
591 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str())); 1313 EXPECT_TRUE(ExecuteScript(stream.str()));
592 observer.Wait(); 1314 observer.Wait();
593 1315
594 // Update Most Visited state. 1316 // Update Most Visited state.
595 EXPECT_TRUE(UpdateSearchState(ntp)); 1317 EXPECT_TRUE(UpdateSearchState(overlay));
596 1318
597 // Make sure we have one less item in there. 1319 // Make sure we have one less item in there.
598 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 1); 1320 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 1);
599 1321
600 // Undo the deletion of the fist Most Visited Item. 1322 // Undo the deletion of the fist Most Visited Item.
601 stream.str(std::string()); 1323 stream.str(std::string());
602 stream << "newTabPageHandle.undoMostVisitedDeletion(" << rid << ");"; 1324 stream << "newTabPageHandle.undoMostVisitedDeletion(" << rid << ");";
603 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str())); 1325 EXPECT_TRUE(ExecuteScript(stream.str()));
604 observer.Wait(); 1326 observer.Wait();
605 1327
606 // Update Most Visited state. 1328 // Update Most Visited state.
607 EXPECT_TRUE(UpdateSearchState(ntp)); 1329 EXPECT_TRUE(UpdateSearchState(overlay));
608 1330
609 // Make sure we have the same number of items as before. 1331 // Make sure we have the same number of items as before.
610 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); 1332 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count);
611 1333
612 // Delete the fist Most Visited Item. 1334 // Delete the fist Most Visited Item.
613 rid = first_most_visited_item_id_; 1335 rid = first_most_visited_item_id_;
614 stream.str(std::string()); 1336 stream.str(std::string());
615 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 1337 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
616 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str())); 1338 EXPECT_TRUE(ExecuteScript(stream.str()));
617 observer.Wait(); 1339 observer.Wait();
618 1340
619 // Update Most Visited state. 1341 // Update Most Visited state.
620 EXPECT_TRUE(UpdateSearchState(ntp)); 1342 EXPECT_TRUE(UpdateSearchState(overlay));
621 1343
622 // Delete the second Most Visited Item. 1344 // Delete the second Most Visited Item.
623 rid = first_most_visited_item_id_; 1345 rid = first_most_visited_item_id_;
624 stream.str(std::string()); 1346 stream.str(std::string());
625 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");"; 1347 stream << "newTabPageHandle.deleteMostVisitedItem(" << rid << ");";
626 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str())); 1348 EXPECT_TRUE(ExecuteScript(stream.str()));
627 observer.Wait(); 1349 observer.Wait();
628 1350
629 // Update Most Visited state. 1351 // Update Most Visited state.
630 EXPECT_TRUE(UpdateSearchState(ntp)); 1352 EXPECT_TRUE(UpdateSearchState(overlay));
631 1353
632 // Make sure we have two less items in there. 1354 // Make sure we have two less items in there.
633 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 2); 1355 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 2);
634 1356
635 // Delete the second Most Visited Item. 1357 // Delete the second Most Visited Item.
636 stream.str(std::string()); 1358 stream.str(std::string());
637 stream << "newTabPageHandle.undoAllMostVisitedDeletions();"; 1359 stream << "newTabPageHandle.undoAllMostVisitedDeletions();";
638 EXPECT_TRUE(content::ExecuteScript(ntp, stream.str())); 1360 EXPECT_TRUE(ExecuteScript(stream.str()));
639 observer.Wait(); 1361 observer.Wait();
640 1362
641 // Update Most Visited state. 1363 // Update Most Visited state.
642 EXPECT_TRUE(UpdateSearchState(ntp)); 1364 EXPECT_TRUE(UpdateSearchState(overlay));
643 1365
644 // Make sure we have the same number of items as before. 1366 // Make sure we have the same number of items as before.
645 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); 1367 EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count);
646 } 1368 }
647 1369
648 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) { 1370 IN_PROC_BROWSER_TEST_F(InstantPolicyTest, ThemeBackgroundAccess) {
649 InstallThemeSource(); 1371 InstallThemeSource();
650 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme")); 1372 ASSERT_NO_FATAL_FAILURE(InstallThemeAndVerify("theme", "camo theme"));
651 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1373 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
652 FocusOmniboxAndWaitForInstantNTPSupport(); 1374 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
653 1375
654 // The "Instant" New Tab should have access to chrome-search: scheme but not 1376 // The "Instant" New Tab should have access to chrome-search: scheme but not
655 // chrome: scheme. 1377 // chrome: scheme.
656 ui_test_utils::NavigateToURLWithDisposition( 1378 ui_test_utils::NavigateToURLWithDisposition(
657 browser(), 1379 browser(),
658 GURL(chrome::kChromeUINewTabURL), 1380 GURL(chrome::kChromeUINewTabURL),
659 NEW_FOREGROUND_TAB, 1381 NEW_FOREGROUND_TAB,
660 ui_test_utils::BROWSER_TEST_NONE); 1382 ui_test_utils::BROWSER_TEST_NONE);
661 1383
662 content::RenderViewHost* rvh = 1384 content::RenderViewHost* rvh =
(...skipping 12 matching lines...) Expand all
675 // TODO(dhollowa): Fix flakes. http://crbug.com/179930. 1397 // TODO(dhollowa): Fix flakes. http://crbug.com/179930.
676 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) { 1398 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_FaviconAccess) {
677 // Create a favicon. 1399 // Create a favicon.
678 history::TopSites* top_sites = browser()->profile()->GetTopSites(); 1400 history::TopSites* top_sites = browser()->profile()->GetTopSites();
679 GURL url("http://www.google.com/foo.html"); 1401 GURL url("http://www.google.com/foo.html");
680 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE)); 1402 gfx::Image thumbnail(CreateBitmap(SK_ColorWHITE));
681 ThumbnailScore high_score(0.0, true, true, base::Time::Now()); 1403 ThumbnailScore high_score(0.0, true, true, base::Time::Now());
682 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score)); 1404 EXPECT_TRUE(top_sites->SetPageThumbnail(url, thumbnail, high_score));
683 1405
684 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1406 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
685 FocusOmniboxAndWaitForInstantNTPSupport(); 1407 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
686 1408
687 // The "Instant" New Tab should have access to chrome-search: scheme but not 1409 // The "Instant" New Tab should have access to chrome-search: scheme but not
688 // chrome: scheme. 1410 // chrome: scheme.
689 ui_test_utils::NavigateToURLWithDisposition( 1411 ui_test_utils::NavigateToURLWithDisposition(
690 browser(), 1412 browser(),
691 GURL(chrome::kChromeUINewTabURL), 1413 GURL(chrome::kChromeUINewTabURL),
692 NEW_FOREGROUND_TAB, 1414 NEW_FOREGROUND_TAB,
693 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1415 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
694 1416
695 content::RenderViewHost* rvh = 1417 content::RenderViewHost* rvh =
696 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(); 1418 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost();
697 1419
698 // Get the favicons. 1420 // Get the favicons.
699 const std::string chrome_favicon_url( 1421 const std::string chrome_favicon_url(
700 "chrome://favicon/largest/http://www.google.com/foo.html"); 1422 "chrome://favicon/largest/http://www.google.com/foo.html");
701 const std::string search_favicon_url( 1423 const std::string search_favicon_url(
702 "chrome-search://favicon/largest/http://www.google.com/foo.html"); 1424 "chrome-search://favicon/largest/http://www.google.com/foo.html");
703 bool loaded = false; 1425 bool loaded = false;
704 ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded)); 1426 ASSERT_TRUE(LoadImage(rvh, chrome_favicon_url, &loaded));
705 EXPECT_FALSE(loaded) << chrome_favicon_url; 1427 EXPECT_FALSE(loaded) << chrome_favicon_url;
706 ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded)); 1428 ASSERT_TRUE(LoadImage(rvh, search_favicon_url, &loaded));
707 EXPECT_TRUE(loaded) << search_favicon_url; 1429 EXPECT_TRUE(loaded) << search_favicon_url;
708 } 1430 }
709 1431
1432 // WebUIBindings should never be enabled on ANY Instant web contents.
1433 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnNTP) {
1434 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1435 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1436
1437 ui_test_utils::NavigateToURLWithDisposition(
1438 browser(),
1439 GURL(chrome::kChromeUINewTabURL),
1440 NEW_FOREGROUND_TAB,
1441 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1442 const content::WebContents* tab =
1443 browser()->tab_strip_model()->GetActiveWebContents();
1444
1445 // Instant-provided NTP should not have any bindings enabled.
1446 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings());
1447 }
1448
1449 // 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) {
1466 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1467 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1468
1469 // Typing in the omnibox shows the overlay.
1470 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query"));
1471 content::WebContents* preview = instant()->GetOverlayContents();
1472 EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
1473 // Commit the search by pressing Enter.
1474 browser()->window()->GetLocationBar()->AcceptInput();
1475 EXPECT_TRUE(instant()->model()->mode().is_default());
1476 const content::WebContents* tab =
1477 browser()->tab_strip_model()->GetActiveWebContents();
1478 EXPECT_EQ(preview, tab);
1479
1480 // The commited Instant page should not have any bindings enabled.
1481 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings());
1482 }
1483
710 // Only implemented in Views and Mac currently: http://crbug.com/164723 1484 // Only implemented in Views and Mac currently: http://crbug.com/164723
711 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX) 1485 #if defined(OS_WIN) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
712 #define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin 1486 #define MAYBE_HomeButtonAffectsMargin HomeButtonAffectsMargin
713 #else 1487 #else
714 #define MAYBE_HomeButtonAffectsMargin DISABLED_HomeButtonAffectsMargin 1488 #define MAYBE_HomeButtonAffectsMargin DISABLED_HomeButtonAffectsMargin
715 #endif 1489 #endif
716
717 // Check that toggling the state of the home button changes the start-edge 1490 // Check that toggling the state of the home button changes the start-edge
718 // margin and width. 1491 // margin and width.
719 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { 1492 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) {
720 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1493 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
721 FocusOmniboxAndWaitForInstantNTPSupport(); 1494 FocusOmniboxAndWaitForInstantOverlaySupport();
722 1495
723 // Get the current value of the start-edge margin and width. 1496 // Get the current value of the start-edge margin and width.
724 int start_margin; 1497 int start_margin;
725 int width; 1498 int width;
726 content::WebContents* ntp = instant()->ntp_->contents(); 1499 content::WebContents* overlay = instant()->GetOverlayContents();
727 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.startMargin", &start_margin)); 1500 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin",
728 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.width", &width)); 1501 &start_margin));
1502 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &width));
729 1503
730 // Toggle the home button visibility pref. 1504 // Toggle the home button visibility pref.
731 PrefService* profile_prefs = browser()->profile()->GetPrefs(); 1505 PrefService* profile_prefs = browser()->profile()->GetPrefs();
732 bool show_home = profile_prefs->GetBoolean(prefs::kShowHomeButton); 1506 bool show_home = profile_prefs->GetBoolean(prefs::kShowHomeButton);
733 profile_prefs->SetBoolean(prefs::kShowHomeButton, !show_home); 1507 profile_prefs->SetBoolean(prefs::kShowHomeButton, !show_home);
734 1508
735 // Make sure the margin and width changed. 1509 // Make sure the margin and width changed.
736 int new_start_margin; 1510 int new_start_margin;
737 int new_width; 1511 int new_width;
738 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.startMargin", 1512 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin",
739 &new_start_margin)); 1513 &new_start_margin));
740 EXPECT_TRUE(GetIntFromJS(ntp, "chrome.searchBox.width", &new_width)); 1514 EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &new_width));
741 EXPECT_NE(start_margin, new_start_margin); 1515 EXPECT_NE(start_margin, new_start_margin);
742 EXPECT_NE(width, new_width); 1516 EXPECT_NE(width, new_width);
743 EXPECT_EQ(new_width - width, start_margin - new_start_margin); 1517 EXPECT_EQ(new_width - width, start_margin - new_start_margin);
744 } 1518 }
745 1519
746 // WebUIBindings should never be enabled on ANY Instant web contents. 1520 // Commit does not happen on Mac: http://crbug.com/178520
747 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnNTP) { 1521 #if defined(OS_MACOSX)
748 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1522 #define MAYBE_CommitWhenFocusLostInFullHeight \
749 FocusOmniboxAndWaitForInstantNTPSupport(); 1523 DISABLED_CommitWhenFocusLostInFullHeight
750 1524 #else
751 ui_test_utils::NavigateToURLWithDisposition( 1525 #define MAYBE_CommitWhenFocusLostInFullHeight CommitWhenFocusLostInFullHeight
752 browser(), 1526 #endif
753 GURL(chrome::kChromeUINewTabURL), 1527 // Test that the overlay is committed when the omnibox loses focus when it is
754 NEW_FOREGROUND_TAB, 1528 // shown at 100% height.
755 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1529 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
756 const content::WebContents* tab = 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 =
757 browser()->tab_strip_model()->GetActiveWebContents(); 1553 browser()->tab_strip_model()->GetActiveWebContents();
758 1554 EXPECT_EQ(overlay, active_tab);
759 // Instant-provided NTP should not have any bindings enabled. 1555 }
760 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); 1556
761 } 1557 #if defined(OS_MACOSX)
762 1558 // http://crbug.com/227076
763 // WebUIBindings should never be enabled on ANY Instant web contents. 1559 #define MAYBE_CommitWhenShownInFullHeightWithoutFocus \
764 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoWebUIBindingsOnResults) { 1560 DISABLED_CommitWhenShownInFullHeightWithoutFocus
765 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1561 #else
766 FocusOmniboxAndWaitForInstantNTPSupport(); 1562 #define MAYBE_CommitWhenShownInFullHeightWithoutFocus \
767 1563 CommitWhenShownInFullHeightWithoutFocus
768 // Type a query and press enter to get results. 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.
769 SetOmniboxText("query"); 1591 SetOmniboxText("query");
770 // Commit the search by pressing Enter. 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"));
771 browser()->window()->GetLocationBar()->AcceptInput(); 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);
772 EXPECT_TRUE(instant()->model()->mode().is_default()); 1655 EXPECT_TRUE(instant()->model()->mode().is_default());
773 const content::WebContents* tab = 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 =
774 browser()->tab_strip_model()->GetActiveWebContents(); 1677 browser()->tab_strip_model()->GetActiveWebContents();
775 1678 EXPECT_EQ(overlay, active_tab);
776 // The commited Instant page should not have any bindings enabled. 1679
777 EXPECT_EQ(0, tab->GetRenderViewHost()->GetEnabledBindings()); 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_);
778 } 1811 }
779 1812
780 // Test that the Bookmark provider is enabled, and returns results. 1813 // Test that the Bookmark provider is enabled, and returns results.
781 // TODO(sreeram): Convert this to a unit test. 1814 // TODO(sreeram): Convert this to a unit test.
782 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_HasBookmarkProvider) { 1815 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_HasBookmarkProvider) {
783 // No need to setup Instant. 1816 // No need to setup Instant.
784 set_browser(browser()); 1817 set_browser(browser());
785 1818
786 BookmarkModel* bookmark_model = 1819 BookmarkModel* bookmark_model =
787 BookmarkModelFactory::GetForProfile(browser()->profile()); 1820 BookmarkModelFactory::GetForProfile(browser()->profile());
788 ASSERT_TRUE(bookmark_model); 1821 ASSERT_TRUE(bookmark_model);
789 ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model); 1822 ui_test_utils::WaitForBookmarkModelToLoad(bookmark_model);
790 bookmark_utils::AddIfNotBookmarked(bookmark_model, GURL("http://angeline/"), 1823 bookmark_utils::AddIfNotBookmarked(bookmark_model, GURL("http://angeline/"),
791 ASCIIToUTF16("angeline")); 1824 ASCIIToUTF16("angeline"));
792 1825
793 SetOmniboxText("angeline"); 1826 SetOmniboxText("angeline");
794 1827
795 bool found_bookmark_match = false; 1828 bool found_bookmark_match = false;
796 1829
797 const AutocompleteResult& result = omnibox()->model()->result(); 1830 const AutocompleteResult& result = omnibox()->model()->result();
798 for (AutocompleteResult::const_iterator iter = result.begin(); 1831 for (AutocompleteResult::const_iterator iter = result.begin();
799 !found_bookmark_match && iter != result.end(); ++iter) { 1832 !found_bookmark_match && iter != result.end(); ++iter) {
800 found_bookmark_match = iter->type == AutocompleteMatchType::BOOKMARK_TITLE; 1833 found_bookmark_match = iter->type == AutocompleteMatchType::BOOKMARK_TITLE;
801 } 1834 }
802 1835
803 EXPECT_TRUE(found_bookmark_match); 1836 EXPECT_TRUE(found_bookmark_match);
804 } 1837 }
805 1838
1839 // Test that the omnibox's temporary text is reset when the popup is closed.
1840 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, TemporaryTextResetWhenPopupClosed) {
1841 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1842 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
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
806 // Test that hitting Esc to clear the omnibox works. http://crbug.com/231744. 1948 // Test that hitting Esc to clear the omnibox works. http://crbug.com/231744.
807 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_EscapeClearsOmnibox) { 1949 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EscapeClearsOmnibox) {
808 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 1950 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
809 FocusOmniboxAndWaitForInstantNTPSupport(); 1951 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
810 1952
811 // Navigate to the Instant NTP, and wait for it to be recognized. 1953 // Navigate to the Instant NTP, and wait for it to be recognized.
812 content::WindowedNotificationObserver instant_tab_observer( 1954 content::WindowedNotificationObserver instant_tab_observer(
813 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 1955 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
814 content::NotificationService::AllSources()); 1956 content::NotificationService::AllSources());
815 ui_test_utils::NavigateToURLWithDisposition( 1957 ui_test_utils::NavigateToURLWithDisposition(
816 browser(), 1958 browser(),
817 GURL(chrome::kChromeUINewTabURL), 1959 GURL(chrome::kChromeUINewTabURL),
818 NEW_FOREGROUND_TAB, 1960 NEW_FOREGROUND_TAB,
819 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1961 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
(...skipping 18 matching lines...) Expand all
838 &query)); 1980 &query));
839 EXPECT_EQ("", query); 1981 EXPECT_EQ("", query);
840 EXPECT_EQ("", GetOmniboxText()); 1982 EXPECT_EQ("", GetOmniboxText());
841 1983
842 EXPECT_TRUE(UpdateSearchState(contents)); 1984 EXPECT_TRUE(UpdateSearchState(contents));
843 EXPECT_LT(0, on_change_calls_); 1985 EXPECT_LT(0, on_change_calls_);
844 EXPECT_EQ(0, submit_count_); 1986 EXPECT_EQ(0, submit_count_);
845 EXPECT_LT(0, on_esc_key_press_event_calls_); 1987 EXPECT_LT(0, on_esc_key_press_event_calls_);
846 } 1988 }
847 1989
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
848 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { 2047 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) {
849 InstantService* instant_service = 2048 InstantService* instant_service =
850 InstantServiceFactory::GetForProfile(browser()->profile()); 2049 InstantServiceFactory::GetForProfile(browser()->profile());
851 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 2050 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
852 2051
853 // Setup Instant. 2052 // Setup Instant.
854 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2053 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
855 FocusOmniboxAndWaitForInstantNTPSupport(); 2054 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
856 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); 2055 EXPECT_EQ(1, instant_service->GetInstantProcessCount());
857 2056
858 // Navigating to the NTP should use the Instant render process. 2057 // Navigating to the NTP should use the Instant render process.
859 ui_test_utils::NavigateToURLWithDisposition( 2058 ui_test_utils::NavigateToURLWithDisposition(
860 browser(), 2059 browser(),
861 GURL(chrome::kChromeUINewTabURL), 2060 GURL(chrome::kChromeUINewTabURL),
862 CURRENT_TAB, 2061 CURRENT_TAB,
863 ui_test_utils::BROWSER_TEST_NONE); 2062 ui_test_utils::BROWSER_TEST_NONE);
864 content::WebContents* ntp_contents = 2063 content::WebContents* ntp_contents =
865 browser()->tab_strip_model()->GetActiveWebContents(); 2064 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 observer.Wait(); 2097 observer.Wait();
899 2098
900 // |ntp_contents| should not use the Instant render process. 2099 // |ntp_contents| should not use the Instant render process.
901 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); 2100 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents));
902 EXPECT_FALSE(instant_service->IsInstantProcess( 2101 EXPECT_FALSE(instant_service->IsInstantProcess(
903 ntp_contents->GetRenderProcessHost()->GetID())); 2102 ntp_contents->GetRenderProcessHost()->GetID()));
904 // Make sure the URL remains the same. 2103 // Make sure the URL remains the same.
905 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); 2104 EXPECT_EQ(ntp_url, ntp_contents->GetURL());
906 } 2105 }
907 2106
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
908 // Test that renderer initiated navigations to an instant URL from a non 2198 // Test that renderer initiated navigations to an instant URL from a non
909 // Instant page do not end up in an Instant process if they are bounced to the 2199 // Instant page do not end up in an Instant process if they are bounced to the
910 // browser. 2200 // browser.
911 IN_PROC_BROWSER_TEST_F( 2201 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
912 InstantExtendedTest, 2202 RendererInitiatedNavigationNotInInstantProcess) {
913 DISABLED_RendererInitiatedNavigationNotInInstantProcess) {
914 InstantService* instant_service = 2203 InstantService* instant_service =
915 InstantServiceFactory::GetForProfile(browser()->profile()); 2204 InstantServiceFactory::GetForProfile(browser()->profile());
916 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 2205 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
917 2206
918 // Setup Instant. 2207 // Setup Instant.
919 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2208 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
920 FocusOmniboxAndWaitForInstantNTPSupport(); 2209 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
921 2210
922 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 2211 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
923 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2212 EXPECT_EQ(1, browser()->tab_strip_model()->count());
924 2213
925 // Don't use https server for the non instant URL so that the browser uses 2214 // Don't use https server for the non instant URL so that the browser uses
926 // different RenderViews. 2215 // different RenderViews.
927 GURL non_instant_url = test_server()->GetURL("files/simple.html"); 2216 GURL non_instant_url = test_server()->GetURL("files/simple.html");
928 ui_test_utils::NavigateToURLWithDisposition( 2217 ui_test_utils::NavigateToURLWithDisposition(
929 browser(), 2218 browser(),
930 non_instant_url, 2219 non_instant_url,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 // Test that renderer initiated navigations to an Instant URL from an 2264 // Test that renderer initiated navigations to an Instant URL from an
976 // Instant process end up in an Instant process. 2265 // Instant process end up in an Instant process.
977 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 2266 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
978 RendererInitiatedNavigationInInstantProcess) { 2267 RendererInitiatedNavigationInInstantProcess) {
979 InstantService* instant_service = 2268 InstantService* instant_service =
980 InstantServiceFactory::GetForProfile(browser()->profile()); 2269 InstantServiceFactory::GetForProfile(browser()->profile());
981 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); 2270 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
982 2271
983 // Setup Instant. 2272 // Setup Instant.
984 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2273 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
985 FocusOmniboxAndWaitForInstantNTPSupport(); 2274 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
986 2275
987 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 2276 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
988 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2277 EXPECT_EQ(1, browser()->tab_strip_model()->count());
989 2278
990 ui_test_utils::NavigateToURLWithDisposition( 2279 ui_test_utils::NavigateToURLWithDisposition(
991 browser(), 2280 browser(),
992 instant_url(), 2281 instant_url(),
993 CURRENT_TAB, 2282 CURRENT_TAB,
994 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 2283 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
995 content::WebContents* contents = 2284 content::WebContents* contents =
(...skipping 17 matching lines...) Expand all
1013 contents, "document.getElementById('toClick').click();")); 2302 contents, "document.getElementById('toClick').click();"));
1014 observer.Wait(); 2303 observer.Wait();
1015 2304
1016 EXPECT_EQ(1, browser()->tab_strip_model()->count()); 2305 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1017 contents = browser()->tab_strip_model()->GetActiveWebContents(); 2306 contents = browser()->tab_strip_model()->GetActiveWebContents();
1018 EXPECT_TRUE(instant_service->IsInstantProcess( 2307 EXPECT_TRUE(instant_service->IsInstantProcess(
1019 contents->GetRenderProcessHost()->GetID())); 2308 contents->GetRenderProcessHost()->GetID()));
1020 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); 2309 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL());
1021 } 2310 }
1022 2311
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
1023 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { 2460 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) {
1024 // Get a committed Instant tab, which will be in the Instant process and thus 2461 // Get a committed Instant tab, which will be in the Instant process and thus
1025 // support chrome::GetSearchTerms(). 2462 // support chrome::GetSearchTerms().
1026 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2463 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1027 FocusOmnibox(); 2464 FocusOmniboxAndWaitForInstantOverlaySupport();
1028 2465
1029 // Create an observer to wait for the instant tab to support Instant. 2466 // Create an observer to wait for the instant tab to support Instant.
1030 content::WindowedNotificationObserver observer( 2467 content::WindowedNotificationObserver observer(
1031 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2468 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1032 content::NotificationService::AllSources()); 2469 content::NotificationService::AllSources());
1033 2470
1034 // Do a search and commit it. 2471 // Do a search and commit it.
1035 SetOmniboxText("foo"); 2472 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo"));
1036 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 2473 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
1037 browser()->window()->GetLocationBar()->AcceptInput(); 2474 browser()->window()->GetLocationBar()->AcceptInput();
1038 observer.Wait(); 2475 observer.Wait();
1039 2476
1040 // Set URL-like search terms for the instant tab. 2477 // Set URL-like search terms for the instant tab.
1041 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 2478 content::WebContents* instant_tab = instant()->instant_tab()->contents();
1042 content::NavigationEntry* visible_entry = 2479 content::NavigationEntry* visible_entry =
1043 instant_tab->GetController().GetVisibleEntry(); 2480 instant_tab->GetController().GetVisibleEntry();
1044 visible_entry->SetExtraData(sessions::kSearchTermsKey, 2481 visible_entry->SetExtraData(sessions::kSearchTermsKey,
1045 ASCIIToUTF16("http://example.com")); 2482 ASCIIToUTF16("http://example.com"));
1046 SetOmniboxText("http://example.com"); 2483 SetOmniboxText("http://example.com");
1047 omnibox()->model()->SetInputInProgress(false); 2484 omnibox()->model()->SetInputInProgress(false);
1048 omnibox()->CloseOmniboxPopup(); 2485 omnibox()->CloseOmniboxPopup();
1049 2486
1050 // Accept the omnibox input. 2487 // Accept the omnibox input.
1051 EXPECT_FALSE(omnibox()->model()->user_input_in_progress()); 2488 EXPECT_FALSE(omnibox()->model()->user_input_in_progress());
1052 EXPECT_TRUE( 2489 EXPECT_TRUE(
1053 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms()); 2490 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms());
1054 GURL instant_tab_url = instant_tab->GetURL(); 2491 GURL instant_tab_url = instant_tab->GetURL();
1055 browser()->window()->GetLocationBar()->AcceptInput(); 2492 browser()->window()->GetLocationBar()->AcceptInput();
1056 EXPECT_EQ(instant_tab_url, instant_tab->GetURL()); 2493 EXPECT_EQ(instant_tab_url, instant_tab->GetURL());
1057 } 2494 }
1058 2495
1059 // TODO(jered): Figure out why this test flakes and fix it. 2496 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingJSSearchDoesNotRunJS) {
1060 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1061 DISABLED_AcceptingJSSearchDoesNotRunJS) {
1062 // Get a committed Instant tab, which will be in the Instant process and thus 2497 // Get a committed Instant tab, which will be in the Instant process and thus
1063 // support chrome::GetSearchTerms(). 2498 // support chrome::GetSearchTerms().
1064 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2499 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1065 FocusOmnibox(); 2500 FocusOmniboxAndWaitForInstantOverlaySupport();
1066 2501
1067 // Create an observer to wait for the instant tab to support Instant. 2502 // Create an observer to wait for the instant tab to support Instant.
1068 content::WindowedNotificationObserver observer( 2503 content::WindowedNotificationObserver observer(
1069 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2504 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1070 content::NotificationService::AllSources()); 2505 content::NotificationService::AllSources());
1071 2506
1072 // Do a search and commit it. 2507 // Do a search and commit it.
1073 SetOmniboxText("foo"); 2508 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo"));
1074 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 2509 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
1075 browser()->window()->GetLocationBar()->AcceptInput(); 2510 browser()->window()->GetLocationBar()->AcceptInput();
1076 observer.Wait(); 2511 observer.Wait();
1077 2512
1078 // Set URL-like search terms for the instant tab. 2513 // Set URL-like search terms for the instant tab.
1079 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 2514 content::WebContents* instant_tab = instant()->instant_tab()->contents();
1080 content::NavigationEntry* visible_entry = 2515 content::NavigationEntry* visible_entry =
1081 instant_tab->GetController().GetVisibleEntry(); 2516 instant_tab->GetController().GetVisibleEntry();
1082 const char kEvilJS[] = "javascript:document.title='evil';1;"; 2517 const char kEvilJS[] = "javascript:document.title='evil';1;";
1083 visible_entry->SetExtraData(sessions::kSearchTermsKey, ASCIIToUTF16(kEvilJS)); 2518 visible_entry->SetExtraData(sessions::kSearchTermsKey, ASCIIToUTF16(kEvilJS));
1084 SetOmniboxText(kEvilJS); 2519 SetOmniboxText(kEvilJS);
1085 omnibox()->model()->SetInputInProgress(false); 2520 omnibox()->model()->SetInputInProgress(false);
1086 omnibox()->CloseOmniboxPopup(); 2521 omnibox()->CloseOmniboxPopup();
1087 2522
1088 // Accept the omnibox input. 2523 // Accept the omnibox input.
1089 EXPECT_FALSE(omnibox()->model()->user_input_in_progress()); 2524 EXPECT_FALSE(omnibox()->model()->user_input_in_progress());
1090 EXPECT_TRUE( 2525 EXPECT_TRUE(
1091 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms()); 2526 browser()->toolbar_model()->WouldReplaceSearchURLWithSearchTerms());
1092 browser()->window()->GetLocationBar()->AcceptInput(); 2527 browser()->window()->GetLocationBar()->AcceptInput();
1093 // Force some Javascript to run in the renderer so the inline javascript: 2528 // Force some Javascript to run in the renderer so the inline javascript:
1094 // would be forced to run if it's going to. 2529 // would be forced to run if it's going to.
1095 EXPECT_TRUE(content::ExecuteScript(instant_tab, "1;")); 2530 EXPECT_TRUE(content::ExecuteScript(instant_tab, "1;"));
1096 EXPECT_NE(ASCIIToUTF16("evil"), instant_tab->GetTitle()); 2531 EXPECT_NE(ASCIIToUTF16("evil"), instant_tab->GetTitle());
1097 } 2532 }
1098 2533
1099 IN_PROC_BROWSER_TEST_F( 2534 // Flaky on mac: http://crbug.com/242164
1100 InstantExtendedTest, 2535 #if defined(OS_MACOSX)
1101 DISABLED_ReloadSearchAfterBackReloadsCorrectQuery) { 2536 #define MAYBE_ReloadSearchAfterBackReloadsCorrectQuery DISABLED_ReloadSearchAfte rBackReloadsCorrectQuery
2537 #else
2538 #define MAYBE_ReloadSearchAfterBackReloadsCorrectQuery ReloadSearchAfterBackRelo adsCorrectQuery
2539 #endif
2540
2541 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
2542 MAYBE_ReloadSearchAfterBackReloadsCorrectQuery) {
1102 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2543 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1103 FocusOmnibox(); 2544 FocusOmniboxAndWaitForInstantOverlaySupport();
1104 2545
1105 // Create an observer to wait for the instant tab to support Instant. 2546 // Create an observer to wait for the instant tab to support Instant.
1106 content::WindowedNotificationObserver observer( 2547 content::WindowedNotificationObserver observer(
1107 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2548 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1108 content::NotificationService::AllSources()); 2549 content::NotificationService::AllSources());
1109 2550
1110 // Search for [foo]. 2551 // Search for [foo].
1111 SetOmniboxText("foo"); 2552 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("foo"));
1112 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText()); 2553 EXPECT_EQ(ASCIIToUTF16("foo"), omnibox()->GetText());
1113 browser()->window()->GetLocationBar()->AcceptInput(); 2554 browser()->window()->GetLocationBar()->AcceptInput();
1114 observer.Wait(); 2555 observer.Wait();
1115 2556
1116 // Search again for [bar]. 2557 // Search again for [bar].
1117 content::WebContents* instant_tab = instant()->instant_tab()->contents(); 2558 content::WebContents* instant_tab = instant()->instant_tab()->contents();
1118 EXPECT_TRUE(content::ExecuteScript(instant_tab, 2559 EXPECT_TRUE(content::ExecuteScript(instant_tab,
1119 "suggestion = 'bart';")); 2560 "suggestion = 'bart';"));
1120 SetOmniboxTextAndWaitForSuggestion("bar"); 2561 SetOmniboxTextAndWaitForSuggestion("bar");
2562 EXPECT_EQ(ASCIIToUTF16("t"), GetGrayText());
1121 2563
1122 // Accept the new query and wait for the page to navigate. 2564 // Accept the new query and wait for the page to navigate.
1123 content::WindowedNotificationObserver nav_observer( 2565 content::WindowedNotificationObserver nav_observer(
1124 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 2566 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
1125 content::NotificationService::AllSources()); 2567 content::NotificationService::AllSources());
1126 browser()->window()->GetLocationBar()->AcceptInput(); 2568 browser()->window()->GetLocationBar()->AcceptInput();
1127 nav_observer.Wait(); 2569 nav_observer.Wait();
1128 2570
1129 // Press back button and reload. 2571 // Press back button and reload.
1130 content::WindowedNotificationObserver back_observer( 2572 content::WindowedNotificationObserver back_observer(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 browser(), 2604 browser(),
1163 GURL(chrome::kChromeUINewTabURL), 2605 GURL(chrome::kChromeUINewTabURL),
1164 NEW_WINDOW, 2606 NEW_WINDOW,
1165 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); 2607 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER);
1166 2608
1167 const BrowserList* native_browser_list = BrowserList::GetInstance( 2609 const BrowserList* native_browser_list = BrowserList::GetInstance(
1168 chrome::HOST_DESKTOP_TYPE_NATIVE); 2610 chrome::HOST_DESKTOP_TYPE_NATIVE);
1169 ASSERT_EQ(2u, native_browser_list->size()); 2611 ASSERT_EQ(2u, native_browser_list->size());
1170 set_browser(native_browser_list->get(1)); 2612 set_browser(native_browser_list->get(1));
1171 2613
1172 FocusOmniboxAndWaitForInstantNTPSupport(); 2614 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1173 2615
1174 // Also make sure our instant_tab_ is loaded. 2616 // Also make sure our instant_tab_ is loaded.
1175 if (!instant()->instant_tab_) { 2617 if (!instant()->instant_tab_) {
1176 content::WindowedNotificationObserver instant_tab_observer( 2618 content::WindowedNotificationObserver instant_tab_observer(
1177 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2619 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1178 content::NotificationService::AllSources()); 2620 content::NotificationService::AllSources());
1179 instant_tab_observer.Wait(); 2621 instant_tab_observer.Wait();
1180 } 2622 }
1181 2623
1182 // NTP contents should be preloaded. 2624 // NTP contents should be preloaded.
1183 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp()); 2625 ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
1184 EXPECT_TRUE(instant()->ntp()->IsLocal()); 2626 EXPECT_TRUE(instant()->ntp()->IsLocal());
1185 2627
2628 // Overlay contents should be preloaded.
2629 ASSERT_NE(static_cast<InstantOverlay*>(NULL), instant()->overlay());
2630 EXPECT_TRUE(instant()->overlay()->IsLocal());
2631
1186 // Instant tab contents should be preloaded. 2632 // Instant tab contents should be preloaded.
1187 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); 2633 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab());
1188 EXPECT_TRUE(instant()->instant_tab()->IsLocal()); 2634 EXPECT_TRUE(instant()->instant_tab()->IsLocal());
1189 } 2635 }
1190 2636
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
1191 // Broken on mac: http://crbug.com/247448 2691 // Broken on mac: http://crbug.com/247448
1192 #if defined(OS_MACOSX) 2692 #if defined(OS_MACOSX)
1193 #define MAYBE_KeyboardTogglesVoiceSearch DISABLED_KeyboardTogglesVoiceSearch 2693 #define MAYBE_KeyboardTogglesVoiceSearch DISABLED_KeyboardTogglesVoiceSearch
1194 #else 2694 #else
1195 #define MAYBE_KeyboardTogglesVoiceSearch KeyboardTogglesVoiceSearch 2695 #define MAYBE_KeyboardTogglesVoiceSearch KeyboardTogglesVoiceSearch
1196 #endif 2696 #endif
1197 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_KeyboardTogglesVoiceSearch) { 2697 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_KeyboardTogglesVoiceSearch) {
1198 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2698 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1199 FocusOmniboxAndWaitForInstantNTPSupport(); 2699 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
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_);
1200 2706
1201 // Open new tab and test that toggle is fired. 2707 // Open new tab and test that toggle is fired.
1202 ui_test_utils::NavigateToURLWithDisposition( 2708 ui_test_utils::NavigateToURLWithDisposition(
1203 browser(), 2709 browser(),
1204 GURL(chrome::kChromeUINewTabURL), 2710 GURL(chrome::kChromeUINewTabURL),
1205 CURRENT_TAB, 2711 NEW_FOREGROUND_TAB,
1206 ui_test_utils::BROWSER_TEST_NONE); 2712 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1207 content::WebContents* active_tab =
1208 browser()->tab_strip_model()->GetActiveWebContents();
1209 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD, 2713 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD,
1210 true, true, false, false)); 2714 true, true, false, false));
1211 EXPECT_TRUE(UpdateSearchState(active_tab)); 2715 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents()));
1212 EXPECT_EQ(1, on_toggle_voice_search_calls_); 2716 EXPECT_EQ(1, on_toggle_voice_search_calls_);
1213 } 2717 }
1214 2718
1215 // Test to verify that the omnibox search query is updated on browser 2719 // Test to verify that the omnibox search query is updated on browser
1216 // back/forward button press events. 2720 // back/forward button press events.
1217 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnNavigation) { 2721 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnNavigation) {
1218 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2722 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1219 2723
1220 // Focus omnibox. 2724 // Focus omnibox and confirm overlay isn't shown.
1221 FocusOmniboxAndWaitForInstantNTPSupport(); 2725 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1222 SetOmniboxText("flowers"); 2726 content::WebContents* overlay = instant()->GetOverlayContents();
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());
1223 2735
1224 // Commit the search by pressing 'Enter'. 2736 // Commit the search by pressing 'Enter'.
1225 PressEnterAndWaitForNavigation(); 2737 PressEnterAndWaitForNavigation();
1226 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); 2738 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText());
1227 2739
1228 // Typing in the new search query in omnibox. 2740 // Typing in the new search query in omnibox.
1229 SetOmniboxText("cattles"); 2741 SetOmniboxText("cattles");
1230 // Commit the search by pressing 'Enter'. 2742 // Commit the search by pressing 'Enter'.
1231 PressEnterAndWaitForNavigation(); 2743 PressEnterAndWaitForNavigation();
1232 // 'Enter' commits the query as it was typed. This creates a navigation entry 2744 // 'Enter' commits the query as it was typed. This creates a navigation entry
(...skipping 10 matching lines...) Expand all
1243 active_tab->GetController().GoBack(); 2755 active_tab->GetController().GoBack();
1244 load_stop_observer.Wait(); 2756 load_stop_observer.Wait();
1245 2757
1246 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); 2758 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText());
1247 // Commit the search by pressing 'Enter'. 2759 // Commit the search by pressing 'Enter'.
1248 FocusOmnibox(); 2760 FocusOmnibox();
1249 PressEnterAndWaitForNavigation(); 2761 PressEnterAndWaitForNavigation();
1250 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); 2762 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText());
1251 } 2763 }
1252 2764
2765 #endif // HTML_INSTANT_EXTENDED_POPUP
2766
2767 #if !defined(HTML_INSTANT_EXTENDED_POPUP)
1253 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { 2768 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) {
1254 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2769 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1255 FocusOmniboxAndWaitForInstantNTPSupport(); 2770 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1256 2771
1257 content::WindowedNotificationObserver observer( 2772 content::WindowedNotificationObserver observer(
1258 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2773 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1259 content::NotificationService::AllSources()); 2774 content::NotificationService::AllSources());
1260 SetOmniboxText("flowers"); 2775 SetOmniboxText("flowers");
1261 PressEnterAndWaitForNavigation(); 2776 PressEnterAndWaitForNavigation();
1262 observer.Wait(); 2777 observer.Wait();
1263 2778
1264 // Just did a regular search. 2779 // Just did a regular search.
1265 content::WebContents* active_tab = 2780 content::WebContents* active_tab =
1266 browser()->tab_strip_model()->GetActiveWebContents(); 2781 browser()->tab_strip_model()->GetActiveWebContents();
1267 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); 2782 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers"));
1268 ASSERT_TRUE(UpdateSearchState(active_tab)); 2783 ASSERT_TRUE(UpdateSearchState(active_tab));
1269 ASSERT_EQ(0, submit_count_); 2784 ASSERT_EQ(0, submit_count_);
1270 2785
1271 SetOmniboxText("puppies"); 2786 SetOmniboxText("puppies");
1272 PressEnterAndWaitForNavigation(); 2787 PressEnterAndWaitForNavigation();
1273 2788
1274 // Should have reused the tab and sent an onsubmit message. 2789 // Should have reused the tab and sent an onsubmit message.
1275 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 2790 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
1276 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); 2791 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies"));
1277 ASSERT_TRUE(UpdateSearchState(active_tab)); 2792 ASSERT_TRUE(UpdateSearchState(active_tab));
1278 EXPECT_EQ(1, submit_count_); 2793 EXPECT_EQ(1, submit_count_);
1279 } 2794 }
1280 2795
1281 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 2796 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1282 SearchDoesntReuseInstantTabWithoutSupport) { 2797 SearchDoesntReuseInstantTabWithoutSupport) {
1283 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2798 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1284 FocusOmniboxAndWaitForInstantNTPSupport(); 2799 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1285 2800
1286 // Don't wait for the navigation to complete. 2801 // Don't wait for the navigation to complete.
1287 SetOmniboxText("flowers"); 2802 SetOmniboxText("flowers");
1288 browser()->window()->GetLocationBar()->AcceptInput(); 2803 browser()->window()->GetLocationBar()->AcceptInput();
1289 2804
1290 SetOmniboxText("puppies"); 2805 SetOmniboxText("puppies");
1291 browser()->window()->GetLocationBar()->AcceptInput(); 2806 browser()->window()->GetLocationBar()->AcceptInput();
1292 2807
1293 // Should not have reused the tab. 2808 // Should not have reused the tab.
1294 ASSERT_THAT( 2809 ASSERT_THAT(
1295 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), 2810 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(),
1296 HasSubstr("q=puppies")); 2811 HasSubstr("q=puppies"));
1297 } 2812 }
1298 2813
1299 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, 2814 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1300 TypedSearchURLDoesntReuseInstantTab) { 2815 TypedSearchURLDoesntReuseInstantTab) {
1301 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2816 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1302 FocusOmniboxAndWaitForInstantNTPSupport(); 2817 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1303 2818
1304 // Create an observer to wait for the instant tab to support Instant. 2819 // Create an observer to wait for the instant tab to support Instant.
1305 content::WindowedNotificationObserver observer_1( 2820 content::WindowedNotificationObserver observer_1(
1306 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2821 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1307 content::NotificationService::AllSources()); 2822 content::NotificationService::AllSources());
1308 SetOmniboxText("flowers"); 2823 SetOmniboxText("flowers");
1309 PressEnterAndWaitForNavigation(); 2824 PressEnterAndWaitForNavigation();
1310 observer_1.Wait(); 2825 observer_1.Wait();
1311 2826
1312 // Just did a regular search. 2827 // Just did a regular search.
(...skipping 11 matching lines...) Expand all
1324 PressEnterAndWaitForNavigation(); 2839 PressEnterAndWaitForNavigation();
1325 observer_2.Wait(); 2840 observer_2.Wait();
1326 2841
1327 // Should not have reused the tab. 2842 // Should not have reused the tab.
1328 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 2843 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
1329 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); 2844 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies"));
1330 } 2845 }
1331 2846
1332 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { 2847 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) {
1333 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2848 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1334 FocusOmniboxAndWaitForInstantNTPSupport(); 2849 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1335 2850
1336 // Create an observer to wait for the instant tab to support Instant. 2851 // Create an observer to wait for the instant tab to support Instant.
1337 content::WindowedNotificationObserver observer( 2852 content::WindowedNotificationObserver observer(
1338 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, 2853 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED,
1339 content::NotificationService::AllSources()); 2854 content::NotificationService::AllSources());
1340 2855
1341 SetOmniboxText("flowers"); 2856 SetOmniboxText("flowers");
1342 browser()->window()->GetLocationBar()->AcceptInput(); 2857 browser()->window()->GetLocationBar()->AcceptInput();
1343 observer.Wait(); 2858 observer.Wait();
1344 2859
1345 const std::string& url = 2860 const std::string& url =
1346 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(); 2861 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec();
1347 // Make sure we actually used search_url, not instant_url. 2862 // Make sure we actually used search_url, not instant_url.
1348 ASSERT_THAT(url, HasSubstr("&is_search")); 2863 ASSERT_THAT(url, HasSubstr("&is_search"));
1349 EXPECT_THAT(url, HasSubstr("&es_sm=")); 2864 EXPECT_THAT(url, HasSubstr("&es_sm="));
1350 } 2865 }
1351 2866
2867 #endif // if !defined(HTML_INSTANT_EXTENDED_POPUP)
2868
1352 // Test to verify that switching tabs should not dispatch onmostvisitedchanged 2869 // Test to verify that switching tabs should not dispatch onmostvisitedchanged
1353 // events. 2870 // events.
1354 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) { 2871 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NoMostVisitedChangedOnTabSwitch) {
1355 // Initialize Instant. 2872 // Initialize Instant.
1356 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 2873 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1357 FocusOmniboxAndWaitForInstantNTPSupport(); 2874 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1358 2875
1359 // Open new tab. Preloaded NTP contents should have been used. 2876 // Open new tab. Preloaded NTP contents should have been used.
1360 ui_test_utils::NavigateToURLWithDisposition( 2877 ui_test_utils::NavigateToURLWithDisposition(
1361 browser(), 2878 browser(),
1362 GURL(chrome::kChromeUINewTabURL), 2879 GURL(chrome::kChromeUINewTabURL),
1363 NEW_FOREGROUND_TAB, 2880 NEW_FOREGROUND_TAB,
1364 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 2881 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1365 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 2882 EXPECT_EQ(2, browser()->tab_strip_model()->count());
1366 2883
1367 // Make sure new tab received the onmostvisitedchanged event once. 2884 // Make sure new tab received the onmostvisitedchanged event once.
1368 content::WebContents* active_tab = 2885 content::WebContents* active_tab =
1369 browser()->tab_strip_model()->GetActiveWebContents(); 2886 browser()->tab_strip_model()->GetActiveWebContents();
1370 EXPECT_TRUE(UpdateSearchState(active_tab)); 2887 EXPECT_TRUE(UpdateSearchState(active_tab));
1371 EXPECT_EQ(2, on_most_visited_change_calls_); 2888 EXPECT_EQ(2, on_most_visited_change_calls_);
1372 2889
1373 // Activate the previous tab. 2890 // Activate the previous tab.
1374 browser()->tab_strip_model()->ActivateTabAt(0, false); 2891 browser()->tab_strip_model()->ActivateTabAt(0, false);
1375 2892
1376 // Switch back to new tab. 2893 // Switch back to new tab.
1377 browser()->tab_strip_model()->ActivateTabAt(1, false); 2894 browser()->tab_strip_model()->ActivateTabAt(1, false);
1378 2895
1379 // Confirm that new tab got no onmostvisitedchanged event. 2896 // Confirm that new tab got no onmostvisitedchanged event.
1380 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); 2897 active_tab = browser()->tab_strip_model()->GetActiveWebContents();
1381 EXPECT_TRUE(UpdateSearchState(active_tab)); 2898 EXPECT_TRUE(UpdateSearchState(active_tab));
1382 EXPECT_EQ(2, on_most_visited_change_calls_); 2899 EXPECT_EQ(2, on_most_visited_change_calls_);
1383 } 2900 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698