OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" | 8 #include "chrome/browser/managed_mode/managed_user_refresh_token_fetcher.h" |
9 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 9 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 " \"code\": \"%s\"" | 36 " \"code\": \"%s\"" |
37 "}"; | 37 "}"; |
38 | 38 |
39 const char kGetRefreshTokenResponseFormat[] = | 39 const char kGetRefreshTokenResponseFormat[] = |
40 "{" | 40 "{" |
41 " \"access_token\": \"<ignored>\"," | 41 " \"access_token\": \"<ignored>\"," |
42 " \"expires_in\": 12345," | 42 " \"expires_in\": 12345," |
43 " \"refresh_token\": \"%s\"" | 43 " \"refresh_token\": \"%s\"" |
44 "}"; | 44 "}"; |
45 | 45 |
46 const char kAccountId[] = "account_id"; | |
Bernhard Bauer
2013/09/03 21:18:38
Can you move this up to the first block of constan
fgorski
2013/09/03 22:03:05
Done.
| |
47 | |
46 // Utility methods -------------------------------------------------- | 48 // Utility methods -------------------------------------------------- |
47 | 49 |
48 // Slightly hacky way to extract a value from a URL-encoded POST request body. | 50 // Slightly hacky way to extract a value from a URL-encoded POST request body. |
49 bool GetValueForKey(const std::string& encoded_string, | 51 bool GetValueForKey(const std::string& encoded_string, |
50 const std::string& key, | 52 const std::string& key, |
51 std::string* value) { | 53 std::string* value) { |
52 GURL url("http://example.com/?" + encoded_string); | 54 GURL url("http://example.com/?" + encoded_string); |
53 return net::GetValueForKeyInQuery(url, key, value); | 55 return net::GetValueForKeyInQuery(url, key, value); |
54 } | 56 } |
55 | 57 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 const GoogleServiceAuthError& error() const { return error_; } | 107 const GoogleServiceAuthError& error() const { return error_; } |
106 const std::string& token() const { return token_; } | 108 const std::string& token() const { return token_; } |
107 | 109 |
108 private: | 110 private: |
109 void OnTokenFetched(const GoogleServiceAuthError& error, | 111 void OnTokenFetched(const GoogleServiceAuthError& error, |
110 const std::string& token); | 112 const std::string& token); |
111 | 113 |
112 content::TestBrowserThreadBundle thread_bundle_; | 114 content::TestBrowserThreadBundle thread_bundle_; |
113 TestingProfile profile_; | 115 TestingProfile profile_; |
114 FakeProfileOAuth2TokenService oauth2_token_service_; | 116 FakeProfileOAuth2TokenService oauth2_token_service_; |
117 std::string account_id_; | |
115 net::TestURLFetcherFactory url_fetcher_factory_; | 118 net::TestURLFetcherFactory url_fetcher_factory_; |
116 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; | 119 scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher_; |
117 | 120 |
118 GoogleServiceAuthError error_; | 121 GoogleServiceAuthError error_; |
119 std::string token_; | 122 std::string token_; |
120 base::WeakPtrFactory<ManagedUserRefreshTokenFetcherTest> weak_ptr_factory_; | 123 base::WeakPtrFactory<ManagedUserRefreshTokenFetcherTest> weak_ptr_factory_; |
121 }; | 124 }; |
122 | 125 |
123 ManagedUserRefreshTokenFetcherTest::ManagedUserRefreshTokenFetcherTest() | 126 ManagedUserRefreshTokenFetcherTest::ManagedUserRefreshTokenFetcherTest() |
124 : token_fetcher_( | 127 : account_id_(kAccountId), |
128 token_fetcher_( | |
125 ManagedUserRefreshTokenFetcher::Create(&oauth2_token_service_, | 129 ManagedUserRefreshTokenFetcher::Create(&oauth2_token_service_, |
126 profile_.GetRequestContext())), | 130 account_id_, |
Bernhard Bauer
2013/09/03 21:18:38
If we don't care about the account ID otherwise, y
fgorski
2013/09/03 22:03:05
Done.
| |
131 profile_.GetRequestContext())), | |
127 error_(GoogleServiceAuthError::NONE), | 132 error_(GoogleServiceAuthError::NONE), |
128 weak_ptr_factory_(this) {} | 133 weak_ptr_factory_(this) {} |
129 | 134 |
130 void ManagedUserRefreshTokenFetcherTest::StartFetching() { | 135 void ManagedUserRefreshTokenFetcherTest::StartFetching() { |
131 oauth2_token_service_.IssueRefreshToken(kOAuth2RefreshToken); | 136 oauth2_token_service_.IssueRefreshToken(kOAuth2RefreshToken); |
132 token_fetcher_->Start(kManagedUserId, kDeviceName, | 137 token_fetcher_->Start(kManagedUserId, kDeviceName, |
133 base::Bind( | 138 base::Bind( |
134 &ManagedUserRefreshTokenFetcherTest::OnTokenFetched, | 139 &ManagedUserRefreshTokenFetcherTest::OnTokenFetched, |
135 weak_ptr_factory_.GetWeakPtr())); | 140 weak_ptr_factory_.GetWeakPtr())); |
136 } | 141 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 | 347 |
343 TEST_F(ManagedUserRefreshTokenFetcherTest, CancelWhileFetchingRefreshToken) { | 348 TEST_F(ManagedUserRefreshTokenFetcherTest, CancelWhileFetchingRefreshToken) { |
344 StartFetching(); | 349 StartFetching(); |
345 MakeOAuth2TokenServiceRequestSucceed(); | 350 MakeOAuth2TokenServiceRequestSucceed(); |
346 MakeIssueTokenRequestSucceed(); | 351 MakeIssueTokenRequestSucceed(); |
347 Reset(); | 352 Reset(); |
348 | 353 |
349 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); | 354 EXPECT_EQ(GoogleServiceAuthError::NONE, error().state()); |
350 EXPECT_EQ(std::string(), token()); | 355 EXPECT_EQ(std::string(), token()); |
351 } | 356 } |
OLD | NEW |