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

Side by Side Diff: metrics_library_test.cc

Issue 6211001: metrics: Send ability to notify chrome of system crashes (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/metrics.git@master
Patch Set: respond to review Created 9 years, 11 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 | « metrics_library.cc ('k') | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <cstring> 5 #include <cstring>
6 6
7 #include <base/file_util.h> 7 #include <base/file_util.h>
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 9
10 #include "c_metrics_library.h" 10 #include "c_metrics_library.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0); 224 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
225 EXPECT_EQ(0, memcmp(exp, buf, kLen)); 225 EXPECT_EQ(0, memcmp(exp, buf, kLen));
226 } 226 }
227 227
228 TEST_F(MetricsLibraryTest, SendUserActionToUMANotEnabled) { 228 TEST_F(MetricsLibraryTest, SendUserActionToUMANotEnabled) {
229 SetMetricsEnabled(false); 229 SetMetricsEnabled(false);
230 EXPECT_TRUE(lib_.SendUserActionToUMA("SomeOtherKeyPressed")); 230 EXPECT_TRUE(lib_.SendUserActionToUMA("SomeOtherKeyPressed"));
231 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile)); 231 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile));
232 } 232 }
233 233
234 TEST_F(MetricsLibraryTest, SendCrashToUMAEnabled) {
235 EXPECT_TRUE(lib_.SendCrashToUMA("kernel"));
236 char exp[100];
237 int len = sprintf(exp, "%c%c%c%ccrash%ckernel",
238 0, 0, 0, 0, 0) + 1;
239 exp[0] = len;
240 char buf[100];
241 EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
242 EXPECT_EQ(0, memcmp(exp, buf, len));
243 }
244
245 TEST_F(MetricsLibraryTest, SendCrashToUMANotEnabled) {
246 SetMetricsEnabled(false);
247 EXPECT_TRUE(lib_.SendCrashToUMA("kernel"));
248 EXPECT_FALSE(file_util::PathExists(kTestUMAEventsFile));
249 }
250
234 class CMetricsLibraryTest : public testing::Test { 251 class CMetricsLibraryTest : public testing::Test {
235 protected: 252 protected:
236 virtual void SetUp() { 253 virtual void SetUp() {
237 lib_ = CMetricsLibraryNew(); 254 lib_ = CMetricsLibraryNew();
238 MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_); 255 MetricsLibrary& ml = *reinterpret_cast<MetricsLibrary*>(lib_);
239 EXPECT_EQ(NULL, ml.uma_events_file_); 256 EXPECT_EQ(NULL, ml.uma_events_file_);
240 CMetricsLibraryInit(lib_); 257 CMetricsLibraryInit(lib_);
241 EXPECT_TRUE(NULL != ml.uma_events_file_); 258 EXPECT_TRUE(NULL != ml.uma_events_file_);
242 ml.uma_events_file_ = kTestUMAEventsFile.value().c_str(); 259 ml.uma_events_file_ = kTestUMAEventsFile.value().c_str();
243 SetMetricsEnabled(true); 260 SetMetricsEnabled(true);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 char buf[100]; 306 char buf[100];
290 const int kLen = 30; 307 const int kLen = 30;
291 EXPECT_TRUE(CMetricsLibrarySendUserActionToUMA(lib_, "SomeKeyPressed")); 308 EXPECT_TRUE(CMetricsLibrarySendUserActionToUMA(lib_, "SomeKeyPressed"));
292 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100)); 309 EXPECT_EQ(kLen, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
293 310
294 char exp[kLen]; 311 char exp[kLen];
295 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0); 312 sprintf(exp, "%c%c%c%cuseraction%cSomeKeyPressed", kLen, 0, 0, 0, 0);
296 EXPECT_EQ(0, memcmp(exp, buf, kLen)); 313 EXPECT_EQ(0, memcmp(exp, buf, kLen));
297 } 314 }
298 315
316 TEST_F(CMetricsLibraryTest, SendCrashToUMA) {
317 char buf[100];
318 char exp[100];
319 int len = sprintf(exp, "%c%c%c%ccrash%cuser", 0, 0, 0, 0, 0) + 1;
320 exp[0] = len;
321 EXPECT_TRUE(CMetricsLibrarySendCrashToUMA(lib_, "user"));
322 EXPECT_EQ(len, file_util::ReadFile(kTestUMAEventsFile, buf, 100));
323
324 EXPECT_EQ(0, memcmp(exp, buf, len));
325 }
326
299 int main(int argc, char** argv) { 327 int main(int argc, char** argv) {
300 testing::InitGoogleTest(&argc, argv); 328 testing::InitGoogleTest(&argc, argv);
301 return RUN_ALL_TESTS(); 329 return RUN_ALL_TESTS();
302 } 330 }
OLDNEW
« no previous file with comments | « metrics_library.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698