target_device_info_unittest.cc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Copyright 2019 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 "components/send_tab_to_self/target_device_info.h"
  5. #include "base/test/scoped_feature_list.h"
  6. #include "components/send_tab_to_self/features.h"
  7. #include "components/sync/driver/test_sync_service.h"
  8. #include "components/sync/protocol/device_info_specifics.pb.h"
  9. #include "components/sync/protocol/sync_enums.pb.h"
  10. #include "components/sync_device_info/device_info.h"
  11. #include "components/sync_device_info/device_info_util.h"
  12. #include "testing/gtest/include/gtest/gtest.h"
  13. namespace send_tab_to_self {
  14. namespace {
  15. class SharingUtilsTest : public testing::Test {
  16. public:
  17. SharingUtilsTest() = default;
  18. protected:
  19. base::test::ScopedFeatureList scoped_feature_list_;
  20. syncer::TestSyncService test_sync_service_;
  21. };
  22. static std::unique_ptr<syncer::DeviceInfo> CreateFakeDeviceInfo(
  23. const std::string& id,
  24. const std::string& name,
  25. sync_pb::SyncEnums_DeviceType device_type,
  26. const std::string& manufacturer_name,
  27. const std::string& model_name) {
  28. return std::make_unique<syncer::DeviceInfo>(
  29. id, name, "chrome_version", "user_agent", device_type, "device_id",
  30. manufacturer_name, model_name,
  31. /*full_hardware_class=*/std::string(),
  32. /*last_updated_timestamp=*/base::Time::Now(),
  33. syncer::DeviceInfoUtil::GetPulseInterval(),
  34. /*send_tab_to_self_receiving_enabled=*/false,
  35. syncer::DeviceInfo::SharingInfo(
  36. {"vapid_fcm_token", "vapid_p256dh", "vapid_auth_secret"},
  37. {"sender_id_fcm_token", "sender_id_p256dh", "sender_id_auth_secret"},
  38. std::set<sync_pb::SharingSpecificFields::EnabledFeatures>{
  39. sync_pb::SharingSpecificFields::CLICK_TO_CALL_V2}),
  40. /*paask_info=*/absl::nullopt,
  41. /*fcm_registration_token=*/std::string(),
  42. /*interested_data_types=*/syncer::ModelTypeSet());
  43. }
  44. } // namespace
  45. TEST_F(SharingUtilsTest, GetSharingDeviceNames_AppleDevices_SigninOnly) {
  46. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  47. "guid", "MacbookPro1,1", sync_pb::SyncEnums_DeviceType_TYPE_MAC,
  48. "Apple Inc.", "MacbookPro1,1");
  49. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  50. EXPECT_EQ("MacbookPro1,1", names.full_name);
  51. EXPECT_EQ("MacbookPro", names.short_name);
  52. }
  53. TEST_F(SharingUtilsTest, GetSharingDeviceNames_AppleDevices_FullySynced) {
  54. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  55. "guid", "Bobs-iMac", sync_pb::SyncEnums_DeviceType_TYPE_MAC, "Apple Inc.",
  56. "MacbookPro1,1");
  57. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  58. EXPECT_EQ("Bobs-iMac", names.full_name);
  59. EXPECT_EQ("Bobs-iMac", names.short_name);
  60. }
  61. TEST_F(SharingUtilsTest, GetSharingDeviceNames_ChromeOSDevices) {
  62. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  63. "guid", "Chromebook", sync_pb::SyncEnums_DeviceType_TYPE_CROS, "Google",
  64. "Chromebook");
  65. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  66. EXPECT_EQ("Google Chromebook", names.full_name);
  67. EXPECT_EQ("Google Chromebook", names.short_name);
  68. }
  69. TEST_F(SharingUtilsTest, GetSharingDeviceNames_AndroidPhones) {
  70. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  71. "guid", "Pixel 2", sync_pb::SyncEnums_DeviceType_TYPE_PHONE, "Google",
  72. "Pixel 2");
  73. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  74. EXPECT_EQ("Google Phone Pixel 2", names.full_name);
  75. EXPECT_EQ("Google Phone", names.short_name);
  76. }
  77. TEST_F(SharingUtilsTest, GetSharingDeviceNames_AndroidTablets) {
  78. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  79. "guid", "Pixel C", sync_pb::SyncEnums_DeviceType_TYPE_TABLET, "Google",
  80. "Pixel C");
  81. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  82. EXPECT_EQ("Google Tablet Pixel C", names.full_name);
  83. EXPECT_EQ("Google Tablet", names.short_name);
  84. }
  85. TEST_F(SharingUtilsTest, GetSharingDeviceNames_Windows_SigninOnly) {
  86. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  87. "guid", "BX123", sync_pb::SyncEnums_DeviceType_TYPE_WIN, "Dell", "BX123");
  88. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  89. EXPECT_EQ("Dell Computer BX123", names.full_name);
  90. EXPECT_EQ("Dell Computer", names.short_name);
  91. }
  92. TEST_F(SharingUtilsTest, GetSharingDeviceNames_Windows_FullySynced) {
  93. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  94. "guid", "BOBS-WINDOWS-1", sync_pb::SyncEnums_DeviceType_TYPE_WIN, "Dell",
  95. "BX123");
  96. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  97. EXPECT_EQ("BOBS-WINDOWS-1", names.full_name);
  98. EXPECT_EQ("BOBS-WINDOWS-1", names.short_name);
  99. }
  100. TEST_F(SharingUtilsTest, GetSharingDeviceNames_Linux_SigninOnly) {
  101. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  102. "guid", "30BDS0RA0G", sync_pb::SyncEnums_DeviceType_TYPE_LINUX, "LENOVO",
  103. "30BDS0RA0G");
  104. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  105. EXPECT_EQ("LENOVO Computer 30BDS0RA0G", names.full_name);
  106. EXPECT_EQ("LENOVO Computer", names.short_name);
  107. }
  108. TEST_F(SharingUtilsTest, GetSharingDeviceNames_Linux_FullySynced) {
  109. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  110. "guid", "bob.chromium.org", sync_pb::SyncEnums_DeviceType_TYPE_LINUX,
  111. "LENOVO", "30BDS0RA0G");
  112. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  113. EXPECT_EQ("bob.chromium.org", names.full_name);
  114. EXPECT_EQ("bob.chromium.org", names.short_name);
  115. }
  116. TEST_F(SharingUtilsTest, CheckManufacturerNameCapitalization) {
  117. std::unique_ptr<syncer::DeviceInfo> device = CreateFakeDeviceInfo(
  118. "guid", "model", sync_pb::SyncEnums_DeviceType_TYPE_WIN, "foo bar",
  119. "model");
  120. SharingDeviceNames names = GetSharingDeviceNames(device.get());
  121. EXPECT_EQ("Foo Bar Computer model", names.full_name);
  122. EXPECT_EQ("Foo Bar Computer", names.short_name);
  123. device = CreateFakeDeviceInfo("guid", "model",
  124. sync_pb::SyncEnums_DeviceType_TYPE_WIN,
  125. "foo1bar", "model");
  126. names = GetSharingDeviceNames(device.get());
  127. EXPECT_EQ("Foo1Bar Computer model", names.full_name);
  128. EXPECT_EQ("Foo1Bar Computer", names.short_name);
  129. device = CreateFakeDeviceInfo("guid", "model",
  130. sync_pb::SyncEnums_DeviceType_TYPE_WIN,
  131. "foo_bar-FOO", "model");
  132. names = GetSharingDeviceNames(device.get());
  133. EXPECT_EQ("Foo_Bar-FOO Computer model", names.full_name);
  134. EXPECT_EQ("Foo_Bar-FOO Computer", names.short_name);
  135. device = CreateFakeDeviceInfo("guid", "model",
  136. sync_pb::SyncEnums_DeviceType_TYPE_WIN,
  137. "foo&bar foo", "model");
  138. names = GetSharingDeviceNames(device.get());
  139. EXPECT_EQ("Foo&Bar Foo Computer model", names.full_name);
  140. EXPECT_EQ("Foo&Bar Foo Computer", names.short_name);
  141. }
  142. } // namespace send_tab_to_self