| 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/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
| 9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
| 10 #include "base/metrics/statistics_recorder.h" | 10 #include "base/metrics/statistics_recorder.h" |
| (...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 &query)); | 865 &query)); |
| 866 EXPECT_EQ("", query); | 866 EXPECT_EQ("", query); |
| 867 EXPECT_EQ("", GetOmniboxText()); | 867 EXPECT_EQ("", GetOmniboxText()); |
| 868 | 868 |
| 869 EXPECT_TRUE(UpdateSearchState(contents)); | 869 EXPECT_TRUE(UpdateSearchState(contents)); |
| 870 EXPECT_LT(0, on_change_calls_); | 870 EXPECT_LT(0, on_change_calls_); |
| 871 EXPECT_EQ(0, submit_count_); | 871 EXPECT_EQ(0, submit_count_); |
| 872 EXPECT_LT(0, on_esc_key_press_event_calls_); | 872 EXPECT_LT(0, on_esc_key_press_event_calls_); |
| 873 } | 873 } |
| 874 | 874 |
| 875 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { | |
| 876 InstantService* instant_service = | |
| 877 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 878 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 879 | |
| 880 // Setup Instant. | |
| 881 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 882 FocusOmniboxAndWaitForInstantNTPSupport(); | |
| 883 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); | |
| 884 | |
| 885 // Navigating to the NTP should use the Instant render process. | |
| 886 ui_test_utils::NavigateToURLWithDisposition( | |
| 887 browser(), | |
| 888 GURL(chrome::kChromeUINewTabURL), | |
| 889 CURRENT_TAB, | |
| 890 ui_test_utils::BROWSER_TEST_NONE); | |
| 891 content::WebContents* ntp_contents = | |
| 892 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 893 EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents)); | |
| 894 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 895 ntp_contents->GetRenderProcessHost()->GetID())); | |
| 896 GURL ntp_url = ntp_contents->GetURL(); | |
| 897 | |
| 898 AddBlankTabAndShow(browser()); | |
| 899 content::WebContents* active_tab = | |
| 900 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 901 EXPECT_FALSE(chrome::IsInstantNTP(active_tab)); | |
| 902 EXPECT_FALSE(instant_service->IsInstantProcess( | |
| 903 active_tab->GetRenderProcessHost()->GetID())); | |
| 904 | |
| 905 TemplateURLData data; | |
| 906 data.short_name = ASCIIToUTF16("t"); | |
| 907 data.SetURL("http://defaultturl/q={searchTerms}"); | |
| 908 data.suggestions_url = "http://defaultturl2/q={searchTerms}"; | |
| 909 data.instant_url = "http://does/not/exist"; | |
| 910 data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}"); | |
| 911 data.search_terms_replacement_key = "strk"; | |
| 912 | |
| 913 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); | |
| 914 TemplateURLService* service = | |
| 915 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | |
| 916 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | |
| 917 service->Add(template_url); // Takes ownership of |template_url|. | |
| 918 | |
| 919 // Change the default search provider. | |
| 920 content::WindowedNotificationObserver observer( | |
| 921 content::NOTIFICATION_LOAD_STOP, | |
| 922 content::Source<content::NavigationController>( | |
| 923 &ntp_contents->GetController())); | |
| 924 service->SetDefaultSearchProvider(template_url); | |
| 925 observer.Wait(); | |
| 926 | |
| 927 // |ntp_contents| should not use the Instant render process. | |
| 928 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); | |
| 929 EXPECT_FALSE(instant_service->IsInstantProcess( | |
| 930 ntp_contents->GetRenderProcessHost()->GetID())); | |
| 931 // Make sure the URL remains the same. | |
| 932 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); | |
| 933 } | |
| 934 | |
| 935 // Test that renderer initiated navigations to an instant URL from a non | 875 // Test that renderer initiated navigations to an instant URL from a non |
| 936 // Instant page do not end up in an Instant process if they are bounced to the | 876 // Instant page do not end up in an Instant process if they are bounced to the |
| 937 // browser. | 877 // browser. |
| 938 IN_PROC_BROWSER_TEST_F( | 878 IN_PROC_BROWSER_TEST_F( |
| 939 InstantExtendedTest, | 879 InstantExtendedTest, |
| 940 DISABLED_RendererInitiatedNavigationNotInInstantProcess) { | 880 DISABLED_RendererInitiatedNavigationNotInInstantProcess) { |
| 941 InstantService* instant_service = | 881 InstantService* instant_service = |
| 942 InstantServiceFactory::GetForProfile(browser()->profile()); | 882 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 943 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | 883 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 944 | 884 |
| (...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 EXPECT_TRUE(active_tab->GetController().CanGoBack()); | 1673 EXPECT_TRUE(active_tab->GetController().CanGoBack()); |
| 1734 active_tab->GetController().GoBack(); | 1674 active_tab->GetController().GoBack(); |
| 1735 back_observer.Wait(); | 1675 back_observer.Wait(); |
| 1736 | 1676 |
| 1737 // Verify that onmostvisitedchange event is dispatched when we navigate from | 1677 // Verify that onmostvisitedchange event is dispatched when we navigate from |
| 1738 // SRP to NTP. | 1678 // SRP to NTP. |
| 1739 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1679 active_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1740 EXPECT_TRUE(UpdateSearchState(active_tab)); | 1680 EXPECT_TRUE(UpdateSearchState(active_tab)); |
| 1741 EXPECT_EQ(1, on_most_visited_change_calls_); | 1681 EXPECT_EQ(1, on_most_visited_change_calls_); |
| 1742 } | 1682 } |
| 1683 |
| 1684 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OnDefaultSearchProviderChanged) { |
| 1685 InstantService* instant_service = |
| 1686 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 1687 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 1688 |
| 1689 // Setup Instant. |
| 1690 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1691 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 1692 EXPECT_EQ(1, instant_service->GetInstantProcessCount()); |
| 1693 |
| 1694 // Navigating to the NTP should use the Instant render process. |
| 1695 ui_test_utils::NavigateToURLWithDisposition( |
| 1696 browser(), |
| 1697 GURL(chrome::kChromeUINewTabURL), |
| 1698 CURRENT_TAB, |
| 1699 ui_test_utils::BROWSER_TEST_NONE); |
| 1700 content::WebContents* ntp_contents = |
| 1701 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1702 EXPECT_TRUE(chrome::IsInstantNTP(ntp_contents)); |
| 1703 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 1704 ntp_contents->GetRenderProcessHost()->GetID())); |
| 1705 GURL ntp_url = ntp_contents->GetURL(); |
| 1706 |
| 1707 AddBlankTabAndShow(browser()); |
| 1708 content::WebContents* active_tab = |
| 1709 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1710 EXPECT_FALSE(chrome::IsInstantNTP(active_tab)); |
| 1711 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 1712 active_tab->GetRenderProcessHost()->GetID())); |
| 1713 |
| 1714 TemplateURLData data; |
| 1715 data.short_name = ASCIIToUTF16("t"); |
| 1716 data.SetURL("http://defaultturl/q={searchTerms}"); |
| 1717 data.suggestions_url = "http://defaultturl2/q={searchTerms}"; |
| 1718 data.instant_url = "http://does/not/exist"; |
| 1719 data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}"); |
| 1720 data.search_terms_replacement_key = "strk"; |
| 1721 |
| 1722 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
| 1723 TemplateURLService* service = |
| 1724 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 1725 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 1726 service->Add(template_url); // Takes ownership of |template_url|. |
| 1727 |
| 1728 // Change the default search provider. |
| 1729 content::WindowedNotificationObserver observer( |
| 1730 content::NOTIFICATION_LOAD_STOP, |
| 1731 content::Source<content::NavigationController>( |
| 1732 &ntp_contents->GetController())); |
| 1733 service->SetDefaultSearchProvider(template_url); |
| 1734 observer.Wait(); |
| 1735 |
| 1736 // |ntp_contents| should not use the Instant render process. |
| 1737 EXPECT_FALSE(chrome::IsInstantNTP(ntp_contents)); |
| 1738 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 1739 ntp_contents->GetRenderProcessHost()->GetID())); |
| 1740 // Make sure the URL remains the same. |
| 1741 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); |
| 1742 } |
| 1743 |
| 1744 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 1745 ReloadLocalNTPOnSearchProviderChange) { |
| 1746 // Setup Instant. |
| 1747 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 1748 FocusOmniboxAndWaitForInstantNTPSupport(); |
| 1749 |
| 1750 // Navigate to Local NTP. |
| 1751 ui_test_utils::NavigateToURLWithDisposition( |
| 1752 browser(), |
| 1753 GURL(chrome::kChromeSearchLocalNtpUrl), |
| 1754 CURRENT_TAB, |
| 1755 ui_test_utils::BROWSER_TEST_NONE); |
| 1756 content::WebContents* ntp_contents = |
| 1757 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1758 GURL ntp_url = ntp_contents->GetURL(); |
| 1759 |
| 1760 TemplateURLData data; |
| 1761 data.short_name = ASCIIToUTF16("t"); |
| 1762 data.SetURL("http://defaultturl/q={searchTerms}"); |
| 1763 data.suggestions_url = "http://defaultturl2/q={searchTerms}"; |
| 1764 data.instant_url = "http://does/not/exist"; |
| 1765 data.alternate_urls.push_back(data.instant_url + "#q={searchTerms}"); |
| 1766 data.search_terms_replacement_key = "strk"; |
| 1767 |
| 1768 TemplateURL* template_url = new TemplateURL(browser()->profile(), data); |
| 1769 TemplateURLService* service = |
| 1770 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 1771 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 1772 service->Add(template_url); // Takes ownership of |template_url|. |
| 1773 |
| 1774 // Change the default search provider. This will reload the local NTP and the |
| 1775 // page URL will remain the same. |
| 1776 content::WindowedNotificationObserver observer( |
| 1777 content::NOTIFICATION_LOAD_STOP, |
| 1778 content::Source<content::NavigationController>( |
| 1779 &ntp_contents->GetController())); |
| 1780 service->SetDefaultSearchProvider(template_url); |
| 1781 observer.Wait(); |
| 1782 |
| 1783 // Make sure the URL remains the same. |
| 1784 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); |
| 1785 } |
| OLD | NEW |