- add sources.
[platform/framework/web/crosswalk.git] / src / google_apis / gaia / gaia_auth_util_unittest.cc
1 // Copyright (c) 2012 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 "google_apis/gaia/gaia_auth_util.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
9
10 namespace gaia {
11
12 TEST(GaiaAuthUtilTest, EmailAddressNoOp) {
13   const char lower_case[] = "user@what.com";
14   EXPECT_EQ(lower_case, CanonicalizeEmail(lower_case));
15 }
16
17 TEST(GaiaAuthUtilTest, EmailAddressIgnoreCaps) {
18   EXPECT_EQ(CanonicalizeEmail("user@what.com"),
19             CanonicalizeEmail("UsEr@what.com"));
20 }
21
22 TEST(GaiaAuthUtilTest, EmailAddressIgnoreDomainCaps) {
23   EXPECT_EQ(CanonicalizeEmail("user@what.com"),
24             CanonicalizeEmail("UsEr@what.COM"));
25 }
26
27 TEST(GaiaAuthUtilTest, EmailAddressRejectOneUsernameDot) {
28   EXPECT_NE(CanonicalizeEmail("u.ser@what.com"),
29             CanonicalizeEmail("UsEr@what.com"));
30 }
31
32 TEST(GaiaAuthUtilTest, EmailAddressMatchWithOneUsernameDot) {
33   EXPECT_EQ(CanonicalizeEmail("u.ser@what.com"),
34             CanonicalizeEmail("U.sEr@what.com"));
35 }
36
37 TEST(GaiaAuthUtilTest, EmailAddressIgnoreOneUsernameDot) {
38   EXPECT_EQ(CanonicalizeEmail("us.er@gmail.com"),
39             CanonicalizeEmail("UsEr@gmail.com"));
40 }
41
42 TEST(GaiaAuthUtilTest, EmailAddressIgnoreManyUsernameDots) {
43   EXPECT_EQ(CanonicalizeEmail("u.ser@gmail.com"),
44             CanonicalizeEmail("Us.E.r@gmail.com"));
45 }
46
47 TEST(GaiaAuthUtilTest, EmailAddressIgnoreConsecutiveUsernameDots) {
48   EXPECT_EQ(CanonicalizeEmail("use.r@gmail.com"),
49             CanonicalizeEmail("Us....E.r@gmail.com"));
50 }
51
52 TEST(GaiaAuthUtilTest, EmailAddressDifferentOnesRejected) {
53   EXPECT_NE(CanonicalizeEmail("who@what.com"),
54             CanonicalizeEmail("Us....E.r@what.com"));
55 }
56
57 TEST(GaiaAuthUtilTest, EmailAddressIgnorePlusSuffix) {
58   const char with_plus[] = "user+cc@what.com";
59   EXPECT_EQ(with_plus, CanonicalizeEmail(with_plus));
60 }
61
62 TEST(GaiaAuthUtilTest, EmailAddressIgnoreMultiPlusSuffix) {
63   const char multi_plus[] = "user+cc+bcc@what.com";
64   EXPECT_EQ(multi_plus, CanonicalizeEmail(multi_plus));
65 }
66
67 TEST(GaiaAuthUtilTest, CanonicalizeDomain) {
68   const char domain[] = "example.com";
69   EXPECT_EQ(domain, CanonicalizeDomain("example.com"));
70   EXPECT_EQ(domain, CanonicalizeDomain("EXAMPLE.cOm"));
71 }
72
73 TEST(GaiaAuthUtilTest, ExtractDomainName) {
74   const char domain[] = "example.com";
75   EXPECT_EQ(domain, ExtractDomainName("who@example.com"));
76   EXPECT_EQ(domain, ExtractDomainName("who@EXAMPLE.cOm"));
77 }
78
79 TEST(GaiaAuthUtilTest, SanitizeMissingDomain) {
80   EXPECT_EQ("nodomain@gmail.com", SanitizeEmail("nodomain"));
81 }
82
83 TEST(GaiaAuthUtilTest, SanitizeExistingDomain) {
84   const char existing[] = "test@example.com";
85   EXPECT_EQ(existing, SanitizeEmail(existing));
86 }
87
88 TEST(GaiaAuthUtilTest, AreEmailsSame) {
89   EXPECT_TRUE(AreEmailsSame("foo", "foo"));
90   EXPECT_TRUE(AreEmailsSame("foo", "foo@gmail.com"));
91   EXPECT_TRUE(AreEmailsSame("foo@gmail.com", "Foo@Gmail.com"));
92   EXPECT_FALSE(AreEmailsSame("foo@gmail.com", "foo@othermail.com"));
93   EXPECT_FALSE(AreEmailsSame("user@gmail.com", "foo@gmail.com"));
94 }
95
96 TEST(GaiaAuthUtilTest, IsGaiaSignonRealm) {
97   // Only https versions of Gaia URLs should be considered valid.
98   EXPECT_TRUE(IsGaiaSignonRealm(GURL("https://accounts.google.com/")));
99   EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://accounts.google.com/")));
100
101   // Other Google URLs are not valid.
102   EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/")));
103   EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/")));
104   EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/")));
105   EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/")));
106
107   // Other https URLs are not valid.
108   EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));
109 }
110
111 }  // namespace gaia