OLD | NEW |
---|---|
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/memory/scoped_ptr.h" | |
8 #include "base/port.h" | 9 #include "base/port.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
14 #include "chrome/browser/google/google_util.h" | |
13 #include "chrome/browser/metrics/metrics_log.h" | 15 #include "chrome/browser/metrics/metrics_log.h" |
14 #include "chrome/browser/prefs/browser_prefs.h" | 16 #include "chrome/browser/prefs/browser_prefs.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/common/metrics/variations/variations_util.h" | 18 #include "chrome/common/metrics/variations/variations_util.h" |
17 #include "chrome/common/metrics/proto/profiler_event.pb.h" | 19 #include "chrome/common/metrics/proto/profiler_event.pb.h" |
18 #include "chrome/common/metrics/proto/system_profile.pb.h" | 20 #include "chrome/common/metrics/proto/system_profile.pb.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "chrome/installer/util/google_update_settings.h" | 22 #include "chrome/installer/util/google_update_settings.h" |
21 #include "chrome/test/base/testing_pref_service.h" | 23 #include "chrome/test/base/testing_pref_service.h" |
22 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/gfx/size.h" | 26 #include "ui/gfx/size.h" |
25 #include "webkit/plugins/webplugininfo.h" | 27 #include "webkit/plugins/webplugininfo.h" |
26 | 28 |
27 using base::TimeDelta; | 29 using base::TimeDelta; |
28 using metrics::ProfilerEventProto; | 30 using metrics::ProfilerEventProto; |
29 using tracked_objects::ProcessDataSnapshot; | 31 using tracked_objects::ProcessDataSnapshot; |
30 using tracked_objects::TaskSnapshot; | 32 using tracked_objects::TaskSnapshot; |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 const char kClientId[] = "bogus client ID"; | 36 const char kClientId[] = "bogus client ID"; |
35 const int kSessionId = 127; | 37 const int kSessionId = 127; |
36 const int kScreenWidth = 1024; | 38 const int kScreenWidth = 1024; |
37 const int kScreenHeight = 768; | 39 const int kScreenHeight = 768; |
38 const int kScreenCount = 3; | 40 const int kScreenCount = 3; |
39 const float kScreenScaleFactor = 2; | 41 const float kScreenScaleFactor = 2; |
42 const char* kBrandForTesting = "brand_for_testing"; | |
Ilya Sherman
2013/01/24 00:31:46
nit: This should have type "const char kBrandForTe
Mark P
2013/01/24 00:43:05
Done.
| |
40 const chrome_variations::ActiveGroupId kFieldTrialIds[] = { | 43 const chrome_variations::ActiveGroupId kFieldTrialIds[] = { |
41 {37, 43}, | 44 {37, 43}, |
42 {13, 47}, | 45 {13, 47}, |
43 {23, 17} | 46 {23, 17} |
44 }; | 47 }; |
45 | 48 |
46 class TestMetricsLog : public MetricsLog { | 49 class TestMetricsLog : public MetricsLog { |
47 public: | 50 public: |
48 TestMetricsLog(const std::string& client_id, int session_id) | 51 TestMetricsLog(const std::string& client_id, int session_id) |
49 : MetricsLog(client_id, session_id) { | 52 : MetricsLog(client_id, session_id) { |
50 chrome::RegisterLocalState(&prefs_); | 53 chrome::RegisterLocalState(&prefs_); |
54 brand_for_testing_.reset( | |
55 new google_util::BrandForTesting(kBrandForTesting)); | |
51 | 56 |
52 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
53 prefs_.SetInteger(prefs::kStabilityChildProcessCrashCount, 10); | 58 prefs_.SetInteger(prefs::kStabilityChildProcessCrashCount, 10); |
54 prefs_.SetInteger(prefs::kStabilityOtherUserCrashCount, 11); | 59 prefs_.SetInteger(prefs::kStabilityOtherUserCrashCount, 11); |
55 prefs_.SetInteger(prefs::kStabilityKernelCrashCount, 12); | 60 prefs_.SetInteger(prefs::kStabilityKernelCrashCount, 12); |
56 prefs_.SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13); | 61 prefs_.SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13); |
57 #endif // OS_CHROMEOS | 62 #endif // OS_CHROMEOS |
58 } | 63 } |
59 virtual ~TestMetricsLog() {} | 64 virtual ~TestMetricsLog() {} |
60 | 65 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { | 97 virtual float GetScreenDeviceScaleFactor() const OVERRIDE { |
93 return kScreenScaleFactor; | 98 return kScreenScaleFactor; |
94 } | 99 } |
95 | 100 |
96 virtual int GetScreenCount() const OVERRIDE { | 101 virtual int GetScreenCount() const OVERRIDE { |
97 return kScreenCount; | 102 return kScreenCount; |
98 } | 103 } |
99 | 104 |
100 TestingPrefServiceSimple prefs_; | 105 TestingPrefServiceSimple prefs_; |
101 | 106 |
107 scoped_ptr<google_util::BrandForTesting> brand_for_testing_; | |
Ilya Sherman
2013/01/23 23:32:54
nit: No need to use a pointer; just allocate as a
Mark P
2013/01/23 23:49:26
I can do that if I make the kBrandForTesting a str
Ilya Sherman
2013/01/24 00:31:46
I don't think the explicit on BrandForTesting's co
Mark P
2013/01/24 00:43:05
Works now (without the explicit conversion). Dunn
| |
108 | |
102 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); | 109 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog); |
103 }; | 110 }; |
104 | 111 |
105 } // namespace | 112 } // namespace |
106 | 113 |
107 class MetricsLogTest : public testing::Test { | 114 class MetricsLogTest : public testing::Test { |
108 protected: | 115 protected: |
109 void TestRecordEnvironment(bool proto_only) { | 116 void TestRecordEnvironment(bool proto_only) { |
110 TestMetricsLog log(kClientId, kSessionId); | 117 TestMetricsLog log(kClientId, kSessionId); |
111 | 118 |
112 std::vector<webkit::WebPluginInfo> plugins; | 119 std::vector<webkit::WebPluginInfo> plugins; |
113 GoogleUpdateMetrics google_update_metrics; | 120 GoogleUpdateMetrics google_update_metrics; |
114 if (proto_only) | 121 if (proto_only) |
115 log.RecordEnvironmentProto(plugins, google_update_metrics); | 122 log.RecordEnvironmentProto(plugins, google_update_metrics); |
116 else | 123 else |
117 log.RecordEnvironment(plugins, google_update_metrics, NULL); | 124 log.RecordEnvironment(plugins, google_update_metrics, NULL); |
118 | 125 |
119 const metrics::SystemProfileProto& system_profile = log.system_profile(); | 126 const metrics::SystemProfileProto& system_profile = log.system_profile(); |
120 ASSERT_EQ(arraysize(kFieldTrialIds), | 127 ASSERT_EQ(arraysize(kFieldTrialIds), |
121 static_cast<size_t>(system_profile.field_trial_size())); | 128 static_cast<size_t>(system_profile.field_trial_size())); |
122 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { | 129 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) { |
123 const metrics::SystemProfileProto::FieldTrial& field_trial = | 130 const metrics::SystemProfileProto::FieldTrial& field_trial = |
124 system_profile.field_trial(i); | 131 system_profile.field_trial(i); |
125 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id()); | 132 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id()); |
126 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id()); | 133 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id()); |
127 } | 134 } |
128 | 135 |
136 EXPECT_EQ(kBrandForTesting, system_profile.brand_code()); | |
137 | |
129 const metrics::SystemProfileProto::Hardware& hardware = | 138 const metrics::SystemProfileProto::Hardware& hardware = |
130 system_profile.hardware(); | 139 system_profile.hardware(); |
131 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width()); | 140 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width()); |
132 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height()); | 141 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height()); |
133 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor()); | 142 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor()); |
134 EXPECT_EQ(kScreenCount, hardware.screen_count()); | 143 EXPECT_EQ(kScreenCount, hardware.screen_count()); |
135 | 144 |
136 // TODO(isherman): Verify other data written into the protobuf as a result | 145 // TODO(isherman): Verify other data written into the protobuf as a result |
137 // of this call. | 146 // of this call. |
138 } | 147 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 EXPECT_NE(std::string::npos, | 316 EXPECT_NE(std::string::npos, |
308 encoded.find(" childprocesscrashcount=\"10\"")); | 317 encoded.find(" childprocesscrashcount=\"10\"")); |
309 EXPECT_EQ(std::string::npos, | 318 EXPECT_EQ(std::string::npos, |
310 encoded.find(" otherusercrashcount=")); | 319 encoded.find(" otherusercrashcount=")); |
311 EXPECT_EQ(std::string::npos, | 320 EXPECT_EQ(std::string::npos, |
312 encoded.find(" kernelcrashcount=")); | 321 encoded.find(" kernelcrashcount=")); |
313 EXPECT_EQ(std::string::npos, | 322 EXPECT_EQ(std::string::npos, |
314 encoded.find(" systemuncleanshutdowns=")); | 323 encoded.find(" systemuncleanshutdowns=")); |
315 } | 324 } |
316 #endif // OS_CHROMEOS | 325 #endif // OS_CHROMEOS |
OLD | NEW |