blob: aabc42fa22a79407ac823bd3442cf9af57ac85d6 (
plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// Copyright 2011 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 "config.h"
#include "CCTimer.h"
#include "CCSchedulerTestCommon.h"
#include <gtest/gtest.h>
using namespace cc;
using namespace WebKitTests;
namespace {
class CCTimerTest : public testing::Test, public CCTimerClient {
public:
CCTimerTest() : m_flag(false) { }
void onTimerFired() { m_flag = true; }
protected:
FakeCCThread m_thread;
bool m_flag;
};
TEST_F(CCTimerTest, OneShot)
{
CCTimer timer(&m_thread, this);
timer.startOneShot(0.001);
EXPECT_TRUE(timer.isActive());
m_thread.runPendingTask();
EXPECT_FALSE(timer.isActive());
EXPECT_TRUE(m_flag);
EXPECT_FALSE(m_thread.hasPendingTask());
}
TEST_F(CCTimerTest, StopManually)
{
CCTimer timer(&m_thread, this);
timer.startOneShot(0.001);
EXPECT_TRUE(timer.isActive());
timer.stop();
EXPECT_FALSE(timer.isActive());
m_thread.runPendingTask();
EXPECT_FALSE(m_flag);
EXPECT_FALSE(m_thread.hasPendingTask());
}
TEST_F(CCTimerTest, StopByScope)
{
{
CCTimer timer(&m_thread, this);
timer.startOneShot(0.001);
}
m_thread.runPendingTask();
EXPECT_FALSE(m_flag);
}
}
|