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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_unittest.cc

Issue 2790633002: predictors: Remove unknown fields from PrecacheManifest before store it. (Closed)
Patch Set: Move implementation into .cc file. Created 3 years, 8 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
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 1034
1035 EXPECT_CALL(*mock_tables_.get(), 1035 EXPECT_CALL(*mock_tables_.get(),
1036 DeleteManifestData(std::vector<std::string>({"google.com"}))); 1036 DeleteManifestData(std::vector<std::string>({"google.com"})));
1037 1037
1038 EXPECT_CALL(*mock_tables_.get(), 1038 EXPECT_CALL(*mock_tables_.get(),
1039 UpdateManifestData("en.wikipedia.org", manifest)); 1039 UpdateManifestData("en.wikipedia.org", manifest));
1040 1040
1041 predictor_->OnManifestFetched("en.wikipedia.org", manifest); 1041 predictor_->OnManifestFetched("en.wikipedia.org", manifest);
1042 } 1042 }
1043 1043
1044 TEST_F(ResourcePrefetchPredictorTest, ManifestUnknownFieldsRemoved) {
1045 precache::PrecacheManifest manifest = CreateManifestData(1);
1046 InitializePrecacheResource(manifest.add_resource(),
1047 "http://cdn.google.com/script.js", 0.9);
1048 InitializePrecacheResource(manifest.add_resource(),
1049 "http://cdn.google.com/style.css", 0.75);
1050
1051 precache::PrecacheManifest manifest_with_unknown_fields(manifest);
1052 manifest_with_unknown_fields.mutable_id()->mutable_unknown_fields()->append(
1053 "DATA");
1054 manifest_with_unknown_fields.mutable_unknown_fields()->append("DATA");
1055 for (auto& resource : *manifest_with_unknown_fields.mutable_resource()) {
1056 resource.mutable_unknown_fields()->append("DATA");
1057 }
1058
1059 int manifest_size = manifest.ByteSize();
1060 auto match_size = [manifest_size](const precache::PrecacheManifest& m) {
1061 return m.ByteSize() == manifest_size;
1062 };
1063 EXPECT_CALL(
1064 *mock_tables_.get(),
1065 UpdateManifestData("google.com",
1066 testing::AllOf(manifest, testing::Truly(match_size))));
1067
1068 predictor_->OnManifestFetched("google.com", manifest_with_unknown_fields);
1069 }
1070
1044 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) { 1071 TEST_F(ResourcePrefetchPredictorTest, DeleteUrls) {
1045 // Add some dummy entries to cache. 1072 // Add some dummy entries to cache.
1046 predictor_->url_table_cache_->insert( 1073 predictor_->url_table_cache_->insert(
1047 std::make_pair("http://www.google.com/page1.html", 1074 std::make_pair("http://www.google.com/page1.html",
1048 CreatePrefetchData("http://www.google.com/page1.html"))); 1075 CreatePrefetchData("http://www.google.com/page1.html")));
1049 predictor_->url_table_cache_->insert( 1076 predictor_->url_table_cache_->insert(
1050 std::make_pair("http://www.google.com/page2.html", 1077 std::make_pair("http://www.google.com/page2.html",
1051 CreatePrefetchData("http://www.google.com/page2.html"))); 1078 CreatePrefetchData("http://www.google.com/page2.html")));
1052 predictor_->url_table_cache_->insert(std::make_pair( 1079 predictor_->url_table_cache_->insert(std::make_pair(
1053 "http://www.yahoo.com/", CreatePrefetchData("http://www.yahoo.com/"))); 1080 "http://www.yahoo.com/", CreatePrefetchData("http://www.yahoo.com/")));
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 predictor_->host_table_cache_->insert( 1861 predictor_->host_table_cache_->insert(
1835 std::make_pair(google.primary_key(), google)); 1862 std::make_pair(google.primary_key(), google));
1836 1863
1837 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); 1864 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL);
1838 predictor_->StopPrefetching(GURL(main_frame_url)); 1865 predictor_->StopPrefetching(GURL(main_frame_url));
1839 histogram_tester_->ExpectTotalCount( 1866 histogram_tester_->ExpectTotalCount(
1840 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); 1867 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1);
1841 } 1868 }
1842 1869
1843 } // namespace predictors 1870 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698