OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "base/debug/trace_event_synthetic_delay.h" | 5 #include "base/debug/trace_event_synthetic_delay.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace base { | 9 namespace base { |
10 namespace debug { | 10 namespace debug { |
(...skipping 23 matching lines...) Expand all Loading... |
34 TraceEventSyntheticDelay* ConfigureDelay(const char* name) { | 34 TraceEventSyntheticDelay* ConfigureDelay(const char* name) { |
35 TraceEventSyntheticDelay* delay = TraceEventSyntheticDelay::Lookup(name); | 35 TraceEventSyntheticDelay* delay = TraceEventSyntheticDelay::Lookup(name); |
36 delay->SetClock(this); | 36 delay->SetClock(this); |
37 delay->SetTargetDuration( | 37 delay->SetTargetDuration( |
38 base::TimeDelta::FromMilliseconds(kTargetDurationMs)); | 38 base::TimeDelta::FromMilliseconds(kTargetDurationMs)); |
39 return delay; | 39 return delay; |
40 } | 40 } |
41 | 41 |
42 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } | 42 void AdvanceTime(base::TimeDelta delta) { now_ += delta; } |
43 | 43 |
44 int TestFunction() { | 44 int64 TestFunction() { |
45 base::TimeTicks start = Now(); | 45 base::TimeTicks start = Now(); |
46 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } | 46 { TRACE_EVENT_SYNTHETIC_DELAY("test.Delay"); } |
47 return (Now() - start).InMilliseconds(); | 47 return (Now() - start).InMilliseconds(); |
48 } | 48 } |
49 | 49 |
50 int AsyncTestFunctionBegin() { | 50 int64 AsyncTestFunctionBegin() { |
51 base::TimeTicks start = Now(); | 51 base::TimeTicks start = Now(); |
52 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); } | 52 { TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("test.AsyncDelay"); } |
53 return (Now() - start).InMilliseconds(); | 53 return (Now() - start).InMilliseconds(); |
54 } | 54 } |
55 | 55 |
56 int AsyncTestFunctionEnd() { | 56 int64 AsyncTestFunctionEnd() { |
57 base::TimeTicks start = Now(); | 57 base::TimeTicks start = Now(); |
58 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); } | 58 { TRACE_EVENT_SYNTHETIC_DELAY_END("test.AsyncDelay"); } |
59 return (Now() - start).InMilliseconds(); | 59 return (Now() - start).InMilliseconds(); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 base::TimeTicks now_; | 63 base::TimeTicks now_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); | 65 DISALLOW_COPY_AND_ASSIGN(TraceEventSyntheticDelayTest); |
66 }; | 66 }; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 delay->EndParallel(end_times[0]); | 147 delay->EndParallel(end_times[0]); |
148 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); | 148 EXPECT_GE((Now() - start_time).InMilliseconds(), kTargetDurationMs); |
149 | 149 |
150 start_time = Now(); | 150 start_time = Now(); |
151 delay->EndParallel(end_times[1]); | 151 delay->EndParallel(end_times[1]); |
152 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); | 152 EXPECT_LT((Now() - start_time).InMilliseconds(), kShortDurationMs); |
153 } | 153 } |
154 | 154 |
155 } // namespace debug | 155 } // namespace debug |
156 } // namespace base | 156 } // namespace base |
OLD | NEW |