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

Unified Diff: third_party/WebKit/Source/core/dom/IdleDeadlineTest.cpp

Issue 2516493002: requestIdleCallback: Yield for high priority work (Closed)
Patch Set: Added a test Created 4 years, 1 month 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
Index: third_party/WebKit/Source/core/dom/IdleDeadlineTest.cpp
diff --git a/third_party/WebKit/Source/core/dom/IdleDeadlineTest.cpp b/third_party/WebKit/Source/core/dom/IdleDeadlineTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c1c66ab62dc0f67bc44e7eb37ceb2988a491e8a5
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/IdleDeadlineTest.cpp
@@ -0,0 +1,74 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/IdleDeadline.h"
+
+#include "platform/testing/TestingPlatformSupport.h"
+#include "public/platform/Platform.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "wtf/CurrentTime.h"
+
+namespace blink {
+namespace {
+
+class MockScheduler final : public TestingPlatformMockScheduler {
+ public:
+ MockScheduler() {}
+ ~MockScheduler() override {}
+ bool shouldYieldForHighPriorityWork() override { return true; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockScheduler);
+};
+
+class MockThread final : public WebThread {
+ public:
+ MockThread() {}
+ ~MockThread() override {}
+ bool isCurrentThread() const override { return true; }
+ WebScheduler* scheduler() const override { return &m_scheduler; }
+
+ private:
+ mutable MockScheduler m_scheduler;
+ DISALLOW_COPY_AND_ASSIGN(MockThread);
+};
+
+class MockPlatform : public TestingPlatformSupport {
+ public:
+ MockPlatform() {}
+ ~MockPlatform() override {}
+ WebThread* currentThread() override { return &m_thread; }
+
+ private:
+ MockThread m_thread;
+ DISALLOW_COPY_AND_ASSIGN(MockPlatform);
+};
+
+} // namespace
+
+TEST(IdleDeadline, deadlineInFuture) {
+ setTimeFunctionsForTesting([] { return 1.0; });
+ IdleDeadline* deadline =
+ IdleDeadline::create(1.25, IdleDeadline::CallbackType::CalledWhenIdle);
+ // Note: the deadline is computed with reduced resolution.
+ EXPECT_FLOAT_EQ(249.995, deadline->timeRemaining());
+}
+
+TEST(IdleDeadline, deadlineInPast) {
+ setTimeFunctionsForTesting([] { return 1.0; });
+ IdleDeadline* deadline =
+ IdleDeadline::create(0.75, IdleDeadline::CallbackType::CalledWhenIdle);
+ EXPECT_FLOAT_EQ(0, deadline->timeRemaining());
+}
+
+TEST(IdleDeadline, yieldForHighPriorityWork) {
+ MockPlatform platform;
+
+ setTimeFunctionsForTesting([] { return 1.0; });
+ IdleDeadline* deadline =
+ IdleDeadline::create(1.25, IdleDeadline::CallbackType::CalledWhenIdle);
+ EXPECT_FLOAT_EQ(0, deadline->timeRemaining());
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698