| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
| 22 #include "chromeos/cryptohome/cryptohome_parameters.h" | 22 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 23 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
| 24 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 25 #include "chromeos/dbus/shill_device_client.h" | 25 #include "chromeos/dbus/shill_device_client.h" |
| 26 #include "chromeos/dbus/shill_ipconfig_client.h" | 26 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 27 #include "chromeos/dbus/shill_manager_client.h" | 27 #include "chromeos/dbus/shill_manager_client.h" |
| 28 #include "chromeos/dbus/shill_profile_client.h" | 28 #include "chromeos/dbus/shill_profile_client.h" |
| 29 #include "chromeos/dbus/shill_service_client.h" | 29 #include "chromeos/dbus/shill_service_client.h" |
| 30 #include "chromeos/network/managed_network_configuration_handler.h" | 30 #include "chromeos/network/managed_network_configuration_handler.h" |
| 31 #include "chromeos/network/network_certificate_handler.h" |
| 31 #include "chromeos/network/network_handler.h" | 32 #include "chromeos/network/network_handler.h" |
| 32 #include "chromeos/network/network_state_handler.h" | 33 #include "chromeos/network/network_state_handler.h" |
| 33 #include "chromeos/network/onc/onc_utils.h" | 34 #include "chromeos/network/onc/onc_utils.h" |
| 34 #include "chromeos/network/portal_detector/network_portal_detector.h" | 35 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 35 #include "components/onc/onc_constants.h" | 36 #include "components/onc/onc_constants.h" |
| 36 #include "components/policy/core/browser/browser_policy_connector.h" | 37 #include "components/policy/core/browser/browser_policy_connector.h" |
| 37 #include "components/policy/core/common/external_data_fetcher.h" | 38 #include "components/policy/core/common/external_data_fetcher.h" |
| 38 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 39 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 39 #include "components/policy/core/common/policy_map.h" | 40 #include "components/policy/core/common/policy_map.h" |
| 40 #include "components/policy/core/common/policy_types.h" | 41 #include "components/policy/core/common/policy_types.h" |
| 41 #include "components/policy/policy_constants.h" | 42 #include "components/policy/policy_constants.h" |
| 42 #include "components/user_manager/user.h" | 43 #include "components/user_manager/user.h" |
| 43 #include "components/user_manager/user_manager.h" | 44 #include "components/user_manager/user_manager.h" |
| 44 #include "components/user_manager/user_names.h" | 45 #include "components/user_manager/user_names.h" |
| 45 #include "content/public/browser/notification_observer.h" | 46 #include "content/public/browser/notification_observer.h" |
| 46 #include "content/public/browser/notification_registrar.h" | 47 #include "content/public/browser/notification_registrar.h" |
| 47 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 48 #include "content/public/browser/notification_source.h" | 49 #include "content/public/browser/notification_source.h" |
| 49 #include "content/public/test/test_utils.h" | 50 #include "content/public/test/test_utils.h" |
| 50 #include "extensions/browser/api/networking_private/networking_private_chromeos.
h" | 51 #include "extensions/browser/api/networking_private/networking_private_chromeos.
h" |
| 51 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" | 52 #include "extensions/browser/api/networking_private/networking_private_delegate_
factory.h" |
| 52 #include "extensions/browser/notification_types.h" | 53 #include "extensions/browser/notification_types.h" |
| 53 #include "extensions/common/switches.h" | 54 #include "extensions/common/switches.h" |
| 55 #include "net/test/cert_test_util.h" |
| 56 #include "net/test/test_data_directory.h" |
| 54 #include "testing/gmock/include/gmock/gmock.h" | 57 #include "testing/gmock/include/gmock/gmock.h" |
| 55 #include "third_party/cros_system_api/dbus/service_constants.h" | 58 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 56 | 59 |
| 57 // This tests the Chrome OS implementation of the networkingPrivate API | 60 // This tests the Chrome OS implementation of the networkingPrivate API |
| 58 // (NetworkingPrivateChromeOS). Note: The test expectations for chromeos, and | 61 // (NetworkingPrivateChromeOS). Note: The test expectations for chromeos, and |
| 59 // win/mac (NetworkingPrivateServiceClient) are different to reflect the | 62 // win/mac (NetworkingPrivateServiceClient) are different to reflect the |
| 60 // different implementations, but should be kept similar where possible. | 63 // different implementations, but should be kept similar where possible. |
| 61 | 64 |
| 62 using testing::Return; | 65 using testing::Return; |
| 63 using testing::_; | 66 using testing::_; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 319 } |
| 317 | 320 |
| 318 void AddService(const std::string& service_path, | 321 void AddService(const std::string& service_path, |
| 319 const std::string& name, | 322 const std::string& name, |
| 320 const std::string& type, | 323 const std::string& type, |
| 321 const std::string& state) { | 324 const std::string& state) { |
| 322 service_test_->AddService(service_path, service_path + "_guid", name, type, | 325 service_test_->AddService(service_path, service_path + "_guid", name, type, |
| 323 state, true /* add_to_visible */); | 326 state, true /* add_to_visible */); |
| 324 } | 327 } |
| 325 | 328 |
| 326 static std::unique_ptr<KeyedService> CreateNetworkingPrivateServiceClient( | 329 static std::unique_ptr<KeyedService> CreateNetworkingPrivateDelegate( |
| 327 content::BrowserContext* context) { | 330 content::BrowserContext* context) { |
| 328 std::unique_ptr<NetworkingPrivateDelegate> result( | 331 std::unique_ptr<NetworkingPrivateDelegate> result( |
| 329 new NetworkingPrivateChromeOS(context)); | 332 new NetworkingPrivateChromeOS(context)); |
| 330 std::unique_ptr<NetworkingPrivateDelegate::UIDelegate> ui_delegate( | 333 std::unique_ptr<NetworkingPrivateDelegate::UIDelegate> ui_delegate( |
| 331 new UIDelegateStub); | 334 new UIDelegateStub); |
| 332 result->set_ui_delegate(std::move(ui_delegate)); | 335 result->set_ui_delegate(std::move(ui_delegate)); |
| 333 return result; | 336 return result; |
| 334 } | 337 } |
| 335 | 338 |
| 336 void SetUp() override { | 339 void SetUp() override { |
| 337 networking_cast_delegate_factory_ = base::Bind( | 340 networking_cast_delegate_factory_ = base::Bind( |
| 338 &NetworkingPrivateChromeOSApiTest::CreateNetworkingCastPrivateDelegate, | 341 &NetworkingPrivateChromeOSApiTest::CreateNetworkingCastPrivateDelegate, |
| 339 base::Unretained(this)); | 342 base::Unretained(this)); |
| 340 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest( | 343 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest( |
| 341 &networking_cast_delegate_factory_); | 344 &networking_cast_delegate_factory_); |
| 342 | 345 |
| 343 ExtensionApiTest::SetUp(); | 346 ExtensionApiTest::SetUp(); |
| 344 } | 347 } |
| 345 | 348 |
| 346 void SetUpOnMainThread() override { | 349 void SetUpOnMainThread() override { |
| 347 detector_ = new NetworkPortalDetectorTestImpl(); | 350 detector_ = new NetworkPortalDetectorTestImpl(); |
| 348 chromeos::network_portal_detector::InitializeForTesting(detector_); | 351 chromeos::network_portal_detector::InitializeForTesting(detector_); |
| 349 | 352 |
| 350 ExtensionApiTest::SetUpOnMainThread(); | 353 ExtensionApiTest::SetUpOnMainThread(); |
| 351 content::RunAllPendingInMessageLoop(); | 354 content::RunAllPendingInMessageLoop(); |
| 352 | 355 |
| 353 NetworkingPrivateDelegateFactory::GetInstance()->SetTestingFactory( | 356 NetworkingPrivateDelegateFactory::GetInstance()->SetTestingFactory( |
| 354 profile(), &CreateNetworkingPrivateServiceClient); | 357 profile(), &CreateNetworkingPrivateDelegate); |
| 355 | 358 |
| 356 InitializeSanitizedUsername(); | 359 InitializeSanitizedUsername(); |
| 357 | 360 |
| 358 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 361 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
| 359 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); | 362 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); |
| 360 profile_test_ = dbus_manager->GetShillProfileClient()->GetTestInterface(); | 363 profile_test_ = dbus_manager->GetShillProfileClient()->GetTestInterface(); |
| 361 service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); | 364 service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); |
| 362 device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); | 365 device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); |
| 363 | 366 |
| 364 ShillIPConfigClient::TestInterface* ip_config_test = | 367 ShillIPConfigClient::TestInterface* ip_config_test = |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 profile_test_->AddService(kUser1ProfilePath, "stub_vpn2"); | 482 profile_test_->AddService(kUser1ProfilePath, "stub_vpn2"); |
| 480 | 483 |
| 481 content::RunAllPendingInMessageLoop(); | 484 content::RunAllPendingInMessageLoop(); |
| 482 } | 485 } |
| 483 | 486 |
| 484 void TearDown() override { | 487 void TearDown() override { |
| 485 ExtensionApiTest::TearDown(); | 488 ExtensionApiTest::TearDown(); |
| 486 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest(nullptr); | 489 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest(nullptr); |
| 487 } | 490 } |
| 488 | 491 |
| 489 private: | |
| 490 std::unique_ptr<ChromeNetworkingCastPrivateDelegate> | 492 std::unique_ptr<ChromeNetworkingCastPrivateDelegate> |
| 491 CreateNetworkingCastPrivateDelegate() { | 493 CreateNetworkingCastPrivateDelegate() { |
| 492 return base::MakeUnique<TestNetworkingCastPrivateDelegate>(); | 494 return base::MakeUnique<TestNetworkingCastPrivateDelegate>(); |
| 493 } | 495 } |
| 494 | 496 |
| 497 bool SetupCertificates() { |
| 498 scoped_refptr<net::X509Certificate> system_ca_cert = |
| 499 net::ImportCertFromFile(net::GetTestCertsDirectory(), |
| 500 "client_1_ca.pem"); |
| 501 if (!system_ca_cert) |
| 502 return false; |
| 503 |
| 504 net::CertificateList cert_list; |
| 505 cert_list.push_back(std::move(system_ca_cert)); |
| 506 // TODO(stevenjb): Figure out a simple way to import a test user cert. |
| 507 |
| 508 chromeos::NetworkHandler::Get() |
| 509 ->network_certificate_handler() |
| 510 ->SetCertificatesForTest(cert_list); |
| 511 return true; |
| 512 } |
| 513 |
| 495 protected: | 514 protected: |
| 496 NetworkPortalDetectorTestImpl* detector() { return detector_; } | 515 NetworkPortalDetectorTestImpl* detector() { return detector_; } |
| 497 | 516 |
| 498 NetworkPortalDetectorTestImpl* detector_; | 517 NetworkPortalDetectorTestImpl* detector_; |
| 499 ShillManagerClient::TestInterface* manager_test_; | 518 ShillManagerClient::TestInterface* manager_test_; |
| 500 ShillProfileClient::TestInterface* profile_test_; | 519 ShillProfileClient::TestInterface* profile_test_; |
| 501 ShillServiceClient::TestInterface* service_test_; | 520 ShillServiceClient::TestInterface* service_test_; |
| 502 ShillDeviceClient::TestInterface* device_test_; | 521 ShillDeviceClient::TestInterface* device_test_; |
| 503 policy::MockConfigurationPolicyProvider provider_; | 522 policy::MockConfigurationPolicyProvider provider_; |
| 504 std::string userhash_; | 523 std::string userhash_; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 OnNetworkListChangedEvent) { | 782 OnNetworkListChangedEvent) { |
| 764 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; | 783 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; |
| 765 } | 784 } |
| 766 | 785 |
| 767 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 786 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
| 768 OnDeviceStateListChangedEvent) { | 787 OnDeviceStateListChangedEvent) { |
| 769 EXPECT_TRUE(RunNetworkingSubtest("onDeviceStateListChangedEvent")) | 788 EXPECT_TRUE(RunNetworkingSubtest("onDeviceStateListChangedEvent")) |
| 770 << message_; | 789 << message_; |
| 771 } | 790 } |
| 772 | 791 |
| 792 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
| 793 OnCertificateListsChangedEvent) { |
| 794 TestListener listener("eventListenerReady", base::Bind([]() { |
| 795 chromeos::NetworkHandler::Get() |
| 796 ->network_certificate_handler() |
| 797 ->NotifyCertificatsChangedForTest(); |
| 798 })); |
| 799 EXPECT_TRUE(RunNetworkingSubtest("onCertificateListsChangedEvent")) |
| 800 << message_; |
| 801 } |
| 802 |
| 773 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyDestination) { | 803 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyDestination) { |
| 774 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; | 804 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; |
| 775 } | 805 } |
| 776 | 806 |
| 777 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 807 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
| 778 VerifyAndEncryptCredentials) { | 808 VerifyAndEncryptCredentials) { |
| 779 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; | 809 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; |
| 780 } | 810 } |
| 781 | 811 |
| 782 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyAndEncryptData) { | 812 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyAndEncryptData) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkManagedProperties")) | 914 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkManagedProperties")) |
| 885 << message_; | 915 << message_; |
| 886 } | 916 } |
| 887 | 917 |
| 888 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 918 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
| 889 Tether_GetTetherNetworkState) { | 919 Tether_GetTetherNetworkState) { |
| 890 SetupTether(); | 920 SetupTether(); |
| 891 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkState")) << message_; | 921 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkState")) << message_; |
| 892 } | 922 } |
| 893 | 923 |
| 924 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetCertificateLists) { |
| 925 ASSERT_TRUE(SetupCertificates()); |
| 926 EXPECT_TRUE(RunNetworkingSubtest("getCertificateLists")) << message_; |
| 927 } |
| 928 |
| 894 // Tests subset of networking API for the networking API alias - to verify that | 929 // Tests subset of networking API for the networking API alias - to verify that |
| 895 // using API methods and event does not cause access exceptions (due to | 930 // using API methods and event does not cause access exceptions (due to |
| 896 // missing permissions). | 931 // missing permissions). |
| 897 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, Alias) { | 932 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, Alias) { |
| 898 SetupCellular(); | 933 SetupCellular(); |
| 899 EXPECT_TRUE(RunPlatformAppTest("networking_private/alias")) << message_; | 934 EXPECT_TRUE(RunPlatformAppTest("networking_private/alias")) << message_; |
| 900 } | 935 } |
| 901 | 936 |
| 902 } // namespace | 937 } // namespace |
| OLD | NEW |