Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / callback_tracker_unittest.cc
blob8ebc3ea34e56f1899450602c8fd383c3254c27c7
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 "chrome/browser/sync_file_system/drive_backend/callback_tracker.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace sync_file_system {
10 namespace drive_backend {
12 namespace {
14 void Receiver(bool* called) {
15 DCHECK(called);
16 EXPECT_FALSE(*called);
17 *called = true;
20 } // namespace
22 TEST(CallbackTrackerTest, AbortAll) {
23 CallbackTracker tracker;
25 bool aborted = false;
26 bool invoked = false;
27 base::Closure callback = tracker.Register(base::Bind(&Receiver, &aborted),
28 base::Bind(&Receiver, &invoked));
29 tracker.AbortAll();
30 EXPECT_TRUE(aborted);
31 EXPECT_FALSE(invoked);
33 callback.Run();
34 EXPECT_TRUE(aborted);
35 EXPECT_FALSE(invoked);
38 TEST(CallbackTrackerTest, Invoke) {
39 CallbackTracker tracker;
41 bool aborted = false;
42 bool invoked = false;
43 base::Closure callback = tracker.Register(base::Bind(&Receiver, &aborted),
44 base::Bind(&Receiver, &invoked));
45 callback.Run();
46 EXPECT_FALSE(aborted);
47 EXPECT_TRUE(invoked);
49 // Second call should not do anything.
50 invoked = false;
51 callback.Run();
52 EXPECT_FALSE(invoked);
54 tracker.AbortAll();
55 EXPECT_FALSE(aborted);
58 } // namespace drive_backend
59 } // namespace sync_file_system