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 GaiaAuthFetcher. | 5 // A complete set of unit tests for GaiaAuthFetcher. |
6 // Originally ported from GoogleAuthenticator tests. | 6 // Originally ported from GoogleAuthenticator tests. |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
24 #include "net/url_request/url_request_status.h" | 24 #include "net/url_request/url_request_status.h" |
25 #include "net/url_request/url_request_test_util.h" | 25 #include "net/url_request/url_request_test_util.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 using ::testing::Invoke; | 30 using ::testing::Invoke; |
31 using ::testing::_; | 31 using ::testing::_; |
32 | 32 |
33 namespace { | 33 const char kGetAuthCodeValidCookie[] = |
34 static const char kGetAuthCodeValidCookie[] = | |
35 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; | 34 "oauth_code=test-code; Path=/test; Secure; HttpOnly"; |
36 static const char kGetAuthCodeCookieNoSecure[] = | 35 const char kGetAuthCodeCookieNoSecure[] = |
37 "oauth_code=test-code; Path=/test; HttpOnly"; | 36 "oauth_code=test-code; Path=/test; HttpOnly"; |
38 static const char kGetAuthCodeCookieNoHttpOnly[] = | 37 const char kGetAuthCodeCookieNoHttpOnly[] = |
39 "oauth_code=test-code; Path=/test; Secure"; | 38 "oauth_code=test-code; Path=/test; Secure"; |
40 static const char kGetAuthCodeCookieNoOAuthCode[] = | 39 const char kGetAuthCodeCookieNoOAuthCode[] = |
41 "Path=/test; Secure; HttpOnly"; | 40 "Path=/test; Secure; HttpOnly"; |
42 static const char kGetTokenPairValidResponse[] = | 41 const char kGetTokenPairValidResponse[] = |
43 "{" | 42 "{" |
44 " \"refresh_token\": \"rt1\"," | 43 " \"refresh_token\": \"rt1\"," |
45 " \"access_token\": \"at1\"," | 44 " \"access_token\": \"at1\"," |
46 " \"expires_in\": 3600," | 45 " \"expires_in\": 3600," |
47 " \"token_type\": \"Bearer\"" | 46 " \"token_type\": \"Bearer\"" |
48 "}"; | 47 "}"; |
49 static const char kClientOAuthValidResponse[] = | |
50 "{" | |
51 " \"oauth2\": {" | |
52 " \"refresh_token\": \"rt1\"," | |
53 " \"access_token\": \"at1\"," | |
54 " \"expires_in\": 3600," | |
55 " \"token_type\": \"Bearer\"" | |
56 " }" | |
57 "}"; | |
58 | |
59 } // namespace | |
60 | 48 |
61 MockFetcher::MockFetcher(bool success, | 49 MockFetcher::MockFetcher(bool success, |
62 const GURL& url, | 50 const GURL& url, |
63 const std::string& results, | 51 const std::string& results, |
64 net::URLFetcher::RequestType request_type, | 52 net::URLFetcher::RequestType request_type, |
65 net::URLFetcherDelegate* d) | 53 net::URLFetcherDelegate* d) |
66 : TestURLFetcher(0, url, d) { | 54 : TestURLFetcher(0, url, d) { |
67 set_url(url); | 55 set_url(url); |
68 net::URLRequestStatus::Status code; | 56 net::URLRequestStatus::Status code; |
69 | 57 |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) | 782 EXPECT_CALL(consumer, OnClientLoginSuccess(result)) |
795 .Times(1); | 783 .Times(1); |
796 | 784 |
797 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 785 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
798 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 786 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
799 MockFetcher mock_fetcher( | 787 MockFetcher mock_fetcher( |
800 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, | 788 oauth_login_gurl_, status, net::HTTP_OK, cookies_, data, |
801 net::URLFetcher::GET, &auth); | 789 net::URLFetcher::GET, &auth); |
802 auth.OnURLFetchComplete(&mock_fetcher); | 790 auth.OnURLFetchComplete(&mock_fetcher); |
803 } | 791 } |
OLD | NEW |