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.
4
5 #include "base/bind.h"
6 #include "base/callback.h"
7 #include "base/command_line.h"
8 #include "base/macros.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/login/users/user.h"
11 #include "chrome/browser/chromeos/login/users/user_manager.h"
12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "extensions/common/switches.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/browser/chromeos/login/helper.h"
20 #include "chrome/browser/chromeos/net/network_portal_detector.h"
21 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
22 #include "chromeos/chromeos_switches.h"
23 #include "chromeos/dbus/cryptohome_client.h"
24 #include "chromeos/dbus/dbus_thread_manager.h"
25 #include "chromeos/dbus/shill_device_client.h"
26 #include "chromeos/dbus/shill_ipconfig_client.h"
27 #include "chromeos/dbus/shill_manager_client.h"
28 #include "chromeos/dbus/shill_profile_client.h"
29 #include "chromeos/dbus/shill_service_client.h"
30 #include "chromeos/network/onc/onc_utils.h"
31 #include "components/onc/onc_constants.h"
32 #include "components/policy/core/browser/browser_policy_connector.h"
33 #include "components/policy/core/common/external_data_fetcher.h"
34 #include "components/policy/core/common/mock_configuration_policy_provider.h"
35 #include "components/policy/core/common/policy_map.h"
36 #include "components/policy/core/common/policy_types.h"
37 #include "content/public/browser/notification_observer.h"
38 #include "content/public/browser/notification_registrar.h"
39 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/notification_source.h"
41 #include "policy/policy_constants.h"
42 #include "third_party/cros_system_api/dbus/service_constants.h"
43 #else // !defined(OS_CHROMEOS)
44 #include "chrome/browser/extensions/api/networking_private/networking_private_credentials_getter.h"
45 #include "chrome/browser/extensions/api/networking_private/networking_private_service_client.h"
46 #include "chrome/browser/extensions/api/networking_private/networking_private_service_client_factory.h"
47 #include "components/wifi/fake_wifi_service.h"
48 #endif // defined(OS_CHROMEOS)
49
50 // TODO(stevenjb/mef): Clean these tests up. crbug.com/371442
51
52 using testing::Return;
53 using testing::_;
54
55 #if defined(OS_CHROMEOS)
56 using chromeos::CryptohomeClient;
57 using chromeos::DBUS_METHOD_CALL_SUCCESS;
58 using chromeos::DBusMethodCallStatus;
59 using chromeos::DBusThreadManager;
60 using chromeos::NetworkPortalDetector;
61 using chromeos::NetworkPortalDetectorTestImpl;
62 using chromeos::ShillDeviceClient;
63 using chromeos::ShillIPConfigClient;
64 using chromeos::ShillManagerClient;
65 using chromeos::ShillProfileClient;
66 using chromeos::ShillServiceClient;
67 #else // !defined(OS_CHROMEOS)
68 using extensions::NetworkingPrivateServiceClientFactory;
69 #endif // defined(OS_CHROMEOS)
70
71 namespace {
72
73 #if defined(OS_CHROMEOS)
74 const char kUser1ProfilePath[] = "/profile/user1/shill";
75 const char kWifiDevicePath[] = "/device/stub_wifi_device1";
76 const char kCellularDevicePath[] = "/device/stub_cellular_device1";
77 const char kIPConfigPath[] = "/ipconfig/ipconfig1";
78
79 class TestListener : public content::NotificationObserver {
80 public:
TestListener(const std::string & message,const base::Closure & callback)81 TestListener(const std::string& message, const base::Closure& callback)
82 : message_(message), callback_(callback) {
83 registrar_.Add(this,
84 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
85 content::NotificationService::AllSources());
86 }
87
Observe(int type,const content::NotificationSource &,const content::NotificationDetails & details)88 virtual void Observe(int type,
89 const content::NotificationSource& /* source */,
90 const content::NotificationDetails& details) OVERRIDE {
91 const std::string& message = *content::Details<std::string>(details).ptr();
92 if (message == message_)
93 callback_.Run();
94 }
95
96 private:
97 std::string message_;
98 base::Closure callback_;
99
100 content::NotificationRegistrar registrar_;
101
102 DISALLOW_COPY_AND_ASSIGN(TestListener);
103 };
104 #else // !defined(OS_CHROMEOS)
105
106 // Stub Verify* methods implementation to satisfy expectations of
107 // networking_private_apitest.
108 // TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto,
109 // and update networking_private_apitest to use and expect valid data.
110 // That will eliminate the need for mock implementation.
111 class CryptoVerifyStub
112 : public extensions::NetworkingPrivateServiceClient::CryptoVerify {
113 virtual void VerifyDestination(scoped_ptr<base::ListValue> args,
114 bool* verified,
115 std::string* error) OVERRIDE {
116 *verified = true;
117 }
118
119 virtual void VerifyAndEncryptCredentials(
120 scoped_ptr<base::ListValue> args,
121 const extensions::NetworkingPrivateServiceClient::CryptoVerify::
122 VerifyAndEncryptCredentialsCallback& callback) OVERRIDE {
123 callback.Run("encrypted_credentials", "");
124 }
125
126 virtual void VerifyAndEncryptData(scoped_ptr<base::ListValue> args,
127 std::string* encoded_data,
128 std::string* error) OVERRIDE {
129 *encoded_data = "encrypted_data";
130 }
131 };
132 #endif // defined(OS_CHROMEOS)
133
134 class ExtensionNetworkingPrivateApiTest
135 : public ExtensionApiTest {
136 public:
ExtensionNetworkingPrivateApiTest()137 ExtensionNetworkingPrivateApiTest()
138 #if defined(OS_CHROMEOS)
139 : detector_(NULL),
140 service_test_(NULL),
141 manager_test_(NULL),
142 device_test_(NULL)
143 #endif
144 {
145 }
146
RunNetworkingSubtest(const std::string & subtest)147 bool RunNetworkingSubtest(const std::string& subtest) {
148 return RunExtensionSubtest(
149 "networking", "main.html?" + subtest,
150 kFlagEnableFileAccess | kFlagLoadAsComponent);
151 }
152
SetUpInProcessBrowserTestFixture()153 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
154 #if defined(OS_CHROMEOS)
155 EXPECT_CALL(provider_, IsInitializationComplete(_))
156 .WillRepeatedly(Return(true));
157 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
158 #endif
159
160 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
161 }
162
163 #if defined(OS_CHROMEOS)
AssignString(std::string * out,DBusMethodCallStatus call_status,const std::string & result)164 static void AssignString(std::string* out,
165 DBusMethodCallStatus call_status,
166 const std::string& result) {
167 CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS);
168 *out = result;
169 }
170
SetUpCommandLine(CommandLine * command_line)171 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
172 ExtensionApiTest::SetUpCommandLine(command_line);
173 // Whitelist the extension ID of the test extension.
174 command_line->AppendSwitchASCII(
175 extensions::switches::kWhitelistedExtensionID,
176 "epcifkihnkjgphfkloaaleeakhpmgdmn");
177
178 // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI
179 // uses the ProfileHelper to obtain the userhash crbug/238623.
180 const std::string login_user = chromeos::login::CanonicalizeUserID(
181 command_line->GetSwitchValueNative(chromeos::switches::kLoginUser));
182 const std::string sanitized_user =
183 CryptohomeClient::GetStubSanitizedUsername(login_user);
184 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
185 sanitized_user);
186 }
187
InitializeSanitizedUsername()188 void InitializeSanitizedUsername() {
189 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
190 chromeos::User* user = user_manager->GetActiveUser();
191 CHECK(user);
192 std::string userhash;
193 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername(
194 user->email(),
195 base::Bind(&AssignString, &userhash_));
196 content::RunAllPendingInMessageLoop();
197 CHECK(!userhash_.empty());
198 }
199
SetupCellular()200 void SetupCellular() {
201 // Add a Cellular Device and set a couple of properties.
202 device_test_->AddDevice(
203 kCellularDevicePath, shill::kTypeCellular, "stub_cellular_device1");
204 device_test_->SetDeviceProperty(kCellularDevicePath,
205 shill::kCarrierProperty,
206 base::StringValue("Cellular1_Carrier"));
207 base::DictionaryValue home_provider;
208 home_provider.SetString("name", "Cellular1_Provider");
209 home_provider.SetString("country", "us");
210 device_test_->SetDeviceProperty(kCellularDevicePath,
211 shill::kHomeProviderProperty,
212 home_provider);
213 AddService("stub_cellular1", "cellular1",
214 shill::kTypeCellular, shill::kStateIdle);
215 // Note: These properties will show up in a "Cellular" object in ONC.
216 service_test_->SetServiceProperty(
217 "stub_cellular1",
218 shill::kNetworkTechnologyProperty,
219 base::StringValue(shill::kNetworkTechnologyGsm));
220 service_test_->SetServiceProperty(
221 "stub_cellular1",
222 shill::kActivationStateProperty,
223 base::StringValue(shill::kActivationStateNotActivated));
224 service_test_->SetServiceProperty(
225 "stub_cellular1",
226 shill::kRoamingStateProperty,
227 base::StringValue(shill::kRoamingStateHome));
228 content::RunAllPendingInMessageLoop();
229 }
230
AddService(const std::string & service_path,const std::string & name,const std::string & type,const std::string & state)231 void AddService(const std::string& service_path,
232 const std::string& name,
233 const std::string& type,
234 const std::string& state) {
235 const bool add_to_visible = true;
236 // Tests need a known GUID, so use 'service_path'.
237 service_test_->AddServiceWithIPConfig(
238 service_path, service_path + "_GUID" /* guid */, name,
239 type, state, "" /* ipconfig_path */,
240 add_to_visible);
241 }
242
SetUpOnMainThread()243 virtual void SetUpOnMainThread() OVERRIDE {
244 detector_ = new NetworkPortalDetectorTestImpl();
245 NetworkPortalDetector::InitializeForTesting(detector_);
246
247 ExtensionApiTest::SetUpOnMainThread();
248 content::RunAllPendingInMessageLoop();
249
250 InitializeSanitizedUsername();
251
252 DBusThreadManager* dbus_manager = DBusThreadManager::Get();
253 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface();
254 service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface();
255 device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface();
256
257 ShillIPConfigClient::TestInterface* ip_config_test =
258 dbus_manager->GetShillIPConfigClient()->GetTestInterface();
259 ShillProfileClient::TestInterface* profile_test =
260 dbus_manager->GetShillProfileClient()->GetTestInterface();
261
262 device_test_->ClearDevices();
263 service_test_->ClearServices();
264
265 // Sends a notification about the added profile.
266 profile_test->AddProfile(kUser1ProfilePath, userhash_);
267
268 // Add IPConfigs
269 base::DictionaryValue ipconfig;
270 ipconfig.SetStringWithoutPathExpansion(shill::kAddressProperty, "0.0.0.0");
271 ipconfig.SetStringWithoutPathExpansion(shill::kGatewayProperty, "0.0.0.1");
272 ipconfig.SetIntegerWithoutPathExpansion(shill::kPrefixlenProperty, 0);
273 ipconfig.SetStringWithoutPathExpansion(shill::kMethodProperty,
274 shill::kTypeIPv4);
275 ip_config_test->AddIPConfig(kIPConfigPath, ipconfig);
276
277 // Add Devices
278 device_test_->AddDevice(
279 kWifiDevicePath, shill::kTypeWifi, "stub_wifi_device1");
280 base::ListValue wifi_ip_configs;
281 wifi_ip_configs.AppendString(kIPConfigPath);
282 device_test_->SetDeviceProperty(
283 kWifiDevicePath, shill::kIPConfigsProperty, wifi_ip_configs);
284 device_test_->SetDeviceProperty(kWifiDevicePath,
285 shill::kAddressProperty,
286 base::StringValue("001122aabbcc"));
287
288 // Add Services
289 AddService("stub_ethernet", "eth0",
290 shill::kTypeEthernet, shill::kStateOnline);
291 service_test_->SetServiceProperty(
292 "stub_ethernet",
293 shill::kProfileProperty,
294 base::StringValue(ShillProfileClient::GetSharedProfilePath()));
295 profile_test->AddService(ShillProfileClient::GetSharedProfilePath(),
296 "stub_ethernet");
297
298 AddService("stub_wifi1", "wifi1", shill::kTypeWifi, shill::kStateOnline);
299 service_test_->SetServiceProperty("stub_wifi1",
300 shill::kSecurityProperty,
301 base::StringValue(shill::kSecurityWep));
302 service_test_->SetServiceProperty("stub_wifi1",
303 shill::kSignalStrengthProperty,
304 base::FundamentalValue(40));
305 service_test_->SetServiceProperty("stub_wifi1",
306 shill::kProfileProperty,
307 base::StringValue(kUser1ProfilePath));
308 service_test_->SetServiceProperty("stub_wifi1",
309 shill::kConnectableProperty,
310 base::FundamentalValue(true));
311 service_test_->SetServiceProperty("stub_wifi1",
312 shill::kDeviceProperty,
313 base::StringValue(kWifiDevicePath));
314 profile_test->AddService(kUser1ProfilePath, "stub_wifi1");
315 base::ListValue frequencies1;
316 frequencies1.AppendInteger(2400);
317 service_test_->SetServiceProperty("stub_wifi1",
318 shill::kWifiFrequencyListProperty,
319 frequencies1);
320 service_test_->SetServiceProperty("stub_wifi1",
321 shill::kWifiFrequency,
322 base::FundamentalValue(2400));
323
324 AddService("stub_wifi2", "wifi2_PSK", shill::kTypeWifi, shill::kStateIdle);
325 service_test_->SetServiceProperty("stub_wifi2",
326 shill::kGuidProperty,
327 base::StringValue("stub_wifi2_GUID"));
328 service_test_->SetServiceProperty("stub_wifi2",
329 shill::kSecurityProperty,
330 base::StringValue(shill::kSecurityPsk));
331 service_test_->SetServiceProperty("stub_wifi2",
332 shill::kSignalStrengthProperty,
333 base::FundamentalValue(80));
334 service_test_->SetServiceProperty("stub_wifi2",
335 shill::kConnectableProperty,
336 base::FundamentalValue(true));
337
338 base::ListValue frequencies2;
339 frequencies2.AppendInteger(2400);
340 frequencies2.AppendInteger(5000);
341 service_test_->SetServiceProperty("stub_wifi2",
342 shill::kWifiFrequencyListProperty,
343 frequencies2);
344 service_test_->SetServiceProperty("stub_wifi2",
345 shill::kWifiFrequency,
346 base::FundamentalValue(5000));
347 service_test_->SetServiceProperty("stub_wifi2",
348 shill::kProfileProperty,
349 base::StringValue(kUser1ProfilePath));
350 profile_test->AddService(kUser1ProfilePath, "stub_wifi2");
351
352 AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline);
353
354 content::RunAllPendingInMessageLoop();
355 }
356 #else // !defined(OS_CHROMEOS)
SetUpCommandLine(CommandLine * command_line)357 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
358 ExtensionApiTest::SetUpCommandLine(command_line);
359 // Whitelist the extension ID of the test extension.
360 command_line->AppendSwitchASCII(
361 extensions::switches::kWhitelistedExtensionID,
362 "epcifkihnkjgphfkloaaleeakhpmgdmn");
363 }
364
CreateNetworkingPrivateServiceClient(content::BrowserContext * profile)365 static KeyedService* CreateNetworkingPrivateServiceClient(
366 content::BrowserContext* profile) {
367 return new extensions::NetworkingPrivateServiceClient(
368 new wifi::FakeWiFiService(), new CryptoVerifyStub());
369 }
370
SetUpOnMainThread()371 virtual void SetUpOnMainThread() OVERRIDE {
372 ExtensionApiTest::SetUpOnMainThread();
373 content::RunAllPendingInMessageLoop();
374 NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory(
375 profile(),
376 &CreateNetworkingPrivateServiceClient);
377 }
378
379 #endif // OS_CHROMEOS
380
381 protected:
382 #if defined(OS_CHROMEOS)
detector()383 NetworkPortalDetectorTestImpl* detector() { return detector_; }
384
385 NetworkPortalDetectorTestImpl* detector_;
386 ShillServiceClient::TestInterface* service_test_;
387 ShillManagerClient::TestInterface* manager_test_;
388 ShillDeviceClient::TestInterface* device_test_;
389 policy::MockConfigurationPolicyProvider provider_;
390 std::string userhash_;
391 #endif
392 };
393
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
396 // other.
397
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,StartConnect)398 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartConnect) {
399 EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_;
400 }
401
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,StartDisconnect)402 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartDisconnect) {
403 EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_;
404 }
405
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,StartConnectNonexistent)406 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
407 StartConnectNonexistent) {
408 EXPECT_TRUE(RunNetworkingSubtest("startConnectNonexistent")) << message_;
409 }
410
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,StartDisconnectNonexistent)411 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
412 StartDisconnectNonexistent) {
413 EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_;
414 }
415
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,StartGetPropertiesNonexistent)416 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
417 StartGetPropertiesNonexistent) {
418 EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent"))
419 << message_;
420 }
421
422 #if defined(OS_CHROMEOS)
423 // TODO(stevenjb/mef): Fix these on non-Chrome OS, crbug.com/371442.
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetNetworks)424 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetNetworks) {
425 // Hide stub_wifi2.
426 service_test_->SetServiceProperty("stub_wifi2",
427 shill::kVisibleProperty,
428 base::FundamentalValue(false));
429 // Add a couple of additional networks that are not configured (saved).
430 AddService("stub_wifi3", "wifi3", shill::kTypeWifi, shill::kStateIdle);
431 AddService("stub_wifi4", "wifi4", shill::kTypeWifi, shill::kStateIdle);
432 content::RunAllPendingInMessageLoop();
433 EXPECT_TRUE(RunNetworkingSubtest("getNetworks")) << message_;
434 }
435
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetVisibleNetworks)436 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) {
437 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_;
438 }
439 #endif
440
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetVisibleNetworksWifi)441 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
442 GetVisibleNetworksWifi) {
443 EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_;
444 }
445
446 #if defined(OS_CHROMEOS)
447 // TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442.
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,RequestNetworkScan)448 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) {
449 EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_;
450 }
451 #endif
452
453 // Properties are filtered and translated through
454 // ShillToONCTranslator::TranslateWiFiWithState
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetProperties)455 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetProperties) {
456 EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_;
457 }
458
459 #if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetCellularProperties)460 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
461 GetCellularProperties) {
462 SetupCellular();
463 EXPECT_TRUE(RunNetworkingSubtest("getPropertiesCellular")) << message_;
464 }
465 #endif
466
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetState)467 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetState) {
468 EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_;
469 }
470
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetStateNonExistent)471 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) {
472 EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_;
473 }
474
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,SetProperties)475 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, SetProperties) {
476 EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_;
477 }
478
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,CreateNetwork)479 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, CreateNetwork) {
480 EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_;
481 }
482
483 #if defined(OS_CHROMEOS)
484 // TODO(stevenjb/mef): Find a maintainable way to support this on win/mac and
485 // a better way to set this up on Chrome OS.
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetManagedProperties)486 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
487 GetManagedProperties) {
488 const std::string uidata_blob =
489 "{ \"user_settings\": {"
490 " \"WiFi\": {"
491 " \"Passphrase\": \"FAKE_CREDENTIAL_VPaJDV9x\" }"
492 " }"
493 "}";
494 service_test_->SetServiceProperty("stub_wifi2",
495 shill::kUIDataProperty,
496 base::StringValue(uidata_blob));
497 service_test_->SetServiceProperty("stub_wifi2",
498 shill::kAutoConnectProperty,
499 base::FundamentalValue(false));
500
501 ShillProfileClient::TestInterface* profile_test =
502 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
503 // Update the profile entry.
504 profile_test->AddService(kUser1ProfilePath, "stub_wifi2");
505
506 content::RunAllPendingInMessageLoop();
507
508 const std::string user_policy_blob =
509 "{ \"NetworkConfigurations\": ["
510 " { \"GUID\": \"stub_wifi2\","
511 " \"Type\": \"WiFi\","
512 " \"Name\": \"My WiFi Network\","
513 " \"WiFi\": {"
514 " \"Passphrase\": \"passphrase\","
515 " \"Recommended\": [ \"AutoConnect\", \"Passphrase\" ],"
516 " \"SSID\": \"wifi2_PSK\","
517 " \"Security\": \"WPA-PSK\" }"
518 " }"
519 " ],"
520 " \"Certificates\": [],"
521 " \"Type\": \"UnencryptedConfiguration\""
522 "}";
523
524 policy::PolicyMap policy;
525 policy.Set(policy::key::kOpenNetworkConfiguration,
526 policy::POLICY_LEVEL_MANDATORY,
527 policy::POLICY_SCOPE_USER,
528 new base::StringValue(user_policy_blob),
529 NULL);
530 provider_.UpdateChromePolicy(policy);
531
532 content::RunAllPendingInMessageLoop();
533
534 EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_;
535 }
536 #endif // OS_CHROMEOS
537
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,OnNetworksChangedEventConnect)538 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
539 OnNetworksChangedEventConnect) {
540 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect"))
541 << message_;
542 }
543
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,OnNetworksChangedEventDisconnect)544 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
545 OnNetworksChangedEventDisconnect) {
546 EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect"))
547 << message_;
548 }
549
550 #if defined(OS_CHROMEOS)
551 // TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442.
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,OnNetworkListChangedEvent)552 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
553 OnNetworkListChangedEvent) {
554 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_;
555 }
556 #endif // OS_CHROMEOS
557
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,VerifyDestination)558 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
559 VerifyDestination) {
560 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_;
561 }
562
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,VerifyAndEncryptCredentials)563 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
564 VerifyAndEncryptCredentials) {
565 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_;
566 }
567
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,VerifyAndEncryptData)568 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
569 VerifyAndEncryptData) {
570 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_;
571 }
572
573 #if defined(OS_CHROMEOS)
574 // Currently TDLS support is only enabled for Chrome OS.
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,SetWifiTDLSEnabledState)575 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
576 SetWifiTDLSEnabledState) {
577 EXPECT_TRUE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_;
578 }
579
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetWifiTDLSStatus)580 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
581 GetWifiTDLSStatus) {
582 EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_;
583 }
584 #endif
585
586 // NetworkPortalDetector is only enabled for Chrome OS.
587 #if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,GetCaptivePortalStatus)588 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
589 GetCaptivePortalStatus) {
590 SetupCellular();
591
592 NetworkPortalDetector::CaptivePortalState state;
593 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
594 detector()->SetDetectionResultsForTesting("stub_ethernet", state);
595
596 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
597 detector()->SetDetectionResultsForTesting("stub_wifi1", state);
598
599 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
600 detector()->SetDetectionResultsForTesting("stub_wifi2", state);
601
602 state.status =
603 NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED;
604 detector()->SetDetectionResultsForTesting("stub_cellular1", state);
605
606 EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_;
607 }
608
IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,CaptivePortalNotification)609 IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest,
610 CaptivePortalNotification) {
611 detector()->SetDefaultNetworkPathForTesting("wifi", "wifi_GUID");
612 NetworkPortalDetector::CaptivePortalState state;
613 state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
614 detector()->SetDetectionResultsForTesting("wifi", state);
615
616 TestListener listener(
617 "notifyPortalDetectorObservers",
618 base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting,
619 base::Unretained(detector())));
620 EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_;
621 }
622 #endif // defined(OS_CHROMEOS)
623
624 } // namespace
625