OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 NET_BASE_NET_LOG_UNITTEST_H_ | 5 #ifndef NET_BASE_NET_LOG_UNITTEST_H_ |
6 #define NET_BASE_NET_LOG_UNITTEST_H_ | 6 #define NET_BASE_NET_LOG_UNITTEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 | 10 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (j >= entries.size()) | 99 if (j >= entries.size()) |
100 return ::testing::AssertionFailure() << j << " is out of bounds."; | 100 return ::testing::AssertionFailure() << j << " is out of bounds."; |
101 const CapturingNetLog::Entry& entry = entries[j]; | 101 const CapturingNetLog::Entry& entry = entries[j]; |
102 if (entry.type != type) | 102 if (entry.type != type) |
103 return ::testing::AssertionFailure() << "Type does not match."; | 103 return ::testing::AssertionFailure() << "Type does not match."; |
104 return ::testing::AssertionSuccess(); | 104 return ::testing::AssertionSuccess(); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 // Expect that the log contains an event, but don't care about where | 108 // Expect that the log contains an event, but don't care about where |
109 // as long as the index where it is found is greater than min_index. | 109 // as long as the first index where it is found is at least |min_index|. |
110 // Returns the position where the event was found. | 110 // Returns the position where the event was found. |
111 inline size_t ExpectLogContainsSomewhere( | 111 inline size_t ExpectLogContainsSomewhere( |
112 const CapturingNetLog::EntryList& entries, | 112 const CapturingNetLog::EntryList& entries, |
113 size_t min_index, | 113 size_t min_index, |
114 NetLog::EventType expected_event, | 114 NetLog::EventType expected_event, |
115 NetLog::EventPhase expected_phase) { | 115 NetLog::EventPhase expected_phase) { |
116 size_t i = 0; | 116 size_t i = 0; |
117 for (; i < entries.size(); ++i) { | 117 for (; i < entries.size(); ++i) { |
118 const CapturingNetLog::Entry& entry = entries[i]; | 118 const CapturingNetLog::Entry& entry = entries[i]; |
119 if (entry.type == expected_event && | 119 if (entry.type == expected_event && |
120 entry.phase == expected_phase) | 120 entry.phase == expected_phase) |
121 break; | 121 break; |
122 } | 122 } |
123 EXPECT_LT(i, entries.size()); | 123 EXPECT_LT(i, entries.size()); |
124 EXPECT_GE(i, min_index); | 124 EXPECT_GE(i, min_index); |
125 return i; | 125 return i; |
126 } | 126 } |
127 | 127 |
| 128 // Expect that the log contains an event, but don't care about where |
| 129 // as long as one index where it is found is at least |min_index|. |
| 130 // Returns the first such position where the event was found. |
| 131 inline size_t ExpectLogContainsSomewhereAfter( |
| 132 const CapturingNetLog::EntryList& entries, |
| 133 size_t min_index, |
| 134 NetLog::EventType expected_event, |
| 135 NetLog::EventPhase expected_phase) { |
| 136 size_t i = min_index; |
| 137 for (; i < entries.size(); ++i) { |
| 138 const CapturingNetLog::Entry& entry = entries[i]; |
| 139 if (entry.type == expected_event && |
| 140 entry.phase == expected_phase) |
| 141 break; |
| 142 } |
| 143 EXPECT_LT(i, entries.size()); |
| 144 return i; |
| 145 } |
| 146 |
128 } // namespace net | 147 } // namespace net |
129 | 148 |
130 #endif // NET_BASE_NET_LOG_UNITTEST_H_ | 149 #endif // NET_BASE_NET_LOG_UNITTEST_H_ |
OLD | NEW |