Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / chromeos / login / users / affiliation_unittest.cc
blob1ab758eaec82ce2bfe48d8182553db6b358916d7
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.
5 #include "chrome/browser/chromeos/login/users/affiliation.h"
7 #include <set>
8 #include <string>
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace chromeos {
14 TEST(AffiliationTest, HaveCommonElementEmptySet) {
15 // Empty sets don't have common elements.
16 EXPECT_FALSE(HaveCommonElement(AffiliationIDSet(), AffiliationIDSet()));
18 AffiliationIDSet not_empty_set;
19 not_empty_set.insert("a");
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()));
27 TEST(AffiliationTest, HaveCommonElementNoOverlap) {
28 AffiliationIDSet set1;
29 AffiliationIDSet set2;
31 // No common elements.
32 set1.insert("a");
33 set1.insert("b");
34 set1.insert("c");
36 set2.insert("d");
37 set2.insert("e");
38 set2.insert("f");
39 EXPECT_FALSE(HaveCommonElement(set1, set2));
42 TEST(AffiliationTest, HaveCommonElementFirstAndLastIsCommon) {
43 AffiliationIDSet set1;
44 AffiliationIDSet set2;
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.
52 set2.insert("d");
53 set2.insert("e");
54 set2.insert("f");
56 EXPECT_TRUE(HaveCommonElement(set1, set2));
57 EXPECT_TRUE(HaveCommonElement(set2, set1));
60 TEST(AffiliationTest, HaveCommonElementCommonInTheMiddle) {
61 AffiliationIDSet set1;
62 AffiliationIDSet set2;
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");
69 set2.insert("c");
70 set2.insert("f");
71 set2.insert("j");
73 EXPECT_TRUE(HaveCommonElement(set1, set2));
74 EXPECT_TRUE(HaveCommonElement(set2, set1));
77 TEST(AffiliationTest, Generic) {
78 AffiliationIDSet user_ids; // User affiliation IDs.
79 AffiliationIDSet device_ids; // Device affiliation IDs.
81 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "", ""));
83 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user", ""));
85 // Not valid email.
86 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user", "user"));
88 EXPECT_FALSE(IsUserAffiliated(user_ids, device_ids, "user@notmanaged.com",
89 "managed.com"));
91 EXPECT_TRUE(IsUserAffiliated(user_ids, device_ids, "user@managed.com",
92 "managed.com"));
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"));
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"));
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"));
108 } // namespace chromeos