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

Side by Side Diff: chrome/browser/android/data_usage/external_data_use_reporter_unittest.cc

Issue 2145863002: Separate data use reporting logic in ExternalDataUseObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments, moved unittests Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/data_usage/external_data_use_observer.h" 5 #include "chrome/browser/android/data_usage/external_data_use_reporter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/metrics/field_trial.h" 15 #include "base/metrics/field_trial.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/test/histogram_tester.h" 19 #include "base/test/histogram_tester.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "chrome/browser/android/data_usage/data_use_tab_model.h" 21 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
22 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
tbansal1 2016/07/15 16:26:30 This include should not be necessary.
Raj 2016/07/15 18:54:41 I have removed most of the calls to EDUO. But EDUO
22 #include "components/data_usage/core/data_use.h" 23 #include "components/data_usage/core/data_use.h"
23 #include "components/data_usage/core/data_use_aggregator.h" 24 #include "components/data_usage/core/data_use_aggregator.h"
24 #include "components/data_usage/core/data_use_amortizer.h"
25 #include "components/data_usage/core/data_use_annotator.h"
26 #include "components/sessions/core/session_id.h" 25 #include "components/sessions/core/session_id.h"
27 #include "components/variations/variations_associated_data.h" 26 #include "components/variations/variations_associated_data.h"
28 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "net/base/network_change_notifier.h" 29 #include "net/base/network_change_notifier.h"
31 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
32 #include "url/gurl.h" 31 #include "url/gurl.h"
33 32
34 namespace { 33 namespace {
35 34
36 const char kUMAMatchingRuleFirstFetchDurationHistogram[] = 35 const char kUMAMatchingRuleFirstFetchDurationHistogram[] =
37 "DataUsage.Perf.MatchingRuleFirstFetchDuration"; 36 "DataUsage.Perf.MatchingRuleFirstFetchDuration";
38 const char kUMAReportSubmissionDurationHistogram[] = 37 const char kUMAReportSubmissionDurationHistogram[] =
39 "DataUsage.Perf.ReportSubmissionDuration"; 38 "DataUsage.Perf.ReportSubmissionDuration";
40 39
41 const char kDefaultLabel[] = "label"; 40 const char kDefaultLabel[] = "label";
42 const SessionID::id_type kDefaultTabId = 0; 41 const SessionID::id_type kDefaultTabId = 0;
43 const char kDefaultURL[] = "http://www.google.com/#q=abc"; 42 const char kDefaultURL[] = "http://www.google.com/#q=abc";
43
44 const char kFooMccMnc[] = "foo_mccmnc"; 44 const char kFooMccMnc[] = "foo_mccmnc";
45 const char kBarMccMnc[] = "bar_mccmnc"; 45 const char kBarMccMnc[] = "bar_mccmnc";
46 const char kBazMccMnc[] = "baz_mccmnc"; 46 const char kBazMccMnc[] = "baz_mccmnc";
47 const char kFooLabel[] = "foo_label"; 47 const char kFooLabel[] = "foo_label";
48 const char kBarLabel[] = "bar_label"; 48 const char kBarLabel[] = "bar_label";
49 49
50 } // namespace 50 } // namespace
51 51
52 namespace chrome { 52 namespace chrome {
53 53
54 namespace android { 54 namespace android {
55 55
56 class ExternalDataUseObserverTest : public testing::Test { 56 class ExternalDataUseReporterTest : public testing::Test {
57 public: 57 public:
58 void SetUp() override { 58 void SetUp() override {
59 thread_bundle_.reset(new content::TestBrowserThreadBundle( 59 thread_bundle_.reset(new content::TestBrowserThreadBundle(
60 content::TestBrowserThreadBundle::IO_MAINLOOP)); 60 content::TestBrowserThreadBundle::IO_MAINLOOP));
61 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( 61 io_task_runner_ = content::BrowserThread::GetTaskRunnerForThread(
62 content::BrowserThread::IO); 62 content::BrowserThread::IO);
63 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread( 63 ui_task_runner_ = content::BrowserThread::GetTaskRunnerForThread(
64 content::BrowserThread::UI); 64 content::BrowserThread::UI);
65 data_use_aggregator_.reset( 65 data_use_aggregator_.reset(
66 new data_usage::DataUseAggregator(nullptr, nullptr)); 66 new data_usage::DataUseAggregator(nullptr, nullptr));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 void OnDataUse(const data_usage::DataUse& data_use) { 130 void OnDataUse(const data_usage::DataUse& data_use) {
131 external_data_use_observer_->OnDataUse(data_use); 131 external_data_use_observer_->OnDataUse(data_use);
132 base::RunLoop().RunUntilIdle(); 132 base::RunLoop().RunUntilIdle();
133 } 133 }
134 134
135 ExternalDataUseObserver* external_data_use_observer() const { 135 ExternalDataUseObserver* external_data_use_observer() const {
136 return external_data_use_observer_.get(); 136 return external_data_use_observer_.get();
137 } 137 }
138 138
139 const ExternalDataUseObserver::DataUseReports& buffered_data_reports() const { 139 ExternalDataUseReporter* external_data_use_reporter() const {
140 return external_data_use_observer_->buffered_data_reports_; 140 return external_data_use_observer_->external_data_use_reporter_;
141 }
142
143 const ExternalDataUseReporter::DataUseReports& buffered_data_reports() const {
144 return external_data_use_reporter()->buffered_data_reports_;
141 } 145 }
142 146
143 int64_t default_upload_bytes() const { return 1; } 147 int64_t default_upload_bytes() const { return 1; }
144 148
145 int64_t default_download_bytes() const { 149 int64_t default_download_bytes() const {
146 return external_data_use_observer_->data_use_report_min_bytes_; 150 return external_data_use_reporter()->data_use_report_min_bytes_;
147 } 151 }
148 152
149 private: 153 private:
150 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_; 154 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_;
151 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_; 155 std::unique_ptr<data_usage::DataUseAggregator> data_use_aggregator_;
152 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_; 156 std::unique_ptr<ExternalDataUseObserver> external_data_use_observer_;
153 157
154 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 158 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
155 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; 159 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
156 }; 160 };
157 161
158 // Verifies that the external data use observer is registered as an observer
159 // only when at least one matching rule is present.
160 TEST_F(ExternalDataUseObserverTest, RegisteredAsDataUseObserver) {
161 EXPECT_FALSE(external_data_use_observer()->registered_as_data_use_observer_);
162
163 AddDefaultMatchingRule();
164 EXPECT_TRUE(external_data_use_observer()->registered_as_data_use_observer_);
165
166 // Push an empty vector. Since no matching rules are present,
167 // |external_data_use_observer| should no longer be registered as a data use
168 // observer.
169 FetchMatchingRulesDone(std::vector<std::string>(), std::vector<std::string>(),
170 std::vector<std::string>());
171 base::RunLoop().RunUntilIdle();
172 EXPECT_FALSE(external_data_use_observer()->registered_as_data_use_observer_);
173 }
174
175 // Verifies that buffer size does not exceed the specified limit. 162 // Verifies that buffer size does not exceed the specified limit.
176 TEST_F(ExternalDataUseObserverTest, BufferSize) { 163 TEST_F(ExternalDataUseReporterTest, BufferSize) {
177 base::HistogramTester histogram_tester; 164 base::HistogramTester histogram_tester;
178 165
179 AddDefaultMatchingRule(); 166 AddDefaultMatchingRule();
180 TriggerTabTrackingOnDefaultTab(); 167 TriggerTabTrackingOnDefaultTab();
181 168
182 // Push more entries than the buffer size. Buffer size should not be exceeded. 169 // Push more entries than the buffer size. Buffer size should not be exceeded.
183 for (size_t i = 0; i < ExternalDataUseObserver::kMaxBufferSize * 2; ++i) { 170 for (size_t i = 0; i < ExternalDataUseReporter::kMaxBufferSize * 2; ++i) {
184 data_usage::DataUse data_use = default_data_use(); 171 data_usage::DataUse data_use = default_data_use();
185 data_use.mcc_mnc = "mccmnc" + base::Int64ToString(i); 172 data_use.mcc_mnc = "mccmnc" + base::Int64ToString(i);
186 OnDataUse(data_use); 173 OnDataUse(data_use);
187 } 174 }
188 175
189 EXPECT_LE(0, external_data_use_observer()->total_bytes_buffered_); 176 EXPECT_LE(0, external_data_use_reporter()->total_bytes_buffered_);
190 177
191 // Verify that total buffered bytes is computed correctly. 178 // Verify that total buffered bytes is computed correctly.
192 EXPECT_EQ( 179 EXPECT_EQ(
193 static_cast<int64_t>(ExternalDataUseObserver::kMaxBufferSize * 180 static_cast<int64_t>(ExternalDataUseReporter::kMaxBufferSize *
194 (default_upload_bytes() + default_download_bytes())), 181 (default_upload_bytes() + default_download_bytes())),
195 external_data_use_observer()->total_bytes_buffered_); 182 external_data_use_reporter()->total_bytes_buffered_);
196 EXPECT_EQ(ExternalDataUseObserver::kMaxBufferSize, 183 EXPECT_EQ(ExternalDataUseReporter::kMaxBufferSize,
197 buffered_data_reports().size()); 184 buffered_data_reports().size());
198 185
199 // Verify the label of the data use report. 186 // Verify the label of the data use report.
200 for (const auto& it : buffered_data_reports()) 187 for (const auto& it : buffered_data_reports())
201 EXPECT_EQ(kDefaultLabel, it.first.label); 188 EXPECT_EQ(kDefaultLabel, it.first.label);
202 189
203 // Verify that metrics were updated correctly for the lost reports. 190 // Verify that metrics were updated correctly for the lost reports.
204 histogram_tester.ExpectUniqueSample( 191 histogram_tester.ExpectUniqueSample(
205 "DataUsage.ReportSubmissionResult", 192 "DataUsage.ReportSubmissionResult",
206 ExternalDataUseObserver::DATAUSAGE_REPORT_SUBMISSION_LOST, 193 ExternalDataUseReporter::DATAUSAGE_REPORT_SUBMISSION_LOST,
207 ExternalDataUseObserver::kMaxBufferSize - 1); 194 ExternalDataUseReporter::kMaxBufferSize - 1);
208 histogram_tester.ExpectUniqueSample( 195 histogram_tester.ExpectUniqueSample(
209 "DataUsage.ReportSubmission.Bytes.Lost", 196 "DataUsage.ReportSubmission.Bytes.Lost",
210 default_upload_bytes() + default_download_bytes(), 197 default_upload_bytes() + default_download_bytes(),
211 ExternalDataUseObserver::kMaxBufferSize - 1); 198 ExternalDataUseReporter::kMaxBufferSize - 1);
212 } 199 }
213 200
214 // Tests that buffered data use reports are merged correctly. 201 // Tests that buffered data use reports are merged correctly.
215 TEST_F(ExternalDataUseObserverTest, ReportsMergedCorrectly) { 202 TEST_F(ExternalDataUseReporterTest, ReportsMergedCorrectly) {
216 AddDefaultMatchingRule(); 203 AddDefaultMatchingRule();
217 TriggerTabTrackingOnDefaultTab(); 204 TriggerTabTrackingOnDefaultTab();
218 205
219 const size_t num_iterations = ExternalDataUseObserver::kMaxBufferSize * 2; 206 const size_t num_iterations = ExternalDataUseReporter::kMaxBufferSize * 2;
220 207
221 for (size_t i = 0; i < num_iterations; ++i) { 208 for (size_t i = 0; i < num_iterations; ++i) {
222 data_usage::DataUse data_use_foo = default_data_use(); 209 data_usage::DataUse data_use_foo = default_data_use();
223 data_use_foo.mcc_mnc = kFooMccMnc; 210 data_use_foo.mcc_mnc = kFooMccMnc;
224 OnDataUse(data_use_foo); 211 OnDataUse(data_use_foo);
225 212
226 data_usage::DataUse data_use_bar = default_data_use(); 213 data_usage::DataUse data_use_bar = default_data_use();
227 data_use_bar.mcc_mnc = kBarMccMnc; 214 data_use_bar.mcc_mnc = kBarMccMnc;
228 OnDataUse(data_use_bar); 215 OnDataUse(data_use_bar);
229 216
230 data_usage::DataUse data_use_baz = default_data_use(); 217 data_usage::DataUse data_use_baz = default_data_use();
231 data_use_baz.mcc_mnc = kBazMccMnc; 218 data_use_baz.mcc_mnc = kBazMccMnc;
232 OnDataUse(data_use_baz); 219 OnDataUse(data_use_baz);
233 } 220 }
234 221
235 ASSERT_EQ(3U, buffered_data_reports().size()); 222 ASSERT_EQ(3U, buffered_data_reports().size());
236 223
237 // One of the foo reports should have been submitted, and all the other foo 224 // One of the foo reports should have been submitted, and all the other foo
238 // reports should have been merged together. All of the bar and baz reports 225 // reports should have been merged together. All of the bar and baz reports
239 // should have been merged together respectively. 226 // should have been merged together respectively.
240 const struct { 227 const struct {
241 std::string mcc_mnc; 228 std::string mcc_mnc;
242 size_t number_of_merged_reports; 229 size_t number_of_merged_reports;
243 } expected_data_use_reports[] = {{kFooMccMnc, num_iterations - 1}, 230 } expected_data_use_reports[] = {{kFooMccMnc, num_iterations - 1},
244 {kBarMccMnc, num_iterations}, 231 {kBarMccMnc, num_iterations},
245 {kBazMccMnc, num_iterations}}; 232 {kBazMccMnc, num_iterations}};
246 233
247 for (const auto& expected_report : expected_data_use_reports) { 234 for (const auto& expected_report : expected_data_use_reports) {
248 const ExternalDataUseObserver::DataUseReportKey key( 235 const ExternalDataUseReporter::DataUseReportKey key(
249 kDefaultLabel, DataUseTabModel::kDefaultTag, 236 kDefaultLabel, DataUseTabModel::kDefaultTag,
250 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, 237 net::NetworkChangeNotifier::CONNECTION_UNKNOWN,
251 expected_report.mcc_mnc); 238 expected_report.mcc_mnc);
252 239
253 EXPECT_NE(buffered_data_reports().end(), buffered_data_reports().find(key)); 240 EXPECT_NE(buffered_data_reports().end(), buffered_data_reports().find(key));
254 EXPECT_EQ(static_cast<int64_t>(expected_report.number_of_merged_reports) * 241 EXPECT_EQ(static_cast<int64_t>(expected_report.number_of_merged_reports) *
255 (default_download_bytes()), 242 (default_download_bytes()),
256 buffered_data_reports().find(key)->second.bytes_downloaded); 243 buffered_data_reports().find(key)->second.bytes_downloaded);
257 EXPECT_EQ(static_cast<int64_t>(expected_report.number_of_merged_reports * 244 EXPECT_EQ(static_cast<int64_t>(expected_report.number_of_merged_reports *
258 (default_upload_bytes())), 245 (default_upload_bytes())),
259 buffered_data_reports().find(key)->second.bytes_uploaded); 246 buffered_data_reports().find(key)->second.bytes_uploaded);
260 } 247 }
261 } 248 }
262 249
263 // Tests that timestamps of merged reports is correct. 250 // Tests that timestamps of merged reports is correct.
264 TEST_F(ExternalDataUseObserverTest, TimestampsMergedCorrectly) { 251 TEST_F(ExternalDataUseReporterTest, TimestampsMergedCorrectly) {
265 AddDefaultMatchingRule(); 252 AddDefaultMatchingRule();
266 253
267 const size_t num_iterations = ExternalDataUseObserver::kMaxBufferSize * 2; 254 const size_t num_iterations = ExternalDataUseReporter::kMaxBufferSize * 2;
268 255
269 base::Time start_timestamp = base::Time::UnixEpoch(); 256 base::Time start_timestamp = base::Time::UnixEpoch();
270 base::Time end_timestamp = start_timestamp + base::TimeDelta::FromSeconds(1); 257 base::Time end_timestamp = start_timestamp + base::TimeDelta::FromSeconds(1);
271 for (size_t i = 0; i < num_iterations; ++i) { 258 for (size_t i = 0; i < num_iterations; ++i) {
272 external_data_use_observer()->BufferDataUseReport( 259 external_data_use_reporter()->BufferDataUseReport(
273 default_data_use(), kDefaultLabel, DataUseTabModel::kDefaultTag, 260 default_data_use(), kDefaultLabel, DataUseTabModel::kDefaultTag,
274 start_timestamp, end_timestamp); 261 start_timestamp, end_timestamp);
275 262
276 start_timestamp += base::TimeDelta::FromSeconds(1); 263 start_timestamp += base::TimeDelta::FromSeconds(1);
277 end_timestamp += base::TimeDelta::FromSeconds(1); 264 end_timestamp += base::TimeDelta::FromSeconds(1);
278 } 265 }
279 266
280 EXPECT_EQ(1U, buffered_data_reports().size()); 267 EXPECT_EQ(1U, buffered_data_reports().size());
281 EXPECT_EQ(0, buffered_data_reports().begin()->second.start_time.ToJavaTime()); 268 EXPECT_EQ(0, buffered_data_reports().begin()->second.start_time.ToJavaTime());
282 // Convert from seconds to milliseconds. 269 // Convert from seconds to milliseconds.
283 EXPECT_EQ(static_cast<int64_t>(num_iterations * 1000), 270 EXPECT_EQ(static_cast<int64_t>(num_iterations * 1000),
284 buffered_data_reports().begin()->second.end_time.ToJavaTime()); 271 buffered_data_reports().begin()->second.end_time.ToJavaTime());
285 } 272 }
286 273
287 // Tests the behavior when multiple matching rules are available for URL and 274 // Tests the behavior when multiple matching rules are available for URL and
288 // package name matching. 275 // package name matching.
289 TEST_F(ExternalDataUseObserverTest, MultipleMatchingRules) { 276 TEST_F(ExternalDataUseReporterTest, MultipleMatchingRules) {
290 std::vector<std::string> url_regexes; 277 std::vector<std::string> url_regexes;
291 url_regexes.push_back( 278 url_regexes.push_back(
292 "http://www[.]foo[.]com/#q=.*|https://www[.]foo[.]com/#q=.*"); 279 "http://www[.]foo[.]com/#q=.*|https://www[.]foo[.]com/#q=.*");
293 url_regexes.push_back( 280 url_regexes.push_back(
294 "http://www[.]bar[.]com/#q=.*|https://www[.]bar[.]com/#q=.*"); 281 "http://www[.]bar[.]com/#q=.*|https://www[.]bar[.]com/#q=.*");
295 282
296 std::vector<std::string> labels; 283 std::vector<std::string> labels;
297 labels.push_back(kFooLabel); 284 labels.push_back(kFooLabel);
298 labels.push_back(kBarLabel); 285 labels.push_back(kBarLabel);
299 286
300 std::vector<std::string> app_package_names; 287 std::vector<std::string> app_package_names;
301 const char kAppFoo[] = "com.example.foo"; 288 const char kAppFoo[] = "com.example.foo";
302 const char kAppBar[] = "com.example.bar"; 289 const char kAppBar[] = "com.example.bar";
303 app_package_names.push_back(kAppFoo); 290 app_package_names.push_back(kAppFoo);
304 app_package_names.push_back(kAppBar); 291 app_package_names.push_back(kAppBar);
305 292
306 FetchMatchingRulesDone(app_package_names, url_regexes, labels); 293 FetchMatchingRulesDone(app_package_names, url_regexes, labels);
307 294
308 external_data_use_observer()->GetDataUseTabModel()->OnNavigationEvent( 295 external_data_use_observer()->GetDataUseTabModel()->OnNavigationEvent(
tbansal1 2016/07/15 16:26:30 Is it possible to call DataUseTabModel directly fr
Raj 2016/07/15 18:54:41 Done.
309 kDefaultTabId, DataUseTabModel::TRANSITION_OMNIBOX_SEARCH, 296 kDefaultTabId, DataUseTabModel::TRANSITION_OMNIBOX_SEARCH,
310 GURL("http://www.foo.com/#q=abc"), std::string(), nullptr); 297 GURL("http://www.foo.com/#q=abc"), std::string(), nullptr);
311 298
312 external_data_use_observer()->GetDataUseTabModel()->OnNavigationEvent( 299 external_data_use_observer()->GetDataUseTabModel()->OnNavigationEvent(
313 kDefaultTabId + 1, DataUseTabModel::TRANSITION_OMNIBOX_SEARCH, 300 kDefaultTabId + 1, DataUseTabModel::TRANSITION_OMNIBOX_SEARCH,
314 GURL("http://www.bar.com/#q=abc"), std::string(), nullptr); 301 GURL("http://www.bar.com/#q=abc"), std::string(), nullptr);
315 302
316 EXPECT_EQ(0U, external_data_use_observer()->buffered_data_reports_.size()); 303 EXPECT_EQ(0U, external_data_use_reporter()->buffered_data_reports_.size());
317 EXPECT_TRUE(external_data_use_observer() 304 EXPECT_TRUE(external_data_use_reporter()
318 ->last_data_report_submitted_ticks_.is_null()); 305 ->last_data_report_submitted_ticks_.is_null());
319 306
320 // Check |kLabelFoo| matching rule. 307 // Check |kLabelFoo| matching rule.
321 data_usage::DataUse data_foo = default_data_use(); 308 data_usage::DataUse data_foo = default_data_use();
322 data_foo.url = GURL("http://www.foo.com/#q=abc"); 309 data_foo.url = GURL("http://www.foo.com/#q=abc");
323 data_foo.mcc_mnc = kFooMccMnc; 310 data_foo.mcc_mnc = kFooMccMnc;
324 OnDataUse(data_foo); 311 OnDataUse(data_foo);
325 312
326 // Check |kLabelBar| matching rule. 313 // Check |kLabelBar| matching rule.
327 data_usage::DataUse data_bar = default_data_use(); 314 data_usage::DataUse data_bar = default_data_use();
328 data_bar.tab_id = kDefaultTabId + 1; 315 data_bar.tab_id = kDefaultTabId + 1;
329 data_bar.url = GURL("http://www.bar.com/#q=abc"); 316 data_bar.url = GURL("http://www.bar.com/#q=abc");
330 data_bar.mcc_mnc = kBarMccMnc; 317 data_bar.mcc_mnc = kBarMccMnc;
331 OnDataUse(data_bar); 318 OnDataUse(data_bar);
332 319
333 // bar report should be present. 320 // bar report should be present.
334 EXPECT_EQ(1U, buffered_data_reports().size()); 321 EXPECT_EQ(1U, buffered_data_reports().size());
335 322
336 const ExternalDataUseObserver::DataUseReportKey key_bar( 323 const ExternalDataUseReporter::DataUseReportKey key_bar(
337 kBarLabel, DataUseTabModel::kDefaultTag, 324 kBarLabel, DataUseTabModel::kDefaultTag,
338 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kBarMccMnc); 325 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kBarMccMnc);
339 EXPECT_NE(buffered_data_reports().end(), 326 EXPECT_NE(buffered_data_reports().end(),
340 buffered_data_reports().find(key_bar)); 327 buffered_data_reports().find(key_bar));
341 } 328 }
342 329
343 // Tests that hash function reports distinct values. This test may fail if there 330 // Tests that hash function reports distinct values. This test may fail if there
344 // is a hash collision, however the chances of that happening are very low. 331 // is a hash collision, however the chances of that happening are very low.
345 TEST_F(ExternalDataUseObserverTest, HashFunction) { 332 TEST_F(ExternalDataUseReporterTest, HashFunction) {
346 ExternalDataUseObserver::DataUseReportKeyHash hash; 333 ExternalDataUseReporter::DataUseReportKeyHash hash;
347 334
348 ExternalDataUseObserver::DataUseReportKey foo( 335 ExternalDataUseReporter::DataUseReportKey foo(
349 kFooLabel, DataUseTabModel::kDefaultTag, 336 kFooLabel, DataUseTabModel::kDefaultTag,
350 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc); 337 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc);
351 ExternalDataUseObserver::DataUseReportKey bar_label( 338 ExternalDataUseReporter::DataUseReportKey bar_label(
352 kBarLabel, DataUseTabModel::kDefaultTag, 339 kBarLabel, DataUseTabModel::kDefaultTag,
353 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc); 340 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc);
354 ExternalDataUseObserver::DataUseReportKey bar_custom_tab_tag( 341 ExternalDataUseReporter::DataUseReportKey bar_custom_tab_tag(
355 kBarLabel, DataUseTabModel::kCustomTabTag, 342 kBarLabel, DataUseTabModel::kCustomTabTag,
356 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc); 343 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kFooMccMnc);
357 ExternalDataUseObserver::DataUseReportKey bar_network_type( 344 ExternalDataUseReporter::DataUseReportKey bar_network_type(
358 kFooLabel, DataUseTabModel::kDefaultTag, 345 kFooLabel, DataUseTabModel::kDefaultTag,
359 net::NetworkChangeNotifier::CONNECTION_WIFI, kFooMccMnc); 346 net::NetworkChangeNotifier::CONNECTION_WIFI, kFooMccMnc);
360 ExternalDataUseObserver::DataUseReportKey bar_mcc_mnc( 347 ExternalDataUseReporter::DataUseReportKey bar_mcc_mnc(
361 kFooLabel, DataUseTabModel::kDefaultTag, 348 kFooLabel, DataUseTabModel::kDefaultTag,
362 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kBarMccMnc); 349 net::NetworkChangeNotifier::CONNECTION_UNKNOWN, kBarMccMnc);
363 350
364 EXPECT_NE(hash(foo), hash(bar_label)); 351 EXPECT_NE(hash(foo), hash(bar_label));
365 EXPECT_NE(hash(foo), hash(bar_custom_tab_tag)); 352 EXPECT_NE(hash(foo), hash(bar_custom_tab_tag));
366 EXPECT_NE(hash(foo), hash(bar_network_type)); 353 EXPECT_NE(hash(foo), hash(bar_network_type));
367 EXPECT_NE(hash(foo), hash(bar_mcc_mnc)); 354 EXPECT_NE(hash(foo), hash(bar_mcc_mnc));
368 } 355 }
369 356
370 // Tests if matching rules are fetched periodically.
371 TEST_F(ExternalDataUseObserverTest, PeriodicFetchMatchingRules) {
372 AddDefaultMatchingRule();
373
374 EXPECT_FALSE(
375 external_data_use_observer()->last_matching_rules_fetch_time_.is_null());
376
377 // Change the time when the fetching rules were fetched.
378 external_data_use_observer()->last_matching_rules_fetch_time_ =
379 base::TimeTicks::Now() -
380 external_data_use_observer()->fetch_matching_rules_duration_;
381 // Matching rules should be expired.
382 EXPECT_GE(base::TimeTicks::Now() -
383 external_data_use_observer()->last_matching_rules_fetch_time_,
384 external_data_use_observer()->fetch_matching_rules_duration_);
385
386 // OnDataUse should trigger fetching of matching rules.
387 OnDataUse(default_data_use());
388
389 // Matching rules should not be expired.
390 EXPECT_LT(base::TimeTicks::Now() -
391 external_data_use_observer()->last_matching_rules_fetch_time_,
392 external_data_use_observer()->fetch_matching_rules_duration_);
393 }
394
395 // Tests the matching rule fetch behavior when the external control app is
396 // installed and not installed. Matching rules should be fetched when control
397 // app gets installed. If control app is installed and no valid rules are found,
398 // matching rules are fetched on every navigation. Rules are not fetched if
399 // control app is not installed or if more than zero valid rules have been
400 // fetched.
401 TEST_F(ExternalDataUseObserverTest, MatchingRuleFetchOnControlAppInstall) {
402 {
403 // Matching rules not fetched on navigation if control app is not installed,
404 // and navigation events will be buffered.
405 external_data_use_observer()->last_matching_rules_fetch_time_ =
406 base::TimeTicks();
407 external_data_use_observer()
408 ->data_use_tab_model_->is_control_app_installed_ = false;
409 base::HistogramTester histogram_tester;
410 external_data_use_observer()->data_use_tab_model_->OnNavigationEvent(
411 kDefaultTabId, DataUseTabModel::TRANSITION_LINK, GURL(kDefaultURL),
412 std::string(), nullptr);
413 base::RunLoop().RunUntilIdle();
414 histogram_tester.ExpectTotalCount("DataUsage.MatchingRulesCount.Valid", 0);
415 }
416
417 {
418 // Matching rules are fetched when control app is installed.
419 base::HistogramTester histogram_tester;
420 external_data_use_observer()
421 ->data_use_tab_model_->OnControlAppInstallStateChange(true);
422 base::RunLoop().RunUntilIdle();
423 histogram_tester.ExpectTotalCount("DataUsage.MatchingRulesCount.Valid", 1);
424 }
425
426 {
427 // Matching rules fetched on every navigation if control app is installed
428 // and zero rules are available.
429 external_data_use_observer()->last_matching_rules_fetch_time_ =
430 base::TimeTicks();
431 base::HistogramTester histogram_tester;
432 external_data_use_observer()->data_use_tab_model_->OnNavigationEvent(
433 kDefaultTabId, DataUseTabModel::TRANSITION_LINK, GURL(kDefaultURL),
434 std::string(), nullptr);
435 base::RunLoop().RunUntilIdle();
436 histogram_tester.ExpectTotalCount("DataUsage.MatchingRulesCount.Valid", 1);
437 }
438
439 {
440 // Matching rules not fetched on navigation if control app is installed and
441 // more than zero rules are available.
442 AddDefaultMatchingRule();
443 external_data_use_observer()->last_matching_rules_fetch_time_ =
444 base::TimeTicks();
445 EXPECT_TRUE(external_data_use_observer()
446 ->last_matching_rules_fetch_time_.is_null());
447 base::HistogramTester histogram_tester;
448 external_data_use_observer()->data_use_tab_model_->OnNavigationEvent(
449 kDefaultTabId, DataUseTabModel::TRANSITION_LINK, GURL(kDefaultURL),
450 std::string(), nullptr);
451 base::RunLoop().RunUntilIdle();
452 histogram_tester.ExpectTotalCount("DataUsage.MatchingRulesCount.Valid", 0);
453 }
454 }
455
456 // Tests if data use reports are sent only after the total bytes sent/received 357 // Tests if data use reports are sent only after the total bytes sent/received
457 // across all buffered reports have reached the specified threshold. 358 // across all buffered reports have reached the specified threshold.
458 TEST_F(ExternalDataUseObserverTest, BufferDataUseReports) { 359 TEST_F(ExternalDataUseReporterTest, BufferDataUseReports) {
459 AddDefaultMatchingRule(); 360 AddDefaultMatchingRule();
460 TriggerTabTrackingOnDefaultTab(); 361 TriggerTabTrackingOnDefaultTab();
461 362
462 // This tests reports 1024 bytes in each loop iteration. For the test to work 363 // This tests reports 1024 bytes in each loop iteration. For the test to work
463 // properly, |data_use_report_min_bytes_| should be a multiple of 1024. 364 // properly, |data_use_report_min_bytes_| should be a multiple of 1024.
464 ASSERT_EQ(0, external_data_use_observer()->data_use_report_min_bytes_ % 1024); 365 ASSERT_EQ(0, external_data_use_reporter()->data_use_report_min_bytes_ % 1024);
465 366
466 const size_t num_iterations = 367 const size_t num_iterations =
467 external_data_use_observer()->data_use_report_min_bytes_ / 1024; 368 external_data_use_reporter()->data_use_report_min_bytes_ / 1024;
468 369
469 for (size_t i = 0; i < num_iterations; ++i) { 370 for (size_t i = 0; i < num_iterations; ++i) {
470 data_usage::DataUse data_use = default_data_use(); 371 data_usage::DataUse data_use = default_data_use();
471 data_use.tx_bytes = 1024; 372 data_use.tx_bytes = 1024;
472 data_use.rx_bytes = 0; 373 data_use.rx_bytes = 0;
473 OnDataUse(data_use); 374 OnDataUse(data_use);
474 375
475 if (i != num_iterations - 1) { 376 if (i != num_iterations - 1) {
476 // Total buffered bytes is less than the minimum threshold. Data use 377 // Total buffered bytes is less than the minimum threshold. Data use
477 // report should not be sent. 378 // report should not be sent.
478 EXPECT_TRUE(external_data_use_observer() 379 EXPECT_TRUE(external_data_use_reporter()
479 ->last_data_report_submitted_ticks_.is_null()); 380 ->last_data_report_submitted_ticks_.is_null());
480 EXPECT_EQ(static_cast<int64_t>(i + 1), 381 EXPECT_EQ(static_cast<int64_t>(i + 1),
481 external_data_use_observer()->total_bytes_buffered_ / 1024); 382 external_data_use_reporter()->total_bytes_buffered_ / 1024);
482 EXPECT_EQ(0, external_data_use_observer()->pending_report_bytes_); 383 EXPECT_EQ(0, external_data_use_reporter()->pending_report_bytes_);
483 384
484 } else { 385 } else {
485 // Total bytes is at least the minimum threshold. This should trigger 386 // Total bytes is at least the minimum threshold. This should trigger
486 // submitting of the buffered data use report. 387 // submitting of the buffered data use report.
487 EXPECT_FALSE(external_data_use_observer() 388 EXPECT_FALSE(external_data_use_reporter()
488 ->last_data_report_submitted_ticks_.is_null()); 389 ->last_data_report_submitted_ticks_.is_null());
489 EXPECT_EQ(0, external_data_use_observer()->total_bytes_buffered_); 390 EXPECT_EQ(0, external_data_use_reporter()->total_bytes_buffered_);
490 } 391 }
491 } 392 }
492 EXPECT_EQ(0, external_data_use_observer()->total_bytes_buffered_); 393 EXPECT_EQ(0, external_data_use_reporter()->total_bytes_buffered_);
493 EXPECT_EQ(static_cast<int64_t>(num_iterations), 394 EXPECT_EQ(static_cast<int64_t>(num_iterations),
494 external_data_use_observer()->pending_report_bytes_ / 1024); 395 external_data_use_reporter()->pending_report_bytes_ / 1024);
495 396
496 base::HistogramTester histogram_tester; 397 base::HistogramTester histogram_tester;
398 base::RunLoop().RunUntilIdle();
tbansal1 2016/07/15 16:26:30 Why is RunLoop needed? IIUC, EDUR and all its depe
Raj 2016/07/15 18:54:41 Done.
497 external_data_use_observer()->OnReportDataUseDone(true); 399 external_data_use_observer()->OnReportDataUseDone(true);
tbansal1 2016/07/15 16:26:30 s//reporter->OnReportDataUseDone(...);/
Raj 2016/07/15 18:54:41 Done.
400 base::RunLoop().RunUntilIdle();
498 401
499 // Verify that metrics were updated correctly for the report that was 402 // Verify that metrics were updated correctly for the report that was
500 // successfully submitted. 403 // successfully submitted.
501 histogram_tester.ExpectUniqueSample( 404 histogram_tester.ExpectUniqueSample(
502 "DataUsage.ReportSubmissionResult", 405 "DataUsage.ReportSubmissionResult",
503 ExternalDataUseObserver::DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL, 1); 406 ExternalDataUseReporter::DATAUSAGE_REPORT_SUBMISSION_SUCCESSFUL, 1);
504 histogram_tester.ExpectUniqueSample( 407 histogram_tester.ExpectUniqueSample(
505 "DataUsage.ReportSubmission.Bytes.Successful", 408 "DataUsage.ReportSubmission.Bytes.Successful",
506 external_data_use_observer()->data_use_report_min_bytes_, 1); 409 external_data_use_reporter()->data_use_report_min_bytes_, 1);
507 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1); 410 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1);
508 411
509 // Verify that metrics were updated correctly for the report that was not 412 // Verify that metrics were updated correctly for the report that was not
510 // successfully submitted. 413 // successfully submitted.
511 OnDataUse(default_data_use()); 414 OnDataUse(default_data_use());
512 external_data_use_observer()->OnReportDataUseDone(false); 415 external_data_use_observer()->OnReportDataUseDone(false);
416 base::RunLoop().RunUntilIdle();
513 histogram_tester.ExpectTotalCount("DataUsage.ReportSubmissionResult", 2); 417 histogram_tester.ExpectTotalCount("DataUsage.ReportSubmissionResult", 2);
514 histogram_tester.ExpectBucketCount( 418 histogram_tester.ExpectBucketCount(
515 "DataUsage.ReportSubmissionResult", 419 "DataUsage.ReportSubmissionResult",
516 ExternalDataUseObserver::DATAUSAGE_REPORT_SUBMISSION_FAILED, 1); 420 ExternalDataUseReporter::DATAUSAGE_REPORT_SUBMISSION_FAILED, 1);
517 histogram_tester.ExpectUniqueSample( 421 histogram_tester.ExpectUniqueSample(
518 "DataUsage.ReportSubmission.Bytes.Failed", 422 "DataUsage.ReportSubmission.Bytes.Failed",
519 external_data_use_observer()->data_use_report_min_bytes_, 1); 423 external_data_use_reporter()->data_use_report_min_bytes_, 1);
520 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 2); 424 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 2);
521 } 425 }
522 426
523 #if defined(OS_ANDROID) 427 #if defined(OS_ANDROID)
524 // Tests data use report submission when application status callback is called. 428 // Tests data use report submission when application status callback is called.
525 // Report should be submitted even if the number of bytes is less than the 429 // Report should be submitted even if the number of bytes is less than the
526 // threshold. Report should not be submitted if there is a pending report. 430 // threshold. Report should not be submitted if there is a pending report.
527 TEST_F(ExternalDataUseObserverTest, DataUseReportingOnApplicationStatusChange) { 431 TEST_F(ExternalDataUseReporterTest, DataUseReportingOnApplicationStatusChange) {
528 base::HistogramTester histogram_tester; 432 base::HistogramTester histogram_tester;
529 AddDefaultMatchingRule(); 433 AddDefaultMatchingRule();
530 TriggerTabTrackingOnDefaultTab(); 434 TriggerTabTrackingOnDefaultTab();
531 435
532 // Report with less than threshold bytes should be reported, on application 436 // Report with less than threshold bytes should be reported, on application
533 // state change to background. 437 // state change to background.
534 data_usage::DataUse data_use = default_data_use(); 438 data_usage::DataUse data_use = default_data_use();
535 data_use.tx_bytes = 1; 439 data_use.tx_bytes = 1;
536 data_use.rx_bytes = 1; 440 data_use.rx_bytes = 1;
537 OnDataUse(data_use); 441 OnDataUse(data_use);
538 EXPECT_TRUE(external_data_use_observer() 442 EXPECT_TRUE(external_data_use_reporter()
539 ->last_data_report_submitted_ticks_.is_null()); 443 ->last_data_report_submitted_ticks_.is_null());
540 EXPECT_EQ(2, external_data_use_observer()->total_bytes_buffered_); 444 EXPECT_EQ(2, external_data_use_reporter()->total_bytes_buffered_);
541 EXPECT_EQ(0, external_data_use_observer()->pending_report_bytes_); 445 EXPECT_EQ(0, external_data_use_reporter()->pending_report_bytes_);
542 446
543 external_data_use_observer()->OnApplicationStateChange( 447 external_data_use_reporter()->OnApplicationStateChange(
544 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES); 448 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES);
545 EXPECT_FALSE(external_data_use_observer() 449 EXPECT_FALSE(external_data_use_reporter()
546 ->last_data_report_submitted_ticks_.is_null()); 450 ->last_data_report_submitted_ticks_.is_null());
547 EXPECT_EQ(0, external_data_use_observer()->total_bytes_buffered_); 451 EXPECT_EQ(0, external_data_use_reporter()->total_bytes_buffered_);
548 EXPECT_EQ(2, external_data_use_observer()->pending_report_bytes_); 452 EXPECT_EQ(2, external_data_use_reporter()->pending_report_bytes_);
549 external_data_use_observer()->OnReportDataUseDone(true); 453 external_data_use_observer()->OnReportDataUseDone(true);
454 base::RunLoop().RunUntilIdle();
550 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1); 455 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1);
551 456
552 // Create pending report. 457 // Create pending report.
553 OnDataUse(default_data_use()); 458 OnDataUse(default_data_use());
554 EXPECT_FALSE(external_data_use_observer() 459 EXPECT_FALSE(external_data_use_reporter()
555 ->last_data_report_submitted_ticks_.is_null()); 460 ->last_data_report_submitted_ticks_.is_null());
556 EXPECT_EQ(0, external_data_use_observer()->total_bytes_buffered_); 461 EXPECT_EQ(0, external_data_use_reporter()->total_bytes_buffered_);
557 EXPECT_EQ(default_upload_bytes() + default_download_bytes(), 462 EXPECT_EQ(default_upload_bytes() + default_download_bytes(),
558 external_data_use_observer()->pending_report_bytes_); 463 external_data_use_reporter()->pending_report_bytes_);
559 464
560 // Application state change should not submit if there is a pending report. 465 // Application state change should not submit if there is a pending report.
561 data_use.tx_bytes = 1; 466 data_use.tx_bytes = 1;
562 data_use.rx_bytes = 1; 467 data_use.rx_bytes = 1;
563 OnDataUse(data_use); 468 OnDataUse(data_use);
564 external_data_use_observer()->OnApplicationStateChange( 469 external_data_use_reporter()->OnApplicationStateChange(
565 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES); 470 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES);
566 EXPECT_FALSE(external_data_use_observer() 471 EXPECT_FALSE(external_data_use_reporter()
567 ->last_data_report_submitted_ticks_.is_null()); 472 ->last_data_report_submitted_ticks_.is_null());
568 EXPECT_EQ(2, external_data_use_observer()->total_bytes_buffered_); 473 EXPECT_EQ(2, external_data_use_reporter()->total_bytes_buffered_);
569 EXPECT_EQ(default_upload_bytes() + default_download_bytes(), 474 EXPECT_EQ(default_upload_bytes() + default_download_bytes(),
570 external_data_use_observer()->pending_report_bytes_); 475 external_data_use_reporter()->pending_report_bytes_);
571 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1); 476 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 1);
572 477
573 // Once pending report submission done callback was received, report should be 478 // Once pending report submission done callback was received, report should be
574 // submitted on next application state change. 479 // submitted on next application state change.
575 external_data_use_observer()->OnReportDataUseDone(true); 480 external_data_use_observer()->OnReportDataUseDone(true);
576 external_data_use_observer()->OnApplicationStateChange( 481 base::RunLoop().RunUntilIdle();
482 external_data_use_reporter()->OnApplicationStateChange(
577 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES); 483 base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES);
578 EXPECT_EQ(0, external_data_use_observer()->total_bytes_buffered_); 484 base::RunLoop().RunUntilIdle();
579 EXPECT_EQ(2, external_data_use_observer()->pending_report_bytes_); 485 EXPECT_EQ(0, external_data_use_reporter()->total_bytes_buffered_);
486 EXPECT_EQ(2, external_data_use_reporter()->pending_report_bytes_);
580 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 2); 487 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 2);
581 } 488 }
582 #endif // OS_ANDROID 489 #endif // OS_ANDROID
583
584 // Tests if the parameters from the field trial are populated correctly.
585 TEST_F(ExternalDataUseObserverTest, Variations) {
586 std::map<std::string, std::string> variation_params;
587
588 const int kFetchMatchingRulesDurationSeconds = 10000;
589 const int kDefaultMaxDataReportSubmitWaitMsec = 20000;
590 const int64_t kDataUseReportMinBytes = 5000;
591 variation_params["fetch_matching_rules_duration_seconds"] =
592 base::Int64ToString(kFetchMatchingRulesDurationSeconds);
593 variation_params["data_report_submit_timeout_msec"] =
594 base::Int64ToString(kDefaultMaxDataReportSubmitWaitMsec);
595 variation_params["data_use_report_min_bytes"] =
596 base::Int64ToString(kDataUseReportMinBytes);
597
598 // Create another ExternalDataUseObserver object.
599 ReplaceExternalDataUseObserver(variation_params);
600 EXPECT_EQ(base::TimeDelta::FromSeconds(kFetchMatchingRulesDurationSeconds),
601 external_data_use_observer()->fetch_matching_rules_duration_);
602 EXPECT_EQ(
603 base::TimeDelta::FromMilliseconds(kDefaultMaxDataReportSubmitWaitMsec),
604 external_data_use_observer()->data_report_submit_timeout_);
605 EXPECT_EQ(kDataUseReportMinBytes,
606 external_data_use_observer()->data_use_report_min_bytes_);
607 }
608 490
609 // Tests if the metrics are recorded correctly. 491 // Tests if the metrics are recorded correctly.
610 TEST_F(ExternalDataUseObserverTest, DataUseReportTimedOut) { 492 TEST_F(ExternalDataUseReporterTest, DataUseReportTimedOut) {
611 base::HistogramTester histogram_tester; 493 base::HistogramTester histogram_tester;
612 std::map<std::string, std::string> variation_params; 494 std::map<std::string, std::string> variation_params;
613 variation_params["data_report_submit_timeout_msec"] = "0"; 495 variation_params["data_report_submit_timeout_msec"] = "0";
614 variation_params["data_use_report_min_bytes"] = "0"; 496 variation_params["data_use_report_min_bytes"] = "0";
615 497
616 // Create another ExternalDataUseObserver object. 498 // Create another ExternalDataUseObserver object.
617 ReplaceExternalDataUseObserver(variation_params); 499 ReplaceExternalDataUseObserver(variation_params);
618 histogram_tester.ExpectTotalCount(kUMAMatchingRuleFirstFetchDurationHistogram, 500 histogram_tester.ExpectTotalCount(kUMAMatchingRuleFirstFetchDurationHistogram,
619 0); 501 0);
620 502
(...skipping 14 matching lines...) Expand all
635 histogram_tester.ExpectTotalCount(kUMAMatchingRuleFirstFetchDurationHistogram, 517 histogram_tester.ExpectTotalCount(kUMAMatchingRuleFirstFetchDurationHistogram,
636 1); 518 1);
637 519
638 AddDefaultMatchingRule(); 520 AddDefaultMatchingRule();
639 TriggerTabTrackingOnDefaultTab(); 521 TriggerTabTrackingOnDefaultTab();
640 OnDataUse(default_data_use()); 522 OnDataUse(default_data_use());
641 OnDataUse(default_data_use()); 523 OnDataUse(default_data_use());
642 // First data use report should be marked as timed out. 524 // First data use report should be marked as timed out.
643 histogram_tester.ExpectUniqueSample( 525 histogram_tester.ExpectUniqueSample(
644 "DataUsage.ReportSubmissionResult", 526 "DataUsage.ReportSubmissionResult",
645 ExternalDataUseObserver::DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT, 1); 527 ExternalDataUseReporter::DATAUSAGE_REPORT_SUBMISSION_TIMED_OUT, 1);
646 histogram_tester.ExpectUniqueSample( 528 histogram_tester.ExpectUniqueSample(
647 "DataUsage.ReportSubmission.Bytes.TimedOut", 529 "DataUsage.ReportSubmission.Bytes.TimedOut",
648 default_upload_bytes() + default_download_bytes(), 1); 530 default_upload_bytes() + default_download_bytes(), 1);
649 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 0); 531 histogram_tester.ExpectTotalCount(kUMAReportSubmissionDurationHistogram, 0);
650 } 532 }
651 533
652 } // namespace android 534 } // namespace android
653 535
654 } // namespace chrome 536 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698