| 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 OAuth2MintTokenFlow. | 5 // A complete set of unit tests for OAuth2MintTokenFlow. | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 #include <vector> | 8 #include <vector> | 
| 9 | 9 | 
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" | 
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" | 
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" | 
| 13 #include "google_apis/gaia/gaia_urls.h" | 13 #include "google_apis/gaia/gaia_urls.h" | 
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 14 #include "google_apis/gaia/google_service_auth_error.h" | 
| 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 15 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 
| 16 #include "google_apis/gaia/oauth2_access_token_fetcher.h" | 16 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h" | 
| 17 #include "google_apis/gaia/oauth2_api_call_flow.h" | 17 #include "google_apis/gaia/oauth2_api_call_flow.h" | 
| 18 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" | 
| 19 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" | 
| 20 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" | 
| 21 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" | 
| 22 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" | 
| 23 #include "net/url_request/url_fetcher_factory.h" | 23 #include "net/url_request/url_fetcher_factory.h" | 
| 24 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" | 
| 25 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" | 
| 26 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 63   virtual ~MockUrlFetcherFactory() {} | 63   virtual ~MockUrlFetcherFactory() {} | 
| 64 | 64 | 
| 65   MOCK_METHOD4( | 65   MOCK_METHOD4( | 
| 66       CreateURLFetcher, | 66       CreateURLFetcher, | 
| 67       URLFetcher* (int id, | 67       URLFetcher* (int id, | 
| 68                    const GURL& url, | 68                    const GURL& url, | 
| 69                    URLFetcher::RequestType request_type, | 69                    URLFetcher::RequestType request_type, | 
| 70                    URLFetcherDelegate* d)); | 70                    URLFetcherDelegate* d)); | 
| 71 }; | 71 }; | 
| 72 | 72 | 
| 73 class MockAccessTokenFetcher : public OAuth2AccessTokenFetcher { | 73 class MockAccessTokenFetcher : public OAuth2AccessTokenFetcherImpl { | 
| 74  public: | 74  public: | 
| 75   MockAccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, | 75   MockAccessTokenFetcher(OAuth2AccessTokenConsumer* consumer, | 
| 76                          net::URLRequestContextGetter* getter) | 76                          net::URLRequestContextGetter* getter) | 
| 77       : OAuth2AccessTokenFetcher(consumer, getter) {} | 77       : OAuth2AccessTokenFetcherImpl(consumer, getter) {} | 
| 78   ~MockAccessTokenFetcher() {} | 78   ~MockAccessTokenFetcher() {} | 
| 79 | 79 | 
| 80   MOCK_METHOD4(Start, | 80   MOCK_METHOD4(Start, | 
| 81                void (const std::string& client_id, | 81                void (const std::string& client_id, | 
| 82                      const std::string& client_secret, | 82                      const std::string& client_secret, | 
| 83                      const std::string& refresh_token, | 83                      const std::string& refresh_token, | 
| 84                      const std::vector<std::string>& scopes)); | 84                      const std::vector<std::string>& scopes)); | 
| 85 }; | 85 }; | 
| 86 | 86 | 
| 87 class MockApiCallFlow : public OAuth2ApiCallFlow { | 87 class MockApiCallFlow : public OAuth2ApiCallFlow { | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 289   scoped_ptr<TestURLFetcher> url_fetcher(SetupApiCall(true, net::HTTP_OK)); | 289   scoped_ptr<TestURLFetcher> url_fetcher(SetupApiCall(true, net::HTTP_OK)); | 
| 290   flow_->CreateURLFetcher(); | 290   flow_->CreateURLFetcher(); | 
| 291   HttpRequestHeaders headers; | 291   HttpRequestHeaders headers; | 
| 292   url_fetcher->GetExtraRequestHeaders(&headers); | 292   url_fetcher->GetExtraRequestHeaders(&headers); | 
| 293   std::string auth_header; | 293   std::string auth_header; | 
| 294   EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); | 294   EXPECT_TRUE(headers.GetHeader("Authorization", &auth_header)); | 
| 295   EXPECT_EQ("Bearer access_token", auth_header); | 295   EXPECT_EQ("Bearer access_token", auth_header); | 
| 296   EXPECT_EQ(url, url_fetcher->GetOriginalURL()); | 296   EXPECT_EQ(url, url_fetcher->GetOriginalURL()); | 
| 297   EXPECT_EQ(body, url_fetcher->upload_data()); | 297   EXPECT_EQ(body, url_fetcher->upload_data()); | 
| 298 } | 298 } | 
| OLD | NEW | 
|---|