OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 |
| 5 #include "chrome/browser/chromeos/login/users/affiliation.h" |
| 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace chromeos { |
| 13 |
| 14 TEST(AffiliationTest, HaveCommonElementEmptySet) { |
| 15 // Empty sets don't have common elements. |
| 16 EXPECT_FALSE(HaveCommonElement(AffiliationIDSet(), AffiliationIDSet())); |
| 17 |
| 18 AffiliationIDSet not_empty_set; |
| 19 not_empty_set.insert("a"); |
| 20 |
| 21 // Only first set is empty. No common elements and no crash. |
| 22 EXPECT_FALSE(HaveCommonElement(AffiliationIDSet(), not_empty_set)); |
| 23 // Now the second set is empty. |
| 24 EXPECT_FALSE(HaveCommonElement(not_empty_set, AffiliationIDSet())); |
| 25 } |
| 26 |
| 27 TEST(AffiliationTest, HaveCommonElementNoOverlap) { |
| 28 AffiliationIDSet set1; |
| 29 AffiliationIDSet set2; |
| 30 |
| 31 // No common elements. |
| 32 set1.insert("a"); |
| 33 set1.insert("b"); |
| 34 set1.insert("c"); |
| 35 |
| 36 set2.insert("d"); |
| 37 set2.insert("e"); |
| 38 set2.insert("f"); |
| 39 EXPECT_FALSE(HaveCommonElement(set1, set2)); |
| 40 } |
| 41 |
| 42 TEST(AffiliationTest, HaveCommonElementFirstAndLastIsCommon) { |
| 43 AffiliationIDSet set1; |
| 44 AffiliationIDSet set2; |
| 45 |
| 46 // The common element is last in set1 and first in set2. |
| 47 set1.insert("a"); |
| 48 set1.insert("b"); |
| 49 set1.insert("c"); |
| 50 set1.insert("d"); // String "d" is common. |
| 51 |
| 52 set2.insert("d"); |
| 53 set2.insert("e"); |
| 54 set2.insert("f"); |
| 55 |
| 56 EXPECT_TRUE(HaveCommonElement(set1, set2)); |
| 57 EXPECT_TRUE(HaveCommonElement(set2, set1)); |
| 58 } |
| 59 |
| 60 TEST(AffiliationTest, HaveCommonElementCommonInTheMiddle) { |
| 61 AffiliationIDSet set1; |
| 62 AffiliationIDSet set2; |
| 63 |
| 64 // The common element is in the middle of the two sets. |
| 65 set1.insert("b"); |
| 66 set1.insert("f"); // String "f" is common. |
| 67 set1.insert("k"); |
| 68 |
| 69 set2.insert("c"); |
| 70 set2.insert("f"); |
| 71 set2.insert("j"); |
| 72 |
| 73 EXPECT_TRUE(HaveCommonElement(set1, set2)); |
| 74 EXPECT_TRUE(HaveCommonElement(set2, set1)); |
| 75 } |
| 76 |
| 77 TEST(AffiliationTest, Generic) { |
| 78 AffiliationIDSet user_ids; // User affiliation IDs. |
| 79 AffiliationIDSet device_ids; // Device affiliation IDs. |
| 80 |
| 81 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "", "")); |
| 82 |
| 83 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user", "")); |
| 84 |
| 85 // Not valid email. |
| 86 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user", "user")); |
| 87 |
| 88 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user@notmanaged.com", |
| 89 "managed.com")); |
| 90 |
| 91 EXPECT_TRUE(IsUserAffiliated(user_ids, device_ids, "user@managed.com", |
| 92 "managed.com")); |
| 93 |
| 94 user_ids.insert("aaaa"); // Only user affiliation IDs present. Compare email. |
| 95 EXPECT_TRUE(IsUserAffiliated(user_ids, device_ids, "user@managed.com", |
| 96 "managed.com")); |
| 97 |
| 98 device_ids.insert("bbbb"); // Device and user IDs do not overlap. |
| 99 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user@managed.com", |
| 100 "managed.com")); |
| 101 |
| 102 user_ids.insert("cccc"); // Device and user IDs do overlap. |
| 103 device_ids.insert("cccc"); |
| 104 EXPECT_TRUE(IsUserAffiliated(user_ids, device_ids, "user@notmanaged.com", |
| 105 "managed.com")); |
| 106 } |
| 107 |
| 108 } // namespace chromeos |
OLD | NEW |