Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: google_apis/gaia/gaia_auth_util_unittest.cc

Issue 166433005: Add URL parameter so that /ListAccounts returns valid json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ListAccount strings in tests Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « google_apis/gaia/gaia_auth_util.cc ('k') | google_apis/gaia/gaia_urls.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gaia/gaia_auth_util.h" 5 #include "google_apis/gaia/gaia_auth_util.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h" 8 #include "url/gurl.h"
9 9
10 namespace gaia { 10 namespace gaia {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/"))); 102 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.google.com/")));
103 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/"))); 103 EXPECT_FALSE(IsGaiaSignonRealm(GURL("http://www.google.com/")));
104 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/"))); 104 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://google.com/")));
105 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/"))); 105 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://mail.google.com/")));
106 106
107 // Other https URLs are not valid. 107 // Other https URLs are not valid.
108 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/"))); 108 EXPECT_FALSE(IsGaiaSignonRealm(GURL("https://www.example.com/")));
109 } 109 }
110 110
111 TEST(GaiaAuthUtilTest, ParseListAccountsData) { 111 TEST(GaiaAuthUtilTest, ParseListAccountsData) {
112 std::vector<std::string> accounts; 112 std::vector<std::pair<std::string, bool> > accounts;
113 ASSERT_FALSE(ParseListAccountsData("", &accounts)); 113 ASSERT_FALSE(ParseListAccountsData("", &accounts));
114 ASSERT_EQ(0u, accounts.size()); 114 ASSERT_EQ(0u, accounts.size());
115 115
116 ASSERT_FALSE(ParseListAccountsData("1", &accounts)); 116 ASSERT_FALSE(ParseListAccountsData("1", &accounts));
117 ASSERT_EQ(0u, accounts.size()); 117 ASSERT_EQ(0u, accounts.size());
118 118
119 ASSERT_FALSE(ParseListAccountsData("[]", &accounts)); 119 ASSERT_FALSE(ParseListAccountsData("[]", &accounts));
120 ASSERT_EQ(0u, accounts.size()); 120 ASSERT_EQ(0u, accounts.size());
121 121
122 ASSERT_FALSE(ParseListAccountsData("[\"foo\", \"bar\"]", &accounts)); 122 ASSERT_FALSE(ParseListAccountsData("[\"foo\", \"bar\"]", &accounts));
123 ASSERT_EQ(0u, accounts.size()); 123 ASSERT_EQ(0u, accounts.size());
124 124
125 ASSERT_TRUE(ParseListAccountsData("[\"foo\", []]", &accounts)); 125 ASSERT_TRUE(ParseListAccountsData("[\"foo\", []]", &accounts));
126 ASSERT_EQ(0u, accounts.size()); 126 ASSERT_EQ(0u, accounts.size());
127 127
128 ASSERT_TRUE(ParseListAccountsData( 128 ASSERT_TRUE(ParseListAccountsData(
129 "[\"foo\", [[\"bar\", 0, \"name\", 0, \"photo\", 0, 0, 0]]]", &accounts)); 129 "[\"foo\", [[\"bar\", 0, \"name\", 0, \"photo\", 0, 0, 0]]]", &accounts));
130 ASSERT_EQ(0u, accounts.size()); 130 ASSERT_EQ(0u, accounts.size());
131 131
132 ASSERT_TRUE(ParseListAccountsData( 132 ASSERT_TRUE(ParseListAccountsData(
133 "[\"foo\", [[\"bar\", 0, \"name\", \"u@g.c\", \"photo\", 0, 0, 0]]]", 133 "[\"foo\", [[\"bar\", 0, \"name\", \"u@g.c\", \"photo\", 0, 0, 0]]]",
134 &accounts)); 134 &accounts));
135 ASSERT_EQ(1u, accounts.size()); 135 ASSERT_EQ(1u, accounts.size());
136 ASSERT_EQ("u@g.c", accounts[0]); 136 ASSERT_EQ("u@g.c", accounts[0].first);
137 ASSERT_TRUE(accounts[0].second);
137 138
138 ASSERT_TRUE(ParseListAccountsData( 139 ASSERT_TRUE(ParseListAccountsData(
139 "[\"foo\", [[\"bar1\", 0, \"name1\", \"u1@g.c\", \"photo1\", 0, 0, 0], " 140 "[\"foo\", [[\"bar1\", 0, \"name1\", \"u1@g.c\", \"photo1\", 0, 0, 0], "
140 "[\"bar2\", 0, \"name2\", \"u2@g.c\", \"photo2\", 0, 0, 0]]]", 141 "[\"bar2\", 0, \"name2\", \"u2@g.c\", \"photo2\", 0, 0, 0]]]",
141 &accounts)); 142 &accounts));
142 ASSERT_EQ(2u, accounts.size()); 143 ASSERT_EQ(2u, accounts.size());
143 ASSERT_EQ("u1@g.c", accounts[0]); 144 ASSERT_EQ("u1@g.c", accounts[0].first);
144 ASSERT_EQ("u2@g.c", accounts[1]); 145 ASSERT_TRUE(accounts[0].second);
146 ASSERT_EQ("u2@g.c", accounts[1].first);
147 ASSERT_TRUE(accounts[1].second);
145 148
146 ASSERT_TRUE(ParseListAccountsData( 149 ASSERT_TRUE(ParseListAccountsData(
147 "[\"foo\", [[\"b1\", 0, \"name1\", \"U1@g.c\", \"photo1\", 0, 0, 0], " 150 "[\"foo\", [[\"b1\", 0, \"name1\", \"U1@g.c\", \"photo1\", 0, 0, 0], "
148 "[\"b2\", 0, \"name2\", \"u.2@g.c\", \"photo2\", 0, 0, 0]]]", 151 "[\"b2\", 0, \"name2\", \"u.2@g.c\", \"photo2\", 0, 0, 0]]]",
149 &accounts)); 152 &accounts));
150 ASSERT_EQ(2u, accounts.size()); 153 ASSERT_EQ(2u, accounts.size());
151 ASSERT_EQ(CanonicalizeEmail("U1@g.c"), accounts[0]); 154 ASSERT_EQ(CanonicalizeEmail("U1@g.c"), accounts[0].first);
152 ASSERT_EQ(CanonicalizeEmail("u.2@g.c"), accounts[1]); 155 ASSERT_TRUE(accounts[0].second);
156 ASSERT_EQ(CanonicalizeEmail("u.2@g.c"), accounts[1].first);
157 ASSERT_TRUE(accounts[1].second);
158 }
159
160 TEST(GaiaAuthUtilTest, ParseListAccountsDataValidSession) {
161 std::vector<std::pair<std::string, bool> > accounts;
162
163 // Missing valid session means: return account.
164 ASSERT_TRUE(ParseListAccountsData(
165 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0]]]",
166 &accounts));
167 ASSERT_EQ(1u, accounts.size());
168 ASSERT_EQ("u@g.c", accounts[0].first);
169 ASSERT_TRUE(accounts[0].second);
170
171 // Valid session is true means: return account.
172 ASSERT_TRUE(ParseListAccountsData(
173 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0, 0, 1]]]",
174 &accounts));
175 ASSERT_EQ(1u, accounts.size());
176 ASSERT_EQ("u@g.c", accounts[0].first);
177 ASSERT_TRUE(accounts[0].second);
178
179 // Valid session is false means: return account with valid bit false.
180 ASSERT_TRUE(ParseListAccountsData(
181 "[\"foo\", [[\"b\", 0, \"n\", \"u@g.c\", \"p\", 0, 0, 0, 0, 0]]]",
182 &accounts));
183 ASSERT_EQ(1u, accounts.size());
184 ASSERT_FALSE(accounts[0].second);
153 } 185 }
154 186
155 } // namespace gaia 187 } // namespace gaia
OLDNEW
« no previous file with comments | « google_apis/gaia/gaia_auth_util.cc ('k') | google_apis/gaia/gaia_urls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698