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

Side by Side 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 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/dom/IdleDeadline.h"
6
7 #include "platform/testing/TestingPlatformSupport.h"
8 #include "public/platform/Platform.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/CurrentTime.h"
11
12 namespace blink {
13 namespace {
14
15 class MockScheduler final : public TestingPlatformMockScheduler {
16 public:
17 MockScheduler() {}
18 ~MockScheduler() override {}
19 bool shouldYieldForHighPriorityWork() override { return true; }
20
21 private:
22 DISALLOW_COPY_AND_ASSIGN(MockScheduler);
23 };
24
25 class MockThread final : public WebThread {
26 public:
27 MockThread() {}
28 ~MockThread() override {}
29 bool isCurrentThread() const override { return true; }
30 WebScheduler* scheduler() const override { return &m_scheduler; }
31
32 private:
33 mutable MockScheduler m_scheduler;
34 DISALLOW_COPY_AND_ASSIGN(MockThread);
35 };
36
37 class MockPlatform : public TestingPlatformSupport {
38 public:
39 MockPlatform() {}
40 ~MockPlatform() override {}
41 WebThread* currentThread() override { return &m_thread; }
42
43 private:
44 MockThread m_thread;
45 DISALLOW_COPY_AND_ASSIGN(MockPlatform);
46 };
47
48 } // namespace
49
50 TEST(IdleDeadline, deadlineInFuture) {
51 setTimeFunctionsForTesting([] { return 1.0; });
52 IdleDeadline* deadline =
53 IdleDeadline::create(1.25, IdleDeadline::CallbackType::CalledWhenIdle);
54 // Note: the deadline is computed with reduced resolution.
55 EXPECT_FLOAT_EQ(249.995, deadline->timeRemaining());
56 }
57
58 TEST(IdleDeadline, deadlineInPast) {
59 setTimeFunctionsForTesting([] { return 1.0; });
60 IdleDeadline* deadline =
61 IdleDeadline::create(0.75, IdleDeadline::CallbackType::CalledWhenIdle);
62 EXPECT_FLOAT_EQ(0, deadline->timeRemaining());
63 }
64
65 TEST(IdleDeadline, yieldForHighPriorityWork) {
66 MockPlatform platform;
67
68 setTimeFunctionsForTesting([] { return 1.0; });
69 IdleDeadline* deadline =
70 IdleDeadline::create(1.25, IdleDeadline::CallbackType::CalledWhenIdle);
71 EXPECT_FLOAT_EQ(0, deadline->timeRemaining());
72 }
73
74 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698