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 2696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2707 browser(), | 2707 browser(), |
2708 GURL(chrome::kChromeUINewTabURL), | 2708 GURL(chrome::kChromeUINewTabURL), |
2709 NEW_FOREGROUND_TAB, | 2709 NEW_FOREGROUND_TAB, |
2710 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 2710 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
2711 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD, | 2711 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_OEM_PERIOD, |
2712 true, true, false, false)); | 2712 true, true, false, false)); |
2713 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); | 2713 EXPECT_TRUE(UpdateSearchState(instant()->instant_tab()->contents())); |
2714 EXPECT_EQ(1, on_toggle_voice_search_calls_); | 2714 EXPECT_EQ(1, on_toggle_voice_search_calls_); |
2715 } | 2715 } |
2716 | 2716 |
2717 // Test to verify that the omnibox search query is updated on browser | |
2718 // back/forward button press events. | |
2719 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnNavigation) { | |
2720 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2721 | |
2722 // Focus omnibox and confirm overlay isn't shown. | |
2723 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
2724 content::WebContents* overlay = instant()->GetOverlayContents(); | |
2725 EXPECT_TRUE(overlay); | |
2726 EXPECT_TRUE(instant()->model()->mode().is_default()); | |
2727 EXPECT_FALSE(instant()->IsOverlayingSearchResults()); | |
2728 | |
2729 // Typing in the omnibox should show the overlay. | |
2730 SetOmniboxTextAndWaitForOverlayToShow("flowers"); | |
2731 EXPECT_TRUE(instant()->IsOverlayingSearchResults()); | |
2732 EXPECT_EQ(overlay, instant()->GetOverlayContents()); | |
2733 | |
2734 // Commit the search by pressing 'Enter'. | |
2735 PressEnterAndWaitForNavigation(); | |
2736 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2737 | |
2738 // Typing in the new search query in omnibox. | |
2739 SetOmniboxText("cattles"); | |
2740 // Commit the search by pressing 'Enter'. | |
2741 PressEnterAndWaitForNavigation(); | |
2742 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
2743 // in the history. | |
2744 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2745 | |
2746 content::WebContents* active_tab = | |
2747 browser()->tab_strip_model()->GetActiveWebContents(); | |
2748 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
2749 content::WindowedNotificationObserver load_stop_observer( | |
2750 content::NOTIFICATION_LOAD_STOP, | |
2751 content::Source<content::NavigationController>( | |
2752 &active_tab->GetController())); | |
2753 active_tab->GetController().GoBack(); | |
2754 load_stop_observer.Wait(); | |
2755 | |
2756 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2757 // Commit the search by pressing 'Enter'. | |
2758 FocusOmnibox(); | |
2759 PressEnterAndWaitForNavigation(); | |
2760 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2761 } | |
2762 | |
2763 #endif // HTML_INSTANT_EXTENDED_POPUP | 2717 #endif // HTML_INSTANT_EXTENDED_POPUP |
2764 | 2718 |
2765 #if !defined(HTML_INSTANT_EXTENDED_POPUP) | 2719 #if !defined(HTML_INSTANT_EXTENDED_POPUP) |
2766 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { | 2720 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, SearchReusesInstantTab) { |
2767 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2721 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2768 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2722 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
2769 | 2723 |
2770 // Create an observer to wait for the instant tab to support Instant. | 2724 // Create an observer to wait for the instant tab to support Instant. |
2771 content::WindowedNotificationObserver observer( | 2725 content::WindowedNotificationObserver observer( |
2772 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 2726 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2890 browser()->tab_strip_model()->ActivateTabAt(0, false); | 2844 browser()->tab_strip_model()->ActivateTabAt(0, false); |
2891 | 2845 |
2892 // Switch back to new tab. | 2846 // Switch back to new tab. |
2893 browser()->tab_strip_model()->ActivateTabAt(1, false); | 2847 browser()->tab_strip_model()->ActivateTabAt(1, false); |
2894 | 2848 |
2895 // Confirm that new tab got no onmostvisitedchanged event. | 2849 // Confirm that new tab got no onmostvisitedchanged event. |
2896 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 2850 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
2897 EXPECT_TRUE(UpdateSearchState(active_tab)); | 2851 EXPECT_TRUE(UpdateSearchState(active_tab)); |
2898 EXPECT_EQ(2, on_most_visited_change_calls_); | 2852 EXPECT_EQ(2, on_most_visited_change_calls_); |
2899 } | 2853 } |
2854 | |
2855 // Test to verify that the omnibox search query is updated on browser | |
2856 // back button press event. | |
2857 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, UpdateSearchQueryOnBackNavigation) { | |
2858 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2859 | |
2860 // Focus omnibox and confirm overlay isn't shown. | |
2861 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
2862 | |
2863 // Create an observer to wait for the instant tab to support Instant. | |
2864 content::WindowedNotificationObserver observer( | |
2865 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
2866 content::NotificationService::AllSources()); | |
2867 | |
2868 SetOmniboxText("flowers"); | |
2869 // Commit the search by pressing 'Enter'. | |
2870 PressEnterAndWaitForNavigation(); | |
2871 observer.Wait(); | |
2872 | |
2873 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2874 | |
2875 // Typing in the new search query in omnibox. | |
2876 SetOmniboxText("cattles"); | |
2877 // Commit the search by pressing 'Enter'. | |
2878 PressEnterAndWaitForNavigation(); | |
2879 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
2880 // in the history. | |
2881 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2882 | |
2883 content::WebContents* active_tab = | |
2884 browser()->tab_strip_model()->GetActiveWebContents(); | |
2885 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
2886 content::WindowedNotificationObserver load_stop_observer( | |
2887 content::NOTIFICATION_LOAD_STOP, | |
2888 content::Source<content::NavigationController>( | |
2889 &active_tab->GetController())); | |
2890 active_tab->GetController().GoBack(); | |
2891 load_stop_observer.Wait(); | |
2892 | |
2893 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2894 // Commit the search by pressing 'Enter'. | |
2895 FocusOmnibox(); | |
2896 PressEnterAndWaitForNavigation(); | |
2897 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2898 } | |
2899 | |
2900 // Test to verify that the omnibox search query is updated on browser | |
2901 // forward button press events. | |
2902 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
2903 UpdateSearchQueryOnForwardNavigation) { | |
2904 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2905 | |
2906 // Focus omnibox and confirm overlay isn't shown. | |
2907 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
2908 | |
2909 // Create an observer to wait for the instant tab to support Instant. | |
2910 content::WindowedNotificationObserver observer( | |
2911 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
2912 content::NotificationService::AllSources()); | |
2913 | |
2914 SetOmniboxText("flowers"); | |
2915 // Commit the search by pressing 'Enter'. | |
2916 PressEnterAndWaitForNavigation(); | |
2917 observer.Wait(); | |
2918 | |
2919 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2920 | |
2921 // Typing in the new search query in omnibox. | |
2922 SetOmniboxText("cattles"); | |
2923 // Commit the search by pressing 'Enter'. | |
2924 PressEnterAndWaitForNavigation(); | |
2925 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
2926 // in the history. | |
2927 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2928 | |
2929 content::WebContents* active_tab = | |
2930 browser()->tab_strip_model()->GetActiveWebContents(); | |
2931 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
2932 content::WindowedNotificationObserver load_stop_observer( | |
2933 content::NOTIFICATION_LOAD_STOP, | |
2934 content::Source<content::NavigationController>( | |
2935 &active_tab->GetController())); | |
2936 active_tab->GetController().GoBack(); | |
2937 load_stop_observer.Wait(); | |
2938 | |
2939 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2940 | |
2941 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
2942 EXPECT_TRUE(active_tab->GetController().CanGoForward()); | |
2943 content::WindowedNotificationObserver load_stop_observer_2( | |
2944 content::NOTIFICATION_LOAD_STOP, | |
2945 content::Source<content::NavigationController>( | |
2946 &active_tab->GetController())); | |
2947 active_tab->GetController().GoForward(); | |
2948 load_stop_observer_2.Wait(); | |
2949 | |
2950 // Commit the search by pressing 'Enter'. | |
2951 FocusOmnibox(); | |
2952 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2953 PressEnterAndWaitForNavigation(); | |
2954 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2955 } | |
2956 | |
2957 // Flaky on Mac Tests bot. | |
2958 #if defined(OS_MACOSX) | |
2959 #define MAYBE_NavigateBackToNTP DISABLED_NavigateBackToNTP | |
2960 #else | |
2961 #define MAYBE_NavigateBackToNTP NavigateBackToNTP | |
2962 #endif | |
2963 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_NavigateBackToNTP) { | |
2964 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
2965 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
2966 | |
2967 // Open a new tab page. | |
2968 ui_test_utils::NavigateToURLWithDisposition( | |
2969 browser(), | |
2970 GURL(chrome::kChromeUINewTabURL), | |
2971 NEW_FOREGROUND_TAB, | |
2972 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | |
2973 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
2974 | |
2975 content::WindowedNotificationObserver observer( | |
2976 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | |
2977 content::NotificationService::AllSources()); | |
2978 SetOmniboxText("flowers"); | |
2979 PressEnterAndWaitForNavigation(); | |
2980 observer.Wait(); | |
2981 | |
2982 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
2983 | |
2984 // Typing in the new search query in omnibox. | |
2985 // Commit the search by pressing 'Enter'. | |
2986 SetOmniboxText("cattles"); | |
2987 PressEnterAndWaitForNavigation(); | |
2988 | |
2989 // 'Enter' commits the query as it was typed. This creates a navigation entry | |
2990 // in the history. | |
2991 EXPECT_EQ(ASCIIToUTF16("cattles"), omnibox()->GetText()); | |
2992 | |
2993 // Navigate back to "flowers" search result page. | |
2994 content::WebContents* active_tab = | |
2995 browser()->tab_strip_model()->GetActiveWebContents(); | |
2996 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
2997 content::WindowedNotificationObserver load_stop_observer( | |
2998 content::NOTIFICATION_LOAD_STOP, | |
2999 content::Source<content::NavigationController>( | |
3000 &active_tab->GetController())); | |
3001 active_tab->GetController().GoBack(); | |
3002 load_stop_observer.Wait(); | |
3003 | |
3004 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
3005 | |
3006 // Commit the search by pressing 'Enter'. | |
Jered
2013/06/19 22:44:55
Why do we press enter here before going back again
kmadhusu
2013/06/21 17:00:59
Good catch. Removed.
| |
3007 FocusOmnibox(); | |
3008 PressEnterAndWaitForNavigation(); | |
3009 EXPECT_EQ(ASCIIToUTF16("flowers"), omnibox()->GetText()); | |
3010 | |
3011 // Navigate back to NTP. | |
3012 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
3013 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | |
3014 content::WindowedNotificationObserver load_stop_observer_2( | |
3015 content::NOTIFICATION_LOAD_STOP, | |
3016 content::Source<content::NavigationController>( | |
3017 &active_tab->GetController())); | |
3018 active_tab->GetController().GoBack(); | |
3019 load_stop_observer_2.Wait(); | |
3020 | |
3021 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
3022 EXPECT_TRUE(chrome::IsInstantNTP(active_tab)); | |
3023 } | |
OLD | NEW |