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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #if defined(OS_CHROMEOS) |
| 16 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
| 17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 19 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" |
| 20 #include "extensions/common/extension_builder.h" |
| 21 #endif |
15 #include "chrome/browser/extensions/api/identity/identity_api.h" | 22 #include "chrome/browser/extensions/api/identity/identity_api.h" |
16 #include "chrome/browser/extensions/component_loader.h" | 23 #include "chrome/browser/extensions/component_loader.h" |
17 #include "chrome/browser/extensions/extension_apitest.h" | 24 #include "chrome/browser/extensions/extension_apitest.h" |
18 #include "chrome/browser/extensions/extension_browsertest.h" | 25 #include "chrome/browser/extensions/extension_browsertest.h" |
19 #include "chrome/browser/extensions/extension_function_test_utils.h" | 26 #include "chrome/browser/extensions/extension_function_test_utils.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 27 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/signin/account_tracker_service_factory.h" | 29 #include "chrome/browser/signin/account_tracker_service_factory.h" |
23 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h" | 30 #include "chrome/browser/signin/fake_gaia_cookie_manager_service.h" |
24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 31 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); | 340 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
334 OnGetTokenFailure(login_token_request_.get(), error); | 341 OnGetTokenFailure(login_token_request_.get(), error); |
335 } | 342 } |
336 } else { | 343 } else { |
337 // Make a request to the token service. The test now must tell | 344 // Make a request to the token service. The test now must tell |
338 // the token service to issue an access token (or an error). | 345 // the token service to issue an access token (or an error). |
339 IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest(); | 346 IdentityGetAuthTokenFunction::StartLoginAccessTokenRequest(); |
340 } | 347 } |
341 } | 348 } |
342 | 349 |
| 350 void StartDeviceLoginAccessTokenRequest() override { |
| 351 StartLoginAccessTokenRequest(); |
| 352 } |
| 353 |
343 void ShowLoginPopup() override { | 354 void ShowLoginPopup() override { |
344 EXPECT_FALSE(login_ui_shown_); | 355 EXPECT_FALSE(login_ui_shown_); |
345 login_ui_shown_ = true; | 356 login_ui_shown_ = true; |
346 if (login_ui_result_) | 357 if (login_ui_result_) |
347 SigninSuccess(); | 358 SigninSuccess(); |
348 else | 359 else |
349 SigninFailed(); | 360 SigninFailed(); |
350 } | 361 } |
351 | 362 |
352 void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice) override { | 363 void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice) override { |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1607 EXPECT_TRUE(value->GetAsString(&access_token)); | 1618 EXPECT_TRUE(value->GetAsString(&access_token)); |
1608 EXPECT_EQ(std::string(kAccessToken), access_token); | 1619 EXPECT_EQ(std::string(kAccessToken), access_token); |
1609 | 1620 |
1610 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); | 1621 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); |
1611 EXPECT_EQ(3ul, token_key->scopes.size()); | 1622 EXPECT_EQ(3ul, token_key->scopes.size()); |
1612 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); | 1623 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); |
1613 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo")); | 1624 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo")); |
1614 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar")); | 1625 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar")); |
1615 } | 1626 } |
1616 | 1627 |
| 1628 |
| 1629 #if defined(OS_CHROMEOS) |
| 1630 class GetAuthTokenFunctionPublicSessionTest : public GetAuthTokenFunctionTest { |
| 1631 public: |
| 1632 GetAuthTokenFunctionPublicSessionTest() |
| 1633 : user_manager_(new chromeos::MockUserManager) {} |
| 1634 |
| 1635 protected: |
| 1636 void SetUpInProcessBrowserTestFixture() override { |
| 1637 GetAuthTokenFunctionTest::SetUpInProcessBrowserTestFixture(); |
| 1638 |
| 1639 // Set up the user manager to fake a public session. |
| 1640 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp()) |
| 1641 .WillRepeatedly(Return(false)); |
| 1642 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount()) |
| 1643 .WillRepeatedly(Return(true)); |
| 1644 |
| 1645 // Set up fake install attributes to make the device appeared as |
| 1646 // enterprise-managed. |
| 1647 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes( |
| 1648 new policy::StubEnterpriseInstallAttributes()); |
| 1649 attributes->SetDomain("example.com"); |
| 1650 attributes->SetRegistrationUser("user@example.com"); |
| 1651 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( |
| 1652 attributes.release()); |
| 1653 } |
| 1654 |
| 1655 scoped_refptr<Extension> CreateTestExtension(const std::string& id) { |
| 1656 return ExtensionBuilder() |
| 1657 .SetManifest( |
| 1658 DictionaryBuilder() |
| 1659 .Set("name", "Test") |
| 1660 .Set("version", "1.0") |
| 1661 .Set( |
| 1662 "oauth2", |
| 1663 DictionaryBuilder() |
| 1664 .Set("client_id", "clientId") |
| 1665 .Set( |
| 1666 "scopes", |
| 1667 ListBuilder().Append("scope1")))) |
| 1668 .SetLocation(Manifest::UNPACKED) |
| 1669 .SetID(id) |
| 1670 .Build(); |
| 1671 } |
| 1672 |
| 1673 // Owned by |user_manager_enabler|. |
| 1674 chromeos::MockUserManager* user_manager_; |
| 1675 }; |
| 1676 |
| 1677 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, NonWhitelisted) { |
| 1678 // GetAuthToken() should return UserNotSignedIn in public sessions for |
| 1679 // non-whitelisted extensions. |
| 1680 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_); |
| 1681 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1682 func->set_extension(CreateTestExtension("test-id")); |
| 1683 std::string error = utils::RunFunctionAndReturnError( |
| 1684 func.get(), "[]", browser()); |
| 1685 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error); |
| 1686 EXPECT_FALSE(func->login_ui_shown()); |
| 1687 EXPECT_FALSE(func->scope_ui_shown()); |
| 1688 } |
| 1689 |
| 1690 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, Whitelisted) { |
| 1691 // GetAuthToken() should return a token for whitelisted extensions. |
| 1692 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_); |
| 1693 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction()); |
| 1694 func->set_extension(CreateTestExtension("ljacajndfccfgnfohlgkdphmbnpkjflk")); |
| 1695 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS); |
| 1696 scoped_ptr<base::Value> value( |
| 1697 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser())); |
| 1698 std::string access_token; |
| 1699 EXPECT_TRUE(value->GetAsString(&access_token)); |
| 1700 EXPECT_EQ(std::string(kAccessToken), access_token); |
| 1701 } |
| 1702 |
| 1703 #endif |
| 1704 |
| 1705 |
1617 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { | 1706 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { |
1618 protected: | 1707 protected: |
1619 bool InvalidateDefaultToken() { | 1708 bool InvalidateDefaultToken() { |
1620 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( | 1709 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( |
1621 new IdentityRemoveCachedAuthTokenFunction); | 1710 new IdentityRemoveCachedAuthTokenFunction); |
1622 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get()); | 1711 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get()); |
1623 return utils::RunFunction( | 1712 return utils::RunFunction( |
1624 func.get(), | 1713 func.get(), |
1625 std::string("[{\"token\": \"") + kAccessToken + "\"}]", | 1714 std::string("[{\"token\": \"") + kAccessToken + "\"}]", |
1626 browser(), | 1715 browser(), |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1926 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1838 url); | 1927 url); |
1839 } | 1928 } |
1840 | 1929 |
1841 } // namespace extensions | 1930 } // namespace extensions |
1842 | 1931 |
1843 // Tests the chrome.identity API implemented by custom JS bindings . | 1932 // Tests the chrome.identity API implemented by custom JS bindings . |
1844 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1933 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
1845 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1934 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
1846 } | 1935 } |
OLD | NEW |