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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 ASSERT_EQ("00:01:02:03:04:05", credentials.device_bssid()); | 136 ASSERT_EQ("00:01:02:03:04:05", credentials.device_bssid()); |
134 ASSERT_EQ("c2lnbmVkX2RhdGE=", credentials.signed_data()); | 137 ASSERT_EQ("c2lnbmVkX2RhdGE=", credentials.signed_data()); |
135 ASSERT_EQ( | 138 ASSERT_EQ( |
136 "Device 0123,device_serial,00:01:02:03:04:05,cHVibGljX2tleQ==,nonce", | 139 "Device 0123,device_serial,00:01:02:03:04:05,cHVibGljX2tleQ==,nonce", |
137 credentials.unsigned_data()); | 140 credentials.unsigned_data()); |
138 } | 141 } |
139 | 142 |
140 DISALLOW_COPY_AND_ASSIGN(TestNetworkingCastPrivateDelegate); | 143 DISALLOW_COPY_AND_ASSIGN(TestNetworkingCastPrivateDelegate); |
141 }; | 144 }; |
142 | 145 |
146 // This is testing NetworkingPrivateChromeOS, so only use overrides here to | |
147 // provide extra functionality or bookkeeping for code paths that are otherwise | |
148 // difficult to replicate in a test environment. | |
149 class NetworkingPrivateChromeOSTestDelegate : public NetworkingPrivateChromeOS { | |
150 public: | |
151 explicit NetworkingPrivateChromeOSTestDelegate( | |
152 content::BrowserContext* context) | |
153 : NetworkingPrivateChromeOS(context) {} | |
154 ~NetworkingPrivateChromeOSTestDelegate() override {} | |
155 | |
156 // NetworkingPrivateChromeOS | |
157 std::unique_ptr<base::DictionaryValue> GetCertificateLists() override { | |
158 // Send a certificates changed notification for testing the event. | |
159 chromeos::NetworkHandler::Get() | |
160 ->network_certificate_handler() | |
161 ->NotifyCertificatsChangedForTest(); | |
162 return NetworkingPrivateChromeOS::GetCertificateLists(); | |
163 } | |
164 | |
tbarzic
2017/05/23 18:01:58
private:
stevenjb
2017/05/25 00:01:11
Done.
| |
165 DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateChromeOSTestDelegate); | |
166 }; | |
167 | |
143 class UIDelegateStub : public NetworkingPrivateDelegate::UIDelegate { | 168 class UIDelegateStub : public NetworkingPrivateDelegate::UIDelegate { |
144 public: | 169 public: |
145 static int s_show_account_details_called_; | 170 static int s_show_account_details_called_; |
146 | 171 |
147 private: | 172 private: |
148 // UIDelegate | 173 // UIDelegate |
149 void ShowAccountDetails(const std::string& guid) const override { | 174 void ShowAccountDetails(const std::string& guid) const override { |
150 ++s_show_account_details_called_; | 175 ++s_show_account_details_called_; |
151 } | 176 } |
152 bool HandleConnectFailed(const std::string& guid, | 177 bool HandleConnectFailed(const std::string& guid, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 } | 341 } |
317 | 342 |
318 void AddService(const std::string& service_path, | 343 void AddService(const std::string& service_path, |
319 const std::string& name, | 344 const std::string& name, |
320 const std::string& type, | 345 const std::string& type, |
321 const std::string& state) { | 346 const std::string& state) { |
322 service_test_->AddService(service_path, service_path + "_guid", name, type, | 347 service_test_->AddService(service_path, service_path + "_guid", name, type, |
323 state, true /* add_to_visible */); | 348 state, true /* add_to_visible */); |
324 } | 349 } |
325 | 350 |
326 static std::unique_ptr<KeyedService> CreateNetworkingPrivateServiceClient( | 351 static std::unique_ptr<KeyedService> CreateNetworkingPrivateDelegate( |
327 content::BrowserContext* context) { | 352 content::BrowserContext* context) { |
328 std::unique_ptr<NetworkingPrivateDelegate> result( | 353 std::unique_ptr<NetworkingPrivateDelegate> result( |
329 new NetworkingPrivateChromeOS(context)); | 354 new NetworkingPrivateChromeOSTestDelegate(context)); |
330 std::unique_ptr<NetworkingPrivateDelegate::UIDelegate> ui_delegate( | 355 std::unique_ptr<NetworkingPrivateDelegate::UIDelegate> ui_delegate( |
331 new UIDelegateStub); | 356 new UIDelegateStub); |
332 result->set_ui_delegate(std::move(ui_delegate)); | 357 result->set_ui_delegate(std::move(ui_delegate)); |
333 return result; | 358 return result; |
334 } | 359 } |
335 | 360 |
336 void SetUp() override { | 361 void SetUp() override { |
337 networking_cast_delegate_factory_ = base::Bind( | 362 networking_cast_delegate_factory_ = base::Bind( |
338 &NetworkingPrivateChromeOSApiTest::CreateNetworkingCastPrivateDelegate, | 363 &NetworkingPrivateChromeOSApiTest::CreateNetworkingCastPrivateDelegate, |
339 base::Unretained(this)); | 364 base::Unretained(this)); |
340 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest( | 365 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest( |
341 &networking_cast_delegate_factory_); | 366 &networking_cast_delegate_factory_); |
342 | 367 |
343 ExtensionApiTest::SetUp(); | 368 ExtensionApiTest::SetUp(); |
344 } | 369 } |
345 | 370 |
346 void SetUpOnMainThread() override { | 371 void SetUpOnMainThread() override { |
347 detector_ = new NetworkPortalDetectorTestImpl(); | 372 detector_ = new NetworkPortalDetectorTestImpl(); |
348 chromeos::network_portal_detector::InitializeForTesting(detector_); | 373 chromeos::network_portal_detector::InitializeForTesting(detector_); |
349 | 374 |
350 ExtensionApiTest::SetUpOnMainThread(); | 375 ExtensionApiTest::SetUpOnMainThread(); |
351 content::RunAllPendingInMessageLoop(); | 376 content::RunAllPendingInMessageLoop(); |
352 | 377 |
353 NetworkingPrivateDelegateFactory::GetInstance()->SetTestingFactory( | 378 NetworkingPrivateDelegateFactory::GetInstance()->SetTestingFactory( |
354 profile(), &CreateNetworkingPrivateServiceClient); | 379 profile(), &CreateNetworkingPrivateDelegate); |
355 | 380 |
356 InitializeSanitizedUsername(); | 381 InitializeSanitizedUsername(); |
357 | 382 |
358 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 383 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
359 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); | 384 manager_test_ = dbus_manager->GetShillManagerClient()->GetTestInterface(); |
360 profile_test_ = dbus_manager->GetShillProfileClient()->GetTestInterface(); | 385 profile_test_ = dbus_manager->GetShillProfileClient()->GetTestInterface(); |
361 service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); | 386 service_test_ = dbus_manager->GetShillServiceClient()->GetTestInterface(); |
362 device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); | 387 device_test_ = dbus_manager->GetShillDeviceClient()->GetTestInterface(); |
363 | 388 |
364 ShillIPConfigClient::TestInterface* ip_config_test = | 389 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"); | 504 profile_test_->AddService(kUser1ProfilePath, "stub_vpn2"); |
480 | 505 |
481 content::RunAllPendingInMessageLoop(); | 506 content::RunAllPendingInMessageLoop(); |
482 } | 507 } |
483 | 508 |
484 void TearDown() override { | 509 void TearDown() override { |
485 ExtensionApiTest::TearDown(); | 510 ExtensionApiTest::TearDown(); |
486 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest(nullptr); | 511 ChromeNetworkingCastPrivateDelegate::SetFactoryCallbackForTest(nullptr); |
487 } | 512 } |
488 | 513 |
489 private: | |
490 std::unique_ptr<ChromeNetworkingCastPrivateDelegate> | 514 std::unique_ptr<ChromeNetworkingCastPrivateDelegate> |
491 CreateNetworkingCastPrivateDelegate() { | 515 CreateNetworkingCastPrivateDelegate() { |
492 return base::MakeUnique<TestNetworkingCastPrivateDelegate>(); | 516 return base::MakeUnique<TestNetworkingCastPrivateDelegate>(); |
493 } | 517 } |
494 | 518 |
519 bool SetupCertificates() { | |
520 scoped_refptr<net::X509Certificate> system_ca_cert = | |
521 net::ImportCertFromFile(net::GetTestCertsDirectory(), | |
522 "client_1_ca.pem"); | |
523 if (!system_ca_cert) | |
524 return false; | |
525 | |
526 net::CertificateList cert_list; | |
527 cert_list.push_back(std::move(system_ca_cert)); | |
528 // TODO(stevenjb): Figure out a simple way to import a test user cert. | |
529 | |
530 chromeos::NetworkHandler::Get() | |
531 ->network_certificate_handler() | |
532 ->SetCertificatesForTest(cert_list); | |
533 return true; | |
534 } | |
535 | |
495 protected: | 536 protected: |
496 NetworkPortalDetectorTestImpl* detector() { return detector_; } | 537 NetworkPortalDetectorTestImpl* detector() { return detector_; } |
497 | 538 |
498 NetworkPortalDetectorTestImpl* detector_; | 539 NetworkPortalDetectorTestImpl* detector_; |
499 ShillManagerClient::TestInterface* manager_test_; | 540 ShillManagerClient::TestInterface* manager_test_; |
500 ShillProfileClient::TestInterface* profile_test_; | 541 ShillProfileClient::TestInterface* profile_test_; |
501 ShillServiceClient::TestInterface* service_test_; | 542 ShillServiceClient::TestInterface* service_test_; |
502 ShillDeviceClient::TestInterface* device_test_; | 543 ShillDeviceClient::TestInterface* device_test_; |
503 policy::MockConfigurationPolicyProvider provider_; | 544 policy::MockConfigurationPolicyProvider provider_; |
504 std::string userhash_; | 545 std::string userhash_; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 OnNetworkListChangedEvent) { | 804 OnNetworkListChangedEvent) { |
764 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; | 805 EXPECT_TRUE(RunNetworkingSubtest("onNetworkListChangedEvent")) << message_; |
765 } | 806 } |
766 | 807 |
767 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 808 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
768 OnDeviceStateListChangedEvent) { | 809 OnDeviceStateListChangedEvent) { |
769 EXPECT_TRUE(RunNetworkingSubtest("onDeviceStateListChangedEvent")) | 810 EXPECT_TRUE(RunNetworkingSubtest("onDeviceStateListChangedEvent")) |
770 << message_; | 811 << message_; |
771 } | 812 } |
772 | 813 |
814 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | |
815 OnCertificateListsChangedEvent) { | |
816 EXPECT_TRUE(RunNetworkingSubtest("onCertificateListsChangedEvent")) | |
817 << message_; | |
818 } | |
819 | |
773 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyDestination) { | 820 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyDestination) { |
774 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; | 821 EXPECT_TRUE(RunNetworkingSubtest("verifyDestination")) << message_; |
775 } | 822 } |
776 | 823 |
777 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 824 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
778 VerifyAndEncryptCredentials) { | 825 VerifyAndEncryptCredentials) { |
779 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; | 826 EXPECT_TRUE(RunNetworkingSubtest("verifyAndEncryptCredentials")) << message_; |
780 } | 827 } |
781 | 828 |
782 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, VerifyAndEncryptData) { | 829 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")) | 931 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkManagedProperties")) |
885 << message_; | 932 << message_; |
886 } | 933 } |
887 | 934 |
888 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, | 935 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, |
889 Tether_GetTetherNetworkState) { | 936 Tether_GetTetherNetworkState) { |
890 SetupTether(); | 937 SetupTether(); |
891 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkState")) << message_; | 938 EXPECT_TRUE(RunNetworkingSubtest("getTetherNetworkState")) << message_; |
892 } | 939 } |
893 | 940 |
941 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, GetCertificateLists) { | |
942 ASSERT_TRUE(SetupCertificates()); | |
943 EXPECT_TRUE(RunNetworkingSubtest("getCertificateLists")) << message_; | |
944 } | |
945 | |
894 // Tests subset of networking API for the networking API alias - to verify that | 946 // 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 | 947 // using API methods and event does not cause access exceptions (due to |
896 // missing permissions). | 948 // missing permissions). |
897 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, Alias) { | 949 IN_PROC_BROWSER_TEST_F(NetworkingPrivateChromeOSApiTest, Alias) { |
898 SetupCellular(); | 950 SetupCellular(); |
899 EXPECT_TRUE(RunPlatformAppTest("networking_private/alias")) << message_; | 951 EXPECT_TRUE(RunPlatformAppTest("networking_private/alias")) << message_; |
900 } | 952 } |
901 | 953 |
902 } // namespace | 954 } // namespace |
OLD | NEW |