Victor Hugo Vianna Silva | 452667a | 2024-07-18 21:57:33 | [diff] [blame] | 1 | // Copyright 2024 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/sync/service/local_data_description.h" |
| 6 | |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | #include "url/gurl.h" |
| 9 | |
| 10 | namespace syncer { |
| 11 | namespace { |
| 12 | |
| 13 | // Convenience helper, since LocalDataDescription doesn't support designated |
| 14 | // inits. |
| 15 | LocalDataDescription BuildDescription(int item_count, |
| 16 | const std::vector<std::string>& domains, |
| 17 | int domain_count) { |
| 18 | LocalDataDescription description; |
| 19 | description.item_count = item_count; |
| 20 | description.domains = domains; |
| 21 | description.domain_count = domain_count; |
| 22 | return description; |
| 23 | } |
| 24 | |
| 25 | TEST(LocalDataDescriptionTest, AtMostThreeDomains) { |
| 26 | EXPECT_EQ(LocalDataDescription({GURL("http://a.com")}), |
| 27 | BuildDescription(1, {"a.com"}, 1)); |
| 28 | EXPECT_EQ(LocalDataDescription({ |
| 29 | GURL("http://a.com"), |
| 30 | GURL("http://b.com"), |
| 31 | }), |
| 32 | BuildDescription(2, {"a.com", "b.com"}, 2)); |
| 33 | EXPECT_EQ(LocalDataDescription({ |
| 34 | GURL("http://a.com"), |
| 35 | GURL("http://b.com"), |
| 36 | GURL("http://c.com"), |
| 37 | }), |
| 38 | BuildDescription(3, {"a.com", "b.com", "c.com"}, 3)); |
| 39 | // d.com is not included. |
| 40 | EXPECT_EQ(LocalDataDescription({ |
| 41 | GURL("http://a.com"), |
| 42 | GURL("http://b.com"), |
| 43 | GURL("http://c.com"), |
| 44 | GURL("http://d.com"), |
| 45 | }), |
| 46 | BuildDescription(4, {"a.com", "b.com", "c.com"}, 4)); |
| 47 | } |
| 48 | |
| 49 | TEST(LocalDataDescriptionTest, DomainsAreSorted) { |
| 50 | EXPECT_EQ(LocalDataDescription({GURL("http://c.com"), GURL("http://b.com"), |
| 51 | GURL("http://a.com")}), |
| 52 | BuildDescription(3, {"a.com", "b.com", "c.com"}, 3)); |
| 53 | // Sorting shouldn't take the scheme into account, http://b.com is < than |
| 54 | // https://a.com but a.com < b.com. |
| 55 | EXPECT_EQ(LocalDataDescription({GURL("http://b.com"), GURL("https://a.com")}), |
| 56 | BuildDescription(2, {"a.com", "b.com"}, 2)); |
| 57 | } |
| 58 | |
| 59 | TEST(LocalDataDescriptionTest, DomainsAreDeduped) { |
| 60 | EXPECT_EQ(LocalDataDescription({GURL("http://a.com"), GURL("https://a.com"), |
| 61 | GURL("https://a.com/foo")}), |
| 62 | BuildDescription(3, {"a.com"}, 1)); |
| 63 | } |
| 64 | |
Victor Hugo Vianna Silva | 9383548 | 2024-07-24 18:08:39 | [diff] [blame] | 65 | TEST(LocalDataDescriptionTest, GetDomainsDisplayText) { |
| 66 | EXPECT_EQ(GetDomainsDisplayText(LocalDataDescription({GURL("http://a.com")})), |
| 67 | u"a.com"); |
| 68 | EXPECT_EQ(GetDomainsDisplayText(LocalDataDescription( |
| 69 | {GURL("http://a.com"), GURL("http://b.com")})), |
| 70 | u"a.com, b.com"); |
| 71 | EXPECT_EQ( |
| 72 | GetDomainsDisplayText(LocalDataDescription( |
| 73 | {GURL("http://a.com"), GURL("http://b.com"), GURL("http://c.com")})), |
| 74 | u"a.com, b.com, and 1 more"); |
| 75 | EXPECT_EQ(GetDomainsDisplayText(LocalDataDescription( |
| 76 | {GURL("http://a.com"), GURL("http://b.com"), |
| 77 | GURL("http://c.com"), GURL("http://d.com")})), |
| 78 | u"a.com, b.com, and 2 more"); |
| 79 | EXPECT_EQ( |
| 80 | GetDomainsDisplayText(LocalDataDescription( |
| 81 | {GURL("http://a.com"), GURL("http://a.com"), GURL("http://b.com")})), |
| 82 | u"a.com, b.com"); |
| 83 | } |
| 84 | |
Victor Hugo Vianna Silva | 452667a | 2024-07-18 21:57:33 | [diff] [blame] | 85 | } // namespace |
| 86 | } // namespace syncer |