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 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 "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" | 8 #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 15 matching lines...) Expand all Loading... |
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 | 28 |
29 using ::testing::_; | 29 using ::testing::_; |
30 | 30 |
31 MockFetcher::MockFetcher(bool success, | 31 MockFetcher::MockFetcher(bool success, |
32 const GURL& url, | 32 const GURL& url, |
33 const std::string& results, | 33 const std::string& results, |
34 content::URLFetcher::RequestType request_type, | 34 content::URLFetcher::RequestType request_type, |
35 content::URLFetcherDelegate* d) | 35 content::URLFetcherDelegate* d) |
36 : TestURLFetcher(0, url, request_type, d) { | 36 : TestURLFetcher(0, url, d) { |
37 set_url(url); | 37 set_url(url); |
38 net::URLRequestStatus::Status code; | 38 net::URLRequestStatus::Status code; |
39 | 39 |
40 if (success) { | 40 if (success) { |
41 set_response_code(RC_REQUEST_OK); | 41 set_response_code(RC_REQUEST_OK); |
42 code = net::URLRequestStatus::SUCCESS; | 42 code = net::URLRequestStatus::SUCCESS; |
43 } else { | 43 } else { |
44 set_response_code(RC_FORBIDDEN); | 44 set_response_code(RC_FORBIDDEN); |
45 code = net::URLRequestStatus::FAILED; | 45 code = net::URLRequestStatus::FAILED; |
46 } | 46 } |
47 | 47 |
48 set_status(net::URLRequestStatus(code, 0)); | 48 set_status(net::URLRequestStatus(code, 0)); |
49 SetResponseString(results); | 49 SetResponseString(results); |
50 } | 50 } |
51 | 51 |
52 MockFetcher::MockFetcher(const GURL& url, | 52 MockFetcher::MockFetcher(const GURL& url, |
53 const net::URLRequestStatus& status, | 53 const net::URLRequestStatus& status, |
54 int response_code, | 54 int response_code, |
55 const net::ResponseCookies& cookies, | 55 const net::ResponseCookies& cookies, |
56 const std::string& results, | 56 const std::string& results, |
57 content::URLFetcher::RequestType request_type, | 57 content::URLFetcher::RequestType request_type, |
58 content::URLFetcherDelegate* d) | 58 content::URLFetcherDelegate* d) |
59 : TestURLFetcher(0, url, request_type, d) { | 59 : TestURLFetcher(0, url, d) { |
60 set_url(url); | 60 set_url(url); |
61 set_status(status); | 61 set_status(status); |
62 set_response_code(response_code); | 62 set_response_code(response_code); |
63 set_cookies(cookies); | 63 set_cookies(cookies); |
64 SetResponseString(results); | 64 SetResponseString(results); |
65 } | 65 } |
66 | 66 |
67 MockFetcher::~MockFetcher() {} | 67 MockFetcher::~MockFetcher() {} |
68 | 68 |
69 void MockFetcher::Start() { | 69 void MockFetcher::Start() { |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 test_fetcher->set_url(final_url); | 632 test_fetcher->set_url(final_url); |
633 test_fetcher->set_status( | 633 test_fetcher->set_status( |
634 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); | 634 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, 0)); |
635 test_fetcher->set_response_code(RC_REQUEST_OK); | 635 test_fetcher->set_response_code(RC_REQUEST_OK); |
636 test_fetcher->set_cookies(cookies_); | 636 test_fetcher->set_cookies(cookies_); |
637 test_fetcher->SetResponseString("<html></html>"); | 637 test_fetcher->SetResponseString("<html></html>"); |
638 | 638 |
639 auth.OnURLFetchComplete(test_fetcher); | 639 auth.OnURLFetchComplete(test_fetcher); |
640 EXPECT_FALSE(auth.HasPendingFetch()); | 640 EXPECT_FALSE(auth.HasPendingFetch()); |
641 } | 641 } |
OLD | NEW |