| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 #if defined(OS_LINUX) | 358 #if defined(OS_LINUX) |
| 359 #define MAYBE_UsesOverlayIfTabNotReady DISABLED_UsesOverlayIfTabNotReady | 359 #define MAYBE_UsesOverlayIfTabNotReady DISABLED_UsesOverlayIfTabNotReady |
| 360 #else | 360 #else |
| 361 #define MAYBE_UsesOverlayIfTabNotReady UsesOverlayIfTabNotReady | 361 #define MAYBE_UsesOverlayIfTabNotReady UsesOverlayIfTabNotReady |
| 362 #endif | 362 #endif |
| 363 | 363 |
| 364 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_UsesOverlayIfTabNotReady) { | 364 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_UsesOverlayIfTabNotReady) { |
| 365 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 365 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 366 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 366 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 367 | 367 |
| 368 // Open a new tab and start typing before InstantTab is properly hooked up. | 368 // Open a new tab and navigate to instant URL. Start typing before InstantTab |
| 369 // Should use the overlay. | 369 // is properly hooked up. Should use the overlay. |
| 370 ui_test_utils::NavigateToURLWithDisposition( | 370 ui_test_utils::NavigateToURLWithDisposition( |
| 371 browser(), | 371 browser(), |
| 372 GURL(chrome::kChromeUINewTabURL), | 372 instant_url(), |
| 373 NEW_FOREGROUND_TAB, | 373 NEW_BACKGROUND_TAB, |
| 374 ui_test_utils::BROWSER_TEST_WAIT_FOR_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); |
| 375 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query")); | 377 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("query")); |
| 376 | 378 |
| 377 // But Instant tab should still exist. | 379 // But Instant tab should still exist. |
| 378 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); | 380 ASSERT_NE(static_cast<InstantTab*>(NULL), instant()->instant_tab()); |
| 379 EXPECT_FALSE(instant()->UseTabForSuggestions()); | 381 EXPECT_FALSE(instant()->UseTabForSuggestions()); |
| 380 | 382 |
| 381 // Wait for Instant Tab support if it still hasn't finished loading. | 383 // Wait for Instant Tab support if it still hasn't finished loading. |
| 382 if (!instant()->instant_tab()->supports_instant()) { | 384 if (!instant()->instant_tab()->supports_instant()) { |
| 383 content::WindowedNotificationObserver instant_tab_observer( | 385 content::WindowedNotificationObserver instant_tab_observer( |
| 384 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 386 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| (...skipping 2375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2760 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | 2762 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); |
| 2761 } | 2763 } |
| 2762 | 2764 |
| 2763 #endif // HTML_INSTANT_EXTENDED_POPUP | 2765 #endif // HTML_INSTANT_EXTENDED_POPUP |
| 2764 | 2766 |
| 2765 #if !defined(HTML_INSTANT_EXTENDED_POPUP) | 2767 #if !defined(HTML_INSTANT_EXTENDED_POPUP) |
| 2766 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { | 2768 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { |
| 2767 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2769 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2768 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2770 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2769 | 2771 |
| 2770 // Create an observer to wait for the instant tab to support Instant. | 2772 // Open new tab. Preloaded NTP contents should have been used. |
| 2771 content::WindowedNotificationObserver observer( | 2773 ui_test_utils::NavigateToURLWithDisposition( |
| 2774 browser(), |
| 2775 GURL(chrome::kChromeUINewTabURL), |
| 2776 NEW_FOREGROUND_TAB, |
| 2777 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 2778 |
| 2779 content::WindowedNotificationObserver observer_1( |
| 2772 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 2780 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2773 content::NotificationService::AllSources()); | 2781 content::NotificationService::AllSources()); |
| 2774 | |
| 2775 SetOmniboxText("flowers"); | 2782 SetOmniboxText("flowers"); |
| 2776 browser()->window()->GetLocationBar()->AcceptInput(); | 2783 PressEnterAndWaitForNavigation(); |
| 2777 observer.Wait(); | 2784 observer_1.Wait(); |
| 2778 | 2785 |
| 2779 // Just did a regular search. | 2786 // Just did a regular search. |
| 2780 ASSERT_THAT( | 2787 content::WebContents* active_tab = |
| 2781 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 2788 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2782 HasSubstr("q=flowers")); | 2789 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); |
| 2783 ASSERT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); | 2790 ASSERT_TRUE(UpdateSearchState(active_tab)); |
| 2784 ASSERT_EQ(0, submit_count_); | 2791 ASSERT_EQ(0, submit_count_); |
| 2785 | 2792 |
| 2793 // Create an observer to wait for the instant tab to support Instant. |
| 2794 content::WindowedNotificationObserver observer_2( |
| 2795 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2796 content::NotificationService::AllSources()); |
| 2786 SetOmniboxText("puppies"); | 2797 SetOmniboxText("puppies"); |
| 2787 browser()->window()->GetLocationBar()->AcceptInput(); | 2798 PressEnterAndWaitForNavigation(); |
| 2799 observer_2.Wait(); |
| 2788 | 2800 |
| 2789 // Should have reused the tab and sent an onsubmit message. | 2801 // Should have reused the tab and sent an onsubmit message. |
| 2790 ASSERT_THAT( | 2802 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2791 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 2803 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
| 2792 HasSubstr("q=flowers")); | 2804 ASSERT_TRUE(UpdateSearchState(active_tab)); |
| 2793 ASSERT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); | |
| 2794 EXPECT_EQ(1, submit_count_); | 2805 EXPECT_EQ(1, submit_count_); |
| 2795 } | 2806 } |
| 2796 | 2807 |
| 2797 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 2808 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 2798 SearchDoesntReuseInstantTabWithoutSupport) { | 2809 SearchDoesntReuseInstantTabWithoutSupport) { |
| 2799 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2810 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2800 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2811 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2801 | 2812 |
| 2802 // Don't wait for the navigation to complete. | 2813 // Don't wait for the navigation to complete. |
| 2803 SetOmniboxText("flowers"); | 2814 SetOmniboxText("flowers"); |
| 2804 browser()->window()->GetLocationBar()->AcceptInput(); | 2815 browser()->window()->GetLocationBar()->AcceptInput(); |
| 2805 | 2816 |
| 2806 SetOmniboxText("puppies"); | 2817 SetOmniboxText("puppies"); |
| 2807 browser()->window()->GetLocationBar()->AcceptInput(); | 2818 browser()->window()->GetLocationBar()->AcceptInput(); |
| 2808 | 2819 |
| 2809 // Should not have reused the tab. | 2820 // Should not have reused the tab. |
| 2810 ASSERT_THAT( | 2821 ASSERT_THAT( |
| 2811 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 2822 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), |
| 2812 HasSubstr("q=puppies")); | 2823 HasSubstr("q=puppies")); |
| 2813 } | 2824 } |
| 2814 | 2825 |
| 2815 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | 2826 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 2816 TypedSearchURLDoesntReuseInstantTab) { | 2827 TypedSearchURLDoesntReuseInstantTab) { |
| 2817 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2828 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2818 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2829 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2819 | 2830 |
| 2831 // Open new tab. Preloaded NTP contents should have been used. |
| 2832 ui_test_utils::NavigateToURLWithDisposition( |
| 2833 browser(), |
| 2834 GURL(chrome::kChromeUINewTabURL), |
| 2835 NEW_FOREGROUND_TAB, |
| 2836 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 2837 |
| 2820 // Create an observer to wait for the instant tab to support Instant. | 2838 // Create an observer to wait for the instant tab to support Instant. |
| 2821 content::WindowedNotificationObserver observer( | 2839 content::WindowedNotificationObserver observer_1( |
| 2822 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 2840 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2823 content::NotificationService::AllSources()); | 2841 content::NotificationService::AllSources()); |
| 2824 | |
| 2825 SetOmniboxText("flowers"); | 2842 SetOmniboxText("flowers"); |
| 2826 browser()->window()->GetLocationBar()->AcceptInput(); | 2843 PressEnterAndWaitForNavigation(); |
| 2827 observer.Wait(); | 2844 observer_1.Wait(); |
| 2828 | 2845 |
| 2829 // Just did a regular search. | 2846 // Just did a regular search. |
| 2830 ASSERT_THAT( | 2847 content::WebContents* active_tab = |
| 2831 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 2848 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2832 HasSubstr("q=flowers")); | 2849 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=flowers")); |
| 2833 ASSERT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); | 2850 ASSERT_TRUE(UpdateSearchState(active_tab)); |
| 2834 ASSERT_EQ(0, submit_count_); | 2851 ASSERT_EQ(0, submit_count_); |
| 2835 | 2852 |
| 2836 // Typed in a search URL "by hand". | 2853 // Typed in a search URL "by hand". |
| 2854 content::WindowedNotificationObserver observer_2( |
| 2855 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2856 content::NotificationService::AllSources()); |
| 2837 SetOmniboxText(instant_url().spec() + "#q=puppies"); | 2857 SetOmniboxText(instant_url().spec() + "#q=puppies"); |
| 2838 browser()->window()->GetLocationBar()->AcceptInput(); | 2858 PressEnterAndWaitForNavigation(); |
| 2859 observer_2.Wait(); |
| 2839 | 2860 |
| 2840 // Should not have reused the tab. | 2861 // Should not have reused the tab. |
| 2841 ASSERT_THAT( | 2862 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2842 browser()->tab_strip_model()->GetActiveWebContents()->GetURL().spec(), | 2863 ASSERT_THAT(active_tab->GetURL().spec(), HasSubstr("q=puppies")); |
| 2843 HasSubstr("q=puppies")); | |
| 2844 } | 2864 } |
| 2845 | 2865 |
| 2846 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { | 2866 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxMarginSetForSearchURLs) { |
| 2847 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2867 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2848 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2868 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2849 | 2869 |
| 2850 // Create an observer to wait for the instant tab to support Instant. | 2870 // Create an observer to wait for the instant tab to support Instant. |
| 2851 content::WindowedNotificationObserver observer( | 2871 content::WindowedNotificationObserver observer( |
| 2852 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 2872 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
| 2853 content::NotificationService::AllSources()); | 2873 content::NotificationService::AllSources()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 browser()->tab_strip_model()->ActivateTabAt(0, false); | 2910 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 2891 | 2911 |
| 2892 // Switch back to new tab. | 2912 // Switch back to new tab. |
| 2893 browser()->tab_strip_model()->ActivateTabAt(1, false); | 2913 browser()->tab_strip_model()->ActivateTabAt(1, false); |
| 2894 | 2914 |
| 2895 // Confirm that new tab got no onmostvisitedchanged event. | 2915 // Confirm that new tab got no onmostvisitedchanged event. |
| 2896 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2916 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2897 EXPECT_TRUE(UpdateSearchState(active_tab)); | 2917 EXPECT_TRUE(UpdateSearchState(active_tab)); |
| 2898 EXPECT_EQ(2, on_most_visited_change_calls_); | 2918 EXPECT_EQ(2, on_most_visited_change_calls_); |
| 2899 } | 2919 } |
| OLD | NEW |