Index: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
diff --git a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
index 4b6a681486df0d4ab3f1f84052205bd135eed63a..e1a8a60e0adccd0d939d1944bf263c0eb7629eb2 100644 |
--- a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
+++ b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
@@ -9,6 +9,7 @@ |
#include "base/command_line.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/string_util.h" |
+#include "base/test/histogram_tester.h" |
#include "chrome/browser/browsing_data/browsing_data_helper.h" |
#include "chrome/browser/browsing_data/browsing_data_remover.h" |
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
@@ -271,7 +272,9 @@ class PrefetchingObserver : public TestObserver { |
ADD_FAILURE() << "Prefetching shouldn't activate learning"; |
} |
- void OnPrefetchingFinished(const GURL& main_frame_url) override { |
+ void OnPrefetchingFinished( |
+ const GURL& main_frame_url, |
+ const ResourcePrefetcher::PrefetcherStats& stats) override { |
EXPECT_EQ(main_frame_url_, main_frame_url); |
run_loop_.Quit(); |
} |
@@ -317,6 +320,7 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); |
ASSERT_TRUE(predictor_); |
EnsurePredictorInitialized(); |
+ histogram_tester_.reset(new base::HistogramTester()); |
} |
void TestLearningAndPrefetching(const GURL& main_frame_url) { |
@@ -599,6 +603,10 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
else |
http_response->AddCustomHeader("Cache-Control", "max-age=2147483648"); |
+ // Add some content, otherwise the prefetch size histogram rounds down to |
+ // 0kB. |
+ http_response->set_content(std::string(1024, static_cast<char>(42))); |
alexilin
2017/02/09 15:24:17
It will cause additional parsing errors in tests.
Benoit L
2017/02/13 16:13:15
Changed to a space, which should be fine for the v
|
+ |
return std::move(http_response); |
} |
@@ -624,6 +632,10 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
return ++visit_count_[main_frame_url]; |
} |
+ protected: |
+ std::unique_ptr<base::HistogramTester> histogram_tester_; |
alexilin
2017/02/09 15:24:18
Could you put it at the end of (first) protected s
Benoit L
2017/02/13 16:13:15
Done.
|
+ |
+ private: |
ResourcePrefetchPredictor* predictor_; |
std::unique_ptr<net::EmbeddedTestServer> https_server_; |
std::map<GURL, ResourceSummary> resources_; |
@@ -642,6 +654,22 @@ IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { |
AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
net::HIGHEST); |
TestLearningAndPrefetching(GetURL(kHtmlSubresourcesPath)); |
+ |
+ // The local cache is cleared. |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchMissesCountCached, 0, 1); |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchMissesCountNotCached, 0, 1); |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchHitsCountCached, 0, 1); |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchHitsCountNotCached, 4, 1); |
+ |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchMissesSize, 0, 1); |
+ // Each request is ~1k, see HandleResourceRequest() above. |
+ histogram_tester_->ExpectBucketCount( |
+ internal::kResourcePrefetchPredictorPrefetchHitsSize, 4, 1); |
} |
IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Redirect) { |