OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/profile_auth_data.h" | 5 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "net/url_request/url_request_context.h" | 31 #include "net/url_request/url_request_context.h" |
32 #include "net/url_request/url_request_context_getter.h" | 32 #include "net/url_request/url_request_context_getter.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
34 #include "url/gurl.h" | 34 #include "url/gurl.h" |
35 | 35 |
36 namespace chromeos { | 36 namespace chromeos { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kProxyAuthURL[] = "http://example.com/"; | 40 const char kProxyAuthURL[] = "http://example.com/"; |
| 41 const char kProxyAuthScheme[] = "basic"; |
41 const char kProxyAuthRealm[] = "realm"; | 42 const char kProxyAuthRealm[] = "realm"; |
42 const char kProxyAuthChallenge[] = "challenge"; | 43 const char kProxyAuthChallenge[] = "challenge"; |
43 const char kProxyAuthPassword1[] = "password 1"; | 44 const char kProxyAuthPassword1[] = "password 1"; |
44 const char kProxyAuthPassword2[] = "password 2"; | 45 const char kProxyAuthPassword2[] = "password 2"; |
45 | 46 |
46 const char kGAIACookieURL[] = "http://google.com/"; | 47 const char kGAIACookieURL[] = "http://google.com/"; |
47 const char kSAMLIdPCookieURL[] = "http://example.com/"; | 48 const char kSAMLIdPCookieURL[] = "http://example.com/"; |
48 const char kCookieName[] = "cookie"; | 49 const char kCookieName[] = "cookie"; |
49 const char kCookieValue1[] = "value 1"; | 50 const char kCookieValue1[] = "value 1"; |
50 const char kCookieValue2[] = "value 2"; | 51 const char kCookieValue2[] = "value 2"; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 run_loop_.reset(new base::RunLoop); | 154 run_loop_.reset(new base::RunLoop); |
154 GetChannelIDs(&user_browser_context_)->GetAllChannelIDs(base::Bind( | 155 GetChannelIDs(&user_browser_context_)->GetAllChannelIDs(base::Bind( |
155 &ProfileAuthDataTest::StoreChannelIDListAndQuitLoop, | 156 &ProfileAuthDataTest::StoreChannelIDListAndQuitLoop, |
156 base::Unretained(this))); | 157 base::Unretained(this))); |
157 run_loop_->Run(); | 158 run_loop_->Run(); |
158 return user_channel_id_list_; | 159 return user_channel_id_list_; |
159 } | 160 } |
160 | 161 |
161 void ProfileAuthDataTest::VerifyTransferredUserProxyAuthEntry() { | 162 void ProfileAuthDataTest::VerifyTransferredUserProxyAuthEntry() { |
162 net::HttpAuthCache::Entry* entry = | 163 net::HttpAuthCache::Entry* entry = |
163 GetProxyAuth(&user_browser_context_)->Lookup( | 164 GetProxyAuth(&user_browser_context_) |
164 GURL(kProxyAuthURL), | 165 ->Lookup(GURL(kProxyAuthURL), kProxyAuthRealm, kProxyAuthScheme); |
165 kProxyAuthRealm, | |
166 net::HttpAuth::AUTH_SCHEME_BASIC); | |
167 ASSERT_TRUE(entry); | 166 ASSERT_TRUE(entry); |
168 EXPECT_EQ(base::ASCIIToUTF16(kProxyAuthPassword1), | 167 EXPECT_EQ(base::ASCIIToUTF16(kProxyAuthPassword1), |
169 entry->credentials().password()); | 168 entry->credentials().password()); |
170 } | 169 } |
171 | 170 |
172 void ProfileAuthDataTest::VerifyUserCookies( | 171 void ProfileAuthDataTest::VerifyUserCookies( |
173 const std::string& expected_gaia_cookie_value, | 172 const std::string& expected_gaia_cookie_value, |
174 const std::string& expected_saml_idp_cookie_value) { | 173 const std::string& expected_saml_idp_cookie_value) { |
175 net::CookieList user_cookies = GetUserCookies(); | 174 net::CookieList user_cookies = GetUserCookies(); |
176 ASSERT_EQ(2u, user_cookies.size()); | 175 ASSERT_EQ(2u, user_cookies.size()); |
(...skipping 16 matching lines...) Expand all Loading... |
193 net::ChannelIDStore::ChannelID* channel_id = &user_channel_ids.front(); | 192 net::ChannelIDStore::ChannelID* channel_id = &user_channel_ids.front(); |
194 EXPECT_EQ(kChannelIDServerIdentifier, channel_id->server_identifier()); | 193 EXPECT_EQ(kChannelIDServerIdentifier, channel_id->server_identifier()); |
195 EXPECT_TRUE(net::KeysEqual(expected_key, channel_id->key())); | 194 EXPECT_TRUE(net::KeysEqual(expected_key, channel_id->key())); |
196 } | 195 } |
197 | 196 |
198 void ProfileAuthDataTest::PopulateBrowserContext( | 197 void ProfileAuthDataTest::PopulateBrowserContext( |
199 content::BrowserContext* browser_context, | 198 content::BrowserContext* browser_context, |
200 const std::string& proxy_auth_password, | 199 const std::string& proxy_auth_password, |
201 const std::string& cookie_value, | 200 const std::string& cookie_value, |
202 scoped_ptr<crypto::ECPrivateKey> channel_id_key) { | 201 scoped_ptr<crypto::ECPrivateKey> channel_id_key) { |
203 GetProxyAuth(browser_context)->Add( | 202 GetProxyAuth(browser_context) |
204 GURL(kProxyAuthURL), | 203 ->Add(GURL(kProxyAuthURL), kProxyAuthRealm, kProxyAuthScheme, |
205 kProxyAuthRealm, | 204 kProxyAuthChallenge, |
206 net::HttpAuth::AUTH_SCHEME_BASIC, | 205 net::AuthCredentials(base::string16(), |
207 kProxyAuthChallenge, | 206 base::ASCIIToUTF16(proxy_auth_password)), |
208 net::AuthCredentials(base::string16(), | 207 std::string()); |
209 base::ASCIIToUTF16(proxy_auth_password)), | |
210 std::string()); | |
211 | 208 |
212 net::CookieMonster* cookies = GetCookies(browser_context); | 209 net::CookieMonster* cookies = GetCookies(browser_context); |
213 // Ensure |cookies| is fully initialized. | 210 // Ensure |cookies| is fully initialized. |
214 run_loop_.reset(new base::RunLoop); | 211 run_loop_.reset(new base::RunLoop); |
215 cookies->GetAllCookiesAsync(base::Bind(&ProfileAuthDataTest::QuitLoop, | 212 cookies->GetAllCookiesAsync(base::Bind(&ProfileAuthDataTest::QuitLoop, |
216 base::Unretained(this))); | 213 base::Unretained(this))); |
217 run_loop_->Run(); | 214 run_loop_->Run(); |
218 | 215 |
219 net::CookieList cookie_list; | 216 net::CookieList cookie_list; |
220 cookie_list.push_back(net::CanonicalCookie( | 217 cookie_list.push_back(net::CanonicalCookie( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 PopulateUserBrowserContext(); | 308 PopulateUserBrowserContext(); |
312 | 309 |
313 Transfer(false, true); | 310 Transfer(false, true); |
314 | 311 |
315 VerifyTransferredUserProxyAuthEntry(); | 312 VerifyTransferredUserProxyAuthEntry(); |
316 VerifyUserCookies(kCookieValue2, kCookieValue1); | 313 VerifyUserCookies(kCookieValue2, kCookieValue1); |
317 VerifyUserChannelID(channel_id_key2_.get()); | 314 VerifyUserChannelID(channel_id_key2_.get()); |
318 } | 315 } |
319 | 316 |
320 } // namespace chromeos | 317 } // namespace chromeos |
OLD | NEW |