Fix bug preventing crashdump uploads.
[chromium-blink-merge.git] / base / test / user_action_tester_unittest.cc
bloba51849f6a5d799e1286abc090223b9f5dba9bb6d
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/test/user_action_tester.h"
7 #include "base/metrics/user_metrics.h"
8 #include "base/metrics/user_metrics_action.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace base {
13 namespace {
15 const char kUserAction1[] = "user.action.1";
16 const char kUserAction2[] = "user.action.2";
17 const char kUserAction3[] = "user.action.3";
19 // Record an action and cause all ActionCallback observers to be notified.
20 void RecordAction(const char user_action[]) {
21 base::RecordAction(base::UserMetricsAction(user_action));
24 } // namespace
26 // Verify user action counts are zero initially.
27 TEST(UserActionTesterTest, GetActionCountWhenNoActionsHaveBeenRecorded) {
28 UserActionTester user_action_tester;
29 EXPECT_EQ(0, user_action_tester.GetActionCount(kUserAction1));
32 // Verify user action counts are tracked properly.
33 TEST(UserActionTesterTest, GetActionCountWhenActionsHaveBeenRecorded) {
34 UserActionTester user_action_tester;
36 RecordAction(kUserAction1);
37 RecordAction(kUserAction2);
38 RecordAction(kUserAction2);
40 EXPECT_EQ(1, user_action_tester.GetActionCount(kUserAction1));
41 EXPECT_EQ(2, user_action_tester.GetActionCount(kUserAction2));
42 EXPECT_EQ(0, user_action_tester.GetActionCount(kUserAction3));
45 // Verify no seg faults occur when resetting action counts when none have been
46 // recorded.
47 TEST(UserActionTesterTest, ResetCountsWhenNoActionsHaveBeenRecorded) {
48 UserActionTester user_action_tester;
49 user_action_tester.ResetCounts();
52 // Verify user action counts are set to zero on a ResetCounts.
53 TEST(UserActionTesterTest, ResetCountsWhenActionsHaveBeenRecorded) {
54 UserActionTester user_action_tester;
56 RecordAction(kUserAction1);
57 RecordAction(kUserAction1);
58 RecordAction(kUserAction2);
59 user_action_tester.ResetCounts();
61 EXPECT_EQ(0, user_action_tester.GetActionCount(kUserAction1));
62 EXPECT_EQ(0, user_action_tester.GetActionCount(kUserAction2));
63 EXPECT_EQ(0, user_action_tester.GetActionCount(kUserAction3));
66 // Verify the UserActionsTester is notified when base::RecordAction is called.
67 TEST(UserActionTesterTest, VerifyUserActionTesterListensForUserActions) {
68 UserActionTester user_action_tester;
70 base::RecordAction(base::UserMetricsAction(kUserAction1));
72 EXPECT_EQ(1, user_action_tester.GetActionCount(kUserAction1));
75 // Verify the UserActionsTester is notified when base::RecordComputedAction is
76 // called.
77 TEST(UserActionTesterTest,
78 VerifyUserActionTesterListensForComputedUserActions) {
79 UserActionTester user_action_tester;
81 base::RecordComputedAction(kUserAction1);
83 EXPECT_EQ(1, user_action_tester.GetActionCount(kUserAction1));
86 } // namespace base