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

Side by Side Diff: components/metrics/metrics_log_unittest.cc

Issue 573403002: Change UMA proto product field to be an int32. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and add a couple of tests. Created 6 years, 2 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 | « components/metrics/metrics_log.cc ('k') | components/metrics/metrics_service_client.h » ('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 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 <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 28 matching lines...) Expand all
39 const variations::ActiveGroupId kSyntheticTrials[] = { 39 const variations::ActiveGroupId kSyntheticTrials[] = {
40 {55, 15}, 40 {55, 15},
41 {66, 16} 41 {66, 16}
42 }; 42 };
43 43
44 class TestMetricsLog : public MetricsLog { 44 class TestMetricsLog : public MetricsLog {
45 public: 45 public:
46 TestMetricsLog(const std::string& client_id, 46 TestMetricsLog(const std::string& client_id,
47 int session_id, 47 int session_id,
48 LogType log_type, 48 LogType log_type,
49 metrics::MetricsServiceClient* client, 49 MetricsServiceClient* client,
50 TestingPrefServiceSimple* prefs) 50 TestingPrefServiceSimple* prefs)
51 : MetricsLog(client_id, session_id, log_type, client, prefs), 51 : MetricsLog(client_id, session_id, log_type, client, prefs),
52 prefs_(prefs) { 52 prefs_(prefs) {
53 InitPrefs(); 53 InitPrefs();
54 } 54 }
55 55
56 virtual ~TestMetricsLog() {} 56 virtual ~TestMetricsLog() {}
57 57
58 const metrics::ChromeUserMetricsExtension& uma_proto() const { 58 const ChromeUserMetricsExtension& uma_proto() const {
59 return *MetricsLog::uma_proto(); 59 return *MetricsLog::uma_proto();
60 } 60 }
61 61
62 const metrics::SystemProfileProto& system_profile() const { 62 const SystemProfileProto& system_profile() const {
63 return uma_proto().system_profile(); 63 return uma_proto().system_profile();
64 } 64 }
65 65
66 private: 66 private:
67 void InitPrefs() { 67 void InitPrefs() {
68 prefs_->SetString(metrics::prefs::kMetricsReportingEnabledTimestamp, 68 prefs_->SetString(prefs::kMetricsReportingEnabledTimestamp,
69 base::Int64ToString(kEnabledDate)); 69 base::Int64ToString(kEnabledDate));
70 } 70 }
71 71
72 virtual void GetFieldTrialIds( 72 virtual void GetFieldTrialIds(
73 std::vector<variations::ActiveGroupId>* field_trial_ids) const 73 std::vector<variations::ActiveGroupId>* field_trial_ids) const
74 OVERRIDE { 74 OVERRIDE {
75 ASSERT_TRUE(field_trial_ids->empty()); 75 ASSERT_TRUE(field_trial_ids->empty());
76 76
77 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { 77 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
78 field_trial_ids->push_back(kFieldTrialIds[i]); 78 field_trial_ids->push_back(kFieldTrialIds[i]);
79 } 79 }
80 } 80 }
81 81
82 // Weak pointer to the PrefsService used by this log. 82 // Weak pointer to the PrefsService used by this log.
83 TestingPrefServiceSimple* prefs_; 83 TestingPrefServiceSimple* prefs_;
84 84
85 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); 85 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
86 }; 86 };
87 87
88 } // namespace 88 } // namespace
89 89
90 class MetricsLogTest : public testing::Test { 90 class MetricsLogTest : public testing::Test {
91 public: 91 public:
92 MetricsLogTest() { 92 MetricsLogTest() {
93 MetricsLog::RegisterPrefs(prefs_.registry()); 93 MetricsLog::RegisterPrefs(prefs_.registry());
94 metrics::MetricsStateManager::RegisterPrefs(prefs_.registry()); 94 MetricsStateManager::RegisterPrefs(prefs_.registry());
95 } 95 }
96 96
97 virtual ~MetricsLogTest() { 97 virtual ~MetricsLogTest() {
98 } 98 }
99 99
100 protected: 100 protected:
101 // Check that the values in |system_values| correspond to the test data 101 // Check that the values in |system_values| correspond to the test data
102 // defined at the top of this file. 102 // defined at the top of this file.
103 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) { 103 void CheckSystemProfile(const SystemProfileProto& system_profile) {
104 EXPECT_EQ(kInstallDateExpected, system_profile.install_date()); 104 EXPECT_EQ(kInstallDateExpected, system_profile.install_date());
105 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date()); 105 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date());
106 106
107 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials), 107 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials),
108 static_cast<size_t>(system_profile.field_trial_size())); 108 static_cast<size_t>(system_profile.field_trial_size()));
109 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { 109 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
110 const metrics::SystemProfileProto::FieldTrial& field_trial = 110 const SystemProfileProto::FieldTrial& field_trial =
111 system_profile.field_trial(i); 111 system_profile.field_trial(i);
112 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id()); 112 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id());
113 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id()); 113 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id());
114 } 114 }
115 // Verify the right data is present for the synthetic trials. 115 // Verify the right data is present for the synthetic trials.
116 for (size_t i = 0; i < arraysize(kSyntheticTrials); ++i) { 116 for (size_t i = 0; i < arraysize(kSyntheticTrials); ++i) {
117 const metrics::SystemProfileProto::FieldTrial& field_trial = 117 const SystemProfileProto::FieldTrial& field_trial =
118 system_profile.field_trial(i + arraysize(kFieldTrialIds)); 118 system_profile.field_trial(i + arraysize(kFieldTrialIds));
119 EXPECT_EQ(kSyntheticTrials[i].name, field_trial.name_id()); 119 EXPECT_EQ(kSyntheticTrials[i].name, field_trial.name_id());
120 EXPECT_EQ(kSyntheticTrials[i].group, field_trial.group_id()); 120 EXPECT_EQ(kSyntheticTrials[i].group, field_trial.group_id());
121 } 121 }
122 122
123 EXPECT_EQ(metrics::TestMetricsServiceClient::kBrandForTesting, 123 EXPECT_EQ(TestMetricsServiceClient::kBrandForTesting,
124 system_profile.brand_code()); 124 system_profile.brand_code());
125 125
126 const metrics::SystemProfileProto::Hardware& hardware = 126 const SystemProfileProto::Hardware& hardware =
127 system_profile.hardware(); 127 system_profile.hardware();
128 128
129 EXPECT_TRUE(hardware.has_cpu()); 129 EXPECT_TRUE(hardware.has_cpu());
130 EXPECT_TRUE(hardware.cpu().has_vendor_name()); 130 EXPECT_TRUE(hardware.cpu().has_vendor_name());
131 EXPECT_TRUE(hardware.cpu().has_signature()); 131 EXPECT_TRUE(hardware.cpu().has_signature());
132 132
133 // TODO(isherman): Verify other data written into the protobuf as a result 133 // TODO(isherman): Verify other data written into the protobuf as a result
134 // of this call. 134 // of this call.
135 } 135 }
136 136
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); 371 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
372 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); 372 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
373 EXPECT_FALSE(stability.has_breakpad_registration_failure_count()); 373 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
374 EXPECT_FALSE(stability.has_debugger_present_count()); 374 EXPECT_FALSE(stability.has_debugger_present_count());
375 EXPECT_FALSE(stability.has_debugger_not_present_count()); 375 EXPECT_FALSE(stability.has_debugger_not_present_count());
376 } 376 }
377 377
378 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { 378 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) {
379 TestMetricsServiceClient client; 379 TestMetricsServiceClient client;
380 TestMetricsLog log( 380 TestMetricsLog log(
381 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 381 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
382 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); 382 EXPECT_TRUE(log.uma_proto().system_profile().has_channel());
383 } 383 }
384 384
385 TEST_F(MetricsLogTest, ProductNotSetIfDefault) {
386 TestMetricsServiceClient client;
387 EXPECT_EQ(ChromeUserMetricsExtension::CHROME, client.GetProduct());
388 TestMetricsLog log(
389 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
390 // Check that the product isn't set, since it's default and also verify the
391 // default value is indeed equal to Chrome.
392 EXPECT_FALSE(log.uma_proto().has_product());
393 EXPECT_EQ(ChromeUserMetricsExtension::CHROME, log.uma_proto().product());
394 }
395
396 TEST_F(MetricsLogTest, ProductSetIfNotDefault) {
397 const int32_t kTestProduct = 100;
398 EXPECT_NE(ChromeUserMetricsExtension::CHROME, kTestProduct);
399
400 TestMetricsServiceClient client;
401 client.set_product(kTestProduct);
402 TestMetricsLog log(
403 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
404 // Check that the product is set to |kTestProduct|.
405 EXPECT_TRUE(log.uma_proto().has_product());
406 EXPECT_EQ(kTestProduct, log.uma_proto().product());
407 }
408
385 } // namespace metrics 409 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log.cc ('k') | components/metrics/metrics_service_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698