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 { | |
26 notifier_.reset(); | |
27 task_runner_ = NULL; | |
28 } | |
29 | |
30 void Notify() { ++notification_count_; } | |
31 | |
32 int NotificationCount() const { return notification_count_; } | |
33 | |
34 void ResetNotificationCount() { notification_count_ = 0; } | |
35 | |
36 void RunUntilIdle() { | |
37 run_loop_ = make_scoped_ptr(new base::RunLoop); | |
38 task_runner_->PostTask(FROM_HERE, run_loop_->QuitClosure()); | |
39 run_loop_->Run(); | |
reveman
2014/05/21 18:08:31
I think you can replace all this with:
base::RunLo
vmpstr
2014/05/21 18:54:54
Done.
| |
40 } | |
41 | |
42 protected: | |
43 int notification_count_; | |
44 scoped_ptr<UniqueNotifier> notifier_; | |
45 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
46 scoped_ptr<base::RunLoop> run_loop_; | |
47 }; | |
48 | |
49 TEST_F(UniqueNotifierTest, Schedule) { | |
50 notifier_ = make_scoped_ptr(new UniqueNotifier( | |
reveman
2014/05/21 18:08:31
Can you put this on the stack instead and remove U
vmpstr
2014/05/21 18:54:54
Done.
| |
51 task_runner_.get(), | |
52 base::Bind(&UniqueNotifierTest::Notify, base::Unretained(this)))); | |
53 | |
54 EXPECT_EQ(0, NotificationCount()); | |
55 | |
56 // Basic schedule should result in a run. | |
57 notifier_->Schedule(); | |
58 | |
59 RunUntilIdle(); | |
60 EXPECT_EQ(1, NotificationCount()); | |
61 | |
62 // Multiple schedules should only result in one run. | |
63 for (int i = 0; i < 5; ++i) | |
64 notifier_->Schedule(); | |
65 | |
66 RunUntilIdle(); | |
67 EXPECT_EQ(2, NotificationCount()); | |
68 | |
69 // Schedule and notifier going away should not result in any runs. | |
70 notifier_->Schedule(); | |
reveman
2014/05/21 19:42:45
I liked this part of test. Could you keep it in la
| |
71 notifier_.reset(); | |
72 | |
73 RunUntilIdle(); | |
74 EXPECT_EQ(2, NotificationCount()); | |
75 } | |
76 | |
77 } // namespace | |
78 } // namespace cc | |
OLD | NEW |