Index: test/unittests/libplatform/default-platform-unittest.cc |
diff --git a/test/unittests/libplatform/default-platform-unittest.cc b/test/unittests/libplatform/default-platform-unittest.cc |
index d2c160e5587557c72c5c138e4a826784aaa4cdb9..ffa3199444eb4457017921bf9e622bf0a1c8ce70 100644 |
--- a/test/unittests/libplatform/default-platform-unittest.cc |
+++ b/test/unittests/libplatform/default-platform-unittest.cc |
@@ -19,6 +19,17 @@ struct MockTask : public Task { |
MOCK_METHOD0(Die, void()); |
}; |
+ |
+class DefaultPlatformWithMockTime : public DefaultPlatform { |
+ public: |
+ DefaultPlatformWithMockTime() : time_(0) {} |
+ double MonotonicallyIncreasingTime() override { return time_; } |
+ void IncreaseTime(double seconds) { time_ += seconds; } |
+ |
+ private: |
+ double time_; |
+}; |
+ |
} // namespace |
@@ -39,5 +50,66 @@ TEST(DefaultPlatformTest, PumpMessageLoop) { |
EXPECT_FALSE(platform.PumpMessageLoop(isolate)); |
} |
+ |
+TEST(DefaultPlatformTest, PumpMessageLoopDelayed) { |
+ InSequence s; |
+ |
+ int dummy; |
+ Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); |
+ |
+ DefaultPlatformWithMockTime platform; |
+ EXPECT_FALSE(platform.PumpMessageLoop(isolate)); |
+ |
+ StrictMock<MockTask>* task1 = new StrictMock<MockTask>; |
+ StrictMock<MockTask>* task2 = new StrictMock<MockTask>; |
+ platform.CallDelayedOnForegroundThread(isolate, task2, 100); |
+ platform.CallDelayedOnForegroundThread(isolate, task1, 10); |
+ |
+ EXPECT_FALSE(platform.PumpMessageLoop(isolate)); |
+ |
+ platform.IncreaseTime(11); |
+ EXPECT_CALL(*task1, Run()); |
+ EXPECT_CALL(*task1, Die()); |
+ EXPECT_TRUE(platform.PumpMessageLoop(isolate)); |
+ |
+ EXPECT_FALSE(platform.PumpMessageLoop(isolate)); |
+ |
+ platform.IncreaseTime(90); |
+ EXPECT_CALL(*task2, Run()); |
+ EXPECT_CALL(*task2, Die()); |
+ EXPECT_TRUE(platform.PumpMessageLoop(isolate)); |
+} |
+ |
+ |
+TEST(DefaultPlatformTest, PumpMessageLoopNoStarvation) { |
+ InSequence s; |
+ |
+ int dummy; |
+ Isolate* isolate = reinterpret_cast<Isolate*>(&dummy); |
+ |
+ DefaultPlatformWithMockTime platform; |
+ EXPECT_FALSE(platform.PumpMessageLoop(isolate)); |
+ |
+ StrictMock<MockTask>* task1 = new StrictMock<MockTask>; |
+ StrictMock<MockTask>* task2 = new StrictMock<MockTask>; |
+ StrictMock<MockTask>* task3 = new StrictMock<MockTask>; |
+ platform.CallOnForegroundThread(isolate, task1); |
+ platform.CallDelayedOnForegroundThread(isolate, task2, 10); |
+ platform.IncreaseTime(11); |
+ |
+ EXPECT_CALL(*task1, Run()); |
+ EXPECT_CALL(*task1, Die()); |
+ EXPECT_TRUE(platform.PumpMessageLoop(isolate)); |
+ |
+ platform.CallOnForegroundThread(isolate, task3); |
+ |
+ EXPECT_CALL(*task2, Run()); |
+ EXPECT_CALL(*task2, Die()); |
+ EXPECT_TRUE(platform.PumpMessageLoop(isolate)); |
+ EXPECT_CALL(*task3, Run()); |
+ EXPECT_CALL(*task3, Die()); |
+ EXPECT_TRUE(platform.PumpMessageLoop(isolate)); |
+} |
+ |
} // namespace platform |
} // namespace v8 |