| 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/policy/network_configuration_updater.h" | 7 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/policy/browser_policy_connector.h" | 9 #include "chrome/browser/policy/browser_policy_connector.h" |
| 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 10 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chromeos/network/onc/onc_utils.h" | 21 #include "chromeos/network/onc/onc_utils.h" |
| 22 #include "policy/policy_constants.h" | 22 #include "policy/policy_constants.h" |
| 23 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 24 | 24 |
| 25 using testing::AnyNumber; | 25 using testing::AnyNumber; |
| 26 using testing::Return; | 26 using testing::Return; |
| 27 using testing::_; | 27 using testing::_; |
| 28 | 28 |
| 29 namespace chromeos { | 29 namespace chromeos { |
| 30 | 30 |
| 31 const char kUserProfilePath[] = "/profile/chronos/shill"; | 31 const char kUser1ProfilePath[] = "/profile/user1/shill"; |
| 32 const char kUser1[] = "user1"; |
| 32 | 33 |
| 33 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest { | 34 class ExtensionNetworkingPrivateApiTest : public ExtensionApiTest { |
| 34 public: | 35 public: |
| 35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 36 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 36 ExtensionApiTest::SetUpCommandLine(command_line); | 37 ExtensionApiTest::SetUpCommandLine(command_line); |
| 37 // Whitelist the extension ID of the test extension. | 38 // Whitelist the extension ID of the test extension. |
| 38 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, | 39 command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID, |
| 39 "epcifkihnkjgphfkloaaleeakhpmgdmn"); | 40 "epcifkihnkjgphfkloaaleeakhpmgdmn"); |
| 40 command_line->AppendSwitch(switches::kUseNewNetworkConfigurationHandlers); | 41 command_line->AppendSwitch(switches::kUseNewNetworkConfigurationHandlers); |
| 41 } | 42 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 EXPECT_CALL(provider_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); | 53 EXPECT_CALL(provider_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); |
| 53 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 54 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 54 | 55 |
| 55 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 56 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 56 } | 57 } |
| 57 | 58 |
| 58 virtual void SetUpOnMainThread() OVERRIDE { | 59 virtual void SetUpOnMainThread() OVERRIDE { |
| 59 ExtensionApiTest::SetUpOnMainThread(); | 60 ExtensionApiTest::SetUpOnMainThread(); |
| 60 content::RunAllPendingInMessageLoop(); | 61 content::RunAllPendingInMessageLoop(); |
| 61 | 62 |
| 63 ShillDeviceClient::TestInterface* device_test = |
| 64 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 62 ShillProfileClient::TestInterface* profile_test = | 65 ShillProfileClient::TestInterface* profile_test = |
| 63 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 66 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 64 profile_test->AddProfile(kUserProfilePath); | 67 ShillServiceClient::TestInterface* service_test = |
| 68 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 65 | 69 |
| 66 g_browser_process->browser_policy_connector()-> | 70 g_browser_process->browser_policy_connector()-> |
| 67 GetNetworkConfigurationUpdater()->OnUserPolicyInitialized(); | 71 GetNetworkConfigurationUpdater()->OnUserPolicyInitialized(); |
| 68 ShillDeviceClient::TestInterface* device_test = | |
| 69 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | |
| 70 device_test->ClearDevices(); | 72 device_test->ClearDevices(); |
| 73 service_test->ClearServices(); |
| 74 |
| 75 // Sends a notification about the added profile. |
| 76 profile_test->AddProfile(kUser1ProfilePath, kUser1); |
| 77 |
| 71 device_test->AddDevice("/device/stub_wifi_device1", | 78 device_test->AddDevice("/device/stub_wifi_device1", |
| 72 flimflam::kTypeWifi, "stub_wifi_device1"); | 79 flimflam::kTypeWifi, "stub_wifi_device1"); |
| 73 device_test->AddDevice("/device/stub_cellular_device1", | 80 device_test->AddDevice("/device/stub_cellular_device1", |
| 74 flimflam::kTypeCellular, "stub_cellular_device1"); | 81 flimflam::kTypeCellular, "stub_cellular_device1"); |
| 75 | 82 |
| 76 ShillServiceClient::TestInterface* service_test = | |
| 77 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 78 service_test->ClearServices(); | |
| 79 const bool add_to_watchlist = true; | 83 const bool add_to_watchlist = true; |
| 80 service_test->AddService("stub_ethernet", "eth0", | 84 service_test->AddService("stub_ethernet", "eth0", |
| 81 flimflam::kTypeEthernet, flimflam::kStateOnline, | 85 flimflam::kTypeEthernet, flimflam::kStateOnline, |
| 82 add_to_watchlist); | 86 add_to_watchlist); |
| 83 | 87 |
| 84 service_test->AddService("stub_wifi1", "wifi1", | 88 service_test->AddService("stub_wifi1", "wifi1", |
| 85 flimflam::kTypeWifi, flimflam::kStateOnline, | 89 flimflam::kTypeWifi, flimflam::kStateOnline, |
| 86 add_to_watchlist); | 90 add_to_watchlist); |
| 87 service_test->SetServiceProperty("stub_wifi1", | 91 service_test->SetServiceProperty("stub_wifi1", |
| 88 flimflam::kSecurityProperty, | 92 flimflam::kSecurityProperty, |
| 89 base::StringValue(flimflam::kSecurityWep)); | 93 base::StringValue(flimflam::kSecurityWep)); |
| 90 | 94 |
| 91 service_test->AddService("stub_wifi2", "wifi2_PSK", | 95 service_test->AddService("stub_wifi2", "wifi2_PSK", |
| 92 flimflam::kTypeWifi, flimflam::kStateIdle, | 96 flimflam::kTypeWifi, flimflam::kStateIdle, |
| 93 add_to_watchlist); | 97 add_to_watchlist); |
| 94 service_test->SetServiceProperty("stub_wifi2", | 98 service_test->SetServiceProperty("stub_wifi2", |
| 95 flimflam::kGuidProperty, | 99 flimflam::kGuidProperty, |
| 96 base::StringValue("stub_wifi2")); | 100 base::StringValue("stub_wifi2")); |
| 97 service_test->SetServiceProperty("stub_wifi2", | 101 service_test->SetServiceProperty("stub_wifi2", |
| 98 flimflam::kSecurityProperty, | 102 flimflam::kSecurityProperty, |
| 99 base::StringValue(flimflam::kSecurityPsk)); | 103 base::StringValue(flimflam::kSecurityPsk)); |
| 100 service_test->SetServiceProperty("stub_wifi2", | 104 service_test->SetServiceProperty("stub_wifi2", |
| 101 flimflam::kSignalStrengthProperty, | 105 flimflam::kSignalStrengthProperty, |
| 102 base::FundamentalValue(80)); | 106 base::FundamentalValue(80)); |
| 107 service_test->SetServiceProperty("stub_wifi2", |
| 108 flimflam::kProfileProperty, |
| 109 base::StringValue(kUser1ProfilePath)); |
| 110 profile_test->AddService("stub_wifi2"); |
| 103 | 111 |
| 104 service_test->AddService("stub_cellular1", "cellular1", | 112 service_test->AddService("stub_cellular1", "cellular1", |
| 105 flimflam::kTypeCellular, flimflam::kStateIdle, | 113 flimflam::kTypeCellular, flimflam::kStateIdle, |
| 106 add_to_watchlist); | 114 add_to_watchlist); |
| 107 service_test->SetServiceProperty( | 115 service_test->SetServiceProperty( |
| 108 "stub_cellular1", | 116 "stub_cellular1", |
| 109 flimflam::kNetworkTechnologyProperty, | 117 flimflam::kNetworkTechnologyProperty, |
| 110 base::StringValue(flimflam::kNetworkTechnologyGsm)); | 118 base::StringValue(flimflam::kNetworkTechnologyGsm)); |
| 111 service_test->SetServiceProperty( | 119 service_test->SetServiceProperty( |
| 112 "stub_cellular1", | 120 "stub_cellular1", |
| 113 flimflam::kActivationStateProperty, | 121 flimflam::kActivationStateProperty, |
| 114 base::StringValue(flimflam::kActivationStateNotActivated)); | 122 base::StringValue(flimflam::kActivationStateNotActivated)); |
| 115 service_test->SetServiceProperty( | 123 service_test->SetServiceProperty( |
| 116 "stub_cellular1", | 124 "stub_cellular1", |
| 117 flimflam::kRoamingStateProperty, | 125 flimflam::kRoamingStateProperty, |
| 118 base::StringValue(flimflam::kRoamingStateHome)); | 126 base::StringValue(flimflam::kRoamingStateHome)); |
| 119 | 127 |
| 120 service_test->AddService("stub_vpn1", "vpn1", | 128 service_test->AddService("stub_vpn1", "vpn1", |
| 121 flimflam::kTypeVPN, | 129 flimflam::kTypeVPN, |
| 122 flimflam::kStateOnline, | 130 flimflam::kStateOnline, |
| 123 add_to_watchlist); | 131 add_to_watchlist); |
| 132 |
| 133 content::RunAllPendingInMessageLoop(); |
| 124 } | 134 } |
| 125 | 135 |
| 126 protected: | 136 protected: |
| 127 policy::MockConfigurationPolicyProvider provider_; | 137 policy::MockConfigurationPolicyProvider provider_; |
| 128 }; | 138 }; |
| 129 | 139 |
| 130 // Place each subtest into a separate browser test so that the stub networking | 140 // Place each subtest into a separate browser test so that the stub networking |
| 131 // library state is reset for each subtest run. This way they won't affect each | 141 // library state is reset for each subtest run. This way they won't affect each |
| 132 // other. | 142 // other. |
| 133 | 143 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; | 192 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; |
| 183 } | 193 } |
| 184 | 194 |
| 185 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, | 195 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, |
| 186 GetManagedProperties) { | 196 GetManagedProperties) { |
| 187 ShillServiceClient::TestInterface* service_test = | 197 ShillServiceClient::TestInterface* service_test = |
| 188 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 198 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 189 const std::string uidata_blob = | 199 const std::string uidata_blob = |
| 190 "{ \"user_settings\": {" | 200 "{ \"user_settings\": {" |
| 191 " \"WiFi\": {" | 201 " \"WiFi\": {" |
| 192 " \"Passphrase\": \"top secret\" }" | 202 " \"Passphrase\": \"FAKE_CREDENTIAL_VPaJDV9x\" }" |
| 193 " }" | 203 " }" |
| 194 "}"; | 204 "}"; |
| 195 service_test->SetServiceProperty("stub_wifi2", | 205 service_test->SetServiceProperty("stub_wifi2", |
| 196 flimflam::kGuidProperty, | |
| 197 base::StringValue("stub_wifi2")); | |
| 198 service_test->SetServiceProperty("stub_wifi2", | |
| 199 flimflam::kUIDataProperty, | 206 flimflam::kUIDataProperty, |
| 200 base::StringValue(uidata_blob)); | 207 base::StringValue(uidata_blob)); |
| 201 service_test->SetServiceProperty("stub_wifi2", | 208 service_test->SetServiceProperty("stub_wifi2", |
| 202 flimflam::kProfileProperty, | |
| 203 base::StringValue(kUserProfilePath)); | |
| 204 service_test->SetServiceProperty("stub_wifi2", | |
| 205 flimflam::kAutoConnectProperty, | 209 flimflam::kAutoConnectProperty, |
| 206 base::FundamentalValue(false)); | 210 base::FundamentalValue(false)); |
| 207 | 211 |
| 208 ShillProfileClient::TestInterface* profile_test = | 212 ShillProfileClient::TestInterface* profile_test = |
| 209 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 213 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 210 | 214 // Update the profile entry. |
| 211 profile_test->AddService("stub_wifi2"); | 215 profile_test->AddService("stub_wifi2"); |
| 212 | 216 |
| 213 content::RunAllPendingInMessageLoop(); | 217 content::RunAllPendingInMessageLoop(); |
| 214 | 218 |
| 215 const std::string user_policy_blob = | 219 const std::string user_policy_blob = |
| 216 "{ \"NetworkConfigurations\": [" | 220 "{ \"NetworkConfigurations\": [" |
| 217 " { \"GUID\": \"stub_wifi2\"," | 221 " { \"GUID\": \"stub_wifi2\"," |
| 218 " \"Type\": \"WiFi\"," | 222 " \"Type\": \"WiFi\"," |
| 219 " \"Name\": \"My WiFi Network\"," | 223 " \"Name\": \"My WiFi Network\"," |
| 220 " \"WiFi\": {" | 224 " \"WiFi\": {" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; | 271 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; |
| 268 } | 272 } |
| 269 | 273 |
| 270 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, | 274 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, |
| 271 VerifyAndEncryptData) { | 275 VerifyAndEncryptData) { |
| 272 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; | 276 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; |
| 273 } | 277 } |
| 274 | 278 |
| 275 | 279 |
| 276 } // namespace chromeos | 280 } // namespace chromeos |
| OLD | NEW |