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

Side by Side Diff: net/reporting/reporting_cache_unittest.cc

Issue 2900553004: Reporting: Add histograms. (Closed)
Patch Set: rebase Created 3 years, 5 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 | « net/reporting/reporting_cache.cc ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "net/reporting/reporting_cache.h" 5 #include "net/reporting/reporting_cache.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 cache()->IncrementReportsAttempts(reports); 102 cache()->IncrementReportsAttempts(reports);
103 EXPECT_EQ(2, observer()->cache_update_count()); 103 EXPECT_EQ(2, observer()->cache_update_count());
104 104
105 cache()->GetReports(&reports); 105 cache()->GetReports(&reports);
106 ASSERT_EQ(1u, reports.size()); 106 ASSERT_EQ(1u, reports.size());
107 report = reports[0]; 107 report = reports[0];
108 ASSERT_TRUE(report); 108 ASSERT_TRUE(report);
109 EXPECT_EQ(1, report->attempts); 109 EXPECT_EQ(1, report->attempts);
110 110
111 cache()->RemoveReports(reports); 111 cache()->RemoveReports(reports, ReportingReport::Outcome::UNKNOWN);
112 EXPECT_EQ(3, observer()->cache_update_count()); 112 EXPECT_EQ(3, observer()->cache_update_count());
113 113
114 cache()->GetReports(&reports); 114 cache()->GetReports(&reports);
115 EXPECT_TRUE(reports.empty()); 115 EXPECT_TRUE(reports.empty());
116 } 116 }
117 117
118 TEST_F(ReportingCacheTest, RemoveAllReports) { 118 TEST_F(ReportingCacheTest, RemoveAllReports) {
119 cache()->AddReport(kUrl1_, kGroup1_, kType_, 119 cache()->AddReport(kUrl1_, kGroup1_, kType_,
120 base::MakeUnique<base::DictionaryValue>(), kNow_, 0); 120 base::MakeUnique<base::DictionaryValue>(), kNow_, 0);
121 cache()->AddReport(kUrl1_, kGroup1_, kType_, 121 cache()->AddReport(kUrl1_, kGroup1_, kType_,
122 base::MakeUnique<base::DictionaryValue>(), kNow_, 0); 122 base::MakeUnique<base::DictionaryValue>(), kNow_, 0);
123 EXPECT_EQ(2, observer()->cache_update_count()); 123 EXPECT_EQ(2, observer()->cache_update_count());
124 124
125 std::vector<const ReportingReport*> reports; 125 std::vector<const ReportingReport*> reports;
126 cache()->GetReports(&reports); 126 cache()->GetReports(&reports);
127 EXPECT_EQ(2u, reports.size()); 127 EXPECT_EQ(2u, reports.size());
128 128
129 cache()->RemoveAllReports(); 129 cache()->RemoveAllReports(ReportingReport::Outcome::UNKNOWN);
130 EXPECT_EQ(3, observer()->cache_update_count()); 130 EXPECT_EQ(3, observer()->cache_update_count());
131 131
132 cache()->GetReports(&reports); 132 cache()->GetReports(&reports);
133 EXPECT_TRUE(reports.empty()); 133 EXPECT_TRUE(reports.empty());
134 } 134 }
135 135
136 TEST_F(ReportingCacheTest, RemovePendingReports) { 136 TEST_F(ReportingCacheTest, RemovePendingReports) {
137 cache()->AddReport(kUrl1_, kGroup1_, kType_, 137 cache()->AddReport(kUrl1_, kGroup1_, kType_,
138 base::MakeUnique<base::DictionaryValue>(), kNow_, 0); 138 base::MakeUnique<base::DictionaryValue>(), kNow_, 0);
139 EXPECT_EQ(1, observer()->cache_update_count()); 139 EXPECT_EQ(1, observer()->cache_update_count());
140 140
141 std::vector<const ReportingReport*> reports; 141 std::vector<const ReportingReport*> reports;
142 cache()->GetReports(&reports); 142 cache()->GetReports(&reports);
143 ASSERT_EQ(1u, reports.size()); 143 ASSERT_EQ(1u, reports.size());
144 EXPECT_FALSE(cache()->IsReportPendingForTesting(reports[0])); 144 EXPECT_FALSE(cache()->IsReportPendingForTesting(reports[0]));
145 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0])); 145 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0]));
146 146
147 cache()->SetReportsPending(reports); 147 cache()->SetReportsPending(reports);
148 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); 148 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0]));
149 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0])); 149 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0]));
150 150
151 cache()->RemoveReports(reports); 151 cache()->RemoveReports(reports, ReportingReport::Outcome::UNKNOWN);
152 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); 152 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0]));
153 EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0])); 153 EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0]));
154 EXPECT_EQ(2, observer()->cache_update_count()); 154 EXPECT_EQ(2, observer()->cache_update_count());
155 155
156 // After removing report, future calls to GetReports should not return it. 156 // After removing report, future calls to GetReports should not return it.
157 std::vector<const ReportingReport*> visible_reports; 157 std::vector<const ReportingReport*> visible_reports;
158 cache()->GetReports(&visible_reports); 158 cache()->GetReports(&visible_reports);
159 EXPECT_TRUE(visible_reports.empty()); 159 EXPECT_TRUE(visible_reports.empty());
160 EXPECT_EQ(1u, cache()->GetFullReportCountForTesting()); 160 EXPECT_EQ(1u, cache()->GetFullReportCountForTesting());
161 161
(...skipping 10 matching lines...) Expand all
172 std::vector<const ReportingReport*> reports; 172 std::vector<const ReportingReport*> reports;
173 cache()->GetReports(&reports); 173 cache()->GetReports(&reports);
174 ASSERT_EQ(1u, reports.size()); 174 ASSERT_EQ(1u, reports.size());
175 EXPECT_FALSE(cache()->IsReportPendingForTesting(reports[0])); 175 EXPECT_FALSE(cache()->IsReportPendingForTesting(reports[0]));
176 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0])); 176 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0]));
177 177
178 cache()->SetReportsPending(reports); 178 cache()->SetReportsPending(reports);
179 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); 179 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0]));
180 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0])); 180 EXPECT_FALSE(cache()->IsReportDoomedForTesting(reports[0]));
181 181
182 cache()->RemoveAllReports(); 182 cache()->RemoveAllReports(ReportingReport::Outcome::UNKNOWN);
183 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0])); 183 EXPECT_TRUE(cache()->IsReportPendingForTesting(reports[0]));
184 EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0])); 184 EXPECT_TRUE(cache()->IsReportDoomedForTesting(reports[0]));
185 EXPECT_EQ(2, observer()->cache_update_count()); 185 EXPECT_EQ(2, observer()->cache_update_count());
186 186
187 // After removing report, future calls to GetReports should not return it. 187 // After removing report, future calls to GetReports should not return it.
188 std::vector<const ReportingReport*> visible_reports; 188 std::vector<const ReportingReport*> visible_reports;
189 cache()->GetReports(&visible_reports); 189 cache()->GetReports(&visible_reports);
190 EXPECT_TRUE(visible_reports.empty()); 190 EXPECT_TRUE(visible_reports.empty());
191 EXPECT_EQ(1u, cache()->GetFullReportCountForTesting()); 191 EXPECT_EQ(1u, cache()->GetFullReportCountForTesting());
192 192
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 cache()->SetClient(kOrigin1_, MakeEndpoint(max_client_count), 533 cache()->SetClient(kOrigin1_, MakeEndpoint(max_client_count),
534 ReportingClient::Subdomains::EXCLUDE, kGroup1_, 534 ReportingClient::Subdomains::EXCLUDE, kGroup1_,
535 tomorrow()); 535 tomorrow());
536 EXPECT_EQ(max_client_count, client_count()); 536 EXPECT_EQ(max_client_count, client_count());
537 EXPECT_FALSE(FindClientInCache(cache(), kOrigin1_, 537 EXPECT_FALSE(FindClientInCache(cache(), kOrigin1_,
538 MakeEndpoint(max_client_count - 1))); 538 MakeEndpoint(max_client_count - 1)));
539 } 539 }
540 540
541 } // namespace 541 } // namespace
542 } // namespace net 542 } // namespace net
OLDNEW
« no previous file with comments | « net/reporting/reporting_cache.cc ('k') | net/reporting/reporting_delivery_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698