Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/chromeos/login/user.h" | 8 #include "chrome/browser/chromeos/login/user.h" |
| 9 #include "chrome/browser/chromeos/login/user_manager.h" | 9 #include "chrome/browser/chromeos/login/user_manager.h" |
| 10 #include "chrome/browser/extensions/api/networking_private/networking_private_pr ocess_client.h" | |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/policy/browser_policy_connector.h" | 12 #include "chrome/browser/policy/browser_policy_connector.h" |
| 12 #include "chrome/browser/policy/external_data_fetcher.h" | 13 #include "chrome/browser/policy/external_data_fetcher.h" |
| 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 14 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
| 15 #include "chrome/browser/policy/policy_types.h" | 16 #include "chrome/browser/policy/policy_types.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/api/networking_private.h" | |
| 17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 18 | 20 |
| 21 #if defined(ENABLE_EXTENSIONS) && defined(OS_CHROMEOS) || defined(OS_WIN) | |
|
tbarzic
2013/10/18 21:28:03
you should exclude the file in gypi file instead o
| |
| 22 | |
| 19 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 20 #include "chromeos/chromeos_switches.h" | 24 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/dbus/cryptohome_client.h" | 25 #include "chromeos/dbus/cryptohome_client.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/shill_device_client.h" | 27 #include "chromeos/dbus/shill_device_client.h" |
| 24 #include "chromeos/dbus/shill_manager_client.h" | 28 #include "chromeos/dbus/shill_manager_client.h" |
| 25 #include "chromeos/dbus/shill_profile_client.h" | 29 #include "chromeos/dbus/shill_profile_client.h" |
| 26 #include "chromeos/dbus/shill_service_client.h" | 30 #include "chromeos/dbus/shill_service_client.h" |
| 27 #include "chromeos/dbus/shill_stub_helper.h" | 31 #include "chromeos/dbus/shill_stub_helper.h" |
| 28 #include "chromeos/network/onc/onc_utils.h" | 32 #include "chromeos/network/onc/onc_utils.h" |
| 29 #include "components/onc/onc_constants.h" | 33 #include "components/onc/onc_constants.h" |
| 30 #include "policy/policy_constants.h" | 34 #include "policy/policy_constants.h" |
| 31 #include "third_party/cros_system_api/dbus/service_constants.h" | 35 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 32 #endif // OS_CHROMEOS | 36 #endif // OS_CHROMEOS |
|
tbarzic
2013/10/18 21:28:03
add a blank line here
mef
2013/10/20 15:59:34
Done.
| |
| 33 using testing::AnyNumber; | 37 using testing::AnyNumber; |
| 34 using testing::Return; | 38 using testing::Return; |
| 35 using testing::_; | 39 using testing::_; |
| 40 using extensions::api::networking_private::VerificationProperties; | |
| 36 | 41 |
| 37 namespace chromeos { | 42 namespace extensions { |
|
tbarzic
2013/10/18 21:28:03
while you're here, put everything in an anonymous
mef
2013/10/20 15:59:34
Done.
| |
| 38 | 43 |
| 39 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 40 const char kUser1ProfilePath[] = "/profile/user1/shill"; | 45 const char kUser1ProfilePath[] = "/profile/user1/shill"; |
| 41 #endif // defined(OS_CHROMEOS) | 46 #endif // defined(OS_CHROMEOS) |
| 42 | 47 |
| 43 | 48 |
| 44 class ExtensionNetworkingPrivateApiTest : | 49 class ExtensionNetworkingPrivateApiTest : |
| 45 public ExtensionApiTest, | 50 public ExtensionApiTest, |
| 46 public testing::WithParamInterface<bool> { | 51 public testing::WithParamInterface<bool> { |
| 47 public: | 52 public: |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 218 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 214 ExtensionApiTest::SetUpCommandLine(command_line); | 219 ExtensionApiTest::SetUpCommandLine(command_line); |
| 215 // Whitelist the extension ID of the test extension. | 220 // Whitelist the extension ID of the test extension. |
| 216 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, | 221 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, |
| 217 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 222 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| 218 } | 223 } |
| 219 | 224 |
| 220 virtual void SetUpOnMainThread() OVERRIDE { | 225 virtual void SetUpOnMainThread() OVERRIDE { |
| 221 ExtensionApiTest::SetUpOnMainThread(); | 226 ExtensionApiTest::SetUpOnMainThread(); |
| 222 content::RunAllPendingInMessageLoop(); | 227 content::RunAllPendingInMessageLoop(); |
| 228 base::DictionaryValue mock_parameters; | |
| 229 process_client_ = | |
| 230 extensions::NetworkingPrivateProcessClient::GetForProfile(profile()); | |
| 231 // Prevent shutdown between calls. | |
| 232 process_client_->AddMessageCallbacks(); | |
| 233 // Use Mocks WiFiService to test plumbing. | |
| 234 process_client_->UseMocks(mock_parameters, new CryptoVerifyMock()); | |
|
tbarzic
2013/10/18 21:28:03
I'd rename UseMocks to SetupForTest and add logic
mef
2013/10/20 15:59:34
Done.
| |
| 223 } | 235 } |
| 236 | |
| 237 // Mock Verify* methods implementation to satisfy expectations of | |
| 238 // networking_private_apitest. | |
| 239 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, | |
| 240 // and update networking_private_apitest to use and expect valid data. | |
| 241 // That will eliminate the need for mock implementation. | |
| 242 class CryptoVerifyMock : public NetworkingPrivateProcessClient::CryptoVerify { | |
|
tbarzic
2013/10/18 21:28:03
move this to anonymous namespace
mef
2013/10/20 15:59:34
Done.
| |
| 243 virtual bool VerifyDestination( | |
| 244 const VerificationProperties& properties) OVERRIDE { | |
| 245 return true; | |
| 246 } | |
| 247 | |
| 248 virtual bool VerifyAndEncryptData(const VerificationProperties& properties, | |
| 249 const std::string& plain_data, | |
| 250 std::string* encoded_data) OVERRIDE { | |
| 251 *encoded_data = "encrypted_data"; | |
| 252 return true; | |
| 253 } | |
| 254 }; | |
| 255 | |
| 256 scoped_refptr<extensions::NetworkingPrivateProcessClient> process_client_; | |
| 224 #endif // OS_CHROMEOS | 257 #endif // OS_CHROMEOS |
| 225 | 258 |
| 226 protected: | 259 protected: |
| 227 policy::MockConfigurationPolicyProvider provider_; | 260 policy::MockConfigurationPolicyProvider provider_; |
| 228 std::string userhash_; | 261 std::string userhash_; |
| 229 }; | 262 }; |
| 230 | 263 |
| 231 // Place each subtest into a separate browser test so that the stub networking | 264 // Place each subtest into a separate browser test so that the stub networking |
| 232 // library state is reset for each subtest run. This way they won't affect each | 265 // library state is reset for each subtest run. This way they won't affect each |
| 233 // other. | 266 // other. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 249 StartDisconnectNonexistent) { | 282 StartDisconnectNonexistent) { |
| 250 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; | 283 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; |
| 251 } | 284 } |
| 252 | 285 |
| 253 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 286 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 254 StartGetPropertiesNonexistent) { | 287 StartGetPropertiesNonexistent) { |
| 255 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) | 288 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) |
| 256 << message_; | 289 << message_; |
| 257 } | 290 } |
| 258 | 291 |
| 259 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) { | |
| 260 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; | |
| 261 } | |
| 262 | |
| 263 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { | 292 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { |
| 264 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; | 293 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; |
| 265 } | 294 } |
| 266 | 295 |
| 267 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 296 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 268 GetVisibleNetworksWifi) { | 297 GetVisibleNetworksWifi) { |
| 269 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; | 298 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; |
| 270 } | 299 } |
| 271 | 300 |
| 272 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { | 301 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { |
| 273 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; | 302 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; |
| 274 } | 303 } |
| 275 | 304 |
| 276 // Properties are filtered and translated through | 305 // Properties are filtered and translated through |
| 277 // ShillToONCTranslator::TranslateWiFiWithState | 306 // ShillToONCTranslator::TranslateWiFiWithState |
| 278 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) { | 307 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) { |
| 279 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; | 308 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; |
| 280 } | 309 } |
| 281 | 310 |
| 282 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) { | 311 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) { |
| 283 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; | 312 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; |
| 284 } | 313 } |
| 285 | 314 |
| 286 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) { | 315 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) { |
| 287 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; | 316 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; |
| 288 } | 317 } |
| 289 | 318 |
| 290 #if defined(OS_CHROMEOS) | 319 #if defined(OS_CHROMEOS) |
| 320 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) { | |
| 321 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; | |
| 322 } | |
| 323 | |
| 291 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { | 324 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { |
| 292 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; | 325 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; |
| 293 } | 326 } |
| 294 | 327 |
| 295 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 328 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 296 GetManagedProperties) { | 329 GetManagedProperties) { |
| 297 ShillServiceClient::TestInterface* service_test = | 330 ShillServiceClient::TestInterface* service_test = |
| 298 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 331 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 299 const std::string uidata_blob = | 332 const std::string uidata_blob = |
| 300 "{ \"user_settings\": {" | 333 "{ \"user_settings\": {" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 | 408 |
| 376 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 409 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 377 VerifyAndEncryptData) { | 410 VerifyAndEncryptData) { |
| 378 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; | 411 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; |
| 379 } | 412 } |
| 380 | 413 |
| 381 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, | 414 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, |
| 382 ExtensionNetworkingPrivateApiTest, | 415 ExtensionNetworkingPrivateApiTest, |
| 383 testing::Bool()); | 416 testing::Bool()); |
| 384 | 417 |
| 385 } // namespace chromeos | 418 } // namespace extensions |
| 419 | |
| 420 #endif // defined(ENABLE_EXTENSIONS) && defined(OS_CHROMEOS) || defined(OS_WIN) | |
| 421 | |
| OLD | NEW |