| 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 GaiaOAuthClient. | 5 // A complete set of unit tests for GaiaOAuthClient. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 net::URLFetcherDelegate* d) | 41 net::URLFetcherDelegate* d) |
| 42 : net::TestURLFetcher(0, url, d), | 42 : net::TestURLFetcher(0, url, d), |
| 43 max_failure_count_(max_failure_count), | 43 max_failure_count_(max_failure_count), |
| 44 current_failure_count_(0), | 44 current_failure_count_(0), |
| 45 complete_immediately_(complete_immediately) { | 45 complete_immediately_(complete_immediately) { |
| 46 set_url(url); | 46 set_url(url); |
| 47 set_response_code(response_code); | 47 set_response_code(response_code); |
| 48 SetResponseString(results); | 48 SetResponseString(results); |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual ~MockOAuthFetcher() { } | 51 ~MockOAuthFetcher() override {} |
| 52 | 52 |
| 53 virtual void Start() override { | 53 void Start() override { |
| 54 if ((GetResponseCode() != net::HTTP_OK) && (max_failure_count_ != -1) && | 54 if ((GetResponseCode() != net::HTTP_OK) && (max_failure_count_ != -1) && |
| 55 (current_failure_count_ == max_failure_count_)) { | 55 (current_failure_count_ == max_failure_count_)) { |
| 56 set_response_code(net::HTTP_OK); | 56 set_response_code(net::HTTP_OK); |
| 57 } | 57 } |
| 58 | 58 |
| 59 net::URLRequestStatus::Status code = net::URLRequestStatus::SUCCESS; | 59 net::URLRequestStatus::Status code = net::URLRequestStatus::SUCCESS; |
| 60 if (GetResponseCode() != net::HTTP_OK) { | 60 if (GetResponseCode() != net::HTTP_OK) { |
| 61 code = net::URLRequestStatus::FAILED; | 61 code = net::URLRequestStatus::FAILED; |
| 62 current_failure_count_++; | 62 current_failure_count_++; |
| 63 } | 63 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class MockOAuthFetcherFactory : public net::URLFetcherFactory, | 82 class MockOAuthFetcherFactory : public net::URLFetcherFactory, |
| 83 public net::ScopedURLFetcherFactory { | 83 public net::ScopedURLFetcherFactory { |
| 84 public: | 84 public: |
| 85 MockOAuthFetcherFactory() | 85 MockOAuthFetcherFactory() |
| 86 : net::ScopedURLFetcherFactory(this), | 86 : net::ScopedURLFetcherFactory(this), |
| 87 response_code_(net::HTTP_OK), | 87 response_code_(net::HTTP_OK), |
| 88 complete_immediately_(true) { | 88 complete_immediately_(true) { |
| 89 } | 89 } |
| 90 virtual ~MockOAuthFetcherFactory() {} | 90 ~MockOAuthFetcherFactory() override {} |
| 91 virtual net::URLFetcher* CreateURLFetcher( | 91 net::URLFetcher* CreateURLFetcher(int id, |
| 92 int id, | 92 const GURL& url, |
| 93 const GURL& url, | 93 net::URLFetcher::RequestType request_type, |
| 94 net::URLFetcher::RequestType request_type, | 94 net::URLFetcherDelegate* d) override { |
| 95 net::URLFetcherDelegate* d) override { | |
| 96 url_fetcher_ = new MockOAuthFetcher( | 95 url_fetcher_ = new MockOAuthFetcher( |
| 97 response_code_, | 96 response_code_, |
| 98 max_failure_count_, | 97 max_failure_count_, |
| 99 complete_immediately_, | 98 complete_immediately_, |
| 100 url, | 99 url, |
| 101 results_, | 100 results_, |
| 102 request_type, | 101 request_type, |
| 103 d); | 102 d); |
| 104 return url_fetcher_; | 103 return url_fetcher_; |
| 105 } | 104 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 382 |
| 384 GaiaOAuthClient auth(GetRequestContext()); | 383 GaiaOAuthClient auth(GetRequestContext()); |
| 385 auth.GetTokenInfo("access_token", 1, &delegate); | 384 auth.GetTokenInfo("access_token", 1, &delegate); |
| 386 | 385 |
| 387 std::string issued_to; | 386 std::string issued_to; |
| 388 ASSERT_TRUE(captured_result->GetString("issued_to", &issued_to)); | 387 ASSERT_TRUE(captured_result->GetString("issued_to", &issued_to)); |
| 389 ASSERT_EQ("1234567890.apps.googleusercontent.com", issued_to); | 388 ASSERT_EQ("1234567890.apps.googleusercontent.com", issued_to); |
| 390 } | 389 } |
| 391 | 390 |
| 392 } // namespace gaia | 391 } // namespace gaia |
| OLD | NEW |