| 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/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chromeos/dbus/shill_profile_client.h" | 23 #include "chromeos/dbus/shill_profile_client.h" |
| 24 #include "chromeos/dbus/shill_service_client.h" | 24 #include "chromeos/dbus/shill_service_client.h" |
| 25 #include "chromeos/dbus/shill_stub_helper.h" | 25 #include "chromeos/dbus/shill_stub_helper.h" |
| 26 #include "chromeos/network/onc/onc_utils.h" | 26 #include "chromeos/network/onc/onc_utils.h" |
| 27 #include "components/onc/onc_constants.h" | 27 #include "components/onc/onc_constants.h" |
| 28 #include "components/policy/core/common/external_data_fetcher.h" | 28 #include "components/policy/core/common/external_data_fetcher.h" |
| 29 #include "components/policy/core/common/policy_map.h" | 29 #include "components/policy/core/common/policy_map.h" |
| 30 #include "components/policy/core/common/policy_types.h" | 30 #include "components/policy/core/common/policy_types.h" |
| 31 #include "policy/policy_constants.h" | 31 #include "policy/policy_constants.h" |
| 32 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 33 #endif // OS_CHROMEOS | 33 #else // !defined(OS_CHROMEOS) |
| 34 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client.h" |
| 35 #include "chrome/browser/extensions/api/networking_private/networking_private_se
rvice_client_factory.h" |
| 36 #include "components/wifi/wifi_service.h" |
| 37 #endif // defined(OS_CHROMEOS) |
| 34 | 38 |
| 35 using testing::Return; | 39 using testing::Return; |
| 36 using testing::_; | 40 using testing::_; |
| 37 | 41 |
| 38 namespace chromeos { | 42 #if defined(OS_CHROMEOS) |
| 43 using chromeos::CryptohomeClient; |
| 44 using chromeos::DBUS_METHOD_CALL_SUCCESS; |
| 45 using chromeos::DBusMethodCallStatus; |
| 46 using chromeos::DBusThreadManager; |
| 47 using chromeos::ShillDeviceClient; |
| 48 using chromeos::ShillManagerClient; |
| 49 using chromeos::ShillProfileClient; |
| 50 using chromeos::ShillServiceClient; |
| 51 #else // !defined(OS_CHROMEOS) |
| 52 using extensions::NetworkingPrivateServiceClientFactory; |
| 53 #endif // defined(OS_CHROMEOS) |
| 54 |
| 55 namespace { |
| 39 | 56 |
| 40 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 41 const char kUser1ProfilePath[] = "/profile/user1/shill"; | 58 const char kUser1ProfilePath[] = "/profile/user1/shill"; |
| 59 #else // !defined(OS_CHROMEOS) |
| 60 |
| 61 // Stub Verify* methods implementation to satisfy expectations of |
| 62 // networking_private_apitest. |
| 63 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, |
| 64 // and update networking_private_apitest to use and expect valid data. |
| 65 // That will eliminate the need for mock implementation. |
| 66 class CryptoVerifyStub |
| 67 : public extensions::NetworkingPrivateServiceClient::CryptoVerify { |
| 68 virtual void VerifyDestination(scoped_ptr<base::ListValue> args, |
| 69 bool* verified, |
| 70 std::string* error) OVERRIDE { |
| 71 *verified = true; |
| 72 } |
| 73 |
| 74 virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args, |
| 75 std::string* encoded_data, |
| 76 std::string* error) OVERRIDE { |
| 77 *encoded_data = "encrypted_data"; |
| 78 } |
| 79 }; |
| 42 #endif // defined(OS_CHROMEOS) | 80 #endif // defined(OS_CHROMEOS) |
| 43 | 81 |
| 44 class ExtensionNetworkingPrivateApiTest : | 82 class ExtensionNetworkingPrivateApiTest : |
| 45 public ExtensionApiTest, | 83 public ExtensionApiTest, |
| 46 public testing::WithParamInterface<bool> { | 84 public testing::WithParamInterface<bool> { |
| 47 public: | 85 public: |
| 48 bool RunNetworkingSubtest(const std::string& subtest) { | 86 bool RunNetworkingSubtest(const std::string& subtest) { |
| 49 return RunExtensionSubtest( | 87 return RunExtensionSubtest( |
| 50 "networking", "main.html?" + subtest, | 88 "networking", "main.html?" + subtest, |
| 51 kFlagEnableFileAccess | kFlagLoadAsComponent); | 89 kFlagEnableFileAccess | kFlagLoadAsComponent); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 71 | 109 |
| 72 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 110 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 73 ExtensionApiTest::SetUpCommandLine(command_line); | 111 ExtensionApiTest::SetUpCommandLine(command_line); |
| 74 // Whitelist the extension ID of the test extension. | 112 // Whitelist the extension ID of the test extension. |
| 75 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, | 113 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, |
| 76 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 114 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| 77 | 115 |
| 78 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI | 116 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI |
| 79 // uses the ProfileHelper to obtain the userhash crbug/238623. | 117 // uses the ProfileHelper to obtain the userhash crbug/238623. |
| 80 std::string login_user = | 118 std::string login_user = |
| 81 command_line->GetSwitchValueNative(switches::kLoginUser); | 119 command_line->GetSwitchValueNative(chromeos::switches::kLoginUser); |
| 82 std::string sanitized_user = CryptohomeClient::GetStubSanitizedUsername( | 120 std::string sanitized_user = CryptohomeClient::GetStubSanitizedUsername( |
| 83 login_user); | 121 login_user); |
| 84 command_line->AppendSwitchASCII(switches::kLoginProfile, sanitized_user); | 122 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 123 sanitized_user); |
| 85 if (GetParam()) | 124 if (GetParam()) |
| 86 command_line->AppendSwitch(::switches::kMultiProfiles); | 125 command_line->AppendSwitch(::switches::kMultiProfiles); |
| 87 } | 126 } |
| 88 | 127 |
| 89 void InitializeSanitizedUsername() { | 128 void InitializeSanitizedUsername() { |
| 90 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 129 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 91 chromeos::User* user = user_manager->GetActiveUser(); | 130 chromeos::User* user = user_manager->GetActiveUser(); |
| 92 CHECK(user); | 131 CHECK(user); |
| 93 std::string userhash; | 132 std::string userhash; |
| 94 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( | 133 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 125 shill::kTypeCellular, "stub_cellular_device1"); | 164 shill::kTypeCellular, "stub_cellular_device1"); |
| 126 | 165 |
| 127 const bool add_to_watchlist = true; | 166 const bool add_to_watchlist = true; |
| 128 const bool add_to_visible = true; | 167 const bool add_to_visible = true; |
| 129 service_test->AddService("stub_ethernet", "eth0", | 168 service_test->AddService("stub_ethernet", "eth0", |
| 130 shill::kTypeEthernet, shill::kStateOnline, | 169 shill::kTypeEthernet, shill::kStateOnline, |
| 131 add_to_visible, add_to_watchlist); | 170 add_to_visible, add_to_watchlist); |
| 132 service_test->SetServiceProperty( | 171 service_test->SetServiceProperty( |
| 133 "stub_ethernet", | 172 "stub_ethernet", |
| 134 shill::kProfileProperty, | 173 shill::kProfileProperty, |
| 135 base::StringValue(shill_stub_helper::kSharedProfilePath)); | 174 base::StringValue(chromeos::shill_stub_helper::kSharedProfilePath)); |
| 136 profile_test->AddService(shill_stub_helper::kSharedProfilePath, | 175 profile_test->AddService(chromeos::shill_stub_helper::kSharedProfilePath, |
| 137 "stub_ethernet"); | 176 "stub_ethernet"); |
| 138 | 177 |
| 139 service_test->AddService("stub_wifi1", "wifi1", | 178 service_test->AddService("stub_wifi1", "wifi1", |
| 140 shill::kTypeWifi, shill::kStateOnline, | 179 shill::kTypeWifi, shill::kStateOnline, |
| 141 add_to_visible, add_to_watchlist); | 180 add_to_visible, add_to_watchlist); |
| 142 service_test->SetServiceProperty("stub_wifi1", | 181 service_test->SetServiceProperty("stub_wifi1", |
| 143 shill::kSecurityProperty, | 182 shill::kSecurityProperty, |
| 144 base::StringValue(shill::kSecurityWep)); | 183 base::StringValue(shill::kSecurityWep)); |
| 145 service_test->SetServiceProperty("stub_wifi1", | 184 service_test->SetServiceProperty("stub_wifi1", |
| 146 shill::kProfileProperty, | 185 shill::kProfileProperty, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 content::RunAllPendingInMessageLoop(); | 250 content::RunAllPendingInMessageLoop(); |
| 212 } | 251 } |
| 213 #else // !defined(OS_CHROMEOS) | 252 #else // !defined(OS_CHROMEOS) |
| 214 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 253 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 215 ExtensionApiTest::SetUpCommandLine(command_line); | 254 ExtensionApiTest::SetUpCommandLine(command_line); |
| 216 // Whitelist the extension ID of the test extension. | 255 // Whitelist the extension ID of the test extension. |
| 217 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, | 256 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, |
| 218 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 257 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| 219 } | 258 } |
| 220 | 259 |
| 260 static BrowserContextKeyedService* |
| 261 CreateNetworkingPrivateServiceClient(content::BrowserContext* profile) { |
| 262 return new extensions::NetworkingPrivateServiceClient( |
| 263 wifi::WiFiService::CreateForTest(), |
| 264 new CryptoVerifyStub()); |
| 265 } |
| 266 |
| 221 virtual void SetUpOnMainThread() OVERRIDE { | 267 virtual void SetUpOnMainThread() OVERRIDE { |
| 222 ExtensionApiTest::SetUpOnMainThread(); | 268 ExtensionApiTest::SetUpOnMainThread(); |
| 223 content::RunAllPendingInMessageLoop(); | 269 content::RunAllPendingInMessageLoop(); |
| 270 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( |
| 271 profile(), |
| 272 &CreateNetworkingPrivateServiceClient); |
| 224 } | 273 } |
| 274 |
| 225 #endif // OS_CHROMEOS | 275 #endif // OS_CHROMEOS |
| 226 | 276 |
| 227 protected: | 277 protected: |
| 228 #if defined(OS_CHROMEOS) | 278 #if defined(OS_CHROMEOS) |
| 229 policy::MockConfigurationPolicyProvider provider_; | 279 policy::MockConfigurationPolicyProvider provider_; |
| 230 std::string userhash_; | 280 std::string userhash_; |
| 231 #endif | 281 #endif |
| 232 }; | 282 }; |
| 233 | 283 |
| 234 // Place each subtest into a separate browser test so that the stub networking | 284 // Place each subtest into a separate browser test so that the stub networking |
| (...skipping 17 matching lines...) Expand all Loading... |
| 252 StartDisconnectNonexistent) { | 302 StartDisconnectNonexistent) { |
| 253 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; | 303 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; |
| 254 } | 304 } |
| 255 | 305 |
| 256 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 306 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 257 StartGetPropertiesNonexistent) { | 307 StartGetPropertiesNonexistent) { |
| 258 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) | 308 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) |
| 259 << message_; | 309 << message_; |
| 260 } | 310 } |
| 261 | 311 |
| 262 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) { | |
| 263 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; | |
| 264 } | |
| 265 | |
| 266 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { | 312 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { |
| 267 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; | 313 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; |
| 268 } | 314 } |
| 269 | 315 |
| 270 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 316 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 271 GetVisibleNetworksWifi) { | 317 GetVisibleNetworksWifi) { |
| 272 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; | 318 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; |
| 273 } | 319 } |
| 274 | 320 |
| 275 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { | 321 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { |
| 276 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; | 322 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; |
| 277 } | 323 } |
| 278 | 324 |
| 279 // Properties are filtered and translated through | 325 // Properties are filtered and translated through |
| 280 // ShillToONCTranslator::TranslateWiFiWithState | 326 // ShillToONCTranslator::TranslateWiFiWithState |
| 281 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) { | 327 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetProperties) { |
| 282 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; | 328 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; |
| 283 } | 329 } |
| 284 | 330 |
| 285 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) { | 331 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetState) { |
| 286 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; | 332 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; |
| 287 } | 333 } |
| 288 | 334 |
| 289 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) { | 335 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, SetProperties) { |
| 290 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; | 336 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; |
| 291 } | 337 } |
| 292 | 338 |
| 293 #if defined(OS_CHROMEOS) | 339 #if defined(OS_CHROMEOS) |
| 340 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) { |
| 341 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; |
| 342 } |
| 343 |
| 294 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { | 344 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { |
| 295 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; | 345 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; |
| 296 } | 346 } |
| 297 | 347 |
| 298 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 348 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 299 GetManagedProperties) { | 349 GetManagedProperties) { |
| 300 ShillServiceClient::TestInterface* service_test = | 350 ShillServiceClient::TestInterface* service_test = |
| 301 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 351 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 302 const std::string uidata_blob = | 352 const std::string uidata_blob = |
| 303 "{ \"user_settings\": {" | 353 "{ \"user_settings\": {" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 | 428 |
| 379 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, | 429 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, |
| 380 VerifyAndEncryptData) { | 430 VerifyAndEncryptData) { |
| 381 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; | 431 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; |
| 382 } | 432 } |
| 383 | 433 |
| 384 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, | 434 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation, |
| 385 ExtensionNetworkingPrivateApiTest, | 435 ExtensionNetworkingPrivateApiTest, |
| 386 testing::Bool()); | 436 testing::Bool()); |
| 387 | 437 |
| 388 } // namespace chromeos | 438 } // namespace |
| 439 |
| OLD | NEW |