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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 std::string query_value_; | 268 std::string query_value_; |
269 int on_focus_changed_calls_; | 269 int on_focus_changed_calls_; |
270 bool is_focused_; | 270 bool is_focused_; |
271 int on_toggle_voice_search_calls_; | 271 int on_toggle_voice_search_calls_; |
272 std::string prefetch_query_value_; | 272 std::string prefetch_query_value_; |
273 }; | 273 }; |
274 | 274 |
275 class InstantExtendedPrefetchTest : public InstantExtendedTest { | 275 class InstantExtendedPrefetchTest : public InstantExtendedTest { |
276 public: | 276 public: |
277 InstantExtendedPrefetchTest() | 277 InstantExtendedPrefetchTest() |
278 : factory_(new net::FakeURLFetcherFactory( | 278 : factory_(new net::URLFetcherImplFactory()), |
279 net::URLFetcherImpl::factory())) { | 279 fake_factory_(new net::FakeURLFetcherFactory(factory_.get())) { |
280 } | 280 } |
281 | 281 |
282 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 282 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
283 chrome::EnableInstantExtendedAPIForTesting(); | 283 chrome::EnableInstantExtendedAPIForTesting(); |
284 ASSERT_TRUE(https_test_server().Start()); | 284 ASSERT_TRUE(https_test_server().Start()); |
285 GURL instant_url = https_test_server().GetURL( | 285 GURL instant_url = https_test_server().GetURL( |
286 "files/instant_extended.html?strk=1&"); | 286 "files/instant_extended.html?strk=1&"); |
287 InstantTestBase::Init(instant_url, true); | 287 InstantTestBase::Init(instant_url, true); |
288 factory_->SetFakeResponse(GoogleURLTracker::kSearchDomainCheckURL, | |
289 ".google.com", true); | |
290 } | 288 } |
291 | 289 |
292 scoped_ptr<net::FakeURLFetcherFactory> factory_; | 290 net::FakeURLFetcherFactory* fake_factory() { return fake_factory_.get(); } |
| 291 |
| 292 private: |
| 293 // Used to instantiate FakeURLFetcherFactory. |
| 294 scoped_ptr<net::URLFetcherImplFactory> factory_; |
| 295 |
| 296 // Used to mock default search provider suggest response. |
| 297 scoped_ptr<net::FakeURLFetcherFactory> fake_factory_; |
293 | 298 |
294 DISALLOW_COPY_AND_ASSIGN(InstantExtendedPrefetchTest); | 299 DISALLOW_COPY_AND_ASSIGN(InstantExtendedPrefetchTest); |
295 }; | 300 }; |
296 | 301 |
297 class InstantExtendedNetworkTest : public InstantExtendedTest { | 302 class InstantExtendedNetworkTest : public InstantExtendedTest { |
298 protected: | 303 protected: |
299 virtual void SetUpOnMainThread() OVERRIDE { | 304 virtual void SetUpOnMainThread() OVERRIDE { |
300 disable_for_test_.reset(new net::NetworkChangeNotifier::DisableForTest); | 305 disable_for_test_.reset(new net::NetworkChangeNotifier::DisableForTest); |
301 fake_network_change_notifier_.reset(new FakeNetworkChangeNotifier); | 306 fake_network_change_notifier_.reset(new FakeNetworkChangeNotifier); |
302 InstantExtendedTest::SetUpOnMainThread(); | 307 InstantExtendedTest::SetUpOnMainThread(); |
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 content::NOTIFICATION_LOAD_STOP, | 1680 content::NOTIFICATION_LOAD_STOP, |
1676 content::Source<content::NavigationController>( | 1681 content::Source<content::NavigationController>( |
1677 &ntp_contents->GetController())); | 1682 &ntp_contents->GetController())); |
1678 service->SetDefaultSearchProvider(template_url); | 1683 service->SetDefaultSearchProvider(template_url); |
1679 observer.Wait(); | 1684 observer.Wait(); |
1680 | 1685 |
1681 // Make sure the URL remains the same. | 1686 // Make sure the URL remains the same. |
1682 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); | 1687 EXPECT_EQ(ntp_url, ntp_contents->GetURL()); |
1683 } | 1688 } |
1684 | 1689 |
1685 // TODO(kmadhusu): Fix this flaky test. crbug.com/280247. | 1690 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, SetPrefetchQuery) { |
1686 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, | |
1687 DISABLED_SetPrefetchQuery) { | |
1688 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 1691 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
1689 FocusOmniboxAndWaitForInstantNTPSupport(); | 1692 FocusOmniboxAndWaitForInstantNTPSupport(); |
1690 | 1693 |
1691 content::WindowedNotificationObserver new_tab_observer( | 1694 content::WindowedNotificationObserver new_tab_observer( |
1692 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1695 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
1693 content::NotificationService::AllSources()); | 1696 content::NotificationService::AllSources()); |
1694 ui_test_utils::NavigateToURLWithDisposition( | 1697 ui_test_utils::NavigateToURLWithDisposition( |
1695 browser(), | 1698 browser(), |
1696 GURL(chrome::kChromeUINewTabURL), | 1699 GURL(chrome::kChromeUINewTabURL), |
1697 CURRENT_TAB, | 1700 CURRENT_TAB, |
1698 ui_test_utils::BROWSER_TEST_NONE); | 1701 ui_test_utils::BROWSER_TEST_NONE); |
1699 new_tab_observer.Wait(); | 1702 new_tab_observer.Wait(); |
1700 | 1703 |
1701 omnibox()->model()->autocomplete_controller()->search_provider()-> | 1704 omnibox()->model()->autocomplete_controller()->search_provider()-> |
1702 kMinimumTimeBetweenSuggestQueriesMs = 0; | 1705 kMinimumTimeBetweenSuggestQueriesMs = 0; |
1703 | 1706 |
1704 // Set the fake response for suggest request. Response has prefetch details. | 1707 // Set the fake response for suggest request. Response has prefetch details. |
1705 // Ensure that the page received the prefetch query. | 1708 // Ensure that the page received the prefetch query. |
1706 factory_->SetFakeResponse( | 1709 fake_factory()->SetFakeResponse( |
1707 instant_url().spec() + "#q=pupp", | 1710 instant_url().spec() + "#q=pupp", |
1708 "[\"pupp\",[\"puppy\", \"puppies\"],[],[]," | 1711 "[\"pupp\",[\"puppy\", \"puppies\"],[],[]," |
1709 "{\"google:clientdata\":{\"phi\": 0}," | 1712 "{\"google:clientdata\":{\"phi\": 0}," |
1710 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," | 1713 "\"google:suggesttype\":[\"QUERY\", \"QUERY\"]," |
1711 "\"google:suggestrelevance\":[1400, 9]}]", | 1714 "\"google:suggestrelevance\":[1400, 9]}]", |
1712 true); | 1715 true); |
1713 | 1716 |
1714 SetOmniboxText("pupp"); | 1717 SetOmniboxText("pupp"); |
1715 while (!omnibox()->model()->autocomplete_controller()->done()) { | 1718 while (!omnibox()->model()->autocomplete_controller()->done()) { |
1716 content::WindowedNotificationObserver ready_observer( | 1719 content::WindowedNotificationObserver ready_observer( |
1717 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 1720 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
1718 content::Source<AutocompleteController>( | 1721 content::Source<AutocompleteController>( |
1719 omnibox()->model()->autocomplete_controller())); | 1722 omnibox()->model()->autocomplete_controller())); |
1720 ready_observer.Wait(); | 1723 ready_observer.Wait(); |
1721 } | 1724 } |
1722 | 1725 |
1723 ASSERT_EQ(3, CountSearchProviderSuggestions()); | 1726 ASSERT_EQ(3, CountSearchProviderSuggestions()); |
1724 content::WebContents* active_tab = | 1727 content::WebContents* active_tab = |
1725 browser()->tab_strip_model()->GetActiveWebContents(); | 1728 browser()->tab_strip_model()->GetActiveWebContents(); |
1726 ASSERT_TRUE(UpdateSearchState(active_tab)); | 1729 ASSERT_TRUE(UpdateSearchState(active_tab)); |
1727 ASSERT_TRUE(SearchProvider::ShouldPrefetch(*( | 1730 ASSERT_TRUE(SearchProvider::ShouldPrefetch(*( |
1728 omnibox()->model()->result().default_match()))); | 1731 omnibox()->model()->result().default_match()))); |
1729 ASSERT_EQ("puppy", prefetch_query_value_); | 1732 ASSERT_EQ("puppy", prefetch_query_value_); |
1730 } | 1733 } |
1731 | 1734 |
1732 // TODO(kmadhusu): Fix this flaky test. crbug.com/280247. | 1735 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, ClearPrefetchedResults) { |
1733 IN_PROC_BROWSER_TEST_F(InstantExtendedPrefetchTest, | |
1734 DISABLED_ClearPrefetchedResults) { | |
1735 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 1736 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
1736 FocusOmniboxAndWaitForInstantNTPSupport(); | 1737 FocusOmniboxAndWaitForInstantNTPSupport(); |
1737 | 1738 |
1738 content::WindowedNotificationObserver new_tab_observer( | 1739 content::WindowedNotificationObserver new_tab_observer( |
1739 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 1740 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
1740 content::NotificationService::AllSources()); | 1741 content::NotificationService::AllSources()); |
1741 ui_test_utils::NavigateToURLWithDisposition( | 1742 ui_test_utils::NavigateToURLWithDisposition( |
1742 browser(), | 1743 browser(), |
1743 GURL(chrome::kChromeUINewTabURL), | 1744 GURL(chrome::kChromeUINewTabURL), |
1744 CURRENT_TAB, | 1745 CURRENT_TAB, |
1745 ui_test_utils::BROWSER_TEST_NONE); | 1746 ui_test_utils::BROWSER_TEST_NONE); |
1746 new_tab_observer.Wait(); | 1747 new_tab_observer.Wait(); |
1747 | 1748 |
1748 omnibox()->model()->autocomplete_controller()->search_provider()-> | 1749 omnibox()->model()->autocomplete_controller()->search_provider()-> |
1749 kMinimumTimeBetweenSuggestQueriesMs = 0; | 1750 kMinimumTimeBetweenSuggestQueriesMs = 0; |
1750 | 1751 |
1751 // Set the fake response for suggest request. Response has no prefetch | 1752 // Set the fake response for suggest request. Response has no prefetch |
1752 // details. Ensure that the page received a blank query to clear the | 1753 // details. Ensure that the page received a blank query to clear the |
1753 // prefetched results. | 1754 // prefetched results. |
1754 factory_->SetFakeResponse( | 1755 fake_factory()->SetFakeResponse( |
1755 instant_url().spec() + "#q=dogs", | 1756 instant_url().spec() + "#q=dogs", |
1756 "[\"dogs\",[\"https://dogs.com\"],[],[]," | 1757 "[\"dogs\",[\"https://dogs.com\"],[],[]," |
1757 "{\"google:suggesttype\":[\"NAVIGATION\"]," | 1758 "{\"google:suggesttype\":[\"NAVIGATION\"]," |
1758 "\"google:suggestrelevance\":[2]}]", | 1759 "\"google:suggestrelevance\":[2]}]", |
1759 true); | 1760 true); |
1760 | 1761 |
1761 SetOmniboxText("dogs"); | 1762 SetOmniboxText("dogs"); |
1762 while (!omnibox()->model()->autocomplete_controller()->done()) { | 1763 while (!omnibox()->model()->autocomplete_controller()->done()) { |
1763 content::WindowedNotificationObserver ready_observer( | 1764 content::WindowedNotificationObserver ready_observer( |
1764 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 1765 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
1765 content::Source<AutocompleteController>( | 1766 content::Source<AutocompleteController>( |
1766 omnibox()->model()->autocomplete_controller())); | 1767 omnibox()->model()->autocomplete_controller())); |
1767 ready_observer.Wait(); | 1768 ready_observer.Wait(); |
1768 } | 1769 } |
1769 | 1770 |
1770 ASSERT_EQ(2, CountSearchProviderSuggestions()); | 1771 ASSERT_EQ(2, CountSearchProviderSuggestions()); |
1771 ASSERT_FALSE(SearchProvider::ShouldPrefetch(*( | 1772 ASSERT_FALSE(SearchProvider::ShouldPrefetch(*( |
1772 omnibox()->model()->result().default_match()))); | 1773 omnibox()->model()->result().default_match()))); |
1773 content::WebContents* active_tab = | 1774 content::WebContents* active_tab = |
1774 browser()->tab_strip_model()->GetActiveWebContents(); | 1775 browser()->tab_strip_model()->GetActiveWebContents(); |
1775 ASSERT_TRUE(UpdateSearchState(active_tab)); | 1776 ASSERT_TRUE(UpdateSearchState(active_tab)); |
1776 ASSERT_EQ("", prefetch_query_value_); | 1777 ASSERT_EQ("", prefetch_query_value_); |
1777 } | 1778 } |
OLD | NEW |