Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / google_apis / gaia / oauth2_mint_token_flow_unittest.cc
index 8fd359f..c60ad31 100644 (file)
@@ -138,8 +138,8 @@ class MockDelegate : public OAuth2MintTokenFlow::Delegate {
 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*());
@@ -154,18 +154,23 @@ class OAuth2MintTokenFlowTest : public testing::Test {
 
  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.
@@ -185,11 +190,11 @@ TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) {
     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.
@@ -225,6 +230,19 @@ TEST_F(OAuth2MintTokenFlowTest, CreateApiCallBody) {
         "&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) {
@@ -333,7 +351,7 @@ TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) {
   {  // 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);
   }
 
@@ -345,20 +363,3 @@ TEST_F(OAuth2MintTokenFlowTest, ProcessApiCallFailure) {
     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);
-  }
-}