Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: test/unittests/libplatform/default-platform-unittest.cc

Issue 1179153002: Add V8 platform API to call delayed task. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Provide empty body to enable roll in Chromium. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698