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 OAuth2MintTokenFetcher. | 5 // A complete set of unit tests for OAuth2MintTokenFetcher. |
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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::URLFetcher; | 30 using content::URLFetcher; |
31 using content::URLFetcherDelegate; | 31 using content::URLFetcherDelegate; |
32 using content::URLFetcherFactory; | 32 using content::URLFetcherFactory; |
33 using net::ResponseCookies; | 33 using net::ResponseCookies; |
34 using net::URLRequestStatus; | 34 using net::URLRequestStatus; |
35 using testing::_; | 35 using testing::_; |
36 using testing::Return; | 36 using testing::Return; |
37 | 37 |
38 namespace { | 38 namespace { |
| 39 |
39 static const char kValidTokenResponse[] = | 40 static const char kValidTokenResponse[] = |
40 "{" | 41 "{" |
41 " \"token\": \"at1\"," | 42 " \"token\": \"at1\"," |
42 " \"issueAdvice\": \"Auto\"" | 43 " \"issueAdvice\": \"Auto\"" |
43 "}"; | 44 "}"; |
44 static const char kTokenResponseNoAccessToken[] = | 45 static const char kTokenResponseNoAccessToken[] = |
45 "{" | 46 "{" |
46 " \"issueAdvice\": \"Auto\"" | 47 " \"issueAdvice\": \"Auto\"" |
47 "}"; | 48 "}"; |
48 } | |
49 | 49 |
50 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, | 50 class MockUrlFetcherFactory : public ScopedURLFetcherFactory, |
51 public URLFetcherFactory { | 51 public URLFetcherFactory { |
52 public: | 52 public: |
53 MockUrlFetcherFactory() | 53 MockUrlFetcherFactory() |
54 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 54 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
55 } | 55 } |
56 virtual ~MockUrlFetcherFactory() {} | 56 virtual ~MockUrlFetcherFactory() {} |
57 | 57 |
58 MOCK_METHOD4( | 58 MOCK_METHOD4( |
59 CreateURLFetcher, | 59 CreateURLFetcher, |
60 URLFetcher* (int id, | 60 URLFetcher* (int id, |
61 const GURL& url, | 61 const GURL& url, |
62 URLFetcher::RequestType request_type, | 62 URLFetcher::RequestType request_type, |
63 URLFetcherDelegate* d)); | 63 URLFetcherDelegate* d)); |
64 }; | 64 }; |
65 | 65 |
66 class MockOAuth2MintTokenConsumer : public OAuth2MintTokenConsumer { | 66 class MockOAuth2MintTokenConsumer : public OAuth2MintTokenConsumer { |
67 public: | 67 public: |
68 MockOAuth2MintTokenConsumer() {} | 68 MockOAuth2MintTokenConsumer() {} |
69 ~MockOAuth2MintTokenConsumer() {} | 69 ~MockOAuth2MintTokenConsumer() {} |
70 | 70 |
71 MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); | 71 MOCK_METHOD1(OnMintTokenSuccess, void(const std::string& access_token)); |
72 MOCK_METHOD1(OnMintTokenFailure, | 72 MOCK_METHOD1(OnMintTokenFailure, |
73 void(const GoogleServiceAuthError& error)); | 73 void(const GoogleServiceAuthError& error)); |
74 }; | 74 }; |
75 | 75 |
| 76 } // namespace |
| 77 |
76 class OAuth2MintTokenFetcherTest : public testing::Test { | 78 class OAuth2MintTokenFetcherTest : public testing::Test { |
77 public: | 79 public: |
78 OAuth2MintTokenFetcherTest() | 80 OAuth2MintTokenFetcherTest() |
79 : ui_thread_(BrowserThread::UI, &message_loop_), | 81 : ui_thread_(BrowserThread::UI, &message_loop_), |
80 fetcher_(&consumer_, profile_.GetRequestContext(), "test") { | 82 fetcher_(&consumer_, profile_.GetRequestContext(), "test") { |
81 test_scopes_.push_back("scope1"); | 83 test_scopes_.push_back("scope1"); |
82 test_scopes_.push_back("scope1"); | 84 test_scopes_.push_back("scope1"); |
83 } | 85 } |
84 | 86 |
85 virtual ~OAuth2MintTokenFetcherTest() { } | 87 virtual ~OAuth2MintTokenFetcherTest() { } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 { // Valid json: all good. | 168 { // Valid json: all good. |
167 TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); | 169 TestURLFetcher url_fetcher(0, GURL("www.google.com"), NULL); |
168 url_fetcher.SetResponseString(kValidTokenResponse); | 170 url_fetcher.SetResponseString(kValidTokenResponse); |
169 | 171 |
170 std::string at; | 172 std::string at; |
171 EXPECT_TRUE(OAuth2MintTokenFetcher::ParseMintTokenResponse( | 173 EXPECT_TRUE(OAuth2MintTokenFetcher::ParseMintTokenResponse( |
172 &url_fetcher, &at)); | 174 &url_fetcher, &at)); |
173 EXPECT_EQ("at1", at); | 175 EXPECT_EQ("at1", at); |
174 } | 176 } |
175 } | 177 } |
OLD | NEW |