OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "base/bind.h" | |
6 #include "base/bind_helpers.h" | |
7 #include "base/message_loop/message_loop_proxy.h" | |
8 #include "base/run_loop.h" | |
9 #include "base/single_thread_task_runner.h" | |
10 #include "cc/base/unique_notifier.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace cc { | |
14 namespace { | |
15 | |
16 class UniqueNotifierTest : public testing::Test { | |
17 public: | |
18 UniqueNotifierTest() : notification_count_(0) {} | |
19 | |
20 virtual void SetUp() OVERRIDE { | |
21 task_runner_ = base::MessageLoopProxy::current(); | |
22 ResetNotificationCount(); | |
23 } | |
24 | |
25 virtual void TearDown() OVERRIDE { task_runner_ = NULL; } | |
26 | |
27 void Notify() { ++notification_count_; } | |
28 | |
29 int NotificationCount() const { return notification_count_; } | |
30 | |
31 void ResetNotificationCount() { notification_count_ = 0; } | |
32 | |
33 protected: | |
34 int notification_count_; | |
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
reveman
2014/05/21 19:42:45
nit: remove this and just use base::MessageLoopPro
| |
36 }; | |
37 | |
38 TEST_F(UniqueNotifierTest, Schedule) { | |
39 UniqueNotifier notifier( | |
40 task_runner_.get(), | |
41 base::Bind(&UniqueNotifierTest::Notify, base::Unretained(this))); | |
42 | |
43 EXPECT_EQ(0, NotificationCount()); | |
44 | |
45 // Basic schedule should result in a run. | |
46 notifier.Schedule(); | |
47 | |
48 base::RunLoop().RunUntilIdle(); | |
49 EXPECT_EQ(1, NotificationCount()); | |
50 | |
51 // Multiple schedules should only result in one run. | |
52 for (int i = 0; i < 5; ++i) | |
53 notifier.Schedule(); | |
54 | |
55 base::RunLoop().RunUntilIdle(); | |
56 EXPECT_EQ(2, NotificationCount()); | |
57 } | |
58 | |
59 } // namespace | |
60 } // namespace cc | |
OLD | NEW |