| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 394 |
| 395 gaia::AccountIds CreateIds(std::string email, std::string obfid) { | 395 gaia::AccountIds CreateIds(std::string email, std::string obfid) { |
| 396 gaia::AccountIds ids; | 396 gaia::AccountIds ids; |
| 397 ids.account_key = email; | 397 ids.account_key = email; |
| 398 ids.email = email; | 398 ids.email = email; |
| 399 ids.gaia = obfid; | 399 ids.gaia = obfid; |
| 400 return ids; | 400 return ids; |
| 401 } | 401 } |
| 402 | 402 |
| 403 class IdentityGetAccountsFunctionTest : public ExtensionBrowserTest { | 403 class IdentityGetAccountsFunctionTest : public ExtensionBrowserTest { |
| 404 void SetUpCommandLine(CommandLine* command_line) override { | 404 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 405 ExtensionBrowserTest::SetUpCommandLine(command_line); | 405 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 406 command_line->AppendSwitch(switches::kExtensionsMultiAccount); | 406 command_line->AppendSwitch(switches::kExtensionsMultiAccount); |
| 407 } | 407 } |
| 408 | 408 |
| 409 protected: | 409 protected: |
| 410 void SetAccountState(gaia::AccountIds ids, bool is_signed_in) { | 410 void SetAccountState(gaia::AccountIds ids, bool is_signed_in) { |
| 411 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( | 411 IdentityAPI::GetFactoryInstance()->Get(profile())->SetAccountStateForTest( |
| 412 ids, is_signed_in); | 412 ids, is_signed_in); |
| 413 } | 413 } |
| 414 | 414 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 SetAccountState(CreateIds("primary@example.com", "1"), true); | 506 SetAccountState(CreateIds("primary@example.com", "1"), true); |
| 507 SetAccountState(CreateIds("secondary@example.com", "2"), true); | 507 SetAccountState(CreateIds("secondary@example.com", "2"), true); |
| 508 std::vector<std::string> two_accounts; | 508 std::vector<std::string> two_accounts; |
| 509 two_accounts.push_back("1"); | 509 two_accounts.push_back("1"); |
| 510 two_accounts.push_back("2"); | 510 two_accounts.push_back("2"); |
| 511 EXPECT_TRUE(ExpectGetAccounts(two_accounts)); | 511 EXPECT_TRUE(ExpectGetAccounts(two_accounts)); |
| 512 } | 512 } |
| 513 | 513 |
| 514 class IdentityOldProfilesGetAccountsFunctionTest | 514 class IdentityOldProfilesGetAccountsFunctionTest |
| 515 : public IdentityGetAccountsFunctionTest { | 515 : public IdentityGetAccountsFunctionTest { |
| 516 void SetUpCommandLine(CommandLine* command_line) override { | 516 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 517 // Don't add the multi-account switch that parent class would have. | 517 // Don't add the multi-account switch that parent class would have. |
| 518 } | 518 } |
| 519 }; | 519 }; |
| 520 | 520 |
| 521 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, | 521 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, |
| 522 MultiAccountOff) { | 522 MultiAccountOff) { |
| 523 EXPECT_FALSE(switches::IsExtensionsMultiAccount()); | 523 EXPECT_FALSE(switches::IsExtensionsMultiAccount()); |
| 524 } | 524 } |
| 525 | 525 |
| 526 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, | 526 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, | 650 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, |
| 651 SignedInNoEmail) { | 651 SignedInNoEmail) { |
| 652 SignIn("president@example.com", "12345"); | 652 SignIn("president@example.com", "12345"); |
| 653 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); | 653 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); |
| 654 EXPECT_TRUE(info->email.empty()); | 654 EXPECT_TRUE(info->email.empty()); |
| 655 EXPECT_EQ("12345", info->id); | 655 EXPECT_EQ("12345", info->id); |
| 656 } | 656 } |
| 657 | 657 |
| 658 class GetAuthTokenFunctionTest : public IdentityTestWithSignin { | 658 class GetAuthTokenFunctionTest : public IdentityTestWithSignin { |
| 659 public: | 659 public: |
| 660 void SetUpCommandLine(CommandLine* command_line) override { | 660 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 661 IdentityTestWithSignin::SetUpCommandLine(command_line); | 661 IdentityTestWithSignin::SetUpCommandLine(command_line); |
| 662 command_line->AppendSwitch(switches::kExtensionsMultiAccount); | 662 command_line->AppendSwitch(switches::kExtensionsMultiAccount); |
| 663 } | 663 } |
| 664 | 664 |
| 665 void IssueLoginRefreshTokenForAccount(const std::string account_key) { | 665 void IssueLoginRefreshTokenForAccount(const std::string account_key) { |
| 666 token_service_->IssueRefreshTokenForUser(account_key, "refresh_token"); | 666 token_service_->IssueRefreshTokenForUser(account_key, "refresh_token"); |
| 667 } | 667 } |
| 668 | 668 |
| 669 void IssueLoginAccessTokenForAccount(const std::string account_key) { | 669 void IssueLoginAccessTokenForAccount(const std::string account_key) { |
| 670 token_service_->IssueAllTokensForAccount( | 670 token_service_->IssueAllTokensForAccount( |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); | 854 EXPECT_TRUE(StartsWithASCII(error, errors::kAuthFailure, false)); |
| 855 EXPECT_FALSE(func->login_ui_shown()); | 855 EXPECT_FALSE(func->login_ui_shown()); |
| 856 EXPECT_FALSE(func->scope_ui_shown()); | 856 EXPECT_FALSE(func->scope_ui_shown()); |
| 857 } | 857 } |
| 858 | 858 |
| 859 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 859 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 860 NoOptionsSuccess) { | 860 NoOptionsSuccess) { |
| 861 SignIn("primary@example.com"); | 861 SignIn("primary@example.com"); |
| 862 #if defined(OS_WIN) && defined(USE_ASH) | 862 #if defined(OS_WIN) && defined(USE_ASH) |
| 863 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 863 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 864 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 864 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 865 switches::kAshBrowserTests)) |
| 865 return; | 866 return; |
| 866 #endif | 867 #endif |
| 867 | 868 |
| 868 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 869 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 869 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 870 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 870 func->set_extension(extension.get()); | 871 func->set_extension(extension.get()); |
| 871 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 872 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 872 scoped_ptr<base::Value> value( | 873 scoped_ptr<base::Value> value( |
| 873 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); | 874 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 874 std::string access_token; | 875 std::string access_token; |
| 875 EXPECT_TRUE(value->GetAsString(&access_token)); | 876 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 876 EXPECT_EQ(std::string(kAccessToken), access_token); | 877 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 877 EXPECT_FALSE(func->login_ui_shown()); | 878 EXPECT_FALSE(func->login_ui_shown()); |
| 878 EXPECT_FALSE(func->scope_ui_shown()); | 879 EXPECT_FALSE(func->scope_ui_shown()); |
| 879 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 880 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 880 GetCachedToken(std::string()).status()); | 881 GetCachedToken(std::string()).status()); |
| 881 } | 882 } |
| 882 | 883 |
| 883 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, | 884 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionTest, |
| 884 NonInteractiveSuccess) { | 885 NonInteractiveSuccess) { |
| 885 SignIn("primary@example.com"); | 886 SignIn("primary@example.com"); |
| 886 #if defined(OS_WIN) && defined(USE_ASH) | 887 #if defined(OS_WIN) && defined(USE_ASH) |
| 887 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 888 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 888 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 889 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 890 switches::kAshBrowserTests)) |
| 889 return; | 891 return; |
| 890 #endif | 892 #endif |
| 891 | 893 |
| 892 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); | 894 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 893 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); | 895 scoped_refptr<const Extension> extension(CreateExtension(CLIENT_ID | SCOPES)); |
| 894 func->set_extension(extension.get()); | 896 func->set_extension(extension.get()); |
| 895 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); | 897 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 896 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 898 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 897 func.get(), "[{}]", browser())); | 899 func.get(), "[{}]", browser())); |
| 898 std::string access_token; | 900 std::string access_token; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1655 SetCachedToken(token); | 1657 SetCachedToken(token); |
| 1656 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, | 1658 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_TOKEN, |
| 1657 GetCachedToken().status()); | 1659 GetCachedToken().status()); |
| 1658 EXPECT_TRUE(InvalidateDefaultToken()); | 1660 EXPECT_TRUE(InvalidateDefaultToken()); |
| 1659 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, | 1661 EXPECT_EQ(IdentityTokenCacheValue::CACHE_STATUS_NOTFOUND, |
| 1660 GetCachedToken().status()); | 1662 GetCachedToken().status()); |
| 1661 } | 1663 } |
| 1662 | 1664 |
| 1663 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { | 1665 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { |
| 1664 public: | 1666 public: |
| 1665 void SetUpCommandLine(CommandLine* command_line) override { | 1667 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1666 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); | 1668 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); |
| 1667 // Reduce performance test variance by disabling background networking. | 1669 // Reduce performance test variance by disabling background networking. |
| 1668 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); | 1670 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); |
| 1669 } | 1671 } |
| 1670 }; | 1672 }; |
| 1671 | 1673 |
| 1672 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { | 1674 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { |
| 1673 net::SpawnedTestServer https_server( | 1675 net::SpawnedTestServer https_server( |
| 1674 net::SpawnedTestServer::TYPE_HTTPS, | 1676 net::SpawnedTestServer::TYPE_HTTPS, |
| 1675 net::SpawnedTestServer::kLocalhost, | 1677 net::SpawnedTestServer::kLocalhost, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 auth_url.spec() + "\"}]"; | 1737 auth_url.spec() + "\"}]"; |
| 1736 std::string error = | 1738 std::string error = |
| 1737 utils::RunFunctionAndReturnError(function.get(), args, browser()); | 1739 utils::RunFunctionAndReturnError(function.get(), args, browser()); |
| 1738 | 1740 |
| 1739 EXPECT_EQ(std::string(errors::kPageLoadFailure), error); | 1741 EXPECT_EQ(std::string(errors::kPageLoadFailure), error); |
| 1740 } | 1742 } |
| 1741 | 1743 |
| 1742 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { | 1744 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, NonInteractiveSuccess) { |
| 1743 #if defined(OS_WIN) && defined(USE_ASH) | 1745 #if defined(OS_WIN) && defined(USE_ASH) |
| 1744 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1746 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1745 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 1747 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1748 switches::kAshBrowserTests)) |
| 1746 return; | 1749 return; |
| 1747 #endif | 1750 #endif |
| 1748 | 1751 |
| 1749 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1752 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1750 new IdentityLaunchWebAuthFlowFunction()); | 1753 new IdentityLaunchWebAuthFlowFunction()); |
| 1751 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1754 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 1752 function->set_extension(empty_extension.get()); | 1755 function->set_extension(empty_extension.get()); |
| 1753 | 1756 |
| 1754 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1757 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1755 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1758 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| 1756 function.get(), | 1759 function.get(), |
| 1757 "[{\"interactive\": false," | 1760 "[{\"interactive\": false," |
| 1758 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", | 1761 "\"url\": \"https://abcdefghij.chromiumapp.org/callback#test\"}]", |
| 1759 browser())); | 1762 browser())); |
| 1760 | 1763 |
| 1761 std::string url; | 1764 std::string url; |
| 1762 EXPECT_TRUE(value->GetAsString(&url)); | 1765 EXPECT_TRUE(value->GetAsString(&url)); |
| 1763 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1766 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1764 url); | 1767 url); |
| 1765 } | 1768 } |
| 1766 | 1769 |
| 1767 IN_PROC_BROWSER_TEST_F( | 1770 IN_PROC_BROWSER_TEST_F( |
| 1768 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { | 1771 LaunchWebAuthFlowFunctionTest, InteractiveFirstNavigationSuccess) { |
| 1769 #if defined(OS_WIN) && defined(USE_ASH) | 1772 #if defined(OS_WIN) && defined(USE_ASH) |
| 1770 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1773 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1771 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 1774 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1775 switches::kAshBrowserTests)) |
| 1772 return; | 1776 return; |
| 1773 #endif | 1777 #endif |
| 1774 | 1778 |
| 1775 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1779 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
| 1776 new IdentityLaunchWebAuthFlowFunction()); | 1780 new IdentityLaunchWebAuthFlowFunction()); |
| 1777 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1781 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
| 1778 function->set_extension(empty_extension.get()); | 1782 function->set_extension(empty_extension.get()); |
| 1779 | 1783 |
| 1780 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1784 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
| 1781 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( | 1785 scoped_ptr<base::Value> value(utils::RunFunctionAndReturnSingleResult( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1820 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1817 url); | 1821 url); |
| 1818 } | 1822 } |
| 1819 | 1823 |
| 1820 } // namespace extensions | 1824 } // namespace extensions |
| 1821 | 1825 |
| 1822 // Tests the chrome.identity API implemented by custom JS bindings . | 1826 // Tests the chrome.identity API implemented by custom JS bindings . |
| 1823 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1827 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
| 1824 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1828 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
| 1825 } | 1829 } |
| OLD | NEW |