OLD | NEW |
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 |
6 #include <map> | 7 #include <map> |
| 8 #include <memory> |
7 #include <utility> | 9 #include <utility> |
8 #include <vector> | 10 #include <vector> |
9 | 11 |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/ptr_util.h" |
14 #include "build/build_config.h" | 16 #include "build/build_config.h" |
15 #include "chrome/browser/extensions/extension_apitest.h" | 17 #include "chrome/browser/extensions/extension_apitest.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
17 #include "components/onc/onc_constants.h" | 19 #include "components/onc/onc_constants.h" |
18 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
19 #include "extensions/browser/api/networking_private/networking_private_delegate.
h" | 21 #include "extensions/browser/api/networking_private/networking_private_delegate.
h" |
20 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" | 22 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" |
21 #include "extensions/common/switches.h" | 23 #include "extensions/common/switches.h" |
22 | 24 |
23 namespace extensions { | 25 namespace extensions { |
24 | 26 |
25 // This tests just the interface for the networkingPrivate API, i.e. it ensures | 27 // This tests just the interface for the networkingPrivate API, i.e. it ensures |
26 // that the delegate methods are called as expected. | 28 // that the delegate methods are called as expected. |
27 | 29 |
28 // The implementations (which differ significantly between chromeos and | 30 // The implementations (which differ significantly between chromeos and |
29 // windows/mac) are tested independently in | 31 // windows/mac) are tested independently in |
30 // networking_private_[chromeos|service_client]_apitest.cc. | 32 // networking_private_[chromeos|service_client]_apitest.cc. |
31 // See also crbug.com/460119. | 33 // See also crbug.com/460119. |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 const char kFailure[] = "Failure"; | 37 const char kFailure[] = "Failure"; |
36 const char kSuccess[] = "Success"; | 38 const char kSuccess[] = "Success"; |
37 const char kGuid[] = "SOME_GUID"; | 39 const char kGuid[] = "SOME_GUID"; |
38 | 40 |
39 class TestDelegate : public NetworkingPrivateDelegate { | 41 class TestDelegate : public NetworkingPrivateDelegate { |
40 public: | 42 public: |
41 explicit TestDelegate(scoped_ptr<VerifyDelegate> verify_delegate) | 43 explicit TestDelegate(std::unique_ptr<VerifyDelegate> verify_delegate) |
42 : NetworkingPrivateDelegate(std::move(verify_delegate)), fail_(false) {} | 44 : NetworkingPrivateDelegate(std::move(verify_delegate)), fail_(false) {} |
43 | 45 |
44 ~TestDelegate() override {} | 46 ~TestDelegate() override {} |
45 | 47 |
46 // Asynchronous methods | 48 // Asynchronous methods |
47 void GetProperties(const std::string& guid, | 49 void GetProperties(const std::string& guid, |
48 const DictionaryCallback& success_callback, | 50 const DictionaryCallback& success_callback, |
49 const FailureCallback& failure_callback) override { | 51 const FailureCallback& failure_callback) override { |
50 DictionaryResult(guid, success_callback, failure_callback); | 52 DictionaryResult(guid, success_callback, failure_callback); |
51 } | 53 } |
52 | 54 |
53 void GetManagedProperties(const std::string& guid, | 55 void GetManagedProperties(const std::string& guid, |
54 const DictionaryCallback& success_callback, | 56 const DictionaryCallback& success_callback, |
55 const FailureCallback& failure_callback) override { | 57 const FailureCallback& failure_callback) override { |
56 DictionaryResult(guid, success_callback, failure_callback); | 58 DictionaryResult(guid, success_callback, failure_callback); |
57 } | 59 } |
58 | 60 |
59 void GetState(const std::string& guid, | 61 void GetState(const std::string& guid, |
60 const DictionaryCallback& success_callback, | 62 const DictionaryCallback& success_callback, |
61 const FailureCallback& failure_callback) override { | 63 const FailureCallback& failure_callback) override { |
62 DictionaryResult(guid, success_callback, failure_callback); | 64 DictionaryResult(guid, success_callback, failure_callback); |
63 } | 65 } |
64 | 66 |
65 void SetProperties(const std::string& guid, | 67 void SetProperties(const std::string& guid, |
66 scoped_ptr<base::DictionaryValue> properties, | 68 std::unique_ptr<base::DictionaryValue> properties, |
67 const VoidCallback& success_callback, | 69 const VoidCallback& success_callback, |
68 const FailureCallback& failure_callback) override { | 70 const FailureCallback& failure_callback) override { |
69 VoidResult(success_callback, failure_callback); | 71 VoidResult(success_callback, failure_callback); |
70 } | 72 } |
71 | 73 |
72 void CreateNetwork(bool shared, | 74 void CreateNetwork(bool shared, |
73 scoped_ptr<base::DictionaryValue> properties, | 75 std::unique_ptr<base::DictionaryValue> properties, |
74 const StringCallback& success_callback, | 76 const StringCallback& success_callback, |
75 const FailureCallback& failure_callback) override { | 77 const FailureCallback& failure_callback) override { |
76 StringResult(success_callback, failure_callback); | 78 StringResult(success_callback, failure_callback); |
77 } | 79 } |
78 | 80 |
79 void ForgetNetwork(const std::string& guid, | 81 void ForgetNetwork(const std::string& guid, |
80 const VoidCallback& success_callback, | 82 const VoidCallback& success_callback, |
81 const FailureCallback& failure_callback) override { | 83 const FailureCallback& failure_callback) override { |
82 VoidResult(success_callback, failure_callback); | 84 VoidResult(success_callback, failure_callback); |
83 } | 85 } |
84 | 86 |
85 void GetNetworks(const std::string& network_type, | 87 void GetNetworks(const std::string& network_type, |
86 bool configured_only, | 88 bool configured_only, |
87 bool visible_only, | 89 bool visible_only, |
88 int limit, | 90 int limit, |
89 const NetworkListCallback& success_callback, | 91 const NetworkListCallback& success_callback, |
90 const FailureCallback& failure_callback) override { | 92 const FailureCallback& failure_callback) override { |
91 if (fail_) { | 93 if (fail_) { |
92 failure_callback.Run(kFailure); | 94 failure_callback.Run(kFailure); |
93 } else { | 95 } else { |
94 scoped_ptr<base::ListValue> result(new base::ListValue); | 96 std::unique_ptr<base::ListValue> result(new base::ListValue); |
95 scoped_ptr<base::DictionaryValue> network(new base::DictionaryValue); | 97 std::unique_ptr<base::DictionaryValue> network(new base::DictionaryValue); |
96 network->SetString(::onc::network_config::kType, | 98 network->SetString(::onc::network_config::kType, |
97 ::onc::network_config::kEthernet); | 99 ::onc::network_config::kEthernet); |
98 network->SetString(::onc::network_config::kGUID, kGuid); | 100 network->SetString(::onc::network_config::kGUID, kGuid); |
99 result->Append(network.release()); | 101 result->Append(network.release()); |
100 success_callback.Run(std::move(result)); | 102 success_callback.Run(std::move(result)); |
101 } | 103 } |
102 } | 104 } |
103 | 105 |
104 void StartConnect(const std::string& guid, | 106 void StartConnect(const std::string& guid, |
105 const VoidCallback& success_callback, | 107 const VoidCallback& success_callback, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 void SetCellularSimState(const std::string& guid, | 154 void SetCellularSimState(const std::string& guid, |
153 bool require_pin, | 155 bool require_pin, |
154 const std::string& current_pin, | 156 const std::string& current_pin, |
155 const std::string& new_pin, | 157 const std::string& new_pin, |
156 const VoidCallback& success_callback, | 158 const VoidCallback& success_callback, |
157 const FailureCallback& failure_callback) override { | 159 const FailureCallback& failure_callback) override { |
158 VoidResult(success_callback, failure_callback); | 160 VoidResult(success_callback, failure_callback); |
159 } | 161 } |
160 | 162 |
161 // Synchronous methods | 163 // Synchronous methods |
162 scoped_ptr<base::ListValue> GetEnabledNetworkTypes() override { | 164 std::unique_ptr<base::ListValue> GetEnabledNetworkTypes() override { |
163 scoped_ptr<base::ListValue> result; | 165 std::unique_ptr<base::ListValue> result; |
164 if (!fail_) { | 166 if (!fail_) { |
165 result.reset(new base::ListValue); | 167 result.reset(new base::ListValue); |
166 result->AppendString(::onc::network_config::kEthernet); | 168 result->AppendString(::onc::network_config::kEthernet); |
167 } | 169 } |
168 return result; | 170 return result; |
169 } | 171 } |
170 | 172 |
171 scoped_ptr<DeviceStateList> GetDeviceStateList() override { | 173 std::unique_ptr<DeviceStateList> GetDeviceStateList() override { |
172 scoped_ptr<DeviceStateList> result; | 174 std::unique_ptr<DeviceStateList> result; |
173 if (fail_) | 175 if (fail_) |
174 return result; | 176 return result; |
175 result.reset(new DeviceStateList); | 177 result.reset(new DeviceStateList); |
176 scoped_ptr<api::networking_private::DeviceStateProperties> properties( | 178 std::unique_ptr<api::networking_private::DeviceStateProperties> properties( |
177 new api::networking_private::DeviceStateProperties); | 179 new api::networking_private::DeviceStateProperties); |
178 properties->type = api::networking_private::NETWORK_TYPE_ETHERNET; | 180 properties->type = api::networking_private::NETWORK_TYPE_ETHERNET; |
179 properties->state = api::networking_private::DEVICE_STATE_TYPE_ENABLED; | 181 properties->state = api::networking_private::DEVICE_STATE_TYPE_ENABLED; |
180 result->push_back(std::move(properties)); | 182 result->push_back(std::move(properties)); |
181 return result; | 183 return result; |
182 } | 184 } |
183 | 185 |
184 bool EnableNetworkType(const std::string& type) override { | 186 bool EnableNetworkType(const std::string& type) override { |
185 enabled_[type] = true; | 187 enabled_[type] = true; |
186 return !fail_; | 188 return !fail_; |
(...skipping 13 matching lines...) Expand all Loading... |
200 bool GetEnabled(const std::string& type) { return enabled_[type]; } | 202 bool GetEnabled(const std::string& type) { return enabled_[type]; } |
201 bool GetDisabled(const std::string& type) { return disabled_[type]; } | 203 bool GetDisabled(const std::string& type) { return disabled_[type]; } |
202 size_t GetScanRequested() { return scan_requested_.size(); } | 204 size_t GetScanRequested() { return scan_requested_.size(); } |
203 | 205 |
204 void DictionaryResult(const std::string& guid, | 206 void DictionaryResult(const std::string& guid, |
205 const DictionaryCallback& success_callback, | 207 const DictionaryCallback& success_callback, |
206 const FailureCallback& failure_callback) { | 208 const FailureCallback& failure_callback) { |
207 if (fail_) { | 209 if (fail_) { |
208 failure_callback.Run(kFailure); | 210 failure_callback.Run(kFailure); |
209 } else { | 211 } else { |
210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 212 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
211 result->SetString(::onc::network_config::kGUID, guid); | 213 result->SetString(::onc::network_config::kGUID, guid); |
212 result->SetString(::onc::network_config::kType, | 214 result->SetString(::onc::network_config::kType, |
213 ::onc::network_config::kWiFi); | 215 ::onc::network_config::kWiFi); |
214 success_callback.Run(std::move(result)); | 216 success_callback.Run(std::move(result)); |
215 } | 217 } |
216 } | 218 } |
217 | 219 |
218 void StringResult(const StringCallback& success_callback, | 220 void StringResult(const StringCallback& success_callback, |
219 const FailureCallback& failure_callback) { | 221 const FailureCallback& failure_callback) { |
220 if (fail_) { | 222 if (fail_) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 TestDelegate* owner_; | 286 TestDelegate* owner_; |
285 | 287 |
286 DISALLOW_COPY_AND_ASSIGN(TestVerifyDelegate); | 288 DISALLOW_COPY_AND_ASSIGN(TestVerifyDelegate); |
287 }; | 289 }; |
288 | 290 |
289 class NetworkingPrivateApiTest : public ExtensionApiTest { | 291 class NetworkingPrivateApiTest : public ExtensionApiTest { |
290 public: | 292 public: |
291 NetworkingPrivateApiTest() { | 293 NetworkingPrivateApiTest() { |
292 if (!s_test_delegate_) { | 294 if (!s_test_delegate_) { |
293 TestVerifyDelegate* verify_delegate = new TestVerifyDelegate; | 295 TestVerifyDelegate* verify_delegate = new TestVerifyDelegate; |
294 scoped_ptr<NetworkingPrivateDelegate::VerifyDelegate> verify_delegate_ptr( | 296 std::unique_ptr<NetworkingPrivateDelegate::VerifyDelegate> |
295 verify_delegate); | 297 verify_delegate_ptr(verify_delegate); |
296 s_test_delegate_ = new TestDelegate(std::move(verify_delegate_ptr)); | 298 s_test_delegate_ = new TestDelegate(std::move(verify_delegate_ptr)); |
297 verify_delegate->set_owner(s_test_delegate_); | 299 verify_delegate->set_owner(s_test_delegate_); |
298 } | 300 } |
299 } | 301 } |
300 | 302 |
301 static scoped_ptr<KeyedService> GetNetworkingPrivateDelegate( | 303 static std::unique_ptr<KeyedService> GetNetworkingPrivateDelegate( |
302 content::BrowserContext* profile) { | 304 content::BrowserContext* profile) { |
303 CHECK(s_test_delegate_); | 305 CHECK(s_test_delegate_); |
304 return make_scoped_ptr(s_test_delegate_); | 306 return base::WrapUnique(s_test_delegate_); |
305 } | 307 } |
306 | 308 |
307 void SetUpCommandLine(base::CommandLine* command_line) override { | 309 void SetUpCommandLine(base::CommandLine* command_line) override { |
308 ExtensionApiTest::SetUpCommandLine(command_line); | 310 ExtensionApiTest::SetUpCommandLine(command_line); |
309 // Whitelist the extension ID of the test extension. | 311 // Whitelist the extension ID of the test extension. |
310 command_line->AppendSwitchASCII( | 312 command_line->AppendSwitchASCII( |
311 extensions::switches::kWhitelistedExtensionID, | 313 extensions::switches::kWhitelistedExtensionID, |
312 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 314 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
313 } | 315 } |
314 | 316 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 EXPECT_FALSE(RunNetworkingSubtest("unlockCellularSim")) << message_; | 558 EXPECT_FALSE(RunNetworkingSubtest("unlockCellularSim")) << message_; |
557 } | 559 } |
558 | 560 |
559 IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetCellularSimState) { | 561 IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetCellularSimState) { |
560 EXPECT_FALSE(RunNetworkingSubtest("setCellularSimState")) << message_; | 562 EXPECT_FALSE(RunNetworkingSubtest("setCellularSimState")) << message_; |
561 } | 563 } |
562 | 564 |
563 #endif // defined(OS_WIN) | 565 #endif // defined(OS_WIN) |
564 | 566 |
565 } // namespace extensions | 567 } // namespace extensions |
OLD | NEW |