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

Side by Side Diff: chromeos/dbus/shill_third_party_vpn_driver_client_unittest.cc

Issue 2314853004: Remove calls to deprecated MessageLoop methods in chromeos. (Closed)
Patch Set: Created 4 years, 3 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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/run_loop.h"
11 #include "chromeos/dbus/shill_client_unittest_base.h" 12 #include "chromeos/dbus/shill_client_unittest_base.h"
12 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" 13 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h"
13 #include "chromeos/dbus/shill_third_party_vpn_observer.h" 14 #include "chromeos/dbus/shill_third_party_vpn_observer.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 15 #include "third_party/cros_system_api/dbus/service_constants.h"
15 16
16 using testing::_; 17 using testing::_;
17 18
18 namespace chromeos { 19 namespace chromeos {
19 20
20 namespace { 21 namespace {
(...skipping 16 matching lines...) Expand all
37 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface, 38 : ShillClientUnittestBase(shill::kFlimflamThirdPartyVpnInterface,
38 dbus::ObjectPath(kExampleIPConfigPath)) {} 39 dbus::ObjectPath(kExampleIPConfigPath)) {}
39 40
40 void SetUp() override { 41 void SetUp() override {
41 ShillClientUnittestBase::SetUp(); 42 ShillClientUnittestBase::SetUp();
42 43
43 // Create a client with the mock bus. 44 // Create a client with the mock bus.
44 client_.reset(ShillThirdPartyVpnDriverClient::Create()); 45 client_.reset(ShillThirdPartyVpnDriverClient::Create());
45 client_->Init(mock_bus_.get()); 46 client_->Init(mock_bus_.get());
46 // Run the message loop to run the signal connection result callback. 47 // Run the message loop to run the signal connection result callback.
47 message_loop_.RunUntilIdle(); 48 base::RunLoop().RunUntilIdle();
48 } 49 }
49 50
50 void TearDown() override { ShillClientUnittestBase::TearDown(); } 51 void TearDown() override { ShillClientUnittestBase::TearDown(); }
51 52
52 MOCK_METHOD0(MockSuccess, void()); 53 MOCK_METHOD0(MockSuccess, void());
53 MOCK_METHOD1(MockSuccessWithWarning, void(const std::string& warning)); 54 MOCK_METHOD1(MockSuccessWithWarning, void(const std::string& warning));
54 static void Failure(const std::string& error_name, 55 static void Failure(const std::string& error_name,
55 const std::string& error_message) { 56 const std::string& error_message) {
56 ADD_FAILURE() << error_name << ": " << error_message; 57 ADD_FAILURE() << error_name << ": " << error_message;
57 } 58 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Check after removing the observer that there is no further signals. 116 // Check after removing the observer that there is no further signals.
116 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0); 117 EXPECT_CALL(observer, OnPlatformMessage(connected_state)).Times(0);
117 EXPECT_CALL(observer, OnPacketReceived(data_packet)).Times(0); 118 EXPECT_CALL(observer, OnPacketReceived(data_packet)).Times(0);
118 119
119 // Run the signal callback. 120 // Run the signal callback.
120 SendPlatformMessageSignal(&pmessage_signal); 121 SendPlatformMessageSignal(&pmessage_signal);
121 SendPacketReceievedSignal(&preceived_signal); 122 SendPacketReceievedSignal(&preceived_signal);
122 123
123 testing::Mock::VerifyAndClearExpectations(&observer); 124 testing::Mock::VerifyAndClearExpectations(&observer);
124 125
125 message_loop_.RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
126 } 127 }
127 128
128 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) { 129 TEST_F(ShillThirdPartyVpnDriverClientTest, SetParameters) {
129 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 130 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
130 dbus::MessageWriter writer(response.get()); 131 dbus::MessageWriter writer(response.get());
131 writer.AppendString(std::string("deadbeef")); 132 writer.AppendString(std::string("deadbeef"));
132 133
133 base::DictionaryValue parameters; 134 base::DictionaryValue parameters;
134 const std::string kAddress("1.1.1.1"); 135 const std::string kAddress("1.1.1.1");
135 parameters.SetStringWithoutPathExpansion( 136 parameters.SetStringWithoutPathExpansion(
136 shill::kAddressParameterThirdPartyVpn, kAddress); 137 shill::kAddressParameterThirdPartyVpn, kAddress);
137 138
138 EXPECT_CALL(*this, MockSuccessWithWarning(std::string("deadbeef"))).Times(1); 139 EXPECT_CALL(*this, MockSuccessWithWarning(std::string("deadbeef"))).Times(1);
139 140
140 PrepareForMethodCall( 141 PrepareForMethodCall(
141 shill::kSetParametersFunction, 142 shill::kSetParametersFunction,
142 base::Bind(&ExpectDictionaryValueArgument, &parameters, true), 143 base::Bind(&ExpectDictionaryValueArgument, &parameters, true),
143 response.get()); 144 response.get());
144 145
145 client_->SetParameters( 146 client_->SetParameters(
146 kExampleIPConfigPath, parameters, 147 kExampleIPConfigPath, parameters,
147 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccessWithWarning, 148 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccessWithWarning,
148 base::Unretained(this)), 149 base::Unretained(this)),
149 base::Bind(&Failure)); 150 base::Bind(&Failure));
150 151
151 message_loop_.RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
152 } 153 }
153 154
154 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) { 155 TEST_F(ShillThirdPartyVpnDriverClientTest, UpdateConnectionState) {
155 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 156 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
156 uint32_t connection_state = 2; 157 uint32_t connection_state = 2;
157 158
158 EXPECT_CALL(*this, MockSuccess()).Times(1); 159 EXPECT_CALL(*this, MockSuccess()).Times(1);
159 160
160 PrepareForMethodCall(shill::kUpdateConnectionStateFunction, 161 PrepareForMethodCall(shill::kUpdateConnectionStateFunction,
161 base::Bind(&ExpectUint32Argument, connection_state), 162 base::Bind(&ExpectUint32Argument, connection_state),
162 response.get()); 163 response.get());
163 164
164 client_->UpdateConnectionState( 165 client_->UpdateConnectionState(
165 kExampleIPConfigPath, connection_state, 166 kExampleIPConfigPath, connection_state,
166 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, 167 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
167 base::Unretained(this)), 168 base::Unretained(this)),
168 base::Bind(&Failure)); 169 base::Bind(&Failure));
169 170
170 message_loop_.RunUntilIdle(); 171 base::RunLoop().RunUntilIdle();
171 } 172 }
172 173
173 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) { 174 TEST_F(ShillThirdPartyVpnDriverClientTest, SendPacket) {
174 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); 175 std::unique_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
175 176
176 const size_t kPacketSize = 5; 177 const size_t kPacketSize = 5;
177 const std::vector<char> data(kPacketSize, 0); 178 const std::vector<char> data(kPacketSize, 0);
178 179
179 EXPECT_CALL(*this, MockSuccess()).Times(1); 180 EXPECT_CALL(*this, MockSuccess()).Times(1);
180 181
181 PrepareForMethodCall(shill::kSendPacketFunction, 182 PrepareForMethodCall(shill::kSendPacketFunction,
182 base::Bind(&ExpectArrayOfBytesArgument, 183 base::Bind(&ExpectArrayOfBytesArgument,
183 std::string(data.begin(), data.end())), 184 std::string(data.begin(), data.end())),
184 response.get()); 185 response.get());
185 186
186 client_->SendPacket( 187 client_->SendPacket(
187 kExampleIPConfigPath, data, 188 kExampleIPConfigPath, data,
188 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess, 189 base::Bind(&ShillThirdPartyVpnDriverClientTest::MockSuccess,
189 base::Unretained(this)), 190 base::Unretained(this)),
190 base::Bind(&Failure)); 191 base::Bind(&Failure));
191 192
192 message_loop_.RunUntilIdle(); 193 base::RunLoop().RunUntilIdle();
193 } 194 }
194 195
195 } // namespace chromeos 196 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698