OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/libplatform/default-platform.h" | 5 #include "src/libplatform/default-platform.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 6 #include "testing/gmock/include/gmock/gmock.h" |
7 | 7 |
8 using testing::InSequence; | 8 using testing::InSequence; |
9 using testing::StrictMock; | 9 using testing::StrictMock; |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace platform { | 12 namespace platform { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 struct MockTask : public Task { | 16 struct MockTask : public Task { |
17 virtual ~MockTask() { Die(); } | 17 virtual ~MockTask() { Die(); } |
18 MOCK_METHOD0(Run, void()); | 18 MOCK_METHOD0(Run, void()); |
19 MOCK_METHOD0(Die, void()); | 19 MOCK_METHOD0(Die, void()); |
20 }; | 20 }; |
21 | 21 |
| 22 struct MockIdleTask : public IdleTask { |
| 23 virtual ~MockIdleTask() { Die(); } |
| 24 MOCK_METHOD1(Run, void(double deadline_in_seconds)); |
| 25 MOCK_METHOD0(Die, void()); |
| 26 }; |
22 | 27 |
23 class DefaultPlatformWithMockTime : public DefaultPlatform { | 28 class DefaultPlatformWithMockTime : public DefaultPlatform { |
24 public: | 29 public: |
25 DefaultPlatformWithMockTime() : time_(0) {} | 30 DefaultPlatformWithMockTime() : time_(0) {} |
26 double MonotonicallyIncreasingTime() override { return time_; } | 31 double MonotonicallyIncreasingTime() override { return time_; } |
27 void IncreaseTime(double seconds) { time_ += seconds; } | 32 void IncreaseTime(double seconds) { time_ += seconds; } |
28 | 33 |
29 private: | 34 private: |
30 double time_; | 35 double time_; |
31 }; | 36 }; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); | 124 Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); |
120 | 125 |
121 { | 126 { |
122 DefaultPlatformWithMockTime platform; | 127 DefaultPlatformWithMockTime platform; |
123 StrictMock<MockTask>* task = new StrictMock<MockTask>; | 128 StrictMock<MockTask>* task = new StrictMock<MockTask>; |
124 platform.CallDelayedOnForegroundThread(isolate, task, 10); | 129 platform.CallDelayedOnForegroundThread(isolate, task, 10); |
125 EXPECT_CALL(*task, Die()); | 130 EXPECT_CALL(*task, Die()); |
126 } | 131 } |
127 } | 132 } |
128 | 133 |
| 134 TEST(DefaultPlatformTest, RunIdleTasks) { |
| 135 InSequence s; |
| 136 |
| 137 int dummy; |
| 138 Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); |
| 139 |
| 140 DefaultPlatformWithMockTime platform; |
| 141 |
| 142 StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>; |
| 143 platform.CallIdleOnForegroundThread(isolate, task); |
| 144 EXPECT_CALL(*task, Run(42.0 + 23.0)); |
| 145 EXPECT_CALL(*task, Die()); |
| 146 platform.IncreaseTime(23.0); |
| 147 platform.RunIdleTasks(isolate, 42.0); |
| 148 } |
| 149 |
| 150 TEST(DefaultPlatformTest, PendingIdleTasksAreDestroyedOnShutdown) { |
| 151 InSequence s; |
| 152 |
| 153 int dummy; |
| 154 Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); |
| 155 |
| 156 { |
| 157 DefaultPlatformWithMockTime platform; |
| 158 StrictMock<MockIdleTask>* task = new StrictMock<MockIdleTask>; |
| 159 platform.CallIdleOnForegroundThread(isolate, task); |
| 160 EXPECT_CALL(*task, Die()); |
| 161 } |
| 162 } |
129 | 163 |
130 } // namespace platform | 164 } // namespace platform |
131 } // namespace v8 | 165 } // namespace v8 |
OLD | NEW |