diff options
9 files changed, 509 insertions, 1221 deletions
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_apitest.cc b/chrome/browser/extensions/api/networking_private/networking_private_apitest.cc index e340861..20bf3a4 100644 --- a/chrome/browser/extensions/api/networking_private/networking_private_apitest.cc +++ b/chrome/browser/extensions/api/networking_private/networking_private_apitest.cc @@ -1,245 +1,374 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <map> -#include <vector> - +#include "base/bind.h" +#include "base/callback.h" #include "base/command_line.h" -#include "base/logging.h" -#include "chrome/browser/extensions/api/networking_private/networking_private_delegate.h" +#include "base/macros.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_apitest.h" -#include "components/keyed_service/core/keyed_service.h" -#include "components/onc/onc_constants.h" -#include "content/public/test/test_utils.h" +#include "chrome/test/base/ui_test_utils.h" +#include "components/user_manager/user.h" +#include "components/user_manager/user_manager.h" #include "extensions/common/switches.h" +#include "testing/gmock/include/gmock/gmock.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/extensions/api/networking_private/networking_private_factory_chromeos.h" -#else +#include "chrome/browser/chromeos/login/helper.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 "chromeos/login/user_names.h" +#include "chromeos/network/onc/onc_utils.h" +#include "chromeos/network/portal_detector/network_portal_detector.h" +#include "components/onc/onc_constants.h" +#include "components/policy/core/browser/browser_policy_connector.h" +#include "components/policy/core/common/external_data_fetcher.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 "extensions/browser/notification_types.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" -#endif +#include "components/wifi/fake_wifi_service.h" +#endif // defined(OS_CHROMEOS) -namespace extensions { +// TODO(stevenjb/mef): Clean these tests up. crbug.com/371442 -// This tests just the interface for the networkingPrivate API, i.e. it ensures -// that the delegate methods are called as expected. +using testing::Return; +using testing::_; + +#if defined(OS_CHROMEOS) +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; +#else // !defined(OS_CHROMEOS) +using extensions::NetworkingPrivateServiceClientFactory; +#endif // defined(OS_CHROMEOS) namespace { -const char kFailure[] = "Failure"; -const char kSuccess[] = "Success"; -const char kGuid[] = "SOME_GUID"; +#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 TestDelegate : public KeyedService, - public NetworkingPrivateDelegate { +class TestListener : public content::NotificationObserver { public: - TestDelegate() : fail_(false) { - } - - // Asynchronous methods - virtual void GetProperties(const std::string& guid, - const DictionaryCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - DictionaryResult(guid, success_callback, failure_callback); + TestListener(const std::string& message, const base::Closure& callback) + : message_(message), callback_(callback) { + registrar_.Add(this, + extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE, + content::NotificationService::AllSources()); } - virtual void GetManagedProperties( - const std::string& guid, - const DictionaryCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - DictionaryResult(guid, success_callback, failure_callback); + 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(); } - virtual void GetState(const std::string& guid, - const DictionaryCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - DictionaryResult(guid, success_callback, failure_callback); - } - - - virtual void SetProperties(const std::string& guid, - scoped_ptr<base::DictionaryValue> properties, - const VoidCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - VoidResult(success_callback, failure_callback); - } - - virtual void CreateNetwork(bool shared, - scoped_ptr<base::DictionaryValue> properties, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); - } - - virtual void GetNetworks(const std::string& network_type, - bool configured_only, - bool visible_only, - int limit, - const NetworkListCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - if (fail_) { - failure_callback.Run(kFailure); - } else { - scoped_ptr<base::ListValue> result(new base::ListValue); - scoped_ptr<base::DictionaryValue> network(new base::DictionaryValue); - network->SetString(::onc::network_config::kType, - ::onc::network_config::kEthernet); - network->SetString(::onc::network_config::kGUID, kGuid); - result->Append(network.release()); - success_callback.Run(result.Pass()); - } - } + private: + std::string message_; + base::Closure callback_; - virtual void StartConnect(const std::string& guid, - const VoidCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - VoidResult(success_callback, failure_callback); - } + content::NotificationRegistrar registrar_; - virtual void StartDisconnect( - const std::string& guid, - const VoidCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - VoidResult(success_callback, failure_callback); - } + DISALLOW_COPY_AND_ASSIGN(TestListener); +}; +#else // !defined(OS_CHROMEOS) - virtual void VerifyDestination( - const VerificationProperties& verification_properties, - const BoolCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - BoolResult(success_callback, failure_callback); +// Stub Verify* methods implementation to satisfy expectations of +// networking_private_apitest. +// TODO(mef): Fix ChromeOS implementation to use NetworkingPrivateCrypto, +// and update networking_private_apitest to use and expect valid data. +// That will eliminate the need for mock implementation. +class CryptoVerifyStub + : public extensions::NetworkingPrivateServiceClient::CryptoVerify { + virtual void VerifyDestination(const Credentials& verification_properties, + bool* verified, + std::string* error) OVERRIDE { + *verified = true; } virtual void VerifyAndEncryptCredentials( - const std::string& guid, - const VerificationProperties& verification_properties, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); - } - - virtual void VerifyAndEncryptData( - const VerificationProperties& verification_properties, - const std::string& data, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); - } - - virtual void SetWifiTDLSEnabledState( - const std::string& ip_or_mac_address, - bool enabled, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); - } - - virtual void GetWifiTDLSStatus( - const std::string& ip_or_mac_address, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); + const std::string& network_guid, + const Credentials& credentials, + const VerifyAndEncryptCredentialsCallback& callback) OVERRIDE { + callback.Run("encrypted_credentials", ""); } - virtual void GetCaptivePortalStatus( - const std::string& guid, - const StringCallback& success_callback, - const FailureCallback& failure_callback) OVERRIDE { - StringResult(success_callback, failure_callback); + virtual void VerifyAndEncryptData(const Credentials& verification_properties, + const std::string& data, + std::string* base64_encoded_ciphertext, + std::string* error) OVERRIDE { + *base64_encoded_ciphertext = "encrypted_data"; } +}; +#endif // defined(OS_CHROMEOS) - // Synchronous methods - virtual scoped_ptr<base::ListValue> GetEnabledNetworkTypes() OVERRIDE { - scoped_ptr<base::ListValue> result; - if (!fail_) { - result.reset(new base::ListValue); - result->AppendString(::onc::network_config::kEthernet); - } - return result.Pass(); +class ExtensionNetworkingPrivateApiTest + : public ExtensionApiTest { + public: + ExtensionNetworkingPrivateApiTest() +#if defined(OS_CHROMEOS) + : detector_(NULL), + service_test_(NULL), + manager_test_(NULL), + device_test_(NULL) +#endif + { } - virtual bool EnableNetworkType(const std::string& type) OVERRIDE{ - enabled_[type] = true; - return !fail_; + bool RunNetworkingSubtest(const std::string& subtest) { + return RunExtensionSubtest( + "networking", "main.html?" + subtest, + kFlagEnableFileAccess | kFlagLoadAsComponent); } - virtual bool DisableNetworkType(const std::string& type) OVERRIDE { - disabled_[type] = true; - return !fail_; - } + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { +#if defined(OS_CHROMEOS) + EXPECT_CALL(provider_, IsInitializationComplete(_)) + .WillRepeatedly(Return(true)); + policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); +#endif - virtual bool RequestScan() OVERRIDE { - scan_requested_.push_back(true); - return !fail_; + ExtensionApiTest::SetUpInProcessBrowserTestFixture(); } - void set_fail(bool fail) { fail_ = fail; } - bool GetEnabled(const std::string& type) { return enabled_[type]; } - bool GetDisabled(const std::string& type) { return disabled_[type]; } - size_t GetScanRequested() { return scan_requested_.size(); } - - private: - void DictionaryResult(const std::string& guid, - const DictionaryCallback& success_callback, - const FailureCallback& failure_callback) { - if (fail_) { - failure_callback.Run(kFailure); - } else { - scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); - result->SetString(::onc::network_config::kGUID, guid); - success_callback.Run(result.Pass()); - } +#if defined(OS_CHROMEOS) + static void AssignString(std::string* out, + DBusMethodCallStatus call_status, + const std::string& result) { + CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS); + *out = result; } - void StringResult(const StringCallback& success_callback, - const FailureCallback& failure_callback) { - if (fail_) { - failure_callback.Run(kFailure); - } else { - success_callback.Run(kSuccess); - } - } + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + ExtensionApiTest::SetUpCommandLine(command_line); + // Whitelist the extension ID of the test extension. + command_line->AppendSwitchASCII( + extensions::switches::kWhitelistedExtensionID, + "epcifkihnkjgphfkloaaleeakhpmgdmn"); - void BoolResult(const BoolCallback& success_callback, - const FailureCallback& failure_callback) { - if (fail_) { - failure_callback.Run(kFailure); - } else { - success_callback.Run(true); - } + // TODO(pneubeck): Remove the following hack, once the NetworkingPrivateAPI + // uses the ProfileHelper to obtain the userhash crbug/238623. + const std::string login_user = chromeos::login::CanonicalizeUserID( + command_line->GetSwitchValueNative(chromeos::switches::kLoginUser)); + const std::string sanitized_user = + CryptohomeClient::GetStubSanitizedUsername(login_user); + command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, + sanitized_user); + } + + void InitializeSanitizedUsername() { + user_manager::UserManager* user_manager = user_manager::UserManager::Get(); + user_manager::User* user = user_manager->GetActiveUser(); + CHECK(user); + std::string userhash; + DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( + user->email(), + base::Bind(&AssignString, &userhash_)); + content::RunAllPendingInMessageLoop(); + CHECK(!userhash_.empty()); + } + + void SetupCellular() { + // Add a Cellular Device and set a couple of properties. + device_test_->AddDevice( + kCellularDevicePath, shill::kTypeCellular, "stub_cellular_device1"); + device_test_->SetDeviceProperty(kCellularDevicePath, + shill::kCarrierProperty, + base::StringValue("Cellular1_Carrier")); + base::DictionaryValue home_provider; + home_provider.SetString("name", "Cellular1_Provider"); + home_provider.SetString("country", "us"); + device_test_->SetDeviceProperty(kCellularDevicePath, + shill::kHomeProviderProperty, + home_provider); + AddService("stub_cellular1", "cellular1", + shill::kTypeCellular, shill::kStateIdle); + // Note: These properties will show up in a "Cellular" object in ONC. + service_test_->SetServiceProperty( + "stub_cellular1", + shill::kAutoConnectProperty, + base::FundamentalValue(true)); + 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)); + content::RunAllPendingInMessageLoop(); } - void VoidResult(const VoidCallback& success_callback, - const FailureCallback& failure_callback) { - if (fail_) { - failure_callback.Run(kFailure); - } else { - success_callback.Run(); - } + void AddService(const std::string& service_path, + const std::string& name, + const std::string& type, + const std::string& state) { + service_test_->AddService( + service_path, service_path + "_guid", name, + type, state, true /* add_to_visible */); } - bool fail_; - std::map<std::string, bool> enabled_; - std::map<std::string, bool> disabled_; - std::vector<bool> scan_requested_; + virtual void SetUpOnMainThread() OVERRIDE { + detector_ = new NetworkPortalDetectorTestImpl(); + NetworkPortalDetector::InitializeForTesting(detector_); - DISALLOW_COPY_AND_ASSIGN(TestDelegate); -}; + ExtensionApiTest::SetUpOnMainThread(); + content::RunAllPendingInMessageLoop(); -class NetworkingPrivateApiTest : public ExtensionApiTest { - public: - NetworkingPrivateApiTest() { - if (!s_test_delegate_) - s_test_delegate_ = new TestDelegate; - } + InitializeSanitizedUsername(); + + DBusThreadManager* dbus_manager = DBusThreadManager::Get(); + manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); + service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); + device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); + + ShillIPConfigClient::TestInterface* ip_config_test = + dbus_manager->GetShillIPConfigClient()->GetTestInterface(); + ShillProfileClient::TestInterface* profile_test = + dbus_manager->GetShillProfileClient()->GetTestInterface(); + + device_test_->ClearDevices(); + service_test_->ClearServices(); + + // Sends a notification about the added profile. + profile_test->AddProfile(kUser1ProfilePath, userhash_); + + // Enable technologies. + manager_test_->AddTechnology("wimax", true); + + // 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_->SetDeviceProperty(kWifiDevicePath, + shill::kAddressProperty, + base::StringValue("001122aabbcc")); + + // Add Services + AddService("stub_ethernet", "eth0", + shill::kTypeEthernet, shill::kStateOnline); + service_test_->SetServiceProperty( + "stub_ethernet", + shill::kProfileProperty, + base::StringValue(ShillProfileClient::GetSharedProfilePath())); + profile_test->AddService(ShillProfileClient::GetSharedProfilePath(), + "stub_ethernet"); + + AddService("stub_wifi1", "wifi1", shill::kTypeWifi, shill::kStateOnline); + 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)); + + AddService("stub_wifi2", "wifi2_PSK", shill::kTypeWifi, shill::kStateIdle); + 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)); + + AddService("stub_wimax", "wimax", shill::kTypeWimax, shill::kStateOnline); + service_test_->SetServiceProperty("stub_wimax", + shill::kSignalStrengthProperty, + base::FundamentalValue(40)); + service_test_->SetServiceProperty("stub_wimax", + shill::kProfileProperty, + base::StringValue(kUser1ProfilePath)); + service_test_->SetServiceProperty("stub_wimax", + shill::kConnectableProperty, + base::FundamentalValue(true)); + profile_test->AddService(kUser1ProfilePath, "stub_wimax"); + + 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)); + profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); + + AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline); - static KeyedService* GetNetworkingPrivateDelegate( - content::BrowserContext* profile) { - CHECK(s_test_delegate_); - return s_test_delegate_; + content::RunAllPendingInMessageLoop(); } - +#else // !defined(OS_CHROMEOS) virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { ExtensionApiTest::SetUpCommandLine(command_line); // Whitelist the extension ID of the test extension. @@ -248,214 +377,263 @@ class NetworkingPrivateApiTest : public ExtensionApiTest { "epcifkihnkjgphfkloaaleeakhpmgdmn"); } + static KeyedService* CreateNetworkingPrivateServiceClient( + content::BrowserContext* profile) { + return new extensions::NetworkingPrivateServiceClient( + new wifi::FakeWiFiService(), new CryptoVerifyStub()); + } + virtual void SetUpOnMainThread() OVERRIDE { ExtensionApiTest::SetUpOnMainThread(); -#if defined(OS_CHROMEOS) - NetworkingPrivateChromeOSFactory::GetInstance()->SetTestingFactory( - profile(), - &NetworkingPrivateApiTest::GetNetworkingPrivateDelegate); -#else + content::RunAllPendingInMessageLoop(); NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( profile(), - &NetworkingPrivateApiTest::GetNetworkingPrivateDelegate); -#endif - content::RunAllPendingInMessageLoop(); - } - - bool GetEnabled(const std::string& type) { - return s_test_delegate_->GetEnabled(type); - } - - bool GetDisabled(const std::string& type) { - return s_test_delegate_->GetDisabled(type); + &CreateNetworkingPrivateServiceClient); } - size_t GetScanRequested() { - return s_test_delegate_->GetScanRequested(); - } +#endif // OS_CHROMEOS protected: - bool RunNetworkingSubtest(const std::string& subtest) { - return RunExtensionSubtest( - "networking_private", "main.html?" + subtest, - kFlagEnableFileAccess | kFlagLoadAsComponent); - } - - // Static pointer to the TestDelegate so that it can be accessed in - // GetNetworkingPrivateDelegate() passed to SetTestingFactory(). - static TestDelegate* s_test_delegate_; - - DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateApiTest); +#if defined(OS_CHROMEOS) + NetworkPortalDetectorTestImpl* detector() { return detector_; } + + NetworkPortalDetectorTestImpl* detector_; + ShillServiceClient::TestInterface* service_test_; + ShillManagerClient::TestInterface* manager_test_; + ShillDeviceClient::TestInterface* device_test_; + policy::MockConfigurationPolicyProvider provider_; + std::string userhash_; +#endif }; -//static -TestDelegate* NetworkingPrivateApiTest::s_test_delegate_ = NULL; - -} // namespace - // Place each subtest into a separate browser test so that the stub networking // library state is reset for each subtest run. This way they won't affect each // other. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartConnect) { + EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetManagedProperties) { - EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, StartDisconnect) { + EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetState) { - EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + StartConnectNonexistent) { + EXPECT_TRUE(RunNetworkingSubtest("startConnectNonexistent")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, SetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + StartDisconnectNonexistent) { + EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, CreateNetwork) { - EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + StartGetPropertiesNonexistent) { + EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) + << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetNetworks) { +#if defined(OS_CHROMEOS) +// TODO(stevenjb/mef): Fix these on non-Chrome OS, crbug.com/371442. +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetNetworks) { + // Hide stub_wifi2. + service_test_->SetServiceProperty("stub_wifi2", + shill::kVisibleProperty, + base::FundamentalValue(false)); + // Add a couple of additional networks that are not configured (saved). + AddService("stub_wifi3", "wifi3", shill::kTypeWifi, shill::kStateIdle); + AddService("stub_wifi4", "wifi4", shill::kTypeWifi, shill::kStateIdle); + content::RunAllPendingInMessageLoop(); EXPECT_TRUE(RunNetworkingSubtest("getNetworks")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetVisibleNetworks) { +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetVisibleNetworks) { EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; } +#endif -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetEnabledNetworkTypes) { - EXPECT_TRUE(RunNetworkingSubtest("getEnabledNetworkTypes")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, EnableNetworkType) { - EXPECT_TRUE(RunNetworkingSubtest("enableNetworkType")) << message_; - EXPECT_TRUE(GetEnabled(::onc::network_config::kEthernet)); -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, DisableNetworkType) { - EXPECT_TRUE(RunNetworkingSubtest("disableNetworkType")) << message_; - EXPECT_TRUE(GetDisabled(::onc::network_config::kEthernet)); +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + GetVisibleNetworksWifi) { + EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, RequestNetworkScan) { +#if defined(OS_CHROMEOS) +// TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442. +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, RequestNetworkScan) { EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; - EXPECT_EQ(1u, GetScanRequested()); } +#endif -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, StartConnect) { - EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; +// Properties are filtered and translated through +// ShillToONCTranslator::TranslateWiFiWithState +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetProperties) { + EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, StartDisconnect) { - EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_; +#if defined(OS_CHROMEOS) +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + GetCellularProperties) { + SetupCellular(); + EXPECT_TRUE(RunNetworkingSubtest("getPropertiesCellular")) << message_; } +#endif -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, VerifyDestination) { - EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetState) { + EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, VerifyAndEncryptCredentials) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, GetStateNonExistent) { + EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, VerifyAndEncryptData) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, SetProperties) { + EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, SetWifiTDLSEnabledState) { - EXPECT_TRUE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, CreateNetwork) { + EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetWifiTDLSStatus) { - EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << 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_F(ExtensionNetworkingPrivateApiTest, + GetManagedProperties) { + 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)); + + ShillProfileClient::TestInterface* profile_test = + DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); + // Update the profile entry. + profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); + + content::RunAllPendingInMessageLoop(); + + const std::string user_policy_blob = + "{ \"NetworkConfigurations\": [" + " { \"GUID\": \"stub_wifi2\"," + " \"Type\": \"WiFi\"," + " \"Name\": \"My WiFi Network\"," + " \"WiFi\": {" + " \"Passphrase\": \"passphrase\"," + " \"Recommended\": [ \"AutoConnect\", \"Passphrase\" ]," + " \"SSID\": \"wifi2_PSK\"," + " \"Security\": \"WPA-PSK\" }" + " }" + " ]," + " \"Certificates\": []," + " \"Type\": \"UnencryptedConfiguration\"" + "}"; + + policy::PolicyMap policy; + policy.Set(policy::key::kOpenNetworkConfiguration, + policy::POLICY_LEVEL_MANDATORY, + policy::POLICY_SCOPE_USER, + new base::StringValue(user_policy_blob), + NULL); + provider_.UpdateChromePolicy(policy); + + content::RunAllPendingInMessageLoop(); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTest, GetCaptivePortalStatus) { - EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; + EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_; } +#endif // OS_CHROMEOS -// Test failure case - -class NetworkingPrivateApiTestFail : public NetworkingPrivateApiTest { - public: - NetworkingPrivateApiTestFail() { - s_test_delegate_->set_fail(true); - } - - protected: - DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateApiTestFail); -}; - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetProperties) { - EXPECT_FALSE(RunNetworkingSubtest("getProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + OnNetworksChangedEventConnect) { + EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect")) + << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetManagedProperties) { - EXPECT_FALSE(RunNetworkingSubtest("getManagedProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + OnNetworksChangedEventDisconnect) { + EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect")) + << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetState) { - EXPECT_FALSE(RunNetworkingSubtest("getState")) << message_; +#if defined(OS_CHROMEOS) +// TODO(stevenjb/mef): Fix this on non-Chrome OS, crbug.com/371442. +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + OnNetworkListChangedEvent) { + EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; } +#endif // OS_CHROMEOS -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetProperties) { - EXPECT_FALSE(RunNetworkingSubtest("setProperties")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + VerifyDestination) { + EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, CreateNetwork) { - EXPECT_FALSE(RunNetworkingSubtest("createNetwork")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + VerifyAndEncryptCredentials) { + EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetNetworks) { - EXPECT_FALSE(RunNetworkingSubtest("getNetworks")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + VerifyAndEncryptData) { + EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetVisibleNetworks) { - EXPECT_FALSE(RunNetworkingSubtest("getVisibleNetworks")) << message_; +#if defined(OS_CHROMEOS) +// Currently TDLS support is only enabled for Chrome OS. +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + SetWifiTDLSEnabledState) { + EXPECT_TRUE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetEnabledNetworkTypes) { - EXPECT_FALSE(RunNetworkingSubtest("getEnabledNetworkTypes")) << message_; +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + GetWifiTDLSStatus) { + EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_; } +#endif -// Note: Synchronous methods never fail: -// * disableNetworkType -// * enableNetworkType -// * requestNetworkScan +// NetworkPortalDetector is only enabled for Chrome OS. +#if defined(OS_CHROMEOS) +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + GetCaptivePortalStatus) { + SetupCellular(); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, StartConnect) { - EXPECT_FALSE(RunNetworkingSubtest("startConnect")) << message_; -} + NetworkPortalDetector::CaptivePortalState state; + state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; + detector()->SetDetectionResultsForTesting("stub_ethernet_guid", state); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, StartDisconnect) { - EXPECT_FALSE(RunNetworkingSubtest("startDisconnect")) << message_; -} + state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; + detector()->SetDetectionResultsForTesting("stub_wifi1_guid", state); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, VerifyDestination) { - EXPECT_FALSE(RunNetworkingSubtest("verifyDestination")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, - VerifyAndEncryptCredentials) { - EXPECT_FALSE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; -} + state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; + detector()->SetDetectionResultsForTesting("stub_wifi2_guid", state); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, VerifyAndEncryptData) { - EXPECT_FALSE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; -} + state.status = + NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; + detector()->SetDetectionResultsForTesting("stub_cellular1_guid", state); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, SetWifiTDLSEnabledState) { - EXPECT_FALSE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_; + EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; } -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetWifiTDLSStatus) { - EXPECT_FALSE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_; -} +IN_PROC_BROWSER_TEST_F(ExtensionNetworkingPrivateApiTest, + CaptivePortalNotification) { + detector()->SetDefaultNetworkForTesting("wifi_guid"); + NetworkPortalDetector::CaptivePortalState state; + state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; + detector()->SetDetectionResultsForTesting("wifi_guid", state); -IN_PROC_BROWSER_TEST_F(NetworkingPrivateApiTestFail, GetCaptivePortalStatus) { - EXPECT_FALSE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; + TestListener listener( + "notifyPortalDetectorObservers", + base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting, + base::Unretained(detector()))); + EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_; } +#endif // defined(OS_CHROMEOS) -} // namespace extensions +} // namespace diff --git a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc b/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc deleted file mode 100644 index 27da917..0000000 --- a/chrome/browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc +++ /dev/null @@ -1,535 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// 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/helper.h" -#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" -#include "chrome/browser/extensions/extension_apitest.h" -#include "chrome/test/base/ui_test_utils.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 "chromeos/login/user_names.h" -#include "chromeos/network/onc/onc_utils.h" -#include "chromeos/network/portal_detector/network_portal_detector.h" -#include "components/onc/onc_constants.h" -#include "components/policy/core/browser/browser_policy_connector.h" -#include "components/policy/core/common/external_data_fetcher.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 "components/user_manager/user.h" -#include "components/user_manager/user_manager.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 "extensions/browser/notification_types.h" -#include "extensions/common/switches.h" -#include "policy/policy_constants.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "third_party/cros_system_api/dbus/service_constants.h" - -// This tests the Chrome OS implementaiton of the networkingPrivate API. -// Note: the expectations in test/data/extensions/api_test/networking/test.js -// are shared between this and the Win/Mac tests. TODO(stevenjb): Develop -// a mechanism to specify the test expecations from here to eliminate that -// dependency. - -using testing::Return; -using testing::_; - -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; - -namespace { - -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, - extensions::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); -}; - -class NetworkingPrivateChromeOSApiTest : public ExtensionApiTest { - public: - NetworkingPrivateChromeOSApiTest() - : detector_(NULL), - service_test_(NULL), - manager_test_(NULL), - device_test_(NULL) {} - - bool RunNetworkingSubtest(const std::string& subtest) { - return RunExtensionSubtest("networking", - "main.html?" + subtest, - kFlagEnableFileAccess | kFlagLoadAsComponent); - } - - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { - EXPECT_CALL(provider_, IsInitializationComplete(_)) - .WillRepeatedly(Return(true)); - policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); - - ExtensionApiTest::SetUpInProcessBrowserTestFixture(); - } - - static void AssignString(std::string* out, - DBusMethodCallStatus call_status, - const std::string& result) { - CHECK_EQ(call_status, DBUS_METHOD_CALL_SUCCESS); - *out = result; - } - - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - ExtensionApiTest::SetUpCommandLine(command_line); - // Whitelist the extension ID of the test extension. - 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. - const std::string login_user = chromeos::login::CanonicalizeUserID( - command_line->GetSwitchValueNative(chromeos::switches::kLoginUser)); - const std::string sanitized_user = - CryptohomeClient::GetStubSanitizedUsername(login_user); - command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, - sanitized_user); - } - - void InitializeSanitizedUsername() { - user_manager::UserManager* user_manager = user_manager::UserManager::Get(); - user_manager::User* user = user_manager->GetActiveUser(); - CHECK(user); - std::string userhash; - DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( - user->email(), base::Bind(&AssignString, &userhash_)); - content::RunAllPendingInMessageLoop(); - CHECK(!userhash_.empty()); - } - - void SetupCellular() { - // Add a Cellular Device and set a couple of properties. - device_test_->AddDevice( - kCellularDevicePath, shill::kTypeCellular, "stub_cellular_device1"); - device_test_->SetDeviceProperty(kCellularDevicePath, - shill::kCarrierProperty, - base::StringValue("Cellular1_Carrier")); - base::DictionaryValue home_provider; - home_provider.SetString("name", "Cellular1_Provider"); - home_provider.SetString("country", "us"); - device_test_->SetDeviceProperty( - kCellularDevicePath, shill::kHomeProviderProperty, home_provider); - AddService( - "stub_cellular1", "cellular1", shill::kTypeCellular, shill::kStateIdle); - // Note: These properties will show up in a "Cellular" object in ONC. - service_test_->SetServiceProperty("stub_cellular1", - shill::kAutoConnectProperty, - base::FundamentalValue(true)); - 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)); - content::RunAllPendingInMessageLoop(); - } - - void AddService(const std::string& service_path, - const std::string& name, - const std::string& type, - const std::string& state) { - service_test_->AddService(service_path, - service_path + "_guid", - name, - type, - state, - true /* add_to_visible */); - } - - virtual void SetUpOnMainThread() OVERRIDE { - detector_ = new NetworkPortalDetectorTestImpl(); - NetworkPortalDetector::InitializeForTesting(detector_); - - ExtensionApiTest::SetUpOnMainThread(); - content::RunAllPendingInMessageLoop(); - - InitializeSanitizedUsername(); - - DBusThreadManager* dbus_manager = DBusThreadManager::Get(); - manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); - service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); - device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); - - ShillIPConfigClient::TestInterface* ip_config_test = - dbus_manager->GetShillIPConfigClient()->GetTestInterface(); - ShillProfileClient::TestInterface* profile_test = - dbus_manager->GetShillProfileClient()->GetTestInterface(); - - device_test_->ClearDevices(); - service_test_->ClearServices(); - - // Sends a notification about the added profile. - profile_test->AddProfile(kUser1ProfilePath, userhash_); - - // Enable technologies. - manager_test_->AddTechnology("wimax", true); - - // 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_->SetDeviceProperty(kWifiDevicePath, - shill::kAddressProperty, - base::StringValue("001122aabbcc")); - - // Add Services - AddService( - "stub_ethernet", "eth0", shill::kTypeEthernet, shill::kStateOnline); - service_test_->SetServiceProperty( - "stub_ethernet", - shill::kProfileProperty, - base::StringValue(ShillProfileClient::GetSharedProfilePath())); - profile_test->AddService(ShillProfileClient::GetSharedProfilePath(), - "stub_ethernet"); - - AddService("stub_wifi1", "wifi1", shill::kTypeWifi, shill::kStateOnline); - 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)); - - AddService("stub_wifi2", "wifi2_PSK", shill::kTypeWifi, shill::kStateIdle); - 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)); - - AddService("stub_wimax", "wimax", shill::kTypeWimax, shill::kStateOnline); - service_test_->SetServiceProperty("stub_wimax", - shill::kSignalStrengthProperty, - base::FundamentalValue(40)); - service_test_->SetServiceProperty("stub_wimax", - shill::kProfileProperty, - base::StringValue(kUser1ProfilePath)); - service_test_->SetServiceProperty("stub_wimax", - shill::kConnectableProperty, - base::FundamentalValue(true)); - profile_test->AddService(kUser1ProfilePath, "stub_wimax"); - - 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)); - profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); - - AddService("stub_vpn1", "vpn1", shill::kTypeVPN, shill::kStateOnline); - - content::RunAllPendingInMessageLoop(); - } - - protected: - NetworkPortalDetectorTestImpl* detector() { return detector_; } - - NetworkPortalDetectorTestImpl* detector_; - ShillServiceClient::TestInterface* service_test_; - ShillManagerClient::TestInterface* manager_test_; - ShillDeviceClient::TestInterface* device_test_; - policy::MockConfigurationPolicyProvider provider_; - std::string userhash_; -}; - -// Place each subtest into a separate browser test so that the stub networking -// library state is reset for each subtest run. This way they won't affect each -// other. - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, StartConnect) { - EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, StartDisconnect) { - EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - StartConnectNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startConnectNonexistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - StartDisconnectNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - StartGetPropertiesNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetNetworks) { - // Hide stub_wifi2. - service_test_->SetServiceProperty( - "stub_wifi2", shill::kVisibleProperty, base::FundamentalValue(false)); - // Add a couple of additional networks that are not configured (saved). - AddService("stub_wifi3", "wifi3", shill::kTypeWifi, shill::kStateIdle); - AddService("stub_wifi4", "wifi4", shill::kTypeWifi, shill::kStateIdle); - content::RunAllPendingInMessageLoop(); - EXPECT_TRUE(RunNetworkingSubtest("getNetworks")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetVisibleNetworks) { - EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - GetVisibleNetworksWifi) { - EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, RequestNetworkScan) { - EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; -} - -// Properties are filtered and translated through -// ShillToONCTranslator::TranslateWiFiWithState -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - GetCellularProperties) { - SetupCellular(); - EXPECT_TRUE(RunNetworkingSubtest("getPropertiesCellular")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetState) { - EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetStateNonExistent) { - EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, SetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, CreateNetwork) { - EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; -} - -// TODO(stevenjb): Find a better way to set this up on Chrome OS. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetManagedProperties) { - 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)); - - ShillProfileClient::TestInterface* profile_test = - DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); - // Update the profile entry. - profile_test->AddService(kUser1ProfilePath, "stub_wifi2"); - - content::RunAllPendingInMessageLoop(); - - const std::string user_policy_blob = - "{ \"NetworkConfigurations\": [" - " { \"GUID\": \"stub_wifi2\"," - " \"Type\": \"WiFi\"," - " \"Name\": \"My WiFi Network\"," - " \"WiFi\": {" - " \"Passphrase\": \"passphrase\"," - " \"Recommended\": [ \"AutoConnect\", \"Passphrase\" ]," - " \"SSID\": \"wifi2_PSK\"," - " \"Security\": \"WPA-PSK\" }" - " }" - " ]," - " \"Certificates\": []," - " \"Type\": \"UnencryptedConfiguration\"" - "}"; - - policy::PolicyMap policy; - policy.Set(policy::key::kOpenNetworkConfiguration, - policy::POLICY_LEVEL_MANDATORY, - policy::POLICY_SCOPE_USER, - new base::StringValue(user_policy_blob), - NULL); - provider_.UpdateChromePolicy(policy); - - content::RunAllPendingInMessageLoop(); - - EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - OnNetworksChangedEventConnect) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - OnNetworksChangedEventDisconnect) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - OnNetworkListChangedEvent) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyDestination) { - EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - VerifyAndEncryptCredentials) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyAndEncryptData) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - SetWifiTDLSEnabledState) { - EXPECT_TRUE(RunNetworkingSubtest("setWifiTDLSEnabledState")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetWifiTDLSStatus) { - EXPECT_TRUE(RunNetworkingSubtest("getWifiTDLSStatus")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - GetCaptivePortalStatus) { - SetupCellular(); - - NetworkPortalDetector::CaptivePortalState state; - state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; - detector()->SetDetectionResultsForTesting("stub_ethernet_guid", state); - - state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; - detector()->SetDetectionResultsForTesting("stub_wifi1_guid", state); - - state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; - detector()->SetDetectionResultsForTesting("stub_wifi2_guid", state); - - state.status = - NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED; - detector()->SetDetectionResultsForTesting("stub_cellular1_guid", state); - - EXPECT_TRUE(RunNetworkingSubtest("getCaptivePortalStatus")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, - CaptivePortalNotification) { - detector()->SetDefaultNetworkForTesting("wifi_guid"); - NetworkPortalDetector::CaptivePortalState state; - state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; - detector()->SetDetectionResultsForTesting("wifi_guid", state); - - TestListener listener( - "notifyPortalDetectorObservers", - base::Bind(&NetworkPortalDetectorTestImpl::NotifyObserversForTesting, - base::Unretained(detector()))); - EXPECT_TRUE(RunNetworkingSubtest("captivePortalNotification")) << message_; -} - -} // namespace diff --git a/chrome/browser/extensions/api/networking_private/networking_private_service_client_apitest.cc b/chrome/browser/extensions/api/networking_private/networking_private_service_client_apitest.cc deleted file mode 100644 index 7d3ba18..0000000 --- a/chrome/browser/extensions/api/networking_private/networking_private_service_client_apitest.cc +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// 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/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 "chrome/browser/extensions/extension_apitest.h" -#include "chrome/test/base/ui_test_utils.h" -#include "components/user_manager/user.h" -#include "components/user_manager/user_manager.h" -#include "components/wifi/fake_wifi_service.h" -#include "extensions/common/switches.h" -#include "testing/gmock/include/gmock/gmock.h" - -using testing::Return; -using testing::_; - -using extensions::NetworkingPrivateServiceClient; -using extensions::NetworkingPrivateServiceClientFactory; - -// This tests the Windows / Mac implementation of the networkingPrivate API. -// Note: the expectations in test/data/extensions/api_test/networking/test.js -// are shared between this and the Chrome OS tests. TODO(stevenjb): Develop -// a mechanism to specify the test expectations from here to eliminate that -// dependency. - -namespace { - -// Stub Verify* methods implementation to satisfy expectations of -// networking_private_apitest. -class CryptoVerifyStub - : public extensions::NetworkingPrivateServiceClient::CryptoVerify { - virtual void VerifyDestination(const Credentials& verification_properties, - bool* verified, - std::string* error) OVERRIDE { - *verified = true; - } - - virtual void VerifyAndEncryptCredentials( - const std::string& network_guid, - const Credentials& credentials, - const VerifyAndEncryptCredentialsCallback& callback) OVERRIDE { - callback.Run("encrypted_credentials", ""); - } - - virtual void VerifyAndEncryptData(const Credentials& verification_properties, - const std::string& data, - std::string* base64_encoded_ciphertext, - std::string* error) OVERRIDE { - *base64_encoded_ciphertext = "encrypted_data"; - } -}; - -class NetworkingPrivateServiceClientApiTest : public ExtensionApiTest { - public: - NetworkingPrivateServiceClientApiTest() {} - - bool RunNetworkingSubtest(const std::string& subtest) { - return RunExtensionSubtest("networking", - "main.html?" + subtest, - kFlagEnableFileAccess | kFlagLoadAsComponent); - } - - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { - ExtensionApiTest::SetUpInProcessBrowserTestFixture(); - } - - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - ExtensionApiTest::SetUpCommandLine(command_line); - // Whitelist the extension ID of the test extension. - command_line->AppendSwitchASCII( - extensions::switches::kWhitelistedExtensionID, - "epcifkihnkjgphfkloaaleeakhpmgdmn"); - } - - static KeyedService* CreateNetworkingPrivateServiceClient( - content::BrowserContext* profile) { - return new NetworkingPrivateServiceClient(new wifi::FakeWiFiService(), - new CryptoVerifyStub()); - } - - virtual void SetUpOnMainThread() OVERRIDE { - ExtensionApiTest::SetUpOnMainThread(); - content::RunAllPendingInMessageLoop(); - NetworkingPrivateServiceClientFactory::GetInstance()->SetTestingFactory( - profile(), &CreateNetworkingPrivateServiceClient); - } - - protected: - DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateServiceClientApiTest); -}; - -// Place each subtest into a separate browser test so that the stub networking -// library state is reset for each subtest run. This way they won't affect each -// other. - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, StartConnect) { - EXPECT_TRUE(RunNetworkingSubtest("startConnect")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, StartDisconnect) { - EXPECT_TRUE(RunNetworkingSubtest("startDisconnect")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - StartConnectNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startConnectNonexistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - StartDisconnectNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startDisconnectNonexistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - StartGetPropertiesNonexistent) { - EXPECT_TRUE(RunNetworkingSubtest("startGetPropertiesNonexistent")) - << message_; -} - -// TODO(stevenjb/mef): Fix these, crbug.com/371442. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - DISABLED_GetNetworks) { - EXPECT_TRUE(RunNetworkingSubtest("getNetworks")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - DISABLED_GetVisibleNetworks) { - EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworks")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - GetVisibleNetworksWifi) { - EXPECT_TRUE(RunNetworkingSubtest("getVisibleNetworksWifi")) << message_; -} - -// TODO(stevenjb/mef): Fix this, crbug.com/371442. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - DISABLED_RequestNetworkScan) { - EXPECT_TRUE(RunNetworkingSubtest("requestNetworkScan")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, GetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("getProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, GetState) { - EXPECT_TRUE(RunNetworkingSubtest("getState")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - GetStateNonExistent) { - EXPECT_TRUE(RunNetworkingSubtest("getStateNonExistent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, SetProperties) { - EXPECT_TRUE(RunNetworkingSubtest("setProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, CreateNetwork) { - EXPECT_TRUE(RunNetworkingSubtest("createNetwork")) << message_; -} - -// TODO(stevenjb/mef): Fix this, crbug.com/371442. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - DISABLED_GetManagedProperties) { - EXPECT_TRUE(RunNetworkingSubtest("getManagedProperties")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - OnNetworksChangedEventConnect) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventConnect")) - << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - OnNetworksChangedEventDisconnect) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworksChangedEventDisconnect")) - << message_; -} - -// TODO(stevenjb/mef): Fix this, crbug.com/371442. -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - DISABLED_OnNetworkListChangedEvent) { - EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - VerifyDestination) { - EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - VerifyAndEncryptCredentials) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; -} - -IN_PROC_BROWSER_TEST_F(NetworkingPrivateServiceClientApiTest, - VerifyAndEncryptData) { - EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptData")) << message_; -} - -} // namespace diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 90276b4..d2aff46 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2065,16 +2065,9 @@ '../components/components.gyp:wifi_test_support', ], }], - ['chromeos == 1', { + ['chromeos == 1 or OS=="win" or OS == "mac"', { 'sources': [ 'browser/extensions/api/networking_private/networking_private_apitest.cc', - 'browser/extensions/api/networking_private/networking_private_chromeos_apitest.cc', - ], - }], - ['OS=="win" or OS == "mac"', { - 'sources': [ - 'browser/extensions/api/networking_private/networking_private_apitest.cc', - 'browser/extensions/api/networking_private/networking_private_service_client_apitest.cc', ], }], ['toolkit_views==1', { diff --git a/chrome/test/data/extensions/api_test/networking/manifest.json b/chrome/test/data/extensions/api_test/networking/manifest.json index 3c63ae1..377b477 100644 --- a/chrome/test/data/extensions/api_test/networking/manifest.json +++ b/chrome/test/data/extensions/api_test/networking/manifest.json @@ -1,6 +1,6 @@ { "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC74Vbx3EbhPc/FOvn6+HxCjMSml0HdPMiuRjj5a3b+MnRML1iJ9OAgbKUYJ/u3s25/cGq8pNB0NbyupHGEqvqAE7TcNr1mdgs0PWxh2IOI1GKrxlzxpqzQuFmxq5WHKr5RrwZ4/Xq0t/+e8JkvhZdW0jarz/28Jom0gkM5lorsewIDAQAB", - "name": "networking private extension API interface test", + "name": "ChromeOS networking private extension API test", "version": "0.1", "manifest_version": 2, "description": "Test of chrome.networkingPrivate methods", diff --git a/chrome/test/data/extensions/api_test/networking/test.js b/chrome/test/data/extensions/api_test/networking/test.js index c3e8b62..2f0a653 100644 --- a/chrome/test/data/extensions/api_test/networking/test.js +++ b/chrome/test/data/extensions/api_test/networking/test.js @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Note: the expectations in this test are shared by both the Chrome OS and -// Win/Mac (ServiceClient) implementations. TODO(stevenjb): Set up a way for -// the test code to specify the correct expectations. - var callbackPass = chrome.test.callbackPass; var callbackFail = chrome.test.callbackFail; var assertTrue = chrome.test.assertTrue; diff --git a/chrome/test/data/extensions/api_test/networking_private/main.html b/chrome/test/data/extensions/api_test/networking_private/main.html deleted file mode 100644 index 395663a..0000000 --- a/chrome/test/data/extensions/api_test/networking_private/main.html +++ /dev/null @@ -1,11 +0,0 @@ -<!-- - * Copyright 2014 The Chromium Authors. All rights reserved. Use of this - * source code is governed by a BSD-style license that can be found in the - * LICENSE file. ---> -<script src="test.js"></script> - -<html> -<head><title>networking private component API interface test</title></head> -<body><h2>chrome.networkingPrivate.* tests</h2></body> -</html> diff --git a/chrome/test/data/extensions/api_test/networking_private/manifest.json b/chrome/test/data/extensions/api_test/networking_private/manifest.json deleted file mode 100644 index 1b1e153..0000000 --- a/chrome/test/data/extensions/api_test/networking_private/manifest.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC74Vbx3EbhPc/FOvn6+HxCjMSml0HdPMiuRjj5a3b+MnRML1iJ9OAgbKUYJ/u3s25/cGq8pNB0NbyupHGEqvqAE7TcNr1mdgs0PWxh2IOI1GKrxlzxpqzQuFmxq5WHKr5RrwZ4/Xq0t/+e8JkvhZdW0jarz/28Jom0gkM5lorsewIDAQAB", - "name": "networking private extension API interface test", - "version": "0.1", - "manifest_version": 2, - "description": "Test of chrome.networkingPrivate interface", - "permissions": [ - "networkingPrivate" - ] -} diff --git a/chrome/test/data/extensions/api_test/networking_private/test.js b/chrome/test/data/extensions/api_test/networking_private/test.js deleted file mode 100644 index 0af2e86..0000000 --- a/chrome/test/data/extensions/api_test/networking_private/test.js +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This just tests the interface. It does not test for specific results, only -// that callbacks are correctly invoked, expected parameters are correct, -// and failures are detected. - -var callbackPass = chrome.test.callbackPass; - -var kFailure = 'Failure'; -var kGuid = 'SOME_GUID'; - -// Test properties for the verification API. -var verificationProperties = { - "certificate": "certificate", - "publicKey": "cHVibGljX2tleQ==", // Base64("public_key") - "nonce": "nonce", - "signedData": "c2lnbmVkX2RhdGE=", // Base64("signed_data") - "deviceSerial": "device_serial", - "deviceSsid": "Device 0123", - "deviceBssid": "00:01:02:03:04:05" -}; - -function callbackResult(result) { - if (chrome.runtime.lastError) - chrome.test.fail(chrome.runtime.lastError.message); - else if (result == false || result == kFailure) - chrome.test.fail('Failed: ' + result); -} - -var availableTests = [ - function getProperties() { - chrome.networkingPrivate.getProperties( - kGuid, callbackPass(callbackResult)); - }, - function getManagedProperties() { - chrome.networkingPrivate.getManagedProperties( - kGuid, callbackPass(callbackResult)); - }, - function getState() { - chrome.networkingPrivate.getState( - kGuid, callbackPass(callbackResult)); - }, - function setProperties() { - chrome.networkingPrivate.setProperties( - kGuid, { 'GUID': kGuid }, callbackPass(callbackResult)); - }, - function createNetwork() { - chrome.networkingPrivate.createNetwork( - false, { 'GUID': kGuid }, callbackPass(callbackResult)); - }, - function getNetworks() { - chrome.networkingPrivate.getNetworks( - { networkType: 'Ethernet' }, callbackPass(callbackResult)); - }, - function getVisibleNetworks() { - chrome.networkingPrivate.getVisibleNetworks( - 'Ethernet', callbackPass(callbackResult)); - }, - function getEnabledNetworkTypes() { - chrome.networkingPrivate.getEnabledNetworkTypes( - callbackPass(callbackResult)); - }, - function enableNetworkType() { - chrome.networkingPrivate.enableNetworkType('Ethernet'); - chrome.test.succeed(); - }, - function disableNetworkType() { - chrome.networkingPrivate.disableNetworkType('Ethernet'); - chrome.test.succeed(); - }, - function requestNetworkScan() { - chrome.networkingPrivate.requestNetworkScan(); - chrome.test.succeed(); - }, - function startConnect() { - chrome.networkingPrivate.startConnect( - kGuid, callbackPass(callbackResult)); - }, - function startDisconnect() { - chrome.networkingPrivate.startDisconnect( - kGuid, callbackPass(callbackResult)); - }, - function verifyDestination() { - chrome.networkingPrivate.verifyDestination( - verificationProperties, callbackPass(callbackResult)); - }, - function verifyAndEncryptCredentials() { - chrome.networkingPrivate.verifyAndEncryptCredentials( - verificationProperties, kGuid, callbackPass(callbackResult)); - }, - function verifyAndEncryptData() { - chrome.networkingPrivate.verifyAndEncryptData( - verificationProperties, 'data', callbackPass(callbackResult)); - }, - function setWifiTDLSEnabledState() { - chrome.networkingPrivate.setWifiTDLSEnabledState( - '', true, callbackPass(callbackResult)); - }, - function getWifiTDLSStatus() { - chrome.networkingPrivate.getWifiTDLSStatus( - '', callbackPass(callbackResult)); - }, - function getCaptivePortalStatus() { - chrome.networkingPrivate.getWifiTDLSStatus( - kGuid, callbackPass(callbackResult)); - }, -]; - -var testToRun = window.location.search.substring(1); -chrome.test.runTests(availableTests.filter(function(op) { - return op.name == testToRun; -})); |