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 27 matching lines...) Expand all Loading... |
38 // Makes this object listen for the given notification with the given source. | 38 // Makes this object listen for the given notification with the given source. |
39 void ListenFor(int type, const NotificationSource& source); | 39 void ListenFor(int type, const NotificationSource& source); |
40 | 40 |
41 // Makes this object listen for notifications of the given type coming from | 41 // Makes this object listen for notifications of the given type coming from |
42 // any source. | 42 // any source. |
43 void ListenForAll(int type); | 43 void ListenForAll(int type); |
44 | 44 |
45 // Clears the list of events. | 45 // Clears the list of events. |
46 void Reset(); | 46 void Reset(); |
47 | 47 |
| 48 // TODO(jyasskin): Replace calls to Check*AndReset() with |
| 49 // EXPECT_THAT(GetTypesAndReset()). |
| 50 // |
48 // Given notifications type(sp, returns true if the list of notifications | 51 // Given notifications type(sp, returns true if the list of notifications |
49 // were exactly those listed in the given arg(s), and in the same order. | 52 // were exactly those listed in the given arg(s), and in the same order. |
50 // | 53 // |
51 // This will also reset the list so that the next call will only check for | 54 // This will also reset the list so that the next call will only check for |
52 // new notifications. Example: | 55 // new notifications. Example: |
53 // <do stuff> | 56 // <do stuff> |
54 // Check1AndReset(NOTIFY_A); | 57 // Check1AndReset(NOTIFY_A); |
55 // <do stuff> | 58 // <do stuff> |
56 // Check2AndReset(NOTIFY_B, NOTIFY_C) | 59 // Check2AndReset(NOTIFY_B, NOTIFY_C) |
57 bool Check1AndReset(int type); | 60 bool Check1AndReset(int type); |
58 bool Check2AndReset(int type1, | 61 bool Check2AndReset(int type1, |
59 int type2); | 62 int type2); |
60 bool Check3AndReset(int type1, | 63 bool Check3AndReset(int type1, |
61 int type2, | 64 int type2, |
62 int type3); | 65 int type3); |
63 | 66 |
| 67 // Returns the types of the received notifications in order. Usable |
| 68 // with EXPECT_THAT(ElementsAre): |
| 69 // EXPECT_THAT(tracker.GetTypesAndReset(), |
| 70 // testing::ElementsAre(content::NOTIFICATION_LOAD_START, ...)); |
| 71 std::vector<int> GetTypes() const; |
| 72 |
| 73 // Like GetTypes, but also calls Reset() so that the next call will |
| 74 // only check for new notifications. |
| 75 std::vector<int> GetTypesAndReset() { |
| 76 std::vector<int> result = GetTypes(); |
| 77 Reset(); |
| 78 return result; |
| 79 } |
| 80 |
64 // Returns the number of notifications received since the last reset. | 81 // Returns the number of notifications received since the last reset. |
65 size_t size() const { return events_.size(); } | 82 size_t size() const { return events_.size(); } |
66 | 83 |
67 // Returns the information about the event at the given index. The index must | 84 // Returns the information about the event at the given index. The index must |
68 // be in [0, size). | 85 // be in [0, size). |
69 const Event& at(size_t i) const { return events_[i]; } | 86 const Event& at(size_t i) const { return events_[i]; } |
70 | 87 |
71 protected: | 88 protected: |
72 virtual void Observe(int type, | 89 virtual void Observe(int type, |
73 const NotificationSource& source, | 90 const NotificationSource& source, |
74 const NotificationDetails& details) OVERRIDE; | 91 const NotificationDetails& details) OVERRIDE; |
75 private: | 92 private: |
76 NotificationRegistrar registrar_; | 93 NotificationRegistrar registrar_; |
77 | 94 |
78 // Lists all received since last cleared, in the order they were received. | 95 // Lists all received since last cleared, in the order they were received. |
79 std::vector<Event> events_; | 96 std::vector<Event> events_; |
80 | 97 |
81 DISALLOW_COPY_AND_ASSIGN(TestNotificationTracker); | 98 DISALLOW_COPY_AND_ASSIGN(TestNotificationTracker); |
82 }; | 99 }; |
83 | 100 |
84 } // namespace content | 101 } // namespace content |
85 | 102 |
86 #endif // CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ | 103 #endif // CONTENT_PUBLIC_TEST_TEST_NOTIFICATION_TRACKER_H_ |
OLD | NEW |