Revert of [Webapp Refactor] Remove remoting.SessionConnector. (patchset #3 id:60001...
[chromium-blink-merge.git] / cc / base / unique_notifier_unittest.cc
blob7b52512d6c700cde45cf7422e39f14eb1e54175f
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.
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "cc/base/unique_notifier.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
14 namespace {
16 class UniqueNotifierTest : public testing::Test {
17 public:
18 UniqueNotifierTest() : notification_count_(0) {}
20 void SetUp() override { ResetNotificationCount(); }
22 void Notify() { ++notification_count_; }
24 int NotificationCount() const { return notification_count_; }
26 void ResetNotificationCount() { notification_count_ = 0; }
28 protected:
29 int notification_count_;
32 TEST_F(UniqueNotifierTest, Schedule) {
34 UniqueNotifier notifier(
35 base::ThreadTaskRunnerHandle::Get().get(),
36 base::Bind(&UniqueNotifierTest::Notify, base::Unretained(this)));
38 EXPECT_EQ(0, NotificationCount());
40 // Basic schedule should result in a run.
41 notifier.Schedule();
43 base::RunLoop().RunUntilIdle();
44 EXPECT_EQ(1, NotificationCount());
46 // Multiple schedules should only result in one run.
47 for (int i = 0; i < 5; ++i)
48 notifier.Schedule();
50 base::RunLoop().RunUntilIdle();
51 EXPECT_EQ(2, NotificationCount());
53 notifier.Schedule();
56 // Notifier went out of scope, so we don't expect to get a notification.
57 base::RunLoop().RunUntilIdle();
58 EXPECT_EQ(2, NotificationCount());
61 } // namespace
62 } // namespace cc