Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/callback_helper_unittest.cc

Issue 259503004: [SyncFS] Refine callback helpers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/sync_file_system/drive_backend/callback_helper.h" 5 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace sync_file_system { 11 namespace sync_file_system {
12 namespace drive_backend { 12 namespace drive_backend {
13 13
14 namespace { 14 namespace {
15 15
16 void SimpleCallback(bool* called, int) { 16 void SimpleCallback(bool* called, int) {
17 ASSERT_TRUE(called); 17 ASSERT_TRUE(called);
18 EXPECT_FALSE(*called); 18 EXPECT_FALSE(*called);
19 *called = true; 19 *called = true;
20 } 20 }
21 21
22 void CallbackWithPassed(bool* called, scoped_ptr<int>) { 22 void CallbackWithPassed(bool* called, scoped_ptr<int>) {
23 ASSERT_TRUE(called); 23 ASSERT_TRUE(called);
24 EXPECT_FALSE(*called); 24 EXPECT_FALSE(*called);
25 *called = true; 25 *called = true;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 TEST(DriveBackendCallbackHelperTest, CreateRelayedCallbackTest) { 30 TEST(DriveBackendCallbackHelperTest, RelayCallbackTest) {
31 base::MessageLoop message_loop; 31 base::MessageLoop message_loop;
32 32
33 bool called = false; 33 bool called = false;
34 CreateRelayedCallback(base::Bind(&SimpleCallback, &called)).Run(0); 34 RelayCallbackToTaskRunner(
peria 2014/04/24 07:30:05 callback_helper.h has 2 interface templates, Relay
peria 2014/04/24 07:30:05 For example, following combination may detect it.
tzik 2014/04/24 07:58:34 I think testing all possible specialization for ea
35 base::MessageLoopProxy::current(),
36 FROM_HERE,
37 base::Bind(&SimpleCallback, &called, 0)).Run();
35 EXPECT_FALSE(called); 38 EXPECT_FALSE(called);
36 base::RunLoop().RunUntilIdle(); 39 base::RunLoop().RunUntilIdle();
37 EXPECT_TRUE(called); 40 EXPECT_TRUE(called);
38 41
39 called = false; 42 called = false;
40 CreateRelayedCallback( 43 RelayCallbackToCurrentThread(
44 FROM_HERE,
45 base::Bind(&SimpleCallback, &called)).Run(0);
46 EXPECT_FALSE(called);
47 base::RunLoop().RunUntilIdle();
48 EXPECT_TRUE(called);
49
50 called = false;
51 RelayCallbackToCurrentThread(
52 FROM_HERE,
41 base::Bind(&CallbackWithPassed, &called)) 53 base::Bind(&CallbackWithPassed, &called))
42 .Run(scoped_ptr<int>(new int)); 54 .Run(scoped_ptr<int>(new int));
43 EXPECT_FALSE(called); 55 EXPECT_FALSE(called);
44 base::RunLoop().RunUntilIdle(); 56 base::RunLoop().RunUntilIdle();
45 EXPECT_TRUE(called); 57 EXPECT_TRUE(called);
46 } 58 }
47 59
48 } // namespace drive_backend 60 } // namespace drive_backend
49 } // namespace sync_file_system 61 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698