OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #ifndef CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ |
6 #define CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ | 6 #define CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // Check1AndReset(NOTIFY_A); | 54 // Check1AndReset(NOTIFY_A); |
55 // <do stuff> | 55 // <do stuff> |
56 // Check2AndReset(NOTIFY_B, NOTIFY_C) | 56 // Check2AndReset(NOTIFY_B, NOTIFY_C) |
57 bool Check1AndReset(int type); | 57 bool Check1AndReset(int type); |
58 bool Check2AndReset(int type1, | 58 bool Check2AndReset(int type1, |
59 int type2); | 59 int type2); |
60 bool Check3AndReset(int type1, | 60 bool Check3AndReset(int type1, |
61 int type2, | 61 int type2, |
62 int type3); | 62 int type3); |
63 | 63 |
64 // Returns the types of the received notifications in order. Usable | |
65 // with EXPECT_THAT(ElementsAre): | |
66 // EXPECT_THAT(tracker.GetTypesAndReset(), | |
67 // testing::ElementsAre(content::NOTIFICATION_LOAD_START, ...)); | |
68 std::vector<int> GetTypes() const; | |
jam
2013/04/07 21:29:18
hmm, we shouldn't be adding more dependencies on n
| |
69 | |
70 // Like GetTypes, but also calls Reset() so that the next call will | |
71 // only check for new notifications. | |
72 std::vector<int> GetTypesAndReset() { | |
73 std::vector<int> result = GetTypes(); | |
74 Reset(); | |
75 return result; | |
76 } | |
77 | |
64 // Returns the number of notifications received since the last reset. | 78 // Returns the number of notifications received since the last reset. |
65 size_t size() const { return events_.size(); } | 79 size_t size() const { return events_.size(); } |
66 | 80 |
67 // Returns the information about the event at the given index. The index must | 81 // Returns the information about the event at the given index. The index must |
68 // be in [0, size). | 82 // be in [0, size). |
69 const Event& at(size_t i) const { return events_[i]; } | 83 const Event& at(size_t i) const { return events_[i]; } |
70 | 84 |
71 protected: | 85 protected: |
72 virtual void Observe(int type, | 86 virtual void Observe(int type, |
73 const NotificationSource& source, | 87 const NotificationSource& source, |
74 const NotificationDetails& details) OVERRIDE; | 88 const NotificationDetails& details) OVERRIDE; |
75 private: | 89 private: |
76 NotificationRegistrar registrar_; | 90 NotificationRegistrar registrar_; |
77 | 91 |
78 // Lists all received since last cleared, in the order they were received. | 92 // Lists all received since last cleared, in the order they were received. |
79 std::vector<Event> events_; | 93 std::vector<Event> events_; |
80 | 94 |
81 DISALLOW_COPY_AND_ASSIGN(TestNotificationTracker); | 95 DISALLOW_COPY_AND_ASSIGN(TestNotificationTracker); |
82 }; | 96 }; |
83 | 97 |
84 } // namespace content | 98 } // namespace content |
85 | 99 |
86 #endif // CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ | 100 #endif // CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ |
OLD | NEW |