| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "cc/base/unique_notifier.h" | 10 #include "cc/base/unique_notifier.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 void ResetNotificationCount() { notification_count_ = 0; } | 26 void ResetNotificationCount() { notification_count_ = 0; } |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 int notification_count_; | 29 int notification_count_; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 TEST_F(UniqueNotifierTest, Schedule) { | 32 TEST_F(UniqueNotifierTest, Schedule) { |
| 33 { | 33 { |
| 34 UniqueNotifier notifier( | 34 UniqueNotifier notifier( |
| 35 base::MessageLoopProxy::current(), | 35 base::MessageLoopProxy::current().get(), |
| 36 base::Bind(&UniqueNotifierTest::Notify, base::Unretained(this))); | 36 base::Bind(&UniqueNotifierTest::Notify, base::Unretained(this))); |
| 37 | 37 |
| 38 EXPECT_EQ(0, NotificationCount()); | 38 EXPECT_EQ(0, NotificationCount()); |
| 39 | 39 |
| 40 // Basic schedule should result in a run. | 40 // Basic schedule should result in a run. |
| 41 notifier.Schedule(); | 41 notifier.Schedule(); |
| 42 | 42 |
| 43 base::RunLoop().RunUntilIdle(); | 43 base::RunLoop().RunUntilIdle(); |
| 44 EXPECT_EQ(1, NotificationCount()); | 44 EXPECT_EQ(1, NotificationCount()); |
| 45 | 45 |
| 46 // Multiple schedules should only result in one run. | 46 // Multiple schedules should only result in one run. |
| 47 for (int i = 0; i < 5; ++i) | 47 for (int i = 0; i < 5; ++i) |
| 48 notifier.Schedule(); | 48 notifier.Schedule(); |
| 49 | 49 |
| 50 base::RunLoop().RunUntilIdle(); | 50 base::RunLoop().RunUntilIdle(); |
| 51 EXPECT_EQ(2, NotificationCount()); | 51 EXPECT_EQ(2, NotificationCount()); |
| 52 | 52 |
| 53 notifier.Schedule(); | 53 notifier.Schedule(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Notifier went out of scope, so we don't expect to get a notification. | 56 // Notifier went out of scope, so we don't expect to get a notification. |
| 57 base::RunLoop().RunUntilIdle(); | 57 base::RunLoop().RunUntilIdle(); |
| 58 EXPECT_EQ(2, NotificationCount()); | 58 EXPECT_EQ(2, NotificationCount()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 } // namespace | 61 } // namespace |
| 62 } // namespace cc | 62 } // namespace cc |
| OLD | NEW |