| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
| 7 #include "chrome/browser/chromeos/login/user.h" |
| 8 #include "chrome/browser/chromeos/login/user_manager.h" |
| 7 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" | 9 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
| 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 11 #include "chrome/browser/policy/policy_map.h" | 13 #include "chrome/browser/policy/policy_map.h" |
| 12 #include "chrome/browser/policy/policy_types.h" | 14 #include "chrome/browser/policy/policy_types.h" |
| 13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
| 18 #include "chromeos/dbus/cryptohome_client.h" |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
| 17 #include "chromeos/dbus/shill_device_client.h" | 20 #include "chromeos/dbus/shill_device_client.h" |
| 18 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
| 19 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
| 20 #include "chromeos/network/onc/onc_constants.h" | 23 #include "chromeos/network/onc/onc_constants.h" |
| 21 #include "chromeos/network/onc/onc_utils.h" | 24 #include "chromeos/network/onc/onc_utils.h" |
| 22 #include "policy/policy_constants.h" | 25 #include "policy/policy_constants.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 27 |
| 25 using testing::AnyNumber; | 28 using testing::AnyNumber; |
| 26 using testing::Return; | 29 using testing::Return; |
| 27 using testing::_; | 30 using testing::_; |
| 28 | 31 |
| 29 namespace chromeos { | 32 namespace chromeos { |
| 30 | 33 |
| 31 const char kUserProfilePath[] = "/profile/chronos/shill"; | 34 namespace { |
| 35 |
| 36 const char kUser1ProfilePath[] = "/profile/user1/shill"; |
| 37 |
| 38 void AssignString(std::string* out, |
| 39 DBusMethodCallStatus call_status, |
| 40 const std::string& result) { |
| 41 CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS); |
| 42 *out = result; |
| 43 } |
| 44 |
| 45 } // namespace |
| 32 | 46 |
| 33 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest { | 47 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest { |
| 34 public: | 48 public: |
| 35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 49 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 36 ExtensionApiTest::SetUpCommandLine(command_line); | 50 ExtensionApiTest::SetUpCommandLine(command_line); |
| 37 // Whitelist the extension ID of the test extension. | 51 // Whitelist the extension ID of the test extension. |
| 38 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, | 52 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, |
| 39 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 53 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| 40 command_line->AppendSwitch(switches::kUseNewNetworkConfigurationHandlers); | 54 command_line->AppendSwitch(switches::kUseNewNetworkConfigurationHandlers); |
| 55 |
| 56 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI |
| 57 // uses the ProfileHelper to obtain the userhash crbug/238623. |
| 58 std::string login_user = |
| 59 command_line->GetSwitchValueNative(switches::kLoginUser); |
| 60 // Do the same as CryptohomeClientStubImpl::GetSanitizedUsername |
| 61 std::string sanitized_user = login_user + "-profile"; |
| 62 command_line->AppendSwitchASCII(switches::kLoginProfile, sanitized_user); |
| 41 } | 63 } |
| 42 | 64 |
| 43 bool RunNetworkingSubtest(const std::string& subtest) { | 65 bool RunNetworkingSubtest(const std::string& subtest) { |
| 44 return RunExtensionSubtest( | 66 return RunExtensionSubtest( |
| 45 "networking", "main.html?" + subtest, | 67 "networking", "main.html?" + subtest, |
| 46 kFlagEnableFileAccess | kFlagLoadAsComponent); | 68 kFlagEnableFileAccess | kFlagLoadAsComponent); |
| 47 } | 69 } |
| 48 | 70 |
| 49 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 71 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 50 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 72 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 51 .WillRepeatedly(Return(true)); | 73 .WillRepeatedly(Return(true)); |
| 52 EXPECT_CALL(provider_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); | 74 EXPECT_CALL(provider_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); |
| 53 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 75 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 54 | 76 |
| 55 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 77 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 56 } | 78 } |
| 57 | 79 |
| 80 void InitializeSanitizedUsername() { |
| 81 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 82 chromeos::User* user = user_manager->GetActiveUser(); |
| 83 CHECK(user); |
| 84 std::string userhash; |
| 85 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( |
| 86 user->email(), |
| 87 base::Bind(&AssignString, &userhash_)); |
| 88 content::RunAllPendingInMessageLoop(); |
| 89 CHECK(!userhash_.empty()); |
| 90 } |
| 91 |
| 58 virtual void SetUpOnMainThread() OVERRIDE { | 92 virtual void SetUpOnMainThread() OVERRIDE { |
| 59 ExtensionApiTest::SetUpOnMainThread(); | 93 ExtensionApiTest::SetUpOnMainThread(); |
| 60 content::RunAllPendingInMessageLoop(); | 94 content::RunAllPendingInMessageLoop(); |
| 61 | 95 |
| 96 InitializeSanitizedUsername(); |
| 97 |
| 98 ShillDeviceClient::TestInterface* device_test = |
| 99 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 62 ShillProfileClient::TestInterface* profile_test = | 100 ShillProfileClient::TestInterface* profile_test = |
| 63 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 101 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 64 profile_test->AddProfile(kUserProfilePath); | 102 ShillServiceClient::TestInterface* service_test = |
| 103 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 65 | 104 |
| 66 g_browser_process->browser_policy_connector()-> | 105 g_browser_process->browser_policy_connector()-> |
| 67 GetNetworkConfigurationUpdater()->OnUserPolicyInitialized( | 106 GetNetworkConfigurationUpdater()->OnUserPolicyInitialized( |
| 68 false, "hash"); | 107 false, userhash_); |
| 69 ShillDeviceClient::TestInterface* device_test = | |
| 70 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | |
| 71 device_test->ClearDevices(); | 108 device_test->ClearDevices(); |
| 109 service_test->ClearServices(); |
| 110 |
| 111 // Sends a notification about the added profile. |
| 112 profile_test->AddProfile(kUser1ProfilePath, userhash_); |
| 113 |
| 72 device_test->AddDevice("/device/stub_wifi_device1", | 114 device_test->AddDevice("/device/stub_wifi_device1", |
| 73 flimflam::kTypeWifi, "stub_wifi_device1"); | 115 flimflam::kTypeWifi, "stub_wifi_device1"); |
| 74 device_test->AddDevice("/device/stub_cellular_device1", | 116 device_test->AddDevice("/device/stub_cellular_device1", |
| 75 flimflam::kTypeCellular, "stub_cellular_device1"); | 117 flimflam::kTypeCellular, "stub_cellular_device1"); |
| 76 | 118 |
| 77 ShillServiceClient::TestInterface* service_test = | |
| 78 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 79 service_test->ClearServices(); | |
| 80 const bool add_to_watchlist = true; | 119 const bool add_to_watchlist = true; |
| 81 service_test->AddService("stub_ethernet", "eth0", | 120 service_test->AddService("stub_ethernet", "eth0", |
| 82 flimflam::kTypeEthernet, flimflam::kStateOnline, | 121 flimflam::kTypeEthernet, flimflam::kStateOnline, |
| 83 add_to_watchlist); | 122 add_to_watchlist); |
| 84 | 123 |
| 85 service_test->AddService("stub_wifi1", "wifi1", | 124 service_test->AddService("stub_wifi1", "wifi1", |
| 86 flimflam::kTypeWifi, flimflam::kStateOnline, | 125 flimflam::kTypeWifi, flimflam::kStateOnline, |
| 87 add_to_watchlist); | 126 add_to_watchlist); |
| 88 service_test->SetServiceProperty("stub_wifi1", | 127 service_test->SetServiceProperty("stub_wifi1", |
| 89 flimflam::kSecurityProperty, | 128 flimflam::kSecurityProperty, |
| 90 base::StringValue(flimflam::kSecurityWep)); | 129 base::StringValue(flimflam::kSecurityWep)); |
| 91 | 130 |
| 92 service_test->AddService("stub_wifi2", "wifi2_PSK", | 131 service_test->AddService("stub_wifi2", "wifi2_PSK", |
| 93 flimflam::kTypeWifi, flimflam::kStateIdle, | 132 flimflam::kTypeWifi, flimflam::kStateIdle, |
| 94 add_to_watchlist); | 133 add_to_watchlist); |
| 95 service_test->SetServiceProperty("stub_wifi2", | 134 service_test->SetServiceProperty("stub_wifi2", |
| 96 flimflam::kGuidProperty, | 135 flimflam::kGuidProperty, |
| 97 base::StringValue("stub_wifi2")); | 136 base::StringValue("stub_wifi2")); |
| 98 service_test->SetServiceProperty("stub_wifi2", | 137 service_test->SetServiceProperty("stub_wifi2", |
| 99 flimflam::kSecurityProperty, | 138 flimflam::kSecurityProperty, |
| 100 base::StringValue(flimflam::kSecurityPsk)); | 139 base::StringValue(flimflam::kSecurityPsk)); |
| 101 service_test->SetServiceProperty("stub_wifi2", | 140 service_test->SetServiceProperty("stub_wifi2", |
| 102 flimflam::kSignalStrengthProperty, | 141 flimflam::kSignalStrengthProperty, |
| 103 base::FundamentalValue(80)); | 142 base::FundamentalValue(80)); |
| 143 service_test->SetServiceProperty("stub_wifi2", |
| 144 flimflam::kProfileProperty, |
| 145 base::StringValue(kUser1ProfilePath)); |
| 146 profile_test->AddService("stub_wifi2"); |
| 104 | 147 |
| 105 service_test->AddService("stub_cellular1", "cellular1", | 148 service_test->AddService("stub_cellular1", "cellular1", |
| 106 flimflam::kTypeCellular, flimflam::kStateIdle, | 149 flimflam::kTypeCellular, flimflam::kStateIdle, |
| 107 add_to_watchlist); | 150 add_to_watchlist); |
| 108 service_test->SetServiceProperty( | 151 service_test->SetServiceProperty( |
| 109 "stub_cellular1", | 152 "stub_cellular1", |
| 110 flimflam::kNetworkTechnologyProperty, | 153 flimflam::kNetworkTechnologyProperty, |
| 111 base::StringValue(flimflam::kNetworkTechnologyGsm)); | 154 base::StringValue(flimflam::kNetworkTechnologyGsm)); |
| 112 service_test->SetServiceProperty( | 155 service_test->SetServiceProperty( |
| 113 "stub_cellular1", | 156 "stub_cellular1", |
| 114 flimflam::kActivationStateProperty, | 157 flimflam::kActivationStateProperty, |
| 115 base::StringValue(flimflam::kActivationStateNotActivated)); | 158 base::StringValue(flimflam::kActivationStateNotActivated)); |
| 116 service_test->SetServiceProperty( | 159 service_test->SetServiceProperty( |
| 117 "stub_cellular1", | 160 "stub_cellular1", |
| 118 flimflam::kRoamingStateProperty, | 161 flimflam::kRoamingStateProperty, |
| 119 base::StringValue(flimflam::kRoamingStateHome)); | 162 base::StringValue(flimflam::kRoamingStateHome)); |
| 120 | 163 |
| 121 service_test->AddService("stub_vpn1", "vpn1", | 164 service_test->AddService("stub_vpn1", "vpn1", |
| 122 flimflam::kTypeVPN, | 165 flimflam::kTypeVPN, |
| 123 flimflam::kStateOnline, | 166 flimflam::kStateOnline, |
| 124 add_to_watchlist); | 167 add_to_watchlist); |
| 168 |
| 169 content::RunAllPendingInMessageLoop(); |
| 125 } | 170 } |
| 126 | 171 |
| 127 protected: | 172 protected: |
| 128 policy::MockConfigurationPolicyProvider provider_; | 173 policy::MockConfigurationPolicyProvider provider_; |
| 174 std::string userhash_; |
| 129 }; | 175 }; |
| 130 | 176 |
| 131 // Place each subtest into a separate browser test so that the stub networking | 177 // Place each subtest into a separate browser test so that the stub networking |
| 132 // library state is reset for each subtest run. This way they won't affect each | 178 // library state is reset for each subtest run. This way they won't affect each |
| 133 // other. | 179 // other. |
| 134 | 180 |
| 135 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartConnect) { | 181 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartConnect) { |
| 136 EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; | 182 EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; |
| 137 } | 183 } |
| 138 | 184 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; | 229 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; |
| 184 } | 230 } |
| 185 | 231 |
| 186 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, | 232 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, |
| 187 GetManagedProperties) { | 233 GetManagedProperties) { |
| 188 ShillServiceClient::TestInterface* service_test = | 234 ShillServiceClient::TestInterface* service_test = |
| 189 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 235 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 190 const std::string uidata_blob = | 236 const std::string uidata_blob = |
| 191 "{ \"user_settings\": {" | 237 "{ \"user_settings\": {" |
| 192 " \"WiFi\": {" | 238 " \"WiFi\": {" |
| 193 " \"Passphrase\": \"top secret\" }" | 239 " \"Passphrase\": \"FAKE_CREDENTIAL_VPaJDV9x\" }" |
| 194 " }" | 240 " }" |
| 195 "}"; | 241 "}"; |
| 196 service_test->SetServiceProperty("stub_wifi2", | 242 service_test->SetServiceProperty("stub_wifi2", |
| 197 flimflam::kGuidProperty, | |
| 198 base::StringValue("stub_wifi2")); | |
| 199 service_test->SetServiceProperty("stub_wifi2", | |
| 200 flimflam::kUIDataProperty, | 243 flimflam::kUIDataProperty, |
| 201 base::StringValue(uidata_blob)); | 244 base::StringValue(uidata_blob)); |
| 202 service_test->SetServiceProperty("stub_wifi2", | 245 service_test->SetServiceProperty("stub_wifi2", |
| 203 flimflam::kProfileProperty, | |
| 204 base::StringValue(kUserProfilePath)); | |
| 205 service_test->SetServiceProperty("stub_wifi2", | |
| 206 flimflam::kAutoConnectProperty, | 246 flimflam::kAutoConnectProperty, |
| 207 base::FundamentalValue(false)); | 247 base::FundamentalValue(false)); |
| 208 | 248 |
| 209 ShillProfileClient::TestInterface* profile_test = | 249 ShillProfileClient::TestInterface* profile_test = |
| 210 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 250 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 211 | 251 // Update the profile entry. |
| 212 profile_test->AddService("stub_wifi2"); | 252 profile_test->AddService("stub_wifi2"); |
| 213 | 253 |
| 214 content::RunAllPendingInMessageLoop(); | 254 content::RunAllPendingInMessageLoop(); |
| 215 | 255 |
| 216 const std::string user_policy_blob = | 256 const std::string user_policy_blob = |
| 217 "{ \"NetworkConfigurations\": [" | 257 "{ \"NetworkConfigurations\": [" |
| 218 " { \"GUID\": \"stub_wifi2\"," | 258 " { \"GUID\": \"stub_wifi2\"," |
| 219 " \"Type\": \"WiFi\"," | 259 " \"Type\": \"WiFi\"," |
| 220 " \"Name\": \"My WiFi Network\"," | 260 " \"Name\": \"My WiFi Network\"," |
| 221 " \"WiFi\": {" | 261 " \"WiFi\": {" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; | 308 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; |
| 269 } | 309 } |
| 270 | 310 |
| 271 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, | 311 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, |
| 272 VerifyAndEncryptData) { | 312 VerifyAndEncryptData) { |
| 273 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; | 313 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; |
| 274 } | 314 } |
| 275 | 315 |
| 276 | 316 |
| 277 } // namespace chromeos | 317 } // namespace chromeos |
| OLD | NEW |