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

Side by Side Diff: base/test/user_action_tester.cc

Issue 1073613002: Added test support to observe and verify UMA user actions during tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
(Empty)
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.
4
5 #include "base/test/user_action_tester.h"
6
7 #include <map>
8 #include <string>
9
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/metrics/user_metrics.h"
13
14 namespace base {
15
16 UserActionTester::UserActionTester()
17 : action_callback_(
18 base::Bind(&UserActionTester::OnUserAction, base::Unretained(this))) {
19 base::AddActionCallback(action_callback_);
20 }
21
22 UserActionTester::~UserActionTester() {
23 base::RemoveActionCallback(action_callback_);
24 }
25
26 int UserActionTester::GetActionCount(const std::string& user_action) const {
27 UserActionCountMap::const_iterator iter = count_map_.find(user_action);
28 return iter == count_map_.end() ? 0 : iter->second;
29 }
30
31 void UserActionTester::ResetCounts() {
32 count_map_.clear();
33 }
34
35 void UserActionTester::OnUserAction_for_test(const std::string& user_action) {
36 OnUserAction(user_action);
37 }
38
39 void UserActionTester::OnUserAction(const std::string& user_action) {
40 ++(count_map_[user_action]);
41 }
42
43 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698