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_LOAD_LOG_UNITTEST_H_ | 5 #ifndef NET_BASE_LOAD_LOG_UNITTEST_H_ |
6 #define NET_BASE_LOAD_LOG_UNITTEST_H_ | 6 #define NET_BASE_LOAD_LOG_UNITTEST_H_ |
7 | 7 |
| 8 #include <cstddef> |
8 #include "net/base/load_log.h" | 9 #include "net/base/load_log.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace net { | 12 namespace net { |
12 | 13 |
13 // Create a timestamp with internal value of |t| milliseconds from the epoch. | 14 // Create a timestamp with internal value of |t| milliseconds from the epoch. |
14 inline base::TimeTicks MakeTime(int t) { | 15 inline base::TimeTicks MakeTime(int t) { |
15 base::TimeTicks ticks; // initialized to 0. | 16 base::TimeTicks ticks; // initialized to 0. |
16 ticks += base::TimeDelta::FromMilliseconds(t); | 17 ticks += base::TimeDelta::FromMilliseconds(t); |
17 return ticks; | 18 return ticks; |
(...skipping 15 matching lines...) Expand all Loading... |
33 // Same as above, but without an expectation for the timestamp. | 34 // Same as above, but without an expectation for the timestamp. |
34 inline void ExpectLogContains(const LoadLog* log, | 35 inline void ExpectLogContains(const LoadLog* log, |
35 size_t i, | 36 size_t i, |
36 LoadLog::EventType expected_event, | 37 LoadLog::EventType expected_event, |
37 LoadLog::EventPhase expected_phase) { | 38 LoadLog::EventPhase expected_phase) { |
38 ASSERT_LT(i, log->events().size()); | 39 ASSERT_LT(i, log->events().size()); |
39 EXPECT_EQ(expected_event, log->events()[i].type); | 40 EXPECT_EQ(expected_event, log->events()[i].type); |
40 EXPECT_EQ(expected_phase, log->events()[i].phase); | 41 EXPECT_EQ(expected_phase, log->events()[i].phase); |
41 } | 42 } |
42 | 43 |
| 44 inline ::testing::AssertionResult LogContains( |
| 45 const LoadLog& log, |
| 46 int i, // Negative indices are reverse indices. |
| 47 LoadLog::EventType expected_event, |
| 48 LoadLog::EventPhase expected_phase) { |
| 49 // Negative indices are reverse indices. |
| 50 size_t j = (i < 0) ? log.events().size() + i : i; |
| 51 if (j >= log.events().size()) |
| 52 return ::testing::AssertionFailure() << j << " is out of bounds."; |
| 53 if (expected_event != log.events()[j].type) { |
| 54 return ::testing::AssertionFailure() |
| 55 << "Actual event: " << LoadLog::EventTypeToString(log.events()[j].type) |
| 56 << ". Expected event: " << LoadLog::EventTypeToString(expected_event) |
| 57 << "."; |
| 58 } |
| 59 if (expected_phase != log.events()[j].phase) { |
| 60 return ::testing::AssertionFailure() |
| 61 << "Actual phase: " << log.events()[j].phase |
| 62 << ". Expected phase: " << expected_phase << "."; |
| 63 } |
| 64 return ::testing::AssertionSuccess(); |
| 65 } |
| 66 |
43 } // namespace net | 67 } // namespace net |
44 | 68 |
45 #endif // NET_BASE_LOAD_LOG_UNITTEST_H_ | 69 #endif // NET_BASE_LOAD_LOG_UNITTEST_H_ |
OLD | NEW |