forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_loop_impl_unittests.cc
43 lines (32 loc) · 1.32 KB
/
message_loop_impl_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#define FML_USED_ON_EMBEDDER
#include "flutter/fml/message_loop_impl.h"
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/time/time_point.h"
#include "gtest/gtest.h"
#define TIMESENSITIVE(x) TimeSensitiveTest_##x
TEST(MessageLoopImpl, TIMESENSITIVE(WakeUpTimersAreSingletons)) {
auto loop_impl = fml::MessageLoopImpl::Create();
const auto t1 = fml::TimeDelta::FromMilliseconds(10);
const auto t2 = fml::TimeDelta::FromMilliseconds(30);
const auto begin = fml::TimePoint::Now();
// Register a task scheduled in the future. This schedules a WakeUp call on
// the MessageLoopImpl with that fml::TimePoint.
loop_impl->PostTask(
[&]() {
auto delta = fml::TimePoint::Now() - begin;
auto ms = delta.ToMillisecondsF();
ASSERT_GE(ms, 20);
ASSERT_LE(ms, 40);
loop_impl->Terminate();
},
begin + t1);
// Call WakeUp manually to change the WakeUp time further in the future. If
// the timer is correctly set up to be rearmed instead of a task being
// scheduled for each WakeUp, the above task will be executed at t2 instead of
// t1 now.
loop_impl->WakeUp(begin + t2);
loop_impl->Run();
}