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