OLD | NEW |
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 "components/metrics/metrics_log.h" | 5 #include "components/metrics/metrics_log.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 prefs_(prefs) { | 67 prefs_(prefs) { |
68 InitPrefs(); | 68 InitPrefs(); |
69 } | 69 } |
70 | 70 |
71 ~TestMetricsLog() override {} | 71 ~TestMetricsLog() override {} |
72 | 72 |
73 const ChromeUserMetricsExtension& uma_proto() const { | 73 const ChromeUserMetricsExtension& uma_proto() const { |
74 return *MetricsLog::uma_proto(); | 74 return *MetricsLog::uma_proto(); |
75 } | 75 } |
76 | 76 |
| 77 ChromeUserMetricsExtension* mutable_uma_proto() { |
| 78 return MetricsLog::uma_proto(); |
| 79 } |
| 80 |
77 const SystemProfileProto& system_profile() const { | 81 const SystemProfileProto& system_profile() const { |
78 return uma_proto().system_profile(); | 82 return uma_proto().system_profile(); |
79 } | 83 } |
80 | 84 |
81 private: | 85 private: |
82 void InitPrefs() { | 86 void InitPrefs() { |
83 prefs_->SetString(prefs::kMetricsReportingEnabledTimestamp, | 87 prefs_->SetString(prefs::kMetricsReportingEnabledTimestamp, |
84 base::Int64ToString(kEnabledDate)); | 88 base::Int64ToString(kEnabledDate)); |
85 } | 89 } |
86 | 90 |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 410 |
407 TestMetricsServiceClient client; | 411 TestMetricsServiceClient client; |
408 client.set_product(kTestProduct); | 412 client.set_product(kTestProduct); |
409 TestMetricsLog log( | 413 TestMetricsLog log( |
410 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 414 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
411 // Check that the product is set to |kTestProduct|. | 415 // Check that the product is set to |kTestProduct|. |
412 EXPECT_TRUE(log.uma_proto().has_product()); | 416 EXPECT_TRUE(log.uma_proto().has_product()); |
413 EXPECT_EQ(kTestProduct, log.uma_proto().product()); | 417 EXPECT_EQ(kTestProduct, log.uma_proto().product()); |
414 } | 418 } |
415 | 419 |
| 420 TEST_F(MetricsLogTest, TruncateEvents) { |
| 421 TestMetricsServiceClient client; |
| 422 TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, |
| 423 &prefs_); |
| 424 |
| 425 for (int i = 0; i < internal::kUserActionEventLimit * 2; ++i) { |
| 426 log.RecordUserAction("BasicAction"); |
| 427 EXPECT_EQ(i + 1, log.uma_proto().user_action_event_size()); |
| 428 } |
| 429 for (int i = 0; i < internal::kOmniboxEventLimit * 2; ++i) { |
| 430 // Add an empty omnibox event. Not fully realistic since these are normally |
| 431 // supplied by a metrics provider. |
| 432 log.mutable_uma_proto()->add_omnibox_event(); |
| 433 EXPECT_EQ(i + 1, log.uma_proto().omnibox_event_size()); |
| 434 } |
| 435 |
| 436 // Truncate, and check that the current size is the limit. |
| 437 log.TruncateEvents(); |
| 438 EXPECT_EQ(internal::kUserActionEventLimit, |
| 439 log.uma_proto().user_action_event_size()); |
| 440 EXPECT_EQ(internal::kOmniboxEventLimit, log.uma_proto().omnibox_event_size()); |
| 441 } |
| 442 |
416 } // namespace metrics | 443 } // namespace metrics |
OLD | NEW |