class MockMintTokenFlow : public OAuth2MintTokenFlow {
public:
explicit MockMintTokenFlow(MockDelegate* delegate,
- const OAuth2MintTokenFlow::Parameters& parameters )
- : OAuth2MintTokenFlow(NULL, delegate, parameters) {}
+ const OAuth2MintTokenFlow::Parameters& parameters)
+ : OAuth2MintTokenFlow(delegate, parameters) {}
~MockMintTokenFlow() {}
MOCK_METHOD0(CreateAccessTokenFetcher, OAuth2AccessTokenFetcher*());
protected:
void CreateFlow(OAuth2MintTokenFlow::Mode mode) {
- return CreateFlow(&delegate_, mode);
+ return CreateFlow(&delegate_, mode, "");
+ }
+
+ void CreateFlowWithDeviceId(const std::string& device_id) {
+ return CreateFlow(&delegate_, OAuth2MintTokenFlow::MODE_ISSUE_ADVICE,
+ device_id);
}
void CreateFlow(MockDelegate* delegate,
- OAuth2MintTokenFlow::Mode mode) {
- std::string rt = "refresh_token";
+ OAuth2MintTokenFlow::Mode mode,
+ const std::string& device_id) {
std::string ext_id = "ext1";
std::string client_id = "client1";
std::vector<std::string> scopes(CreateTestScopes());
flow_.reset(new MockMintTokenFlow(
- delegate,
- OAuth2MintTokenFlow::Parameters(rt, ext_id, client_id, scopes, mode)));
+ delegate, OAuth2MintTokenFlow::Parameters(ext_id, client_id, scopes,
+ device_id, mode)));
}
// Helper to parse the given string to DictionaryValue.
CreateFlow(OAuth2MintTokenFlow::MODE_ISSUE_ADVICE);
std::string body = flow_->CreateApiCallBody();
std::string expected_body(
- "force=false"
- "&response_type=none"
- "&scope=http://scope1+http://scope2"
- "&client_id=client1"
- "&origin=ext1");
+ "force=false"
+ "&response_type=none"
+ "&scope=http://scope1+http://scope2"
+ "&client_id=client1"
+ "&origin=ext1");
EXPECT_EQ(expected_body, body);
}
{ // Record grant mode.
"&origin=ext1");
EXPECT_EQ(expected_body, body);
}
+ { // Mint token with device_id.
+ CreateFlowWithDeviceId("device_id1");
+ std::string body = flow_->CreateApiCallBody();
+ std::string expected_body(
+ "force=false"
+ "&response_type=none"
+ "&scope=http://scope1+http://scope2"
+ "&client_id=client1"
+ "&origin=ext1"
+ "&device_id=device_id1"
+ "&device_type=chrome");
+ EXPECT_EQ(expected_body, body);
+ }
}
TEST_F(OAuth2MintTokenFlowTest, ParseMintTokenResponse) {
{ // Null delegate should work fine.
TestURLFetcher url_fetcher(1, GURL("http://www.google.com"), NULL);
url_fetcher.set_status(URLRequestStatus(URLRequestStatus::FAILED, 101));
- CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
+ CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE, "");
flow_->ProcessApiCallFailure(&url_fetcher);
}
flow_->ProcessApiCallFailure(&url_fetcher);
}
}
-
-TEST_F(OAuth2MintTokenFlowTest, ProcessMintAccessTokenFailure) {
- { // Null delegate should work fine.
- GoogleServiceAuthError error(
- GoogleServiceAuthError::FromConnectionError(101));
- CreateFlow(NULL, OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
- flow_->ProcessMintAccessTokenFailure(error);
- }
-
- { // Non-null delegate.
- GoogleServiceAuthError error(
- GoogleServiceAuthError::FromConnectionError(101));
- CreateFlow(OAuth2MintTokenFlow::MODE_MINT_TOKEN_NO_FORCE);
- EXPECT_CALL(delegate_, OnMintTokenFailure(error));
- flow_->ProcessMintAccessTokenFailure(error);
- }
-}