| 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 #include <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 scoped_ptr<OAuth2MintTokenFlow> flow_; | 440 scoped_ptr<OAuth2MintTokenFlow> flow_; |
| 441 | 441 |
| 442 std::string login_access_token_; | 442 std::string login_access_token_; |
| 443 }; | 443 }; |
| 444 | 444 |
| 445 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { | 445 class MockQueuedMintRequest : public IdentityMintRequestQueue::Request { |
| 446 public: | 446 public: |
| 447 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); | 447 MOCK_METHOD1(StartMintToken, void(IdentityMintRequestQueue::MintType)); |
| 448 }; | 448 }; |
| 449 | 449 |
| 450 AccountIds CreateIds(std::string email, std::string obfid) { | 450 gaia::AccountIds CreateIds(std::string email, std::string obfid) { |
| 451 AccountIds ids; | 451 gaia::AccountIds ids; |
| 452 ids.account_key = email; | 452 ids.account_key = email; |
| 453 ids.email = email; | 453 ids.email = email; |
| 454 ids.gaia = obfid; | 454 ids.gaia = obfid; |
| 455 return ids; | 455 return ids; |
| 456 } | 456 } |
| 457 | 457 |
| 458 class IdentityGetAccountsFunctionTest : public ExtensionBrowserTest { | 458 class IdentityGetAccountsFunctionTest : public ExtensionBrowserTest { |
| 459 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 459 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 460 ExtensionBrowserTest::SetUpCommandLine(command_line); | 460 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 461 command_line->AppendSwitch(switches::kExtensionsMultiAccount); | 461 command_line->AppendSwitch(switches::kExtensionsMultiAccount); |
| 462 } | 462 } |
| 463 | 463 |
| 464 protected: | 464 protected: |
| 465 void SetAccountState(AccountIds ids, bool is_signed_in) { | 465 void SetAccountState(gaia::AccountIds ids, bool is_signed_in) { |
| 466 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( | 466 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( |
| 467 ids, is_signed_in); | 467 ids, is_signed_in); |
| 468 } | 468 } |
| 469 | 469 |
| 470 testing::AssertionResult ExpectGetAccounts( | 470 testing::AssertionResult ExpectGetAccounts( |
| 471 const std::vector<std::string>& accounts) { | 471 const std::vector<std::string>& accounts) { |
| 472 scoped_refptr<IdentityGetAccountsFunction> func( | 472 scoped_refptr<IdentityGetAccountsFunction> func( |
| 473 new IdentityGetAccountsFunction); | 473 new IdentityGetAccountsFunction); |
| 474 func->set_extension(utils::CreateEmptyExtension(kExtensionId).get()); | 474 func->set_extension(utils::CreateEmptyExtension(kExtensionId).get()); |
| 475 if (!utils::RunFunction( | 475 if (!utils::RunFunction( |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 } | 700 } |
| 701 | 701 |
| 702 void SignIn(const std::string account_key) { | 702 void SignIn(const std::string account_key) { |
| 703 #if defined(OS_CHROMEOS) | 703 #if defined(OS_CHROMEOS) |
| 704 signin_manager_->SetAuthenticatedUsername(account_key); | 704 signin_manager_->SetAuthenticatedUsername(account_key); |
| 705 #else | 705 #else |
| 706 signin_manager_->SignIn(account_key, "password"); | 706 signin_manager_->SignIn(account_key, "password"); |
| 707 #endif | 707 #endif |
| 708 } | 708 } |
| 709 | 709 |
| 710 void SetAccountState(AccountIds ids, bool is_signed_in) { | 710 void SetAccountState(gaia::AccountIds ids, bool is_signed_in) { |
| 711 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( | 711 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( |
| 712 ids, is_signed_in); | 712 ids, is_signed_in); |
| 713 } | 713 } |
| 714 | 714 |
| 715 protected: | 715 protected: |
| 716 enum OAuth2Fields { | 716 enum OAuth2Fields { |
| 717 NONE = 0, | 717 NONE = 0, |
| 718 CLIENT_ID = 1, | 718 CLIENT_ID = 1, |
| 719 SCOPES = 2, | 719 SCOPES = 2, |
| 720 AS_COMPONENT = 4 | 720 AS_COMPONENT = 4 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 EXPECT_CALL(*func.get(), HasLoginToken()) | 882 EXPECT_CALL(*func.get(), HasLoginToken()) |
| 883 .WillOnce(Return(true)); | 883 .WillOnce(Return(true)); |
| 884 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 884 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 885 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); | 885 TestOAuth2MintTokenFlow::MINT_TOKEN_BAD_CREDENTIALS, func.get()); |
| 886 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 886 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 887 std::string error = utils::RunFunctionAndReturnError( | 887 std::string error = utils::RunFunctionAndReturnError( |
| 888 func.get(), "[{}]", browser()); | 888 func.get(), "[{}]", browser()); |
| 889 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 889 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 890 EXPECT_FALSE(func->login_ui_shown()); | 890 EXPECT_FALSE(func->login_ui_shown()); |
| 891 EXPECT_FALSE(func->scope_ui_shown()); | 891 EXPECT_FALSE(func->scope_ui_shown()); |
| 892 | |
| 893 EXPECT_EQ(GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, | |
| 894 id_api()->GetAuthStatusForTest().state()); | |
| 895 } | 892 } |
| 896 | 893 |
| 897 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 894 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 898 NonInteractiveMintServiceError) { | 895 NonInteractiveMintServiceError) { |
| 899 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); | 896 scoped_refptr<MockGetAuthTokenFunction> func(new MockGetAuthTokenFunction()); |
| 900 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); | 897 func->set_extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 901 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); | 898 EXPECT_CALL(*func.get(), HasLoginToken()).WillOnce(Return(true)); |
| 902 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( | 899 TestOAuth2MintTokenFlow* flow = new TestOAuth2MintTokenFlow( |
| 903 TestOAuth2MintTokenFlow::MINT_TOKEN_SERVICE_ERROR, func.get()); | 900 TestOAuth2MintTokenFlow::MINT_TOKEN_SERVICE_ERROR, func.get()); |
| 904 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); | 901 EXPECT_CALL(*func.get(), CreateMintTokenFlow(_)).WillOnce(Return(flow)); |
| 905 std::string error = | 902 std::string error = |
| 906 utils::RunFunctionAndReturnError(func.get(), "[{}]", browser()); | 903 utils::RunFunctionAndReturnError(func.get(), "[{}]", browser()); |
| 907 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 904 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 908 EXPECT_FALSE(func->login_ui_shown()); | 905 EXPECT_FALSE(func->login_ui_shown()); |
| 909 EXPECT_FALSE(func->scope_ui_shown()); | 906 EXPECT_FALSE(func->scope_ui_shown()); |
| 910 | |
| 911 EXPECT_EQ(GoogleServiceAuthError::AuthErrorNone(), | |
| 912 id_api()->GetAuthStatusForTest()); | |
| 913 } | 907 } |
| 914 | 908 |
| 915 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 909 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 916 NoOptionsSuccess) { | 910 NoOptionsSuccess) { |
| 917 #if defined(OS_WIN) && defined(USE_ASH) | 911 #if defined(OS_WIN) && defined(USE_ASH) |
| 918 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 912 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 919 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 913 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 920 return; | 914 return; |
| 921 #endif | 915 #endif |
| 922 | 916 |
| (...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1887 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1894 url); | 1888 url); |
| 1895 } | 1889 } |
| 1896 | 1890 |
| 1897 } // namespace extensions | 1891 } // namespace extensions |
| 1898 | 1892 |
| 1899 // Tests the chrome.identity API implemented by custom JS bindings . | 1893 // Tests the chrome.identity API implemented by custom JS bindings . |
| 1900 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1894 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
| 1901 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1895 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
| 1902 } | 1896 } |
| OLD | NEW |