esim_manager_unittest.cc 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/services/cellular_setup/esim_manager.h"
  5. #include "ash/services/cellular_setup/esim_test_base.h"
  6. #include "ash/services/cellular_setup/esim_test_utils.h"
  7. #include "ash/services/cellular_setup/public/mojom/esim_manager.mojom.h"
  8. #include "chromeos/ash/components/dbus/hermes/hermes_clients.h"
  9. #include "chromeos/ash/components/dbus/hermes/hermes_euicc_client.h"
  10. #include "third_party/cros_system_api/dbus/hermes/dbus-constants.h"
  11. namespace ash::cellular_setup {
  12. class ESimManagerTest : public ESimTestBase {
  13. public:
  14. ESimManagerTest() = default;
  15. ESimManagerTest(const ESimManagerTest&) = delete;
  16. ESimManagerTest& operator=(const ESimManagerTest&) = delete;
  17. };
  18. TEST_F(ESimManagerTest, GetAvailableEuiccs) {
  19. ASSERT_EQ(0u, GetAvailableEuiccs().size());
  20. SetupEuicc();
  21. // Verify that GetAvailableEuiccs call returns list of euiccs.
  22. std::vector<mojo::PendingRemote<mojom::Euicc>> available_euiccs =
  23. GetAvailableEuiccs();
  24. ASSERT_EQ(1u, available_euiccs.size());
  25. mojo::Remote<mojom::Euicc> euicc(std::move(available_euiccs.front()));
  26. mojom::EuiccPropertiesPtr properties = GetEuiccProperties(euicc);
  27. EXPECT_EQ(kTestEid, properties->eid);
  28. }
  29. TEST_F(ESimManagerTest, ListChangeNotification) {
  30. SetupEuicc();
  31. // Verify that available euicc list change is notified.
  32. ASSERT_EQ(1, observer()->available_euicc_list_change_count());
  33. // Add an installed profile and verify the profile list change is notified to
  34. // observer.
  35. HermesEuiccClient::TestInterface* euicc_test =
  36. HermesEuiccClient::Get()->GetTestInterface();
  37. dbus::ObjectPath active_profile_path = euicc_test->AddFakeCarrierProfile(
  38. dbus::ObjectPath(kTestEuiccPath), hermes::profile::State::kActive, "",
  39. HermesEuiccClient::TestInterface::AddCarrierProfileBehavior::
  40. kAddProfileWithService);
  41. // Wait for events to propagate.
  42. base::RunLoop().RunUntilIdle();
  43. EXPECT_EQ(1u, observer()->profile_list_change_calls().size());
  44. // Add a pending profile and verify the profile list change is notified to
  45. // observer.
  46. dbus::ObjectPath pending_profile_path = euicc_test->AddFakeCarrierProfile(
  47. dbus::ObjectPath(kTestEuiccPath), hermes::profile::State::kPending, "",
  48. HermesEuiccClient::TestInterface::AddCarrierProfileBehavior::
  49. kAddProfileWithService);
  50. // Wait for events to propagate.
  51. base::RunLoop().RunUntilIdle();
  52. EXPECT_EQ(2u, observer()->profile_list_change_calls().size());
  53. }
  54. TEST_F(ESimManagerTest, EuiccChangeNotification) {
  55. SetupEuicc();
  56. HermesEuiccClient::Properties* dbus_properties =
  57. HermesEuiccClient::Get()->GetProperties(dbus::ObjectPath(kTestEuiccPath));
  58. dbus_properties->is_active().ReplaceValue(false);
  59. base::RunLoop().RunUntilIdle();
  60. ASSERT_EQ(1u, observer()->euicc_change_calls().size());
  61. mojo::Remote<mojom::Euicc> euicc(observer()->PopLastChangedEuicc());
  62. mojom::EuiccPropertiesPtr mojo_properties = GetEuiccProperties(euicc);
  63. EXPECT_EQ(kTestEid, mojo_properties->eid);
  64. }
  65. TEST_F(ESimManagerTest, ESimProfileChangeNotification) {
  66. SetupEuicc();
  67. HermesEuiccClient::TestInterface* euicc_test =
  68. HermesEuiccClient::Get()->GetTestInterface();
  69. dbus::ObjectPath profile_path = euicc_test->AddFakeCarrierProfile(
  70. dbus::ObjectPath(kTestEuiccPath), hermes::profile::kActive, "",
  71. HermesEuiccClient::TestInterface::AddCarrierProfileBehavior::
  72. kAddProfileWithService);
  73. base::RunLoop().RunUntilIdle();
  74. HermesProfileClient::Properties* dbus_properties =
  75. HermesProfileClient::Get()->GetProperties(dbus::ObjectPath(profile_path));
  76. dbus_properties->state().ReplaceValue(hermes::profile::kInactive);
  77. base::RunLoop().RunUntilIdle();
  78. ASSERT_EQ(1u, observer()->profile_change_calls().size());
  79. mojo::Remote<mojom::ESimProfile> esim_profile(
  80. observer()->PopLastChangedESimProfile());
  81. mojom::ESimProfilePropertiesPtr mojo_properties =
  82. GetESimProfileProperties(esim_profile);
  83. EXPECT_EQ(dbus_properties->iccid().value(), mojo_properties->iccid);
  84. }
  85. } // namespace ash::cellular_setup