Chromium Code Reviews| Index: base/test/user_action_tester.h |
| diff --git a/base/test/user_action_tester.h b/base/test/user_action_tester.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..38b426319483123032809d88d07ce696e6c09851 |
| --- /dev/null |
| +++ b/base/test/user_action_tester.h |
| @@ -0,0 +1,49 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TEST_USER_ACTION_TESTER_H_ |
| +#define BASE_TEST_USER_ACTION_TESTER_H_ |
| + |
| +#include <map> |
| +#include <string> |
| + |
| +#include "base/metrics/user_metrics.h" |
| + |
| +namespace base { |
| + |
| +// This class observes and collects user action notifications that are sent |
| +// by the tests, so that they can be examined afterwards for correctness. |
| +class UserActionTester { |
| + public: |
| + UserActionTester(); |
| + virtual ~UserActionTester(); |
|
Ilya Sherman
2015/04/08 20:49:19
nit: Does this really need to be virtual? That is
bruthig
2015/04/09 23:17:52
Done.
|
| + |
| + // Returns the number of times the given |user_action| occurred. |
| + int GetActionCount(const std::string& user_action) const; |
| + |
| + // Resets all user action counts to 0. |
| + void ResetCounts(); |
| + |
| + // A wrapper for the OnUserAction function that is accessible for tests of the |
| + // UserActionTester. |
| + void OnUserAction_for_test(const std::string& user_action); |
| + |
| + private: |
| + typedef std::map<std::string, int> UserActionCountMap; |
| + |
| + // The callback that is notified when a user actions occurs. |
| + void OnUserAction(const std::string& user_action); |
| + |
| + // A map that tracks the number of times a user action has occurred. |
| + UserActionCountMap count_map_; |
| + |
| + // The callback that is added to the global action callback list. |
| + base::ActionCallback action_callback_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UserActionTester); |
| +}; |
| + |
| +} // namespace base |
| + |
| +#endif // BASE_TEST_USER_ACTION_TESTER_H_ |