| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 fetcher_.OnURLFetchComplete(url_fetcher); | 118 fetcher_.OnURLFetchComplete(url_fetcher); |
| 119 } | 119 } |
| 120 | 120 |
| 121 TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenResponseCodeFailure) { | 121 TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenResponseCodeFailure) { |
| 122 TestURLFetcher* url_fetcher = SetupGetAccessToken(true, RC_FORBIDDEN, ""); | 122 TestURLFetcher* url_fetcher = SetupGetAccessToken(true, RC_FORBIDDEN, ""); |
| 123 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); | 123 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); |
| 124 fetcher_.Start("refresh_token"); | 124 fetcher_.Start("refresh_token"); |
| 125 fetcher_.OnURLFetchComplete(url_fetcher); | 125 fetcher_.OnURLFetchComplete(url_fetcher); |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST_F(OAuth2AccessTokenFetcherTest, GetAccessTokenResponseNoAccessToken) { | |
| 129 TestURLFetcher* url_fetcher = SetupGetAccessToken( | |
| 130 true, RC_REQUEST_OK, kTokenResponseNoAccessToken); | |
| 131 EXPECT_CALL(consumer_, OnGetTokenFailure(_)).Times(1); | |
| 132 fetcher_.Start("refresh_token"); | |
| 133 fetcher_.OnURLFetchComplete(url_fetcher); | |
| 134 } | |
| 135 | |
| 136 TEST_F(OAuth2AccessTokenFetcherTest, Success) { | 128 TEST_F(OAuth2AccessTokenFetcherTest, Success) { |
| 137 TestURLFetcher* url_fetcher = SetupGetAccessToken( | 129 TestURLFetcher* url_fetcher = SetupGetAccessToken( |
| 138 true, RC_REQUEST_OK, kValidTokenResponse); | 130 true, RC_REQUEST_OK, kValidTokenResponse); |
| 139 EXPECT_CALL(consumer_, OnGetTokenSuccess("at1")).Times(1); | 131 EXPECT_CALL(consumer_, OnGetTokenSuccess("at1")).Times(1); |
| 140 fetcher_.Start("refresh_token"); | 132 fetcher_.Start("refresh_token"); |
| 141 fetcher_.OnURLFetchComplete(url_fetcher); | 133 fetcher_.OnURLFetchComplete(url_fetcher); |
| 142 } | 134 } |
| 143 | 135 |
| 144 TEST_F(OAuth2AccessTokenFetcherTest, ParseGetAccessTokenResponse) { | 136 TEST_F(OAuth2AccessTokenFetcherTest, ParseGetAccessTokenResponse) { |
| 145 { // No body. | 137 { // No body. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 { // Valid json: all good. | 163 { // Valid json: all good. |
| 172 TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); | 164 TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); |
| 173 url_fetcher.SetResponseString(kValidTokenResponse); | 165 url_fetcher.SetResponseString(kValidTokenResponse); |
| 174 | 166 |
| 175 std::string at; | 167 std::string at; |
| 176 EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( | 168 EXPECT_TRUE(OAuth2AccessTokenFetcher::ParseGetAccessTokenResponse( |
| 177 &url_fetcher, &at)); | 169 &url_fetcher, &at)); |
| 178 EXPECT_EQ("at1", at); | 170 EXPECT_EQ("at1", at); |
| 179 } | 171 } |
| 180 } | 172 } |
| OLD | NEW |