| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "net/base/net_log.h" | 10 #include "net/base/net_log.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const CapturingNetLog::EntryList& entries, | 23 const CapturingNetLog::EntryList& entries, |
| 24 int i, // Negative indices are reverse indices. | 24 int i, // Negative indices are reverse indices. |
| 25 const base::TimeTicks& expected_time, | 25 const base::TimeTicks& expected_time, |
| 26 bool check_time, | 26 bool check_time, |
| 27 NetLog::EventType expected_event, | 27 NetLog::EventType expected_event, |
| 28 NetLog::EventPhase expected_phase) { | 28 NetLog::EventPhase expected_phase) { |
| 29 // Negative indices are reverse indices. | 29 // Negative indices are reverse indices. |
| 30 size_t j = (i < 0) ? entries.size() + i : i; | 30 size_t j = (i < 0) ? entries.size() + i : i; |
| 31 if (j >= entries.size()) | 31 if (j >= entries.size()) |
| 32 return ::testing::AssertionFailure() << j << " is out of bounds."; | 32 return ::testing::AssertionFailure() << j << " is out of bounds."; |
| 33 const NetLog::Entry& entry = entries[j]; | 33 const CapturingNetLog::Entry& entry = entries[j]; |
| 34 if (entry.type != NetLog::Entry::TYPE_EVENT) | 34 if (expected_event != entry.type) { |
| 35 return ::testing::AssertionFailure() << "Not a TYPE_EVENT entry"; | |
| 36 if (expected_event != entry.event.type) { | |
| 37 return ::testing::AssertionFailure() | 35 return ::testing::AssertionFailure() |
| 38 << "Actual event: " << NetLog::EventTypeToString(entry.event.type) | 36 << "Actual event: " << NetLog::EventTypeToString(entry.type) |
| 39 << ". Expected event: " << NetLog::EventTypeToString(expected_event) | 37 << ". Expected event: " << NetLog::EventTypeToString(expected_event) |
| 40 << "."; | 38 << "."; |
| 41 } | 39 } |
| 42 if (expected_phase != entry.event.phase) { | 40 if (expected_phase != entry.phase) { |
| 43 return ::testing::AssertionFailure() | 41 return ::testing::AssertionFailure() |
| 44 << "Actual phase: " << entry.event.phase | 42 << "Actual phase: " << entry.phase |
| 45 << ". Expected phase: " << expected_phase << "."; | 43 << ". Expected phase: " << expected_phase << "."; |
| 46 } | 44 } |
| 47 if (check_time) { | 45 if (check_time) { |
| 48 if (expected_time != entry.time) { | 46 if (expected_time != entry.time) { |
| 49 return ::testing::AssertionFailure() | 47 return ::testing::AssertionFailure() |
| 50 << "Actual time: " << entry.time.ToInternalValue() | 48 << "Actual time: " << entry.time.ToInternalValue() |
| 51 << ". Expected time: " << expected_time.ToInternalValue() | 49 << ". Expected time: " << expected_time.ToInternalValue() |
| 52 << "."; | 50 << "."; |
| 53 } | 51 } |
| 54 } | 52 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 inline ::testing::AssertionResult LogContainsEndEvent( | 85 inline ::testing::AssertionResult LogContainsEndEvent( |
| 88 const CapturingNetLog::EntryList& log, | 86 const CapturingNetLog::EntryList& log, |
| 89 int i, // Negative indices are reverse indices. | 87 int i, // Negative indices are reverse indices. |
| 90 NetLog::EventType expected_event) { | 88 NetLog::EventType expected_event) { |
| 91 return LogContainsEvent(log, i, expected_event, NetLog::PHASE_END); | 89 return LogContainsEvent(log, i, expected_event, NetLog::PHASE_END); |
| 92 } | 90 } |
| 93 | 91 |
| 94 inline ::testing::AssertionResult LogContainsEntryWithType( | 92 inline ::testing::AssertionResult LogContainsEntryWithType( |
| 95 const CapturingNetLog::EntryList& entries, | 93 const CapturingNetLog::EntryList& entries, |
| 96 int i, // Negative indices are reverse indices. | 94 int i, // Negative indices are reverse indices. |
| 97 NetLog::Entry::Type type) { | 95 NetLog::EventType type) { |
| 98 // Negative indices are reverse indices. | 96 // Negative indices are reverse indices. |
| 99 size_t j = (i < 0) ? entries.size() + i : i; | 97 size_t j = (i < 0) ? entries.size() + i : i; |
| 100 if (j >= entries.size()) | 98 if (j >= entries.size()) |
| 101 return ::testing::AssertionFailure() << j << " is out of bounds."; | 99 return ::testing::AssertionFailure() << j << " is out of bounds."; |
| 102 const NetLog::Entry& entry = entries[j]; | 100 const CapturingNetLog::Entry& entry = entries[j]; |
| 103 if (entry.type != type) | 101 if (entry.type != type) |
| 104 return ::testing::AssertionFailure() << "Type does not match."; | 102 return ::testing::AssertionFailure() << "Type does not match."; |
| 105 return ::testing::AssertionSuccess(); | 103 return ::testing::AssertionSuccess(); |
| 106 } | 104 } |
| 107 | 105 |
| 108 | 106 |
| 109 // Expect that the log contains an event, but don't care about where | 107 // Expect that the log contains an event, but don't care about where |
| 110 // as long as the index where it is found is greater than min_index. | 108 // as long as the index where it is found is greater than min_index. |
| 111 // Returns the position where the event was found. | 109 // Returns the position where the event was found. |
| 112 inline size_t ExpectLogContainsSomewhere( | 110 inline size_t ExpectLogContainsSomewhere( |
| 113 const CapturingNetLog::EntryList& entries, | 111 const CapturingNetLog::EntryList& entries, |
| 114 size_t min_index, | 112 size_t min_index, |
| 115 NetLog::EventType expected_event, | 113 NetLog::EventType expected_event, |
| 116 NetLog::EventPhase expected_phase) { | 114 NetLog::EventPhase expected_phase) { |
| 117 size_t i = 0; | 115 size_t i = 0; |
| 118 for (; i < entries.size(); ++i) { | 116 for (; i < entries.size(); ++i) { |
| 119 const NetLog::Entry& entry = entries[i]; | 117 const CapturingNetLog::Entry& entry = entries[i]; |
| 120 if (entry.type == NetLog::Entry::TYPE_EVENT && | 118 if (entry.type == expected_event && |
| 121 entry.event.type == expected_event && | 119 entry.phase == expected_phase) |
| 122 entry.event.phase == expected_phase) | |
| 123 break; | 120 break; |
| 124 } | 121 } |
| 125 EXPECT_LT(i, entries.size()); | 122 EXPECT_LT(i, entries.size()); |
| 126 EXPECT_GE(i, min_index); | 123 EXPECT_GE(i, min_index); |
| 127 return i; | 124 return i; |
| 128 } | 125 } |
| 129 | 126 |
| 130 } // namespace net | 127 } // namespace net |
| 131 | 128 |
| 132 #endif // NET_BASE_NET_LOG_UNITTEST_H_ | 129 #endif // NET_BASE_NET_LOG_UNITTEST_H_ |
| OLD | NEW |