| 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 | |
| 7 #include <map> | 6 #include <map> |
| 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/extensions/extension_apitest.h" | 15 #include "chrome/browser/extensions/extension_apitest.h" |
| 16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
| 17 #include "components/onc/onc_constants.h" | 17 #include "components/onc/onc_constants.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kFailure[] = "Failure"; | 35 const char kFailure[] = "Failure"; |
| 36 const char kSuccess[] = "Success"; | 36 const char kSuccess[] = "Success"; |
| 37 const char kGuid[] = "SOME_GUID"; | 37 const char kGuid[] = "SOME_GUID"; |
| 38 | 38 |
| 39 class TestDelegate : public NetworkingPrivateDelegate { | 39 class TestDelegate : public NetworkingPrivateDelegate { |
| 40 public: | 40 public: |
| 41 explicit TestDelegate(scoped_ptr<VerifyDelegate> verify_delegate) | 41 explicit TestDelegate(scoped_ptr<VerifyDelegate> verify_delegate) |
| 42 : NetworkingPrivateDelegate(verify_delegate.Pass()), fail_(false) {} | 42 : NetworkingPrivateDelegate(std::move(verify_delegate)), fail_(false) {} |
| 43 | 43 |
| 44 ~TestDelegate() override {} | 44 ~TestDelegate() override {} |
| 45 | 45 |
| 46 // Asynchronous methods | 46 // Asynchronous methods |
| 47 void GetProperties(const std::string& guid, | 47 void GetProperties(const std::string& guid, |
| 48 const DictionaryCallback& success_callback, | 48 const DictionaryCallback& success_callback, |
| 49 const FailureCallback& failure_callback) override { | 49 const FailureCallback& failure_callback) override { |
| 50 DictionaryResult(guid, success_callback, failure_callback); | 50 DictionaryResult(guid, success_callback, failure_callback); |
| 51 } | 51 } |
| 52 | 52 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 const FailureCallback& failure_callback) override { | 90 const FailureCallback& failure_callback) override { |
| 91 if (fail_) { | 91 if (fail_) { |
| 92 failure_callback.Run(kFailure); | 92 failure_callback.Run(kFailure); |
| 93 } else { | 93 } else { |
| 94 scoped_ptr<base::ListValue> result(new base::ListValue); | 94 scoped_ptr<base::ListValue> result(new base::ListValue); |
| 95 scoped_ptr<base::DictionaryValue> network(new base::DictionaryValue); | 95 scoped_ptr<base::DictionaryValue> network(new base::DictionaryValue); |
| 96 network->SetString(::onc::network_config::kType, | 96 network->SetString(::onc::network_config::kType, |
| 97 ::onc::network_config::kEthernet); | 97 ::onc::network_config::kEthernet); |
| 98 network->SetString(::onc::network_config::kGUID, kGuid); | 98 network->SetString(::onc::network_config::kGUID, kGuid); |
| 99 result->Append(network.release()); | 99 result->Append(network.release()); |
| 100 success_callback.Run(result.Pass()); | 100 success_callback.Run(std::move(result)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 void StartConnect(const std::string& guid, | 104 void StartConnect(const std::string& guid, |
| 105 const VoidCallback& success_callback, | 105 const VoidCallback& success_callback, |
| 106 const FailureCallback& failure_callback) override { | 106 const FailureCallback& failure_callback) override { |
| 107 VoidResult(success_callback, failure_callback); | 107 VoidResult(success_callback, failure_callback); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void StartDisconnect(const std::string& guid, | 110 void StartDisconnect(const std::string& guid, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 VoidResult(success_callback, failure_callback); | 158 VoidResult(success_callback, failure_callback); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Synchronous methods | 161 // Synchronous methods |
| 162 scoped_ptr<base::ListValue> GetEnabledNetworkTypes() override { | 162 scoped_ptr<base::ListValue> GetEnabledNetworkTypes() override { |
| 163 scoped_ptr<base::ListValue> result; | 163 scoped_ptr<base::ListValue> result; |
| 164 if (!fail_) { | 164 if (!fail_) { |
| 165 result.reset(new base::ListValue); | 165 result.reset(new base::ListValue); |
| 166 result->AppendString(::onc::network_config::kEthernet); | 166 result->AppendString(::onc::network_config::kEthernet); |
| 167 } | 167 } |
| 168 return result.Pass(); | 168 return result; |
| 169 } | 169 } |
| 170 | 170 |
| 171 scoped_ptr<DeviceStateList> GetDeviceStateList() override { | 171 scoped_ptr<DeviceStateList> GetDeviceStateList() override { |
| 172 scoped_ptr<DeviceStateList> result; | 172 scoped_ptr<DeviceStateList> result; |
| 173 if (fail_) | 173 if (fail_) |
| 174 return result.Pass(); | 174 return result; |
| 175 result.reset(new DeviceStateList); | 175 result.reset(new DeviceStateList); |
| 176 scoped_ptr<api::networking_private::DeviceStateProperties> properties( | 176 scoped_ptr<api::networking_private::DeviceStateProperties> properties( |
| 177 new api::networking_private::DeviceStateProperties); | 177 new api::networking_private::DeviceStateProperties); |
| 178 properties->type = api::networking_private::NETWORK_TYPE_ETHERNET; | 178 properties->type = api::networking_private::NETWORK_TYPE_ETHERNET; |
| 179 properties->state = api::networking_private::DEVICE_STATE_TYPE_ENABLED; | 179 properties->state = api::networking_private::DEVICE_STATE_TYPE_ENABLED; |
| 180 result->push_back(properties.Pass()); | 180 result->push_back(std::move(properties)); |
| 181 return result.Pass(); | 181 return result; |
| 182 } | 182 } |
| 183 | 183 |
| 184 bool EnableNetworkType(const std::string& type) override { | 184 bool EnableNetworkType(const std::string& type) override { |
| 185 enabled_[type] = true; | 185 enabled_[type] = true; |
| 186 return !fail_; | 186 return !fail_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 bool DisableNetworkType(const std::string& type) override { | 189 bool DisableNetworkType(const std::string& type) override { |
| 190 disabled_[type] = true; | 190 disabled_[type] = true; |
| 191 return !fail_; | 191 return !fail_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 204 void DictionaryResult(const std::string& guid, | 204 void DictionaryResult(const std::string& guid, |
| 205 const DictionaryCallback& success_callback, | 205 const DictionaryCallback& success_callback, |
| 206 const FailureCallback& failure_callback) { | 206 const FailureCallback& failure_callback) { |
| 207 if (fail_) { | 207 if (fail_) { |
| 208 failure_callback.Run(kFailure); | 208 failure_callback.Run(kFailure); |
| 209 } else { | 209 } else { |
| 210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 210 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
| 211 result->SetString(::onc::network_config::kGUID, guid); | 211 result->SetString(::onc::network_config::kGUID, guid); |
| 212 result->SetString(::onc::network_config::kType, | 212 result->SetString(::onc::network_config::kType, |
| 213 ::onc::network_config::kWiFi); | 213 ::onc::network_config::kWiFi); |
| 214 success_callback.Run(result.Pass()); | 214 success_callback.Run(std::move(result)); |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 | 217 |
| 218 void StringResult(const StringCallback& success_callback, | 218 void StringResult(const StringCallback& success_callback, |
| 219 const FailureCallback& failure_callback) { | 219 const FailureCallback& failure_callback) { |
| 220 if (fail_) { | 220 if (fail_) { |
| 221 failure_callback.Run(kFailure); | 221 failure_callback.Run(kFailure); |
| 222 } else { | 222 } else { |
| 223 success_callback.Run(kSuccess); | 223 success_callback.Run(kSuccess); |
| 224 } | 224 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 DISALLOW_COPY_AND_ASSIGN(TestVerifyDelegate); | 286 DISALLOW_COPY_AND_ASSIGN(TestVerifyDelegate); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 class NetworkingPrivateApiTest : public ExtensionApiTest { | 289 class NetworkingPrivateApiTest : public ExtensionApiTest { |
| 290 public: | 290 public: |
| 291 NetworkingPrivateApiTest() { | 291 NetworkingPrivateApiTest() { |
| 292 if (!s_test_delegate_) { | 292 if (!s_test_delegate_) { |
| 293 TestVerifyDelegate* verify_delegate = new TestVerifyDelegate; | 293 TestVerifyDelegate* verify_delegate = new TestVerifyDelegate; |
| 294 scoped_ptr<NetworkingPrivateDelegate::VerifyDelegate> verify_delegate_ptr( | 294 scoped_ptr<NetworkingPrivateDelegate::VerifyDelegate> verify_delegate_ptr( |
| 295 verify_delegate); | 295 verify_delegate); |
| 296 s_test_delegate_ = new TestDelegate(verify_delegate_ptr.Pass()); | 296 s_test_delegate_ = new TestDelegate(std::move(verify_delegate_ptr)); |
| 297 verify_delegate->set_owner(s_test_delegate_); | 297 verify_delegate->set_owner(s_test_delegate_); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 static scoped_ptr<KeyedService> GetNetworkingPrivateDelegate( | 301 static scoped_ptr<KeyedService> GetNetworkingPrivateDelegate( |
| 302 content::BrowserContext* profile) { | 302 content::BrowserContext* profile) { |
| 303 CHECK(s_test_delegate_); | 303 CHECK(s_test_delegate_); |
| 304 return make_scoped_ptr(s_test_delegate_); | 304 return make_scoped_ptr(s_test_delegate_); |
| 305 } | 305 } |
| 306 | 306 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 EXPECT_FALSE(RunNetworkingSubtest("unlockCellularSim")) << message_; | 556 EXPECT_FALSE(RunNetworkingSubtest("unlockCellularSim")) << message_; |
| 557 } | 557 } |
| 558 | 558 |
| 559 IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetCellularSimState) { | 559 IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetCellularSimState) { |
| 560 EXPECT_FALSE(RunNetworkingSubtest("setCellularSimState")) << message_; | 560 EXPECT_FALSE(RunNetworkingSubtest("setCellularSimState")) << message_; |
| 561 } | 561 } |
| 562 | 562 |
| 563 #endif // defined(OS_WIN) | 563 #endif // defined(OS_WIN) |
| 564 | 564 |
| 565 } // namespace extensions | 565 } // namespace extensions |
| OLD | NEW |