OLD | NEW |
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 // A complete set of unit tests for OAuth2AccessTokenFetcher. | 5 // A complete set of unit tests for OAuth2AccessTokenFetcher. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 MessageLoop message_loop_; | 113 MessageLoop message_loop_; |
114 content::TestBrowserThread ui_thread_; | 114 content::TestBrowserThread ui_thread_; |
115 MockUrlFetcherFactory factory_; | 115 MockUrlFetcherFactory factory_; |
116 MockOAuth2AccessTokenConsumer consumer_; | 116 MockOAuth2AccessTokenConsumer consumer_; |
117 TestingProfile profile_; | 117 TestingProfile profile_; |
118 OAuth2AccessTokenFetcher fetcher_; | 118 OAuth2AccessTokenFetcher fetcher_; |
119 }; | 119 }; |
120 | 120 |
121 // These four tests time out, see http://crbug.com/113446. | 121 // These four tests time out, see http://crbug.com/113446. |
122 TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_GetAccessTokenRequestFailure) { | 122 TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_GetAccessTokenRequestFailure) { |
123 TestURLFetcher* url_fetcher = SetupGetAccessToken(false, 0, ""); | 123 TestURLFetcher* url_fetcher = SetupGetAccessToken(false, 0, std::string()); |
124 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); | 124 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); |
125 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); | 125 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); |
126 fetcher_.OnURLFetchComplete(url_fetcher); | 126 fetcher_.OnURLFetchComplete(url_fetcher); |
127 } | 127 } |
128 | 128 |
129 TEST_F(OAuth2AccessTokenFetcherTest, | 129 TEST_F(OAuth2AccessTokenFetcherTest, |
130 DISABLED_GetAccessTokenResponseCodeFailure) { | 130 DISABLED_GetAccessTokenResponseCodeFailure) { |
131 TestURLFetcher* url_fetcher = | 131 TestURLFetcher* url_fetcher = |
132 SetupGetAccessToken(true, net::HTTP_FORBIDDEN, ""); | 132 SetupGetAccessToken(true, net::HTTP_FORBIDDEN, std::string()); |
133 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); | 133 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); |
134 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); | 134 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); |
135 fetcher_.OnURLFetchComplete(url_fetcher); | 135 fetcher_.OnURLFetchComplete(url_fetcher); |
136 } | 136 } |
137 | 137 |
138 TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_Success) { | 138 TEST_F(OAuth2AccessTokenFetcherTest, DISABLED_Success) { |
139 TestURLFetcher* url_fetcher = SetupGetAccessToken( | 139 TestURLFetcher* url_fetcher = SetupGetAccessToken( |
140 true, net::HTTP_OK, kValidTokenResponse); | 140 true, net::HTTP_OK, kValidTokenResponse); |
141 EXPECT_CALL(consumer_, OnGetTokenSuccess("at1", _)).Times(1); | 141 EXPECT_CALL(consumer_, OnGetTokenSuccess("at1", _)).Times(1); |
142 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); | 142 fetcher_.Start("client_id", "client_secret", "refresh_token", ScopeList()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 url_fetcher.SetResponseString(kValidTokenResponse); | 226 url_fetcher.SetResponseString(kValidTokenResponse); |
227 | 227 |
228 std::string at; | 228 std::string at; |
229 int expires_in; | 229 int expires_in; |
230 EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( | 230 EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( |
231 &url_fetcher, &at, &expires_in)); | 231 &url_fetcher, &at, &expires_in)); |
232 EXPECT_EQ("at1", at); | 232 EXPECT_EQ("at1", at); |
233 EXPECT_EQ(3600, expires_in); | 233 EXPECT_EQ(3600, expires_in); |
234 } | 234 } |
235 } | 235 } |
OLD | NEW |