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

Side by Side Diff: chrome/browser/metrics/metrics_log_unittest.cc

Issue 12036047: Add Brand Code to UMA Uploads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_log.cc ('k') | chrome/common/metrics/proto/system_profile.proto » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/port.h" 8 #include "base/port.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/tracked_objects.h" 12 #include "base/tracked_objects.h"
13 #include "chrome/browser/google/google_util.h"
13 #include "chrome/browser/metrics/metrics_log.h" 14 #include "chrome/browser/metrics/metrics_log.h"
14 #include "chrome/browser/prefs/browser_prefs.h" 15 #include "chrome/browser/prefs/browser_prefs.h"
15 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/metrics/variations/variations_util.h" 17 #include "chrome/common/metrics/variations/variations_util.h"
17 #include "chrome/common/metrics/proto/profiler_event.pb.h" 18 #include "chrome/common/metrics/proto/profiler_event.pb.h"
18 #include "chrome/common/metrics/proto/system_profile.pb.h" 19 #include "chrome/common/metrics/proto/system_profile.pb.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
20 #include "chrome/installer/util/google_update_settings.h" 21 #include "chrome/installer/util/google_update_settings.h"
21 #include "chrome/test/base/testing_pref_service.h" 22 #include "chrome/test/base/testing_pref_service.h"
22 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gfx/size.h" 25 #include "ui/gfx/size.h"
25 #include "webkit/plugins/webplugininfo.h" 26 #include "webkit/plugins/webplugininfo.h"
26 27
27 using base::TimeDelta; 28 using base::TimeDelta;
28 using metrics::ProfilerEventProto; 29 using metrics::ProfilerEventProto;
29 using tracked_objects::ProcessDataSnapshot; 30 using tracked_objects::ProcessDataSnapshot;
30 using tracked_objects::TaskSnapshot; 31 using tracked_objects::TaskSnapshot;
31 32
32 namespace { 33 namespace {
33 34
34 const char kClientId[] = "bogus client ID"; 35 const char kClientId[] = "bogus client ID";
35 const int kSessionId = 127; 36 const int kSessionId = 127;
36 const int kScreenWidth = 1024; 37 const int kScreenWidth = 1024;
37 const int kScreenHeight = 768; 38 const int kScreenHeight = 768;
38 const int kScreenCount = 3; 39 const int kScreenCount = 3;
39 const float kScreenScaleFactor = 2; 40 const float kScreenScaleFactor = 2;
41 const char kBrandForTesting[] = "brand_for_testing";
40 const chrome_variations::ActiveGroupId kFieldTrialIds[] = { 42 const chrome_variations::ActiveGroupId kFieldTrialIds[] = {
41 {37, 43}, 43 {37, 43},
42 {13, 47}, 44 {13, 47},
43 {23, 17} 45 {23, 17}
44 }; 46 };
45 47
46 class TestMetricsLog : public MetricsLog { 48 class TestMetricsLog : public MetricsLog {
47 public: 49 public:
48 TestMetricsLog(const std::string& client_id, int session_id) 50 TestMetricsLog(const std::string& client_id, int session_id)
49 : MetricsLog(client_id, session_id) { 51 : MetricsLog(client_id, session_id),
52 brand_for_testing_(kBrandForTesting) {
50 chrome::RegisterLocalState(&prefs_); 53 chrome::RegisterLocalState(&prefs_);
51 54
52 #if defined(OS_CHROMEOS) 55 #if defined(OS_CHROMEOS)
53 prefs_.SetInteger(prefs::kStabilityChildProcessCrashCount, 10); 56 prefs_.SetInteger(prefs::kStabilityChildProcessCrashCount, 10);
54 prefs_.SetInteger(prefs::kStabilityOtherUserCrashCount, 11); 57 prefs_.SetInteger(prefs::kStabilityOtherUserCrashCount, 11);
55 prefs_.SetInteger(prefs::kStabilityKernelCrashCount, 12); 58 prefs_.SetInteger(prefs::kStabilityKernelCrashCount, 12);
56 prefs_.SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13); 59 prefs_.SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13);
57 #endif // OS_CHROMEOS 60 #endif // OS_CHROMEOS
58 } 61 }
59 virtual ~TestMetricsLog() {} 62 virtual ~TestMetricsLog() {}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { 95 virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
93 return kScreenScaleFactor; 96 return kScreenScaleFactor;
94 } 97 }
95 98
96 virtual int GetScreenCount() const OVERRIDE { 99 virtual int GetScreenCount() const OVERRIDE {
97 return kScreenCount; 100 return kScreenCount;
98 } 101 }
99 102
100 TestingPrefServiceSimple prefs_; 103 TestingPrefServiceSimple prefs_;
101 104
105 google_util::BrandForTesting brand_for_testing_;
106
102 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); 107 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
103 }; 108 };
104 109
105 } // namespace 110 } // namespace
106 111
107 class MetricsLogTest : public testing::Test { 112 class MetricsLogTest : public testing::Test {
108 protected: 113 protected:
109 void TestRecordEnvironment(bool proto_only) { 114 void TestRecordEnvironment(bool proto_only) {
110 TestMetricsLog log(kClientId, kSessionId); 115 TestMetricsLog log(kClientId, kSessionId);
111 116
112 std::vector<webkit::WebPluginInfo> plugins; 117 std::vector<webkit::WebPluginInfo> plugins;
113 GoogleUpdateMetrics google_update_metrics; 118 GoogleUpdateMetrics google_update_metrics;
114 if (proto_only) 119 if (proto_only)
115 log.RecordEnvironmentProto(plugins, google_update_metrics); 120 log.RecordEnvironmentProto(plugins, google_update_metrics);
116 else 121 else
117 log.RecordEnvironment(plugins, google_update_metrics, NULL); 122 log.RecordEnvironment(plugins, google_update_metrics, NULL);
118 123
119 const metrics::SystemProfileProto& system_profile = log.system_profile(); 124 const metrics::SystemProfileProto& system_profile = log.system_profile();
120 ASSERT_EQ(arraysize(kFieldTrialIds), 125 ASSERT_EQ(arraysize(kFieldTrialIds),
121 static_cast<size_t>(system_profile.field_trial_size())); 126 static_cast<size_t>(system_profile.field_trial_size()));
122 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { 127 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
123 const metrics::SystemProfileProto::FieldTrial& field_trial = 128 const metrics::SystemProfileProto::FieldTrial& field_trial =
124 system_profile.field_trial(i); 129 system_profile.field_trial(i);
125 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id()); 130 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id());
126 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id()); 131 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id());
127 } 132 }
128 133
134 EXPECT_EQ(kBrandForTesting, system_profile.brand_code());
135
129 const metrics::SystemProfileProto::Hardware& hardware = 136 const metrics::SystemProfileProto::Hardware& hardware =
130 system_profile.hardware(); 137 system_profile.hardware();
131 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width()); 138 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
132 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height()); 139 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
133 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor()); 140 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
134 EXPECT_EQ(kScreenCount, hardware.screen_count()); 141 EXPECT_EQ(kScreenCount, hardware.screen_count());
135 142
136 // TODO(isherman): Verify other data written into the protobuf as a result 143 // TODO(isherman): Verify other data written into the protobuf as a result
137 // of this call. 144 // of this call.
138 } 145 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 EXPECT_NE(std::string::npos, 314 EXPECT_NE(std::string::npos,
308 encoded.find(" childprocesscrashcount=\"10\"")); 315 encoded.find(" childprocesscrashcount=\"10\""));
309 EXPECT_EQ(std::string::npos, 316 EXPECT_EQ(std::string::npos,
310 encoded.find(" otherusercrashcount=")); 317 encoded.find(" otherusercrashcount="));
311 EXPECT_EQ(std::string::npos, 318 EXPECT_EQ(std::string::npos,
312 encoded.find(" kernelcrashcount=")); 319 encoded.find(" kernelcrashcount="));
313 EXPECT_EQ(std::string::npos, 320 EXPECT_EQ(std::string::npos,
314 encoded.find(" systemuncleanshutdowns=")); 321 encoded.find(" systemuncleanshutdowns="));
315 } 322 }
316 #endif // OS_CHROMEOS 323 #endif // OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log.cc ('k') | chrome/common/metrics/proto/system_profile.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698