| 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/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 void CreateFlow(OAuth2MintTokenFlow::Mode mode) { | 154 void CreateFlow(OAuth2MintTokenFlow::Mode mode) { |
| 155 return CreateFlow(&delegate_, mode); | 155 return CreateFlow(&delegate_, mode); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void CreateFlow(MockDelegate* delegate, | 158 void CreateFlow(MockDelegate* delegate, |
| 159 OAuth2MintTokenFlow::Mode mode) { | 159 OAuth2MintTokenFlow::Mode mode) { |
| 160 std::string rt = "refresh_token"; | 160 std::string rt = "refresh_token"; |
| 161 std::string ext_id = "ext1"; | 161 std::string ext_id = "ext1"; |
| 162 std::string client_id = "client1"; | 162 std::string client_id = "client1"; |
| 163 std::vector<std::string> scopes(CreateTestScopes()); | 163 std::vector<std::string> scopes(CreateTestScopes()); |
| 164 flow_.reset(new MockMintTokenFlow( | 164 flow_ = new MockMintTokenFlow( |
| 165 delegate, | 165 delegate, |
| 166 OAuth2MintTokenFlow::Parameters(rt, ext_id, client_id, scopes, mode))); | 166 OAuth2MintTokenFlow::Parameters(rt, ext_id, client_id, scopes, mode)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Helper to parse the given string to DictionaryValue. | 169 // Helper to parse the given string to DictionaryValue. |
| 170 static base::DictionaryValue* ParseJson(const std::string& str) { | 170 static base::DictionaryValue* ParseJson(const std::string& str) { |
| 171 scoped_ptr<Value> value(base::JSONReader::Read(str)); | 171 scoped_ptr<Value> value(base::JSONReader::Read(str)); |
| 172 EXPECT_TRUE(value.get()); | 172 EXPECT_TRUE(value.get()); |
| 173 EXPECT_EQ(Value::TYPE_DICTIONARY, value->GetType()); | 173 EXPECT_EQ(Value::TYPE_DICTIONARY, value->GetType()); |
| 174 return static_cast<base::DictionaryValue*>(value.release()); | 174 return static_cast<base::DictionaryValue*>(value.release()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 scoped_ptr<MockMintTokenFlow> flow_; | 177 scoped_refptr<MockMintTokenFlow> flow_; |
| 178 StrictMock<MockDelegate> delegate_; | 178 StrictMock<MockDelegate> delegate_; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) { | 181 TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) { |
| 182 { // Issue advice mode. | 182 { // Issue advice mode. |
| 183 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); | 183 CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE); |
| 184 std::string body = flow_->CreateApiCallBody(); | 184 std::string body = flow_->CreateApiCallBody(); |
| 185 std::string expected_body( | 185 std::string expected_body( |
| 186 "force=false" | 186 "force=false" |
| 187 "&response_type=none" | 187 "&response_type=none" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 348 } |
| 349 | 349 |
| 350 { // Non-null delegate. | 350 { // Non-null delegate. |
| 351 GoogleServiceAuthError error( | 351 GoogleServiceAuthError error( |
| 352 GoogleServiceAuthError::FromConnectionError(101)); | 352 GoogleServiceAuthError::FromConnectionError(101)); |
| 353 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); | 353 CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE); |
| 354 EXPECT_CALL(delegate_, OnMintTokenFailure(error)); | 354 EXPECT_CALL(delegate_, OnMintTokenFailure(error)); |
| 355 flow_->ProcessMintAccessTokenFailure(error); | 355 flow_->ProcessMintAccessTokenFailure(error); |
| 356 } | 356 } |
| 357 } | 357 } |
| OLD | NEW |