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/metrics/user_action_tester.h" 6 7 #include "base/bind.h" 8 #include "base/bind_helpers.h" 9 #include "base/test/test_simple_task_runner.h" 10 11 namespace base { 12 UserActionTester()13UserActionTester::UserActionTester() 14 : task_runner_(new base::TestSimpleTaskRunner), 15 action_callback_( 16 base::Bind(&UserActionTester::OnUserAction, base::Unretained(this))) { 17 base::SetRecordActionTaskRunner(task_runner_); 18 base::AddActionCallback(action_callback_); 19 } 20 ~UserActionTester()21UserActionTester::~UserActionTester() { 22 base::RemoveActionCallback(action_callback_); 23 } 24 GetActionCount(const std::string & user_action) const25int UserActionTester::GetActionCount(const std::string& user_action) const { 26 UserActionCountMap::const_iterator iter = count_map_.find(user_action); 27 return iter == count_map_.end() ? 0 : iter->second; 28 } 29 ResetCounts()30void UserActionTester::ResetCounts() { 31 count_map_.clear(); 32 } 33 OnUserAction(const std::string & user_action)34void UserActionTester::OnUserAction(const std::string& user_action) { 35 ++(count_map_[user_action]); 36 } 37 38 } // namespace base 39