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"
10 #include "testing/gtest/include/gtest/gtest.h"
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.
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.
50 set1
.insert("d"); // String "d" is common.
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.
66 set1
.insert("f"); // String "f" is common.
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", ""));
86 EXPECT_FALSE(IsUserAffiliated(user_ids
, device_ids
, "user", "user"));
88 EXPECT_FALSE(IsUserAffiliated(user_ids
, device_ids
, "user@notmanaged.com",
91 EXPECT_TRUE(IsUserAffiliated(user_ids
, device_ids
, "user@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",
98 device_ids
.insert("bbbb"); // Device and user IDs do not overlap.
99 EXPECT_FALSE(IsUserAffiliated(user_ids
, device_ids
, "user@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",
108 } // namespace chromeos