Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / networking_private / networking_private_apitest.cc
index 92cfe2d..45eeadf 100644 (file)
@@ -2,21 +2,28 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "base/bind.h"
 #include "base/callback.h"
 #include "base/command_line.h"
+#include "base/macros.h"
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/chromeos/login/user.h"
 #include "chrome/browser/chromeos/login/user_manager.h"
 #include "chrome/browser/extensions/extension_apitest.h"
 #include "chrome/common/chrome_switches.h"
 #include "chrome/test/base/ui_test_utils.h"
+#include "extensions/common/switches.h"
 #include "testing/gmock/include/gmock/gmock.h"
 
 #if defined(OS_CHROMEOS)
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/net/network_portal_detector.h"
+#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
 #include "chromeos/chromeos_switches.h"
 #include "chromeos/dbus/cryptohome_client.h"
 #include "chromeos/dbus/dbus_thread_manager.h"
 #include "chromeos/dbus/shill_device_client.h"
+#include "chromeos/dbus/shill_ipconfig_client.h"
 #include "chromeos/dbus/shill_manager_client.h"
 #include "chromeos/dbus/shill_profile_client.h"
 #include "chromeos/dbus/shill_service_client.h"
 #include "components/policy/core/common/mock_configuration_policy_provider.h"
 #include "components/policy/core/common/policy_map.h"
 #include "components/policy/core/common/policy_types.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
 #include "policy/policy_constants.h"
 #include "third_party/cros_system_api/dbus/service_constants.h"
 #else  // !defined(OS_CHROMEOS)
 #include "chrome/browser/extensions/api/networking_private/networking_private_credentials_getter.h"
 #include "chrome/browser/extensions/api/networking_private/networking_private_service_client.h"
 #include "chrome/browser/extensions/api/networking_private/networking_private_service_client_factory.h"
-#include "components/wifi/wifi_service.h"
+#include "components/wifi/fake_wifi_service.h"
 #endif  // defined(OS_CHROMEOS)
 
+// TODO(stevenjb/mef): Clean these tests up. crbug.com/371442
+
 using testing::Return;
 using testing::_;
 
@@ -44,7 +57,10 @@ using chromeos::CryptohomeClient;
 using chromeos::DBUS_METHOD_CALL_SUCCESS;
 using chromeos::DBusMethodCallStatus;
 using chromeos::DBusThreadManager;
+using chromeos::NetworkPortalDetector;
+using chromeos::NetworkPortalDetectorTestImpl;
 using chromeos::ShillDeviceClient;
+using chromeos::ShillIPConfigClient;
 using chromeos::ShillManagerClient;
 using chromeos::ShillProfileClient;
 using chromeos::ShillServiceClient;
@@ -56,6 +72,35 @@ namespace {
 
 #if defined(OS_CHROMEOS)
 const char kUser1ProfilePath[] = "/profile/user1/shill";
+const char kWifiDevicePath[] = "/device/stub_wifi_device1";
+const char kCellularDevicePath[] = "/device/stub_cellular_device1";
+const char kIPConfigPath[] = "/ipconfig/ipconfig1";
+
+class TestListener : public content::NotificationObserver {
+ public:
+  TestListener(const std::string& message, const base::Closure& callback)
+      : message_(message), callback_(callback) {
+    registrar_.Add(this,
+                   chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
+                   content::NotificationService::AllSources());
+  }
+
+  virtual void Observe(int type,
+                       const content::NotificationSource& /* source */,
+                       const content::NotificationDetails& details) OVERRIDE {
+    const std::string& message = *content::Details<std::string>(details).ptr();
+    if (message == message_)
+      callback_.Run();
+  }
+
+ private:
+  std::string message_;
+  base::Closure callback_;
+
+  content::NotificationRegistrar registrar_;
+
+  DISALLOW_COPY_AND_ASSIGN(TestListener);
+};
 #else  // !defined(OS_CHROMEOS)
 
 // Stub Verify* methods implementation to satisfy expectations of
@@ -74,7 +119,7 @@ class CryptoVerifyStub
   virtual void VerifyAndEncryptCredentials(
       scoped_ptr<base::ListValue> args,
       const extensions::NetworkingPrivateServiceClient::CryptoVerify::
-          VerifyAndEncryptCredentialsCallback& callback) OVERRIDE {
+      VerifyAndEncryptCredentialsCallback& callback) OVERRIDE {
     callback.Run("encrypted_credentials", "");
   }
 
@@ -86,10 +131,18 @@ class CryptoVerifyStub
 };
 #endif  // defined(OS_CHROMEOS)
 
-class ExtensionNetworkingPrivateApiTest :
-    public ExtensionApiTest,
-    public testing::WithParamInterface<bool> {
+class ExtensionNetworkingPrivateApiTest
+    public ExtensionApiTest,
+      public testing::WithParamInterface<bool> {
  public:
+  ExtensionNetworkingPrivateApiTest()
+#if defined(OS_CHROMEOS)
+      : detector_(NULL),
+        service_test_(NULL)
+#endif
+  {
+  }
+
   bool RunNetworkingSubtest(const std::string& subtest) {
     return RunExtensionSubtest(
         "networking", "main.html?" + subtest,
@@ -108,8 +161,8 @@ class ExtensionNetworkingPrivateApiTest :
 
 #if defined(OS_CHROMEOS)
   static void AssignString(std::string* out,
-                    DBusMethodCallStatus call_status,
-                    const std::string& result) {
+                           DBusMethodCallStatus call_status,
+                           const std::string& result) {
     CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS);
     *out = result;
   }
@@ -117,8 +170,9 @@ class ExtensionNetworkingPrivateApiTest :
   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     ExtensionApiTest::SetUpCommandLine(command_line);
     // Whitelist the extension ID of the test extension.
-    command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID,
-                                    "epcifkihnkjgphfkloaaleeakhpmgdmn");
+    command_line->AppendSwitchASCII(
+        extensions::switches::kWhitelistedExtensionID,
+        "epcifkihnkjgphfkloaaleeakhpmgdmn");
 
     // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI
     // uses the ProfileHelper to obtain the userhash crbug/238623.
@@ -145,112 +199,126 @@ class ExtensionNetworkingPrivateApiTest :
   }
 
   virtual void SetUpOnMainThread() OVERRIDE {
+    detector_ = new NetworkPortalDetectorTestImpl();
+    NetworkPortalDetector::InitializeForTesting(detector_);
+
     ExtensionApiTest::SetUpOnMainThread();
     content::RunAllPendingInMessageLoop();
 
     InitializeSanitizedUsername();
 
+    DBusThreadManager* dbus_manager = DBusThreadManager::Get();
     ShillManagerClient::TestInterface* manager_test =
-        DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface();
+        dbus_manager->GetShillManagerClient()->GetTestInterface();
+    ShillIPConfigClient::TestInterface* ip_config_test =
+        dbus_manager->GetShillIPConfigClient()->GetTestInterface();
     ShillDeviceClient::TestInterface* device_test =
-        DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface();
+        dbus_manager->GetShillDeviceClient()->GetTestInterface();
     ShillProfileClient::TestInterface* profile_test =
-        DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
-    ShillServiceClient::TestInterface* service_test =
-        DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
+        dbus_manager->GetShillProfileClient()->GetTestInterface();
+
+    service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface();
 
     device_test->ClearDevices();
-    service_test->ClearServices();
+    service_test_->ClearServices();
 
     // Sends a notification about the added profile.
     profile_test->AddProfile(kUser1ProfilePath, userhash_);
 
-    device_test->AddDevice("/device/stub_wifi_device1",
-                           shill::kTypeWifi, "stub_wifi_device1");
-    device_test->AddDevice("/device/stub_cellular_device1",
-                           shill::kTypeCellular, "stub_cellular_device1");
-
+    // Add IPConfigs
+    base::DictionaryValue ipconfig;
+    ipconfig.SetStringWithoutPathExpansion(shill::kAddressProperty, "0.0.0.0");
+    ipconfig.SetStringWithoutPathExpansion(shill::kGatewayProperty, "0.0.0.1");
+    ipconfig.SetIntegerWithoutPathExpansion(shill::kPrefixlenProperty, 0);
+    ipconfig.SetStringWithoutPathExpansion(
+        shill::kMethodProperty, shill::kTypeIPv4);
+    ip_config_test->AddIPConfig(kIPConfigPath, ipconfig);
+
+    // Add Devices
+    device_test->AddDevice(
+        kWifiDevicePath, shill::kTypeWifi, "stub_wifi_device1");
+    base::ListValue wifi_ip_configs;
+    wifi_ip_configs.AppendString(kIPConfigPath);
+    device_test->SetDeviceProperty(
+        kWifiDevicePath, shill::kIPConfigsProperty, wifi_ip_configs);
+    device_test->AddDevice(
+        kCellularDevicePath, shill::kTypeCellular, "stub_cellular_device1");
+
+    // Add Services
     const bool add_to_watchlist = true;
     const bool add_to_visible = true;
-    service_test->AddService("stub_ethernet", "eth0",
-                             shill::kTypeEthernet, shill::kStateOnline,
-                             add_to_visible, add_to_watchlist);
-    service_test->SetServiceProperty(
+    service_test_->AddService("stub_ethernet", "eth0",
+                              shill::kTypeEthernet, shill::kStateOnline,
+                              add_to_visible, add_to_watchlist);
+    service_test_->SetServiceProperty(
         "stub_ethernet",
         shill::kProfileProperty,
         base::StringValue(ShillProfileClient::GetSharedProfilePath()));
     profile_test->AddService(ShillProfileClient::GetSharedProfilePath(),
                              "stub_ethernet");
 
-    service_test->AddService("stub_wifi1", "wifi1",
-                             shill::kTypeWifi, shill::kStateOnline,
-                             add_to_visible, add_to_watchlist);
-    service_test->SetServiceProperty("stub_wifi1",
-                                     shill::kSecurityProperty,
-                                     base::StringValue(shill::kSecurityWep));
-    service_test->SetServiceProperty("stub_wifi1",
-                                     shill::kProfileProperty,
-                                     base::StringValue(kUser1ProfilePath));
+    service_test_->AddService("stub_wifi1", "wifi1",
+                              shill::kTypeWifi, shill::kStateOnline,
+                              add_to_visible, add_to_watchlist);
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kSecurityProperty,
+                                      base::StringValue(shill::kSecurityWep));
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kSignalStrengthProperty,
+                                      base::FundamentalValue(40));
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kProfileProperty,
+                                      base::StringValue(kUser1ProfilePath));
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kConnectableProperty,
+                                      base::FundamentalValue(true));
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kDeviceProperty,
+                                      base::StringValue(kWifiDevicePath));
     profile_test->AddService(kUser1ProfilePath, "stub_wifi1");
     base::ListValue frequencies1;
     frequencies1.AppendInteger(2400);
-    service_test->SetServiceProperty("stub_wifi1",
-                                     shill::kWifiFrequencyListProperty,
-                                     frequencies1);
-    service_test->SetServiceProperty("stub_wifi1",
-                                     shill::kWifiFrequency,
-                                     base::FundamentalValue(2400));
-
-    service_test->AddService("stub_wifi2", "wifi2_PSK",
-                             shill::kTypeWifi, shill::kStateIdle,
-                             add_to_visible, add_to_watchlist);
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kGuidProperty,
-                                     base::StringValue("stub_wifi2"));
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kSecurityProperty,
-                                     base::StringValue(shill::kSecurityPsk));
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kSignalStrengthProperty,
-                                     base::FundamentalValue(80));
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kConnectableProperty,
-                                     base::FundamentalValue(true));
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kWifiFrequencyListProperty,
+                                      frequencies1);
+    service_test_->SetServiceProperty("stub_wifi1",
+                                      shill::kWifiFrequency,
+                                      base::FundamentalValue(2400));
+
+    service_test_->AddService("stub_wifi2", "wifi2_PSK",
+                              shill::kTypeWifi, shill::kStateIdle,
+                              add_to_visible, add_to_watchlist);
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kGuidProperty,
+                                      base::StringValue("stub_wifi2"));
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kSecurityProperty,
+                                      base::StringValue(shill::kSecurityPsk));
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kSignalStrengthProperty,
+                                      base::FundamentalValue(80));
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kConnectableProperty,
+                                      base::FundamentalValue(true));
 
     base::ListValue frequencies2;
     frequencies2.AppendInteger(2400);
     frequencies2.AppendInteger(5000);
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kWifiFrequencyListProperty,
-                                     frequencies2);
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kWifiFrequency,
-                                     base::FundamentalValue(5000));
-    service_test->SetServiceProperty("stub_wifi2",
-                                     shill::kProfileProperty,
-                                     base::StringValue(kUser1ProfilePath));
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kWifiFrequencyListProperty,
+                                      frequencies2);
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kWifiFrequency,
+                                      base::FundamentalValue(5000));
+    service_test_->SetServiceProperty("stub_wifi2",
+                                      shill::kProfileProperty,
+                                      base::StringValue(kUser1ProfilePath));
     profile_test->AddService(kUser1ProfilePath, "stub_wifi2");
 
-    service_test->AddService("stub_cellular1", "cellular1",
-                             shill::kTypeCellular, shill::kStateIdle,
-                             add_to_visible, add_to_watchlist);
-    service_test->SetServiceProperty(
-        "stub_cellular1",
-        shill::kNetworkTechnologyProperty,
-        base::StringValue(shill::kNetworkTechnologyGsm));
-    service_test->SetServiceProperty(
-        "stub_cellular1",
-        shill::kActivationStateProperty,
-        base::StringValue(shill::kActivationStateNotActivated));
-    service_test->SetServiceProperty(
-        "stub_cellular1",
-        shill::kRoamingStateProperty,
-        base::StringValue(shill::kRoamingStateHome));
-
-    service_test->AddService("stub_vpn1", "vpn1",
-                             shill::kTypeVPN,
-                             shill::kStateOnline,
-                             add_to_visible, add_to_watchlist);
+    service_test_->AddService("stub_vpn1", "vpn1",
+                              shill::kTypeVPN,
+                              shill::kStateOnline,
+                              add_to_visible, add_to_watchlist);
 
     manager_test->SortManagerServices();
 
@@ -260,15 +328,15 @@ class ExtensionNetworkingPrivateApiTest :
   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     ExtensionApiTest::SetUpCommandLine(command_line);
     // Whitelist the extension ID of the test extension.
-    command_line->AppendSwitchASCII(::switches::kWhitelistedExtensionID,
-                                    "epcifkihnkjgphfkloaaleeakhpmgdmn");
+    command_line->AppendSwitchASCII(
+        extensions::switches::kWhitelistedExtensionID,
+        "epcifkihnkjgphfkloaaleeakhpmgdmn");
   }
 
   static KeyedService* CreateNetworkingPrivateServiceClient(
       content::BrowserContext* profile) {
     return new extensions::NetworkingPrivateServiceClient(
-        wifi::WiFiService::CreateForTest(),
-        new CryptoVerifyStub());
+        new wifi::FakeWiFiService(), new CryptoVerifyStub());
   }
 
   virtual void SetUpOnMainThread() OVERRIDE {
@@ -283,6 +351,10 @@ class ExtensionNetworkingPrivateApiTest :
 
  protected:
 #if defined(OS_CHROMEOS)
+  NetworkPortalDetectorTestImpl* detector() { return detector_; }
+
+  NetworkPortalDetectorTestImpl* detector_;
+  ShillServiceClient::TestInterface* service_test_;
   policy::MockConfigurationPolicyProvider provider_;
   std::string userhash_;
 #endif
@@ -316,18 +388,24 @@ IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
       << message_;
 }
 
+#if defined(OS_CHROMEOS)
+// Non-Chrome OS only supports wifi currently.
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) {
   EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_;
 }
+#endif
 
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
                        GetVisibleNetworksWifi) {
   EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_;
 }
 
+#if defined(OS_CHROMEOS)
+// TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442.
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) {
   EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_;
 }
+#endif
 
 // Properties are filtered and translated through
 // ShillToONCTranslator::TranslateWiFiWithState
@@ -351,24 +429,23 @@ IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest, CreateNetwork) {
   EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_;
 }
 
+#if defined(OS_CHROMEOS)
+// TODO(stevenjb/mef): Find a maintainable way to support this on win/mac and
+// a better way to set this up on Chrome OS.
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
                        GetManagedProperties) {
-#if defined(OS_CHROMEOS)
-  // TODO(mef): Move this to ChromeOS-specific helper or SetUpOnMainThread.
-  ShillServiceClient::TestInterface* service_test =
-      DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
   const std::string uidata_blob =
       "{ \"user_settings\": {"
       "      \"WiFi\": {"
       "        \"Passphrase\": \"FAKE_CREDENTIAL_VPaJDV9x\" }"
       "    }"
       "}";
-  service_test->SetServiceProperty("stub_wifi2",
-                                   shill::kUIDataProperty,
-                                   base::StringValue(uidata_blob));
-  service_test->SetServiceProperty("stub_wifi2",
-                                   shill::kAutoConnectProperty,
-                                   base::FundamentalValue(false));
+  service_test_->SetServiceProperty("stub_wifi2",
+                                    shill::kUIDataProperty,
+                                    base::StringValue(uidata_blob));
+  service_test_->SetServiceProperty("stub_wifi2",
+                                    shill::kAutoConnectProperty,
+                                    base::FundamentalValue(false));
 
   ShillProfileClient::TestInterface* profile_test =
       DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface();
@@ -402,10 +479,10 @@ IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
   provider_.UpdateChromePolicy(policy);
 
   content::RunAllPendingInMessageLoop();
-#endif  // OS_CHROMEOS
 
   EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_;
 }
+#endif  // OS_CHROMEOS
 
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
                        OnNetworksChangedEventConnect) {
@@ -419,10 +496,13 @@ IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
       << message_;
 }
 
+#if defined(OS_CHROMEOS)
+// TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442.
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
                        OnNetworkListChangedEvent) {
   EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_;
 }
+#endif  // OS_CHROMEOS
 
 IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
                        VerifyDestination) {
@@ -452,6 +532,62 @@ IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
 }
 #endif
 
+// NetworkPortalDetector is only enabled for Chrome OS.
+#if defined(OS_CHROMEOS)
+IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
+                       GetCaptivePortalStatus) {
+  service_test_->AddService("stub_cellular1", "cellular1",
+                            shill::kTypeCellular, shill::kStateIdle,
+                            true /* add_to_visible */,
+                            true /* add_to_watchlist */);
+  service_test_->SetServiceProperty(
+      "stub_cellular1",
+      shill::kNetworkTechnologyProperty,
+      base::StringValue(shill::kNetworkTechnologyGsm));
+  service_test_->SetServiceProperty(
+      "stub_cellular1",
+      shill::kActivationStateProperty,
+      base::StringValue(shill::kActivationStateNotActivated));
+  service_test_->SetServiceProperty(
+      "stub_cellular1",
+      shill::kRoamingStateProperty,
+      base::StringValue(shill::kRoamingStateHome));
+  DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
+      SortManagerServices();
+  content::RunAllPendingInMessageLoop();
+
+  NetworkPortalDetector::CaptivePortalState state;
+  state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
+  detector()->SetDetectionResultsForTesting("stub_ethernet", state);
+
+  state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
+  detector()->SetDetectionResultsForTesting("stub_wifi1", state);
+
+  state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
+  detector()->SetDetectionResultsForTesting("stub_wifi2", state);
+
+  state.status =
+      NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED;
+  detector()->SetDetectionResultsForTesting("stub_cellular1", state);
+
+  EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_P(ExtensionNetworkingPrivateApiTest,
+                       CaptivePortalNotification) {
+  detector()->SetDefaultNetworkPathForTesting("wifi");
+  NetworkPortalDetector::CaptivePortalState state;
+  state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
+  detector()->SetDetectionResultsForTesting("wifi", state);
+
+  TestListener listener(
+      "notifyPortalDetectorObservers",
+      base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting,
+                 base::Unretained(detector())));
+  EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_;
+}
+#endif  // defined(OS_CHROMEOS)
+
 INSTANTIATE_TEST_CASE_P(ExtensionNetworkingPrivateApiTestInstantiation,
                         ExtensionNetworkingPrivateApiTest,
                         testing::Bool());