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