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

Side by Side Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <deque> 5 #include <deque>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/test/histogram_tester.h"
20 #include "base/test/test_timeouts.h" 21 #include "base/test/test_timeouts.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "chrome/browser/browsing_data/browsing_data_helper.h" 23 #include "chrome/browser/browsing_data/browsing_data_helper.h"
23 #include "chrome/browser/browsing_data/browsing_data_remover.h" 24 #include "chrome/browser/browsing_data/browsing_data_remover.h"
24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 25 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
25 #include "chrome/browser/chrome_content_browser_client.h" 26 #include "chrome/browser/chrome_content_browser_client.h"
26 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/host_content_settings_map.h" 28 #include "chrome/browser/content_settings/host_content_settings_map.h"
28 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 29 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
29 #include "chrome/browser/extensions/extension_apitest.h" 30 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 27 matching lines...) Expand all
57 #include "chrome/browser/ui/tabs/tab_strip_model.h" 58 #include "chrome/browser/ui/tabs/tab_strip_model.h"
58 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" 59 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
59 #include "chrome/common/chrome_paths.h" 60 #include "chrome/common/chrome_paths.h"
60 #include "chrome/common/chrome_switches.h" 61 #include "chrome/common/chrome_switches.h"
61 #include "chrome/common/extensions/extension_constants.h" 62 #include "chrome/common/extensions/extension_constants.h"
62 #include "chrome/common/extensions/manifest_handlers/mime_types_handler.h" 63 #include "chrome/common/extensions/manifest_handlers/mime_types_handler.h"
63 #include "chrome/common/pref_names.h" 64 #include "chrome/common/pref_names.h"
64 #include "chrome/test/base/in_process_browser_test.h" 65 #include "chrome/test/base/in_process_browser_test.h"
65 #include "chrome/test/base/test_switches.h" 66 #include "chrome/test/base/test_switches.h"
66 #include "chrome/test/base/ui_test_utils.h" 67 #include "chrome/test/base/ui_test_utils.h"
67 #include "chrome/test/base/uma_histogram_helper.h"
68 #include "content/public/browser/browser_message_filter.h" 68 #include "content/public/browser/browser_message_filter.h"
69 #include "content/public/browser/devtools_agent_host.h" 69 #include "content/public/browser/devtools_agent_host.h"
70 #include "content/public/browser/navigation_controller.h" 70 #include "content/public/browser/navigation_controller.h"
71 #include "content/public/browser/navigation_entry.h" 71 #include "content/public/browser/navigation_entry.h"
72 #include "content/public/browser/notification_service.h" 72 #include "content/public/browser/notification_service.h"
73 #include "content/public/browser/render_frame_host.h" 73 #include "content/public/browser/render_frame_host.h"
74 #include "content/public/browser/render_process_host.h" 74 #include "content/public/browser/render_process_host.h"
75 #include "content/public/browser/render_view_host.h" 75 #include "content/public/browser/render_view_host.h"
76 #include "content/public/browser/site_instance.h" 76 #include "content/public/browser/site_instance.h"
77 #include "content/public/browser/web_contents.h" 77 #include "content/public/browser/web_contents.h"
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 result)); 1496 result));
1497 } 1497 }
1498 1498
1499 void RunJS(const char* js) { 1499 void RunJS(const char* js) {
1500 ASSERT_TRUE(content::ExecuteScript( 1500 ASSERT_TRUE(content::ExecuteScript(
1501 GetActiveWebContents(), 1501 GetActiveWebContents(),
1502 base::StringPrintf("window.domAutomationController.send(%s)", 1502 base::StringPrintf("window.domAutomationController.send(%s)",
1503 js).c_str())); 1503 js).c_str()));
1504 } 1504 }
1505 1505
1506 const base::HistogramTester& histogram_tester() { return histogram_tester_; }
1507
1506 protected: 1508 protected:
1507 bool autostart_test_server_; 1509 bool autostart_test_server_;
1508 1510
1509 private: 1511 private:
1510 // TODO(davidben): Remove this altogether so the tests don't globally assume 1512 // TODO(davidben): Remove this altogether so the tests don't globally assume
1511 // only one prerender. 1513 // only one prerender.
1512 TestPrerenderContents* GetPrerenderContents() const { 1514 TestPrerenderContents* GetPrerenderContents() const {
1513 return GetPrerenderContentsFor(dest_url_); 1515 return GetPrerenderContentsFor(dest_url_);
1514 } 1516 }
1515 1517
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 #endif 1648 #endif
1647 NeverRunsExternalProtocolHandlerDelegate external_protocol_handler_delegate_; 1649 NeverRunsExternalProtocolHandlerDelegate external_protocol_handler_delegate_;
1648 GURL dest_url_; 1650 GURL dest_url_;
1649 scoped_ptr<net::SpawnedTestServer> https_src_server_; 1651 scoped_ptr<net::SpawnedTestServer> https_src_server_;
1650 bool call_javascript_; 1652 bool call_javascript_;
1651 bool check_load_events_; 1653 bool check_load_events_;
1652 std::string loader_host_override_; 1654 std::string loader_host_override_;
1653 std::string loader_path_; 1655 std::string loader_path_;
1654 std::string loader_query_; 1656 std::string loader_query_;
1655 Browser* explicitly_set_browser_; 1657 Browser* explicitly_set_browser_;
1658 base::HistogramTester histogram_tester_;
1656 }; 1659 };
1657 1660
1658 // Checks that a page is correctly prerendered in the case of a 1661 // Checks that a page is correctly prerendered in the case of a
1659 // <link rel=prerender> tag and then loaded into a tab in response to a 1662 // <link rel=prerender> tag and then loaded into a tab in response to a
1660 // navigation. 1663 // navigation.
1661 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) { 1664 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPage) {
1662 UMAHistogramHelper histograms;
1663
1664 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 1665 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
1665 EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0)); 1666 EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0));
1666 histograms.Fetch(); 1667 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
1667 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 1668 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
1668 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 1669 histogram_tester().ExpectTotalCount(
1669 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 1670 "Prerender.none_PerceivedPLTMatchedComplete", 0);
1670 histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1); 1671 histogram_tester().ExpectTotalCount(
1672 "Prerender.websame_PrerenderNotSwappedInPLT", 1);
1671 1673
1672 ChannelDestructionWatcher channel_close_watcher; 1674 ChannelDestructionWatcher channel_close_watcher;
1673 channel_close_watcher.WatchChannel( 1675 channel_close_watcher.WatchChannel(
1674 GetActiveWebContents()->GetRenderProcessHost()); 1676 GetActiveWebContents()->GetRenderProcessHost());
1675 NavigateToDestURL(); 1677 NavigateToDestURL();
1676 channel_close_watcher.WaitForChannelClose(); 1678 channel_close_watcher.WaitForChannelClose();
1677 1679
1678 histograms.Fetch(); 1680 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
1679 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); 1681 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
1680 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 1); 1682 1);
1681 histograms.ExpectTotalCount( 1683 histogram_tester().ExpectTotalCount(
1682 "Prerender.websame_PerceivedPLTMatchedComplete", 1); 1684 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
1683 1685
1684 ASSERT_TRUE(IsEmptyPrerenderLinkManager()); 1686 ASSERT_TRUE(IsEmptyPrerenderLinkManager());
1685 } 1687 }
1686 1688
1687 // Checks that cross-domain prerenders emit the correct histograms. 1689 // Checks that cross-domain prerenders emit the correct histograms.
1688 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageCrossDomain) { 1690 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPageCrossDomain) {
1689 UMAHistogramHelper histograms;
1690
1691 PrerenderTestURL(GetCrossDomainTestUrl("files/prerender/prerender_page.html"), 1691 PrerenderTestURL(GetCrossDomainTestUrl("files/prerender/prerender_page.html"),
1692 FINAL_STATUS_USED, 1); 1692 FINAL_STATUS_USED, 1);
1693 histograms.Fetch(); 1693 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
1694 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 1694 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
1695 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 1695 histogram_tester().ExpectTotalCount(
1696 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 1696 "Prerender.none_PerceivedPLTMatchedComplete", 0);
1697 histograms.ExpectTotalCount("Prerender.webcross_PrerenderNotSwappedInPLT", 1); 1697 histogram_tester().ExpectTotalCount(
1698 "Prerender.webcross_PrerenderNotSwappedInPLT", 1);
1698 1699
1699 NavigateToDestURL(); 1700 NavigateToDestURL();
1700 histograms.Fetch(); 1701 histogram_tester().ExpectTotalCount("Prerender.webcross_PerceivedPLT", 1);
1701 histograms.ExpectTotalCount("Prerender.webcross_PerceivedPLT", 1); 1702 histogram_tester().ExpectTotalCount("Prerender.webcross_PerceivedPLTMatched",
1702 histograms.ExpectTotalCount("Prerender.webcross_PerceivedPLTMatched", 1); 1703 1);
1703 histograms.ExpectTotalCount( 1704 histogram_tester().ExpectTotalCount(
1704 "Prerender.webcross_PerceivedPLTMatchedComplete", 1); 1705 "Prerender.webcross_PerceivedPLTMatchedComplete", 1);
1705 } 1706 }
1706 1707
1707 // Checks that pending prerenders launch and receive proper event treatment. 1708 // Checks that pending prerenders launch and receive proper event treatment.
1708 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPagePending) { 1709 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPagePending) {
1709 scoped_ptr<TestPrerender> prerender = 1710 scoped_ptr<TestPrerender> prerender =
1710 PrerenderTestURL("files/prerender/prerender_page_pending.html", 1711 PrerenderTestURL("files/prerender/prerender_page_pending.html",
1711 FINAL_STATUS_USED, 1); 1712 FINAL_STATUS_USED, 1);
1712 1713
1713 // Navigate to the prerender. 1714 // Navigate to the prerender.
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 FINAL_STATUS_USED, 2073 FINAL_STATUS_USED,
2073 2); 2074 2);
2074 NavigateToURL("files/prerender/prerender_page.html"); 2075 NavigateToURL("files/prerender/prerender_page.html");
2075 } 2076 }
2076 2077
2077 // Checks that we get the right PPLT histograms for client redirect prerenders 2078 // Checks that we get the right PPLT histograms for client redirect prerenders
2078 // and navigations when the referring page is Google. 2079 // and navigations when the referring page is Google.
2079 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2080 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2080 PrerenderLocationReplaceGWSHistograms) { 2081 PrerenderLocationReplaceGWSHistograms) {
2081 DisableJavascriptCalls(); 2082 DisableJavascriptCalls();
2082 UMAHistogramHelper histograms;
2083 2083
2084 // The loader page should look like Google. 2084 // The loader page should look like Google.
2085 const std::string kGoogleDotCom("www.google.com"); 2085 const std::string kGoogleDotCom("www.google.com");
2086 SetLoaderHostOverride(kGoogleDotCom); 2086 SetLoaderHostOverride(kGoogleDotCom);
2087 set_loader_path("files/prerender/prerender_loader_with_replace_state.html"); 2087 set_loader_path("files/prerender/prerender_loader_with_replace_state.html");
2088 2088
2089 GURL dest_url = GetCrossDomainTestUrl( 2089 GURL dest_url = GetCrossDomainTestUrl(
2090 "files/prerender/prerender_deferred_image.html"); 2090 "files/prerender/prerender_deferred_image.html");
2091 2091
2092 GURL prerender_url = test_server()->GetURL( 2092 GURL prerender_url = test_server()->GetURL(
2093 "files/prerender/prerender_location_replace.html?" + 2093 "files/prerender/prerender_location_replace.html?" +
2094 net::EscapeQueryParamValue(dest_url.spec(), false) + 2094 net::EscapeQueryParamValue(dest_url.spec(), false) +
2095 "#prerender"); 2095 "#prerender");
2096 GURL::Replacements replacements; 2096 GURL::Replacements replacements;
2097 replacements.SetHostStr(kGoogleDotCom); 2097 replacements.SetHostStr(kGoogleDotCom);
2098 prerender_url = prerender_url.ReplaceComponents(replacements); 2098 prerender_url = prerender_url.ReplaceComponents(replacements);
2099 2099
2100 // The prerender will not completely load until after the swap, so wait for a 2100 // The prerender will not completely load until after the swap, so wait for a
2101 // title change before calling DidPrerenderPass. 2101 // title change before calling DidPrerenderPass.
2102 scoped_ptr<TestPrerender> prerender = 2102 scoped_ptr<TestPrerender> prerender =
2103 PrerenderTestURL(prerender_url, FINAL_STATUS_USED, 1); 2103 PrerenderTestURL(prerender_url, FINAL_STATUS_USED, 1);
2104 WaitForASCIITitle(prerender->contents()->prerender_contents(), kReadyTitle); 2104 WaitForASCIITitle(prerender->contents()->prerender_contents(), kReadyTitle);
2105 EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents())); 2105 EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents()));
2106 EXPECT_EQ(1, prerender->number_of_loads()); 2106 EXPECT_EQ(1, prerender->number_of_loads());
2107 2107
2108 histograms.Fetch(); 2108 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
2109 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 2109 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
2110 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 2110 histogram_tester().ExpectTotalCount(
2111 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 2111 "Prerender.none_PerceivedPLTMatchedComplete", 0);
2112 // Although there is a client redirect, it is dropped from histograms because 2112 // Although there is a client redirect, it is dropped from histograms because
2113 // it is a Google URL. The target page itself does not load until after the 2113 // it is a Google URL. The target page itself does not load until after the
2114 // swap. 2114 // swap.
2115 histograms.ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT", 0); 2115 histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT",
2116 0);
2116 2117
2117 GURL navigate_url = test_server()->GetURL( 2118 GURL navigate_url = test_server()->GetURL(
2118 "files/prerender/prerender_location_replace.html?" + 2119 "files/prerender/prerender_location_replace.html?" +
2119 net::EscapeQueryParamValue(dest_url.spec(), false) + 2120 net::EscapeQueryParamValue(dest_url.spec(), false) +
2120 "#navigate"); 2121 "#navigate");
2121 navigate_url = navigate_url.ReplaceComponents(replacements); 2122 navigate_url = navigate_url.ReplaceComponents(replacements);
2122 2123
2123 NavigationOrSwapObserver swap_observer( 2124 NavigationOrSwapObserver swap_observer(
2124 current_browser()->tab_strip_model(), 2125 current_browser()->tab_strip_model(),
2125 GetActiveWebContents(), 2); 2126 GetActiveWebContents(), 2);
2126 current_browser()->OpenURL(OpenURLParams( 2127 current_browser()->OpenURL(OpenURLParams(
2127 navigate_url, Referrer(), CURRENT_TAB, 2128 navigate_url, Referrer(), CURRENT_TAB,
2128 content::PAGE_TRANSITION_TYPED, false)); 2129 content::PAGE_TRANSITION_TYPED, false));
2129 swap_observer.Wait(); 2130 swap_observer.Wait();
2130 2131
2131 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); 2132 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
2132 2133
2133 histograms.Fetch(); 2134 histogram_tester().ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT",
2134 histograms.ExpectTotalCount("Prerender.gws_PrerenderNotSwappedInPLT", 0); 2135 0);
2135 histograms.ExpectTotalCount("Prerender.gws_PerceivedPLT", 1); 2136 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLT", 1);
2136 histograms.ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1); 2137 histogram_tester().ExpectTotalCount("Prerender.gws_PerceivedPLTMatched", 1);
2137 histograms.ExpectTotalCount( 2138 histogram_tester().ExpectTotalCount(
2138 "Prerender.gws_PerceivedPLTMatchedComplete", 1); 2139 "Prerender.gws_PerceivedPLTMatchedComplete", 1);
2139 2140
2140 // The client redirect does /not/ count as a miss because it's a Google URL. 2141 // The client redirect does /not/ count as a miss because it's a Google URL.
2141 histograms.ExpectTotalCount("Prerender.PerceivedPLTFirstAfterMiss", 0); 2142 histogram_tester().ExpectTotalCount("Prerender.PerceivedPLTFirstAfterMiss",
2143 0);
2142 } 2144 }
2143 2145
2144 // Checks that client-issued redirects work with prerendering. 2146 // Checks that client-issued redirects work with prerendering.
2145 // This version navigates to the final destination page, rather than the 2147 // This version navigates to the final destination page, rather than the
2146 // page which does the redirection via a mouse click. 2148 // page which does the redirection via a mouse click.
2147 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 2149 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
2148 PrerenderClientRedirectNavigateToSecondViaClick) { 2150 PrerenderClientRedirectNavigateToSecondViaClick) {
2149 GURL prerender_url = test_server()->GetURL( 2151 GURL prerender_url = test_server()->GetURL(
2150 CreateClientRedirect("files/prerender/prerender_page.html")); 2152 CreateClientRedirect("files/prerender/prerender_page.html"));
2151 GURL destination_url = test_server()->GetURL( 2153 GURL destination_url = test_server()->GetURL(
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
3336 PrerenderTestURL("files/prerender/prerender_xhr_put.html", 3338 PrerenderTestURL("files/prerender/prerender_xhr_put.html",
3337 FINAL_STATUS_WOULD_HAVE_BEEN_USED, 0); 3339 FINAL_STATUS_WOULD_HAVE_BEEN_USED, 0);
3338 OpenDestURLViaClick(); 3340 OpenDestURLViaClick();
3339 } 3341 }
3340 3342
3341 // Make sure that the MatchComplete dummy works in the normal case. Once 3343 // Make sure that the MatchComplete dummy works in the normal case. Once
3342 // a prerender is cancelled because of a script, a dummy must be created to 3344 // a prerender is cancelled because of a script, a dummy must be created to
3343 // account for the MatchComplete case, and it must have a final status of 3345 // account for the MatchComplete case, and it must have a final status of
3344 // FINAL_STATUS_WOULD_HAVE_BEEN_USED. 3346 // FINAL_STATUS_WOULD_HAVE_BEEN_USED.
3345 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) { 3347 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, MatchCompleteDummy) {
3346 UMAHistogramHelper histograms;
3347 3348
3348 std::vector<FinalStatus> expected_final_status_queue; 3349 std::vector<FinalStatus> expected_final_status_queue;
3349 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD); 3350 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD);
3350 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); 3351 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
3351 PrerenderTestURL("files/prerender/prerender_xhr_put.html", 3352 PrerenderTestURL("files/prerender/prerender_xhr_put.html",
3352 expected_final_status_queue, 1); 3353 expected_final_status_queue, 1);
3353 histograms.Fetch(); 3354 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
3354 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 3355 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3355 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 3356 histogram_tester().ExpectTotalCount(
3356 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 3357 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3357 histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1); 3358 histogram_tester().ExpectTotalCount(
3359 "Prerender.websame_PrerenderNotSwappedInPLT", 1);
3358 3360
3359 NavigateToDestURL(); 3361 NavigateToDestURL();
3360 histograms.Fetch(); 3362 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
3361 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); 3363 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
3362 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 0); 3364 0);
3363 histograms.ExpectTotalCount( 3365 histogram_tester().ExpectTotalCount(
3364 "Prerender.websame_PerceivedPLTMatchedComplete", 1); 3366 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
3365 } 3367 }
3366 3368
3367 // Verify that a navigation that hits a MatchComplete dummy while another is in 3369 // Verify that a navigation that hits a MatchComplete dummy while another is in
3368 // progress does not also classify the previous navigation as a MatchComplete. 3370 // progress does not also classify the previous navigation as a MatchComplete.
3369 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 3371 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
3370 MatchCompleteDummyCancelNavigation) { 3372 MatchCompleteDummyCancelNavigation) {
3371 UMAHistogramHelper histograms;
3372
3373 // Arrange for a URL to hang. 3373 // Arrange for a URL to hang.
3374 const GURL kNoCommitUrl("http://never-respond.example.com"); 3374 const GURL kNoCommitUrl("http://never-respond.example.com");
3375 base::FilePath file(FILE_PATH_LITERAL( 3375 base::FilePath file(FILE_PATH_LITERAL(
3376 "chrome/test/data/prerender/prerender_page.html")); 3376 "chrome/test/data/prerender/prerender_page.html"));
3377 base::RunLoop hang_loop; 3377 base::RunLoop hang_loop;
3378 BrowserThread::PostTask( 3378 BrowserThread::PostTask(
3379 BrowserThread::IO, FROM_HERE, 3379 BrowserThread::IO, FROM_HERE,
3380 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl, 3380 base::Bind(&CreateHangingFirstRequestInterceptorOnIO, kNoCommitUrl,
3381 file, hang_loop.QuitClosure())); 3381 file, hang_loop.QuitClosure()));
3382 3382
3383 // First, fire a prerender that aborts after it completes its load. 3383 // First, fire a prerender that aborts after it completes its load.
3384 std::vector<FinalStatus> expected_final_status_queue; 3384 std::vector<FinalStatus> expected_final_status_queue;
3385 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD); 3385 expected_final_status_queue.push_back(FINAL_STATUS_INVALID_HTTP_METHOD);
3386 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED); 3386 expected_final_status_queue.push_back(FINAL_STATUS_WOULD_HAVE_BEEN_USED);
3387 PrerenderTestURL("files/prerender/prerender_xhr_put.html", 3387 PrerenderTestURL("files/prerender/prerender_xhr_put.html",
3388 expected_final_status_queue, 1); 3388 expected_final_status_queue, 1);
3389 histograms.Fetch(); 3389 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
3390 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 3390 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3391 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 3391 histogram_tester().ExpectTotalCount(
3392 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 3392 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3393 histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 1); 3393 histogram_tester().ExpectTotalCount(
3394 "Prerender.websame_PrerenderNotSwappedInPLT", 1);
3394 3395
3395 // Open the hanging URL in a new tab. Wait for both the new tab to open and 3396 // Open the hanging URL in a new tab. Wait for both the new tab to open and
3396 // the hanging request to be scheduled. 3397 // the hanging request to be scheduled.
3397 ui_test_utils::NavigateToURLWithDisposition( 3398 ui_test_utils::NavigateToURLWithDisposition(
3398 current_browser(), kNoCommitUrl, NEW_FOREGROUND_TAB, 3399 current_browser(), kNoCommitUrl, NEW_FOREGROUND_TAB,
3399 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 3400 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
3400 hang_loop.Run(); 3401 hang_loop.Run();
3401 3402
3402 // Now interrupt that navigation and navigate to the destination URL. This 3403 // Now interrupt that navigation and navigate to the destination URL. This
3403 // should forcibly complete the previous navigation and also complete a 3404 // should forcibly complete the previous navigation and also complete a
3404 // WOULD_HAVE_BEEN_PRERENDERED navigation. 3405 // WOULD_HAVE_BEEN_PRERENDERED navigation.
3405 NavigateToDestURL(); 3406 NavigateToDestURL();
3406 histograms.Fetch(); 3407 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 2);
3407 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 2); 3408 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3408 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 3409 histogram_tester().ExpectTotalCount(
3409 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 3410 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3410 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); 3411 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
3411 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 0); 3412 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
3412 histograms.ExpectTotalCount( 3413 0);
3414 histogram_tester().ExpectTotalCount(
3413 "Prerender.websame_PerceivedPLTMatchedComplete", 1); 3415 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
3414 } 3416 }
3415 3417
3416 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest { 3418 class PrerenderBrowserTestWithNaCl : public PrerenderBrowserTest {
3417 public: 3419 public:
3418 PrerenderBrowserTestWithNaCl() {} 3420 PrerenderBrowserTestWithNaCl() {}
3419 virtual ~PrerenderBrowserTestWithNaCl() {} 3421 virtual ~PrerenderBrowserTestWithNaCl() {}
3420 3422
3421 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 3423 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
3422 PrerenderBrowserTest::SetUpCommandLine(command_line); 3424 PrerenderBrowserTest::SetUpCommandLine(command_line);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
3785 prerenders[1]->WaitForStop(); 3787 prerenders[1]->WaitForStop();
3786 3788
3787 // Check the referring page only got one copy of the event. 3789 // Check the referring page only got one copy of the event.
3788 EXPECT_FALSE(HadPrerenderEventErrors()); 3790 EXPECT_FALSE(HadPrerenderEventErrors());
3789 } 3791 }
3790 3792
3791 // Checks that a deferred redirect to an image is not loaded until the page is 3793 // Checks that a deferred redirect to an image is not loaded until the page is
3792 // visible. Also test the right histogram events are emitted in this case. 3794 // visible. Also test the right histogram events are emitted in this case.
3793 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredImage) { 3795 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderDeferredImage) {
3794 DisableJavascriptCalls(); 3796 DisableJavascriptCalls();
3795 UMAHistogramHelper histograms;
3796 3797
3797 // The prerender will not completely load until after the swap, so wait for a 3798 // The prerender will not completely load until after the swap, so wait for a
3798 // title change before calling DidPrerenderPass. 3799 // title change before calling DidPrerenderPass.
3799 scoped_ptr<TestPrerender> prerender = 3800 scoped_ptr<TestPrerender> prerender =
3800 PrerenderTestURL( 3801 PrerenderTestURL(
3801 "files/prerender/prerender_deferred_image.html", 3802 "files/prerender/prerender_deferred_image.html",
3802 FINAL_STATUS_USED, 0); 3803 FINAL_STATUS_USED, 0);
3803 WaitForASCIITitle(prerender->contents()->prerender_contents(), kReadyTitle); 3804 WaitForASCIITitle(prerender->contents()->prerender_contents(), kReadyTitle);
3804 EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0)); 3805 EXPECT_EQ(1, GetPrerenderDomContentLoadedEventCountForLinkNumber(0));
3805 EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents())); 3806 EXPECT_TRUE(DidPrerenderPass(prerender->contents()->prerender_contents()));
3806 EXPECT_EQ(0, prerender->number_of_loads()); 3807 EXPECT_EQ(0, prerender->number_of_loads());
3807 histograms.Fetch(); 3808 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
3808 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 3809 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
3809 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 3810 histogram_tester().ExpectTotalCount(
3810 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 3811 "Prerender.none_PerceivedPLTMatchedComplete", 0);
3811 histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 0); 3812 histogram_tester().ExpectTotalCount(
3813 "Prerender.websame_PrerenderNotSwappedInPLT", 0);
3812 3814
3813 // Swap. 3815 // Swap.
3814 NavigationOrSwapObserver swap_observer(current_browser()->tab_strip_model(), 3816 NavigationOrSwapObserver swap_observer(current_browser()->tab_strip_model(),
3815 GetActiveWebContents()); 3817 GetActiveWebContents());
3816 ui_test_utils::NavigateToURLWithDisposition( 3818 ui_test_utils::NavigateToURLWithDisposition(
3817 current_browser(), dest_url(), CURRENT_TAB, 3819 current_browser(), dest_url(), CURRENT_TAB,
3818 ui_test_utils::BROWSER_TEST_NONE); 3820 ui_test_utils::BROWSER_TEST_NONE);
3819 swap_observer.Wait(); 3821 swap_observer.Wait();
3820 3822
3821 // The prerender never observes the final load. 3823 // The prerender never observes the final load.
3822 EXPECT_EQ(0, prerender->number_of_loads()); 3824 EXPECT_EQ(0, prerender->number_of_loads());
3823 3825
3824 // Now check DidDisplayPass. 3826 // Now check DidDisplayPass.
3825 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents())); 3827 EXPECT_TRUE(DidDisplayPass(GetActiveWebContents()));
3826 3828
3827 histograms.Fetch(); 3829 histogram_tester().ExpectTotalCount(
3828 histograms.ExpectTotalCount("Prerender.websame_PrerenderNotSwappedInPLT", 0); 3830 "Prerender.websame_PrerenderNotSwappedInPLT", 0);
3829 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLT", 1); 3831 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLT", 1);
3830 histograms.ExpectTotalCount("Prerender.websame_PerceivedPLTMatched", 1); 3832 histogram_tester().ExpectTotalCount("Prerender.websame_PerceivedPLTMatched",
3831 histograms.ExpectTotalCount( 3833 1);
3834 histogram_tester().ExpectTotalCount(
3832 "Prerender.websame_PerceivedPLTMatchedComplete", 1); 3835 "Prerender.websame_PerceivedPLTMatchedComplete", 1);
3833 } 3836 }
3834 3837
3835 // Checks that a deferred redirect to an image is not loaded until the 3838 // Checks that a deferred redirect to an image is not loaded until the
3836 // page is visible, even after another redirect. 3839 // page is visible, even after another redirect.
3837 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 3840 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
3838 PrerenderDeferredImageAfterRedirect) { 3841 PrerenderDeferredImageAfterRedirect) {
3839 DisableJavascriptCalls(); 3842 DisableJavascriptCalls();
3840 3843
3841 // The prerender will not completely load until after the swap, so wait for a 3844 // The prerender will not completely load until after the swap, so wait for a
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 base::Bind(&CreateCountingInterceptorOnIO, 4169 base::Bind(&CreateCountingInterceptorOnIO,
4167 kPingURL, empty_file, ping_counter.AsWeakPtr())); 4170 kPingURL, empty_file, ping_counter.AsWeakPtr()));
4168 4171
4169 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1); 4172 PrerenderTestURL("files/prerender/prerender_page.html", FINAL_STATUS_USED, 1);
4170 OpenDestURLViaClickPing(kPingURL); 4173 OpenDestURLViaClickPing(kPingURL);
4171 4174
4172 ping_counter.WaitForCount(1); 4175 ping_counter.WaitForCount(1);
4173 } 4176 }
4174 4177
4175 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) { 4178 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderPPLTNormalNavigation) {
4176 UMAHistogramHelper histograms;
4177
4178 GURL url = test_server()->GetURL("files/prerender/prerender_page.html"); 4179 GURL url = test_server()->GetURL("files/prerender/prerender_page.html");
4179 ui_test_utils::NavigateToURL(current_browser(), url); 4180 ui_test_utils::NavigateToURL(current_browser(), url);
4180 histograms.Fetch(); 4181 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLT", 1);
4181 histograms.ExpectTotalCount("Prerender.none_PerceivedPLT", 1); 4182 histogram_tester().ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0);
4182 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatched", 0); 4183 histogram_tester().ExpectTotalCount(
4183 histograms.ExpectTotalCount("Prerender.none_PerceivedPLTMatchedComplete", 0); 4184 "Prerender.none_PerceivedPLTMatchedComplete", 0);
4184 } 4185 }
4185 4186
4186 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, 4187 IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest,
4187 PrerenderCookieChangeConflictTest) { 4188 PrerenderCookieChangeConflictTest) {
4188 NavigateStraightToURL( 4189 NavigateStraightToURL(
4189 "files/prerender/prerender_cookie.html?set=1&key=c&value=1"); 4190 "files/prerender/prerender_cookie.html?set=1&key=c&value=1");
4190 4191
4191 GURL url = test_server()->GetURL( 4192 GURL url = test_server()->GetURL(
4192 "files/prerender/prerender_cookie.html?set=1&key=c&value=2"); 4193 "files/prerender/prerender_cookie.html?set=1&key=c&value=2");
4193 4194
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
4415 4416
4416 // Navigate to the URL entered. 4417 // Navigate to the URL entered.
4417 omnibox_view->model()->AcceptInput(CURRENT_TAB, false); 4418 omnibox_view->model()->AcceptInput(CURRENT_TAB, false);
4418 4419
4419 // Prerender should be running, but abandoned. 4420 // Prerender should be running, but abandoned.
4420 EXPECT_TRUE( 4421 EXPECT_TRUE(
4421 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting()); 4422 GetAutocompleteActionPredictor()->IsPrerenderAbandonedForTesting());
4422 } 4423 }
4423 4424
4424 } // namespace prerender 4425 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/external_metrics_unittest.cc ('k') | chrome/browser/signin/account_reconcilor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698