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
3 // found in the LICENSE file.
6 #include "base/callback.h"
7 #include "base/command_line.h"
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/login/helper.h"
12 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
13 #include "chrome/browser/extensions/api/networking_private/networking_private_credentials_getter.h"
14 #include "chrome/browser/extensions/extension_apitest.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "chromeos/dbus/cryptohome_client.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/shill_device_client.h"
19 #include "chromeos/dbus/shill_ipconfig_client.h"
20 #include "chromeos/dbus/shill_manager_client.h"
21 #include "chromeos/dbus/shill_profile_client.h"
22 #include "chromeos/dbus/shill_service_client.h"
23 #include "chromeos/login/user_names.h"
24 #include "chromeos/network/network_handler.h"
25 #include "chromeos/network/network_state_handler.h"
26 #include "chromeos/network/onc/onc_utils.h"
27 #include "chromeos/network/portal_detector/network_portal_detector.h"
28 #include "components/onc/onc_constants.h"
29 #include "components/policy/core/browser/browser_policy_connector.h"
30 #include "components/policy/core/common/external_data_fetcher.h"
31 #include "components/policy/core/common/mock_configuration_policy_provider.h"
32 #include "components/policy/core/common/policy_map.h"
33 #include "components/policy/core/common/policy_types.h"
34 #include "components/user_manager/user.h"
35 #include "components/user_manager/user_manager.h"
36 #include "content/public/browser/notification_observer.h"
37 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/notification_source.h"
40 #include "content/public/test/test_utils.h"
41 #include "extensions/browser/api/networking_private/networking_private_chromeos.h"
42 #include "extensions/browser/api/networking_private/networking_private_delegate_factory.h"
43 #include "extensions/browser/notification_types.h"
44 #include "extensions/common/switches.h"
45 #include "policy/policy_constants.h"
46 #include "testing/gmock/include/gmock/gmock.h"
47 #include "third_party/cros_system_api/dbus/service_constants.h"
49 // This tests the Chrome OS implementation of the networkingPrivate API
50 // (NetworkingPrivateChromeOS). Note: The test expectations for chromeos, and
51 // win/mac (NetworkingPrivateServiceClient) are different to reflect the
52 // different implementations, but should be kept similar where possible.
54 using testing::Return
;
57 using chromeos::CryptohomeClient
;
58 using chromeos::DBUS_METHOD_CALL_SUCCESS
;
59 using chromeos::DBusMethodCallStatus
;
60 using chromeos::DBusThreadManager
;
61 using chromeos::NetworkPortalDetector
;
62 using chromeos::NetworkPortalDetectorTestImpl
;
63 using chromeos::ShillDeviceClient
;
64 using chromeos::ShillIPConfigClient
;
65 using chromeos::ShillManagerClient
;
66 using chromeos::ShillProfileClient
;
67 using chromeos::ShillServiceClient
;
69 using extensions::NetworkingPrivateDelegate
;
70 using extensions::NetworkingPrivateDelegateFactory
;
71 using extensions::NetworkingPrivateChromeOS
;
75 const char kUser1ProfilePath
[] = "/profile/user1/shill";
76 const char kEthernetDevicePath
[] = "/device/stub_ethernet_device";
77 const char kWifiDevicePath
[] = "/device/stub_wifi_device1";
78 const char kCellularDevicePath
[] = "/device/stub_cellular_device1";
79 const char kIPConfigPath
[] = "/ipconfig/ipconfig1";
81 const char kWifi1ServicePath
[] = "stub_wifi1";
82 const char kWifi2ServicePath
[] = "stub_wifi2";
83 const char kCellular1ServicePath
[] = "stub_cellular1";
85 // Stub Verify* methods implementation to satisfy expectations of
86 // networking_private_apitest.
87 class CryptoVerifyStub
: public NetworkingPrivateDelegate::VerifyDelegate
{
88 void VerifyDestination(const VerificationProperties
& verification_properties
,
89 const BoolCallback
& success_callback
,
90 const FailureCallback
& failure_callback
) override
{
91 success_callback
.Run(true);
94 void VerifyAndEncryptCredentials(
95 const std::string
& guid
,
96 const VerificationProperties
& verification_properties
,
97 const StringCallback
& success_callback
,
98 const FailureCallback
& failure_callback
) override
{
99 success_callback
.Run("encrypted_credentials");
102 void VerifyAndEncryptData(
103 const VerificationProperties
& verification_properties
,
104 const std::string
& data
,
105 const StringCallback
& success_callback
,
106 const FailureCallback
& failure_callback
) override
{
107 success_callback
.Run("encrypted_data");
111 class TestListener
: public content::NotificationObserver
{
113 TestListener(const std::string
& message
, const base::Closure
& callback
)
114 : message_(message
), callback_(callback
) {
115 registrar_
.Add(this, extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE
,
116 content::NotificationService::AllSources());
119 void Observe(int type
,
120 const content::NotificationSource
& /* source */,
121 const content::NotificationDetails
& details
) override
{
122 const std::string
& message
= *content::Details
<std::string
>(details
).ptr();
123 if (message
== message_
)
128 std::string message_
;
129 base::Closure callback_
;
131 content::NotificationRegistrar registrar_
;
133 DISALLOW_COPY_AND_ASSIGN(TestListener
);
136 class NetworkingPrivateChromeOSApiTest
: public ExtensionApiTest
{
138 NetworkingPrivateChromeOSApiTest()
139 : detector_(nullptr),
140 manager_test_(nullptr),
141 profile_test_(nullptr),
142 service_test_(nullptr),
143 device_test_(nullptr) {}
145 bool RunNetworkingSubtest(const std::string
& subtest
) {
146 return RunExtensionSubtest("networking_private/chromeos",
147 "main.html?" + subtest
,
148 kFlagEnableFileAccess
| kFlagLoadAsComponent
);
151 void SetUpInProcessBrowserTestFixture() override
{
152 EXPECT_CALL(provider_
, IsInitializationComplete(_
))
153 .WillRepeatedly(Return(true));
154 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_
);
156 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
159 static void AssignString(std::string
* out
,
160 DBusMethodCallStatus call_status
,
161 const std::string
& result
) {
162 CHECK_EQ(call_status
, DBUS_METHOD_CALL_SUCCESS
);
166 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
167 ExtensionApiTest::SetUpCommandLine(command_line
);
168 // Whitelist the extension ID of the test extension.
169 command_line
->AppendSwitchASCII(
170 extensions::switches::kWhitelistedExtensionID
,
171 "epcifkihnkjgphfkloaaleeakhpmgdmn");
173 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI
174 // uses the ProfileHelper to obtain the userhash crbug/238623.
175 const std::string login_user
= chromeos::login::CanonicalizeUserID(
176 command_line
->GetSwitchValueNative(chromeos::switches::kLoginUser
));
177 const std::string sanitized_user
=
178 CryptohomeClient::GetStubSanitizedUsername(login_user
);
179 command_line
->AppendSwitchASCII(chromeos::switches::kLoginProfile
,
183 void InitializeSanitizedUsername() {
184 user_manager::UserManager
* user_manager
= user_manager::UserManager::Get();
185 user_manager::User
* user
= user_manager
->GetActiveUser();
187 std::string userhash
;
188 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername(
189 user
->email(), base::Bind(&AssignString
, &userhash_
));
190 content::RunAllPendingInMessageLoop();
191 CHECK(!userhash_
.empty());
194 void SetupCellular() {
195 // Add a Cellular Device and set a couple of properties.
196 device_test_
->AddDevice(kCellularDevicePath
, shill::kTypeCellular
,
197 "stub_cellular_device1");
198 device_test_
->SetDeviceProperty(kCellularDevicePath
,
199 shill::kCarrierProperty
,
200 base::StringValue("Cellular1_Carrier"));
201 base::DictionaryValue home_provider
;
202 home_provider
.SetString("name", "Cellular1_Provider");
203 home_provider
.SetString("country", "us");
204 device_test_
->SetDeviceProperty(
205 kCellularDevicePath
, shill::kHomeProviderProperty
, home_provider
);
206 AddService(kCellular1ServicePath
, "cellular1", shill::kTypeCellular
,
208 // Note: These properties will show up in a "Cellular" object in ONC.
209 service_test_
->SetServiceProperty(kCellular1ServicePath
,
210 shill::kAutoConnectProperty
,
211 base::FundamentalValue(true));
212 service_test_
->SetServiceProperty(
213 kCellular1ServicePath
, shill::kNetworkTechnologyProperty
,
214 base::StringValue(shill::kNetworkTechnologyGsm
));
215 service_test_
->SetServiceProperty(
216 kCellular1ServicePath
, shill::kActivationStateProperty
,
217 base::StringValue(shill::kActivationStateNotActivated
));
218 service_test_
->SetServiceProperty(
219 kCellular1ServicePath
, shill::kRoamingStateProperty
,
220 base::StringValue(shill::kRoamingStateHome
));
221 profile_test_
->AddService(kUser1ProfilePath
, kCellular1ServicePath
);
222 content::RunAllPendingInMessageLoop();
225 void AddService(const std::string
& service_path
,
226 const std::string
& name
,
227 const std::string
& type
,
228 const std::string
& state
) {
229 service_test_
->AddService(service_path
, service_path
+ "_guid", name
, type
,
230 state
, true /* add_to_visible */);
233 static scoped_ptr
<KeyedService
> CreateNetworkingPrivateServiceClient(
234 content::BrowserContext
* context
) {
235 scoped_ptr
<CryptoVerifyStub
> crypto_verify(new CryptoVerifyStub
);
236 return make_scoped_ptr(
237 new NetworkingPrivateChromeOS(context
, crypto_verify
.Pass()));
240 void SetUpOnMainThread() override
{
241 detector_
= new NetworkPortalDetectorTestImpl();
242 NetworkPortalDetector::InitializeForTesting(detector_
);
244 ExtensionApiTest::SetUpOnMainThread();
245 content::RunAllPendingInMessageLoop();
247 NetworkingPrivateDelegateFactory::GetInstance()->SetTestingFactory(
248 profile(), &CreateNetworkingPrivateServiceClient
);
250 InitializeSanitizedUsername();
252 DBusThreadManager
* dbus_manager
= DBusThreadManager::Get();
253 manager_test_
= dbus_manager
->GetShillManagerClient()->GetTestInterface();
254 profile_test_
= dbus_manager
->GetShillProfileClient()->GetTestInterface();
255 service_test_
= dbus_manager
->GetShillServiceClient()->GetTestInterface();
256 device_test_
= dbus_manager
->GetShillDeviceClient()->GetTestInterface();
258 ShillIPConfigClient::TestInterface
* ip_config_test
=
259 dbus_manager
->GetShillIPConfigClient()->GetTestInterface();
261 device_test_
->ClearDevices();
262 service_test_
->ClearServices();
264 // Sends a notification about the added profile.
265 profile_test_
->AddProfile(kUser1ProfilePath
, userhash_
);
267 // Enable technologies.
268 manager_test_
->AddTechnology("wimax", true);
271 base::DictionaryValue ipconfig
;
272 ipconfig
.SetStringWithoutPathExpansion(shill::kAddressProperty
, "0.0.0.0");
273 ipconfig
.SetStringWithoutPathExpansion(shill::kGatewayProperty
, "0.0.0.1");
274 ipconfig
.SetIntegerWithoutPathExpansion(shill::kPrefixlenProperty
, 0);
275 ipconfig
.SetStringWithoutPathExpansion(shill::kMethodProperty
,
277 ip_config_test
->AddIPConfig(kIPConfigPath
, ipconfig
);
280 device_test_
->AddDevice(kEthernetDevicePath
, shill::kTypeEthernet
,
281 "stub_ethernet_device1");
283 device_test_
->AddDevice(kWifiDevicePath
, shill::kTypeWifi
,
284 "stub_wifi_device1");
285 base::ListValue wifi_ip_configs
;
286 wifi_ip_configs
.AppendString(kIPConfigPath
);
287 device_test_
->SetDeviceProperty(kWifiDevicePath
, shill::kIPConfigsProperty
,
289 device_test_
->SetDeviceProperty(kWifiDevicePath
, shill::kAddressProperty
,
290 base::StringValue("001122aabbcc"));
293 AddService("stub_ethernet", "eth0", shill::kTypeEthernet
,
294 shill::kStateOnline
);
295 service_test_
->SetServiceProperty(
296 "stub_ethernet", shill::kProfileProperty
,
297 base::StringValue(ShillProfileClient::GetSharedProfilePath()));
298 profile_test_
->AddService(ShillProfileClient::GetSharedProfilePath(),
301 AddService(kWifi1ServicePath
, "wifi1", shill::kTypeWifi
,
302 shill::kStateOnline
);
303 service_test_
->SetServiceProperty(kWifi1ServicePath
,
304 shill::kSecurityClassProperty
,
305 base::StringValue(shill::kSecurityWep
));
306 service_test_
->SetServiceProperty(kWifi1ServicePath
,
307 shill::kSignalStrengthProperty
,
308 base::FundamentalValue(40));
309 service_test_
->SetServiceProperty(kWifi1ServicePath
,
310 shill::kProfileProperty
,
311 base::StringValue(kUser1ProfilePath
));
312 service_test_
->SetServiceProperty(kWifi1ServicePath
,
313 shill::kConnectableProperty
,
314 base::FundamentalValue(true));
315 service_test_
->SetServiceProperty(kWifi1ServicePath
, shill::kDeviceProperty
,
316 base::StringValue(kWifiDevicePath
));
317 base::DictionaryValue static_ipconfig
;
318 static_ipconfig
.SetStringWithoutPathExpansion(shill::kAddressProperty
,
320 service_test_
->SetServiceProperty(
321 kWifi1ServicePath
, shill::kStaticIPConfigProperty
, static_ipconfig
);
322 base::ListValue frequencies1
;
323 frequencies1
.AppendInteger(2400);
324 service_test_
->SetServiceProperty(
325 kWifi1ServicePath
, shill::kWifiFrequencyListProperty
, frequencies1
);
326 service_test_
->SetServiceProperty(kWifi1ServicePath
, shill::kWifiFrequency
,
327 base::FundamentalValue(2400));
328 profile_test_
->AddService(kUser1ProfilePath
, kWifi1ServicePath
);
330 AddService(kWifi2ServicePath
, "wifi2_PSK", shill::kTypeWifi
,
332 service_test_
->SetServiceProperty(kWifi2ServicePath
,
333 shill::kSecurityClassProperty
,
334 base::StringValue(shill::kSecurityPsk
));
335 service_test_
->SetServiceProperty(kWifi2ServicePath
,
336 shill::kSignalStrengthProperty
,
337 base::FundamentalValue(80));
338 service_test_
->SetServiceProperty(kWifi2ServicePath
,
339 shill::kConnectableProperty
,
340 base::FundamentalValue(true));
342 AddService("stub_wimax", "wimax", shill::kTypeWimax
, shill::kStateOnline
);
343 service_test_
->SetServiceProperty("stub_wimax",
344 shill::kSignalStrengthProperty
,
345 base::FundamentalValue(40));
346 service_test_
->SetServiceProperty("stub_wimax", shill::kProfileProperty
,
347 base::StringValue(kUser1ProfilePath
));
348 service_test_
->SetServiceProperty("stub_wimax", shill::kConnectableProperty
,
349 base::FundamentalValue(true));
350 profile_test_
->AddService(kUser1ProfilePath
, "stub_wimax");
352 base::ListValue frequencies2
;
353 frequencies2
.AppendInteger(2400);
354 frequencies2
.AppendInteger(5000);
355 service_test_
->SetServiceProperty(
356 kWifi2ServicePath
, shill::kWifiFrequencyListProperty
, frequencies2
);
357 service_test_
->SetServiceProperty(kWifi2ServicePath
, shill::kWifiFrequency
,
358 base::FundamentalValue(5000));
359 service_test_
->SetServiceProperty(kWifi2ServicePath
,
360 shill::kProfileProperty
,
361 base::StringValue(kUser1ProfilePath
));
362 profile_test_
->AddService(kUser1ProfilePath
, kWifi2ServicePath
);
364 AddService("stub_vpn1", "vpn1", shill::kTypeVPN
, shill::kStateOnline
);
365 service_test_
->SetServiceProperty(
366 "stub_vpn1", shill::kProviderTypeProperty
,
367 base::StringValue(shill::kProviderOpenVpn
));
368 profile_test_
->AddService(kUser1ProfilePath
, "stub_vpn1");
370 AddService("stub_vpn2", "vpn2", shill::kTypeVPN
, shill::kStateOffline
);
371 service_test_
->SetServiceProperty(
372 "stub_vpn2", shill::kProviderTypeProperty
,
373 base::StringValue(shill::kProviderThirdPartyVpn
));
374 service_test_
->SetServiceProperty(
375 "stub_vpn2", shill::kProviderHostProperty
,
376 base::StringValue("third_party_provider_extension_id"));
377 profile_test_
->AddService(kUser1ProfilePath
, "stub_vpn2");
379 content::RunAllPendingInMessageLoop();
383 NetworkPortalDetectorTestImpl
* detector() { return detector_
; }
385 NetworkPortalDetectorTestImpl
* detector_
;
386 ShillManagerClient::TestInterface
* manager_test_
;
387 ShillProfileClient::TestInterface
* profile_test_
;
388 ShillServiceClient::TestInterface
* service_test_
;
389 ShillDeviceClient::TestInterface
* device_test_
;
390 policy::MockConfigurationPolicyProvider provider_
;
391 std::string userhash_
;
394 // Place each subtest into a separate browser test so that the stub networking
395 // library state is reset for each subtest run. This way they won't affect each
398 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, StartConnect
) {
399 EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_
;
402 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, StartDisconnect
) {
403 EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_
;
406 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, StartActivate
) {
408 EXPECT_TRUE(RunNetworkingSubtest("startActivate")) << message_
;
411 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
412 StartConnectNonexistent
) {
413 EXPECT_TRUE(RunNetworkingSubtest("startConnectNonexistent")) << message_
;
416 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
417 StartDisconnectNonexistent
) {
418 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_
;
421 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
422 StartGetPropertiesNonexistent
) {
423 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent"))
427 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetNetworks
) {
429 service_test_
->SetServiceProperty(kWifi2ServicePath
, shill::kVisibleProperty
,
430 base::FundamentalValue(false));
431 // Add a couple of additional networks that are not configured (saved).
432 AddService("stub_wifi3", "wifi3", shill::kTypeWifi
, shill::kStateIdle
);
433 AddService("stub_wifi4", "wifi4", shill::kTypeWifi
, shill::kStateIdle
);
434 content::RunAllPendingInMessageLoop();
435 EXPECT_TRUE(RunNetworkingSubtest("getNetworks")) << message_
;
438 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetVisibleNetworks
) {
439 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_
;
442 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
443 GetVisibleNetworksWifi
) {
444 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_
;
447 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, EnabledNetworkTypes
) {
448 EXPECT_TRUE(RunNetworkingSubtest("enabledNetworkTypes")) << message_
;
451 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetDeviceStates
) {
453 manager_test_
->RemoveTechnology("cellular");
454 manager_test_
->AddTechnology("cellular", false /* disabled */);
455 manager_test_
->SetTechnologyInitializing("cellular", true);
456 manager_test_
->RemoveTechnology("wimax");
457 manager_test_
->AddTechnology("wimax", false /* disabled */);
458 EXPECT_TRUE(RunNetworkingSubtest("getDeviceStates")) << message_
;
461 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, RequestNetworkScan
) {
462 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_
;
465 // Properties are filtered and translated through
466 // ShillToONCTranslator::TranslateWiFiWithState
467 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetProperties
) {
468 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_
;
471 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
472 GetCellularProperties
) {
474 EXPECT_TRUE(RunNetworkingSubtest("getPropertiesCellular")) << message_
;
477 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetState
) {
478 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_
;
481 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetStateNonExistent
) {
482 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_
;
485 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
486 SetCellularProperties
) {
488 EXPECT_TRUE(RunNetworkingSubtest("setCellularProperties")) << message_
;
491 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, SetWiFiProperties
) {
492 EXPECT_TRUE(RunNetworkingSubtest("setWiFiProperties")) << message_
;
495 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, SetVPNProperties
) {
496 EXPECT_TRUE(RunNetworkingSubtest("setVPNProperties")) << message_
;
499 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, CreateNetwork
) {
500 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_
;
503 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, ForgetNetwork
) {
504 EXPECT_TRUE(RunNetworkingSubtest("forgetNetwork")) << message_
;
507 // TODO(stevenjb): Find a better way to set this up on Chrome OS.
508 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetManagedProperties
) {
509 const std::string uidata_blob
=
510 "{ \"user_settings\": {"
512 " \"Passphrase\": \"FAKE_CREDENTIAL_VPaJDV9x\" }"
515 service_test_
->SetServiceProperty(kWifi2ServicePath
, shill::kUIDataProperty
,
516 base::StringValue(uidata_blob
));
517 service_test_
->SetServiceProperty(kWifi2ServicePath
,
518 shill::kAutoConnectProperty
,
519 base::FundamentalValue(false));
521 // Update the profile entry.
522 profile_test_
->AddService(kUser1ProfilePath
, kWifi2ServicePath
);
524 content::RunAllPendingInMessageLoop();
526 const std::string user_policy_blob
=
527 "{ \"NetworkConfigurations\": ["
528 " { \"GUID\": \"stub_wifi2\","
529 " \"Type\": \"WiFi\","
530 " \"Name\": \"My WiFi Network\","
532 " \"HexSSID\": \"77696669325F50534B\"," // "wifi2_PSK"
533 " \"Passphrase\": \"passphrase\","
534 " \"Recommended\": [ \"AutoConnect\", \"Passphrase\" ],"
535 " \"Security\": \"WPA-PSK\" }"
538 " \"Certificates\": [],"
539 " \"Type\": \"UnencryptedConfiguration\""
542 policy::PolicyMap policy
;
543 policy
.Set(policy::key::kOpenNetworkConfiguration
,
544 policy::POLICY_LEVEL_MANDATORY
, policy::POLICY_SCOPE_USER
,
545 new base::StringValue(user_policy_blob
), nullptr);
546 provider_
.UpdateChromePolicy(policy
);
548 content::RunAllPendingInMessageLoop();
550 EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_
;
553 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetErrorState
) {
554 chromeos::NetworkHandler::Get()->network_state_handler()->SetLastErrorForTest(
555 kWifi1ServicePath
, "TestErrorState");
556 EXPECT_TRUE(RunNetworkingSubtest("getErrorState")) << message_
;
559 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
560 OnNetworksChangedEventConnect
) {
561 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect"))
565 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
566 OnNetworksChangedEventDisconnect
) {
567 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect"))
571 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
572 OnNetworkListChangedEvent
) {
573 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_
;
576 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
577 OnDeviceStateListChangedEvent
) {
578 EXPECT_TRUE(RunNetworkingSubtest("onDeviceStateListChangedEvent"))
582 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, VerifyDestination
) {
583 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_
;
586 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
587 VerifyAndEncryptCredentials
) {
588 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_
;
591 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, VerifyAndEncryptData
) {
592 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_
;
595 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
596 SetWifiTDLSEnabledState
) {
597 device_test_
->SetTDLSState(shill::kTDLSConnectedState
);
598 EXPECT_TRUE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_
;
601 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
, GetWifiTDLSStatus
) {
602 device_test_
->SetTDLSState(shill::kTDLSConnectedState
);
603 EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_
;
606 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
607 GetCaptivePortalStatus
) {
610 NetworkPortalDetector::CaptivePortalState state
;
611 state
.status
= NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE
;
612 detector()->SetDetectionResultsForTesting("stub_ethernet_guid", state
);
614 state
.status
= NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE
;
615 detector()->SetDetectionResultsForTesting("stub_wifi1_guid", state
);
617 state
.status
= NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL
;
618 detector()->SetDetectionResultsForTesting("stub_wifi2_guid", state
);
621 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED
;
622 detector()->SetDetectionResultsForTesting("stub_cellular1_guid", state
);
624 EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_
;
627 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest
,
628 CaptivePortalNotification
) {
629 detector()->SetDefaultNetworkForTesting("wifi_guid");
630 NetworkPortalDetector::CaptivePortalState state
;
631 state
.status
= NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE
;
632 detector()->SetDetectionResultsForTesting("wifi_guid", state
);
634 TestListener
listener(
635 "notifyPortalDetectorObservers",
636 base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting
,
637 base::Unretained(detector())));
638 EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_
;