OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "remoting/protocol/protocol_mock_objects.h" | 5 #include "remoting/protocol/protocol_mock_objects.h" |
6 | 6 |
7 namespace remoting { | 7 namespace remoting { |
8 namespace protocol { | 8 namespace protocol { |
9 | 9 |
10 MockConnectionToClient::MockConnectionToClient( | 10 MockConnectionToClient::MockConnectionToClient( |
(...skipping 30 matching lines...) Expand all Loading... | |
41 MockVideoStub::~MockVideoStub() {} | 41 MockVideoStub::~MockVideoStub() {} |
42 | 42 |
43 MockSession::MockSession() {} | 43 MockSession::MockSession() {} |
44 | 44 |
45 MockSession::~MockSession() {} | 45 MockSession::~MockSession() {} |
46 | 46 |
47 MockSessionManager::MockSessionManager() {} | 47 MockSessionManager::MockSessionManager() {} |
48 | 48 |
49 MockSessionManager::~MockSessionManager() {} | 49 MockSessionManager::~MockSessionManager() {} |
50 | 50 |
51 MockPairingRegistryDelegate::MockPairingRegistryDelegate() { | 51 MockPairingRegistryDelegate::MockPairingRegistryDelegate() |
52 : run_save_callback_automatically_(true) { | |
52 } | 53 } |
53 | 54 |
54 MockPairingRegistryDelegate::~MockPairingRegistryDelegate() { | 55 MockPairingRegistryDelegate::~MockPairingRegistryDelegate() { |
55 } | 56 } |
56 | 57 |
57 void MockPairingRegistryDelegate::Save( | 58 void MockPairingRegistryDelegate::Save( |
58 const std::string& pairings_json, | 59 const std::string& pairings_json, |
59 const PairingRegistry::SaveCallback& callback) { | 60 const PairingRegistry::SaveCallback& callback) { |
61 EXPECT_TRUE(load_callback_.is_null()); | |
62 EXPECT_TRUE(save_callback_.is_null()); | |
63 if (run_save_callback_automatically_) { | |
64 SetPairingsJsonAndRunCallback(pairings_json, callback); | |
65 } else { | |
66 save_callback_ = base::Bind( | |
67 &MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback, | |
68 base::Unretained(this), pairings_json, callback); | |
69 } | |
70 } | |
71 | |
72 void MockPairingRegistryDelegate::SetPairingsJsonAndRunCallback( | |
73 const std::string& pairings_json, | |
74 const PairingRegistry::SaveCallback& callback) { | |
60 pairings_json_ = pairings_json; | 75 pairings_json_ = pairings_json; |
61 if (!callback.is_null()) { | 76 if (!callback.is_null()) { |
62 callback.Run(true); | 77 callback.Run(true); |
63 } | 78 } |
64 } | 79 } |
65 | 80 |
66 void MockPairingRegistryDelegate::Load( | 81 void MockPairingRegistryDelegate::Load( |
67 const PairingRegistry::LoadCallback& callback) { | 82 const PairingRegistry::LoadCallback& callback) { |
68 load_callback_ = base::Bind(base::Bind(callback), pairings_json_); | 83 EXPECT_TRUE(load_callback_.is_null()); |
84 EXPECT_TRUE(save_callback_.is_null()); | |
85 load_callback_ = base::Bind(callback, pairings_json_); | |
69 } | 86 } |
70 | 87 |
71 void MockPairingRegistryDelegate::RunCallback() { | 88 void MockPairingRegistryDelegate::RunCallback() { |
72 DCHECK(!load_callback_.is_null()); | 89 if (!load_callback_.is_null()) { |
Lambros
2013/07/19 01:54:21
You only need one if..elif..else.. chain here. In
Jamie
2013/07/19 02:10:13
Done.
| |
73 load_callback_.Run(); | 90 EXPECT_TRUE(save_callback_.is_null()); |
74 load_callback_.Reset(); | 91 } else if (!save_callback_.is_null()) { |
92 EXPECT_TRUE(load_callback_.is_null()); | |
93 } else { | |
94 ADD_FAILURE() << "RunCallback called without any callbacks set."; | |
95 } | |
96 if (!load_callback_.is_null()) { | |
97 base::Closure load_callback = load_callback_; | |
98 load_callback_.Reset(); | |
99 load_callback.Run(); | |
100 } else { | |
101 base::Closure save_callback = save_callback_; | |
102 save_callback_.Reset(); | |
103 save_callback.Run(); | |
104 } | |
75 } | 105 } |
76 | 106 |
77 } // namespace protocol | 107 } // namespace protocol |
78 } // namespace remoting | 108 } // namespace remoting |
OLD | NEW |