Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: chrome/browser/extensions/api/identity/identity_apitest.cc

Issue 1306053013: White-listing Chrome Remote Desktop to use the identity API in Public Session (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compiler error on Windows Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 #if defined(OS_CHROMEOS)
351 void StartDeviceLoginAccessTokenRequest() override {
352 StartLoginAccessTokenRequest();
353 }
354 #endif
355
343 void ShowLoginPopup() override { 356 void ShowLoginPopup() override {
344 EXPECT_FALSE(login_ui_shown_); 357 EXPECT_FALSE(login_ui_shown_);
345 login_ui_shown_ = true; 358 login_ui_shown_ = true;
346 if (login_ui_result_) 359 if (login_ui_result_)
347 SigninSuccess(); 360 SigninSuccess();
348 else 361 else
349 SigninFailed(); 362 SigninFailed();
350 } 363 }
351 364
352 void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice) override { 365 void ShowOAuthApprovalDialog(const IssueAdviceInfo& issue_advice) override {
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 EXPECT_TRUE(value->GetAsString(&access_token)); 1620 EXPECT_TRUE(value->GetAsString(&access_token));
1608 EXPECT_EQ(std::string(kAccessToken), access_token); 1621 EXPECT_EQ(std::string(kAccessToken), access_token);
1609 1622
1610 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest(); 1623 const ExtensionTokenKey* token_key = func->GetExtensionTokenKeyForTest();
1611 EXPECT_EQ(3ul, token_key->scopes.size()); 1624 EXPECT_EQ(3ul, token_key->scopes.size());
1612 EXPECT_TRUE(ContainsKey(token_key->scopes, "email")); 1625 EXPECT_TRUE(ContainsKey(token_key->scopes, "email"));
1613 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo")); 1626 EXPECT_TRUE(ContainsKey(token_key->scopes, "foo"));
1614 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar")); 1627 EXPECT_TRUE(ContainsKey(token_key->scopes, "bar"));
1615 } 1628 }
1616 1629
1630
1631 #if defined(OS_CHROMEOS)
1632 class GetAuthTokenFunctionPublicSessionTest : public GetAuthTokenFunctionTest {
1633 public:
1634 GetAuthTokenFunctionPublicSessionTest()
1635 : user_manager_(new chromeos::MockUserManager) {}
1636
1637 protected:
1638 void SetUpInProcessBrowserTestFixture() override {
1639 GetAuthTokenFunctionTest::SetUpInProcessBrowserTestFixture();
1640
1641 // Set up the user manager to fake a public session.
1642 EXPECT_CALL(*user_manager_, IsLoggedInAsKioskApp())
1643 .WillRepeatedly(Return(false));
1644 EXPECT_CALL(*user_manager_, IsLoggedInAsPublicAccount())
1645 .WillRepeatedly(Return(true));
1646
1647 // Set up fake install attributes to make the device appeared as
1648 // enterprise-managed.
1649 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes(
1650 new policy::StubEnterpriseInstallAttributes());
1651 attributes->SetDomain("example.com");
1652 attributes->SetRegistrationUser("user@example.com");
1653 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
1654 attributes.release());
1655 }
1656
1657 scoped_refptr<Extension> CreateTestExtension(const std::string& id) {
1658 return ExtensionBuilder()
1659 .SetManifest(
1660 DictionaryBuilder()
1661 .Set("name", "Test")
1662 .Set("version", "1.0")
1663 .Set(
1664 "oauth2",
1665 DictionaryBuilder()
1666 .Set("client_id", "clientId")
1667 .Set(
1668 "scopes",
1669 ListBuilder().Append("scope1"))))
1670 .SetLocation(Manifest::UNPACKED)
1671 .SetID(id)
1672 .Build();
1673 }
1674
1675 // Owned by |user_manager_enabler|.
1676 chromeos::MockUserManager* user_manager_;
1677 };
1678
1679 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, NonWhitelisted) {
1680 // GetAuthToken() should return UserNotSignedIn in public sessions for
1681 // non-whitelisted extensions.
1682 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_);
1683 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
1684 func->set_extension(CreateTestExtension("test-id"));
1685 std::string error = utils::RunFunctionAndReturnError(
1686 func.get(), "[]", browser());
1687 EXPECT_EQ(std::string(errors::kUserNotSignedIn), error);
1688 EXPECT_FALSE(func->login_ui_shown());
1689 EXPECT_FALSE(func->scope_ui_shown());
1690 }
1691
1692 IN_PROC_BROWSER_TEST_F(GetAuthTokenFunctionPublicSessionTest, Whitelisted) {
1693 // GetAuthToken() should return a token for whitelisted extensions.
1694 chromeos::ScopedUserManagerEnabler user_manager_enabler(user_manager_);
1695 scoped_refptr<FakeGetAuthTokenFunction> func(new FakeGetAuthTokenFunction());
1696 func->set_extension(CreateTestExtension("ljacajndfccfgnfohlgkdphmbnpkjflk"));
1697 func->set_mint_token_result(TestOAuth2MintTokenFlow::MINT_TOKEN_SUCCESS);
1698 scoped_ptr<base::Value> value(
1699 utils::RunFunctionAndReturnSingleResult(func.get(), "[{}]", browser()));
1700 std::string access_token;
1701 EXPECT_TRUE(value->GetAsString(&access_token));
1702 EXPECT_EQ(std::string(kAccessToken), access_token);
1703 }
1704
1705 #endif
1706
1707
1617 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest { 1708 class RemoveCachedAuthTokenFunctionTest : public ExtensionBrowserTest {
1618 protected: 1709 protected:
1619 bool InvalidateDefaultToken() { 1710 bool InvalidateDefaultToken() {
1620 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func( 1711 scoped_refptr<IdentityRemoveCachedAuthTokenFunction> func(
1621 new IdentityRemoveCachedAuthTokenFunction); 1712 new IdentityRemoveCachedAuthTokenFunction);
1622 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get()); 1713 func->set_extension(test_util::CreateEmptyExtension(kExtensionId).get());
1623 return utils::RunFunction( 1714 return utils::RunFunction(
1624 func.get(), 1715 func.get(),
1625 std::string("[{\"token\": \"") + kAccessToken + "\"}]", 1716 std::string("[{\"token\": \"") + kAccessToken + "\"}]",
1626 browser(), 1717 browser(),
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), 1928 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"),
1838 url); 1929 url);
1839 } 1930 }
1840 1931
1841 } // namespace extensions 1932 } // namespace extensions
1842 1933
1843 // Tests the chrome.identity API implemented by custom JS bindings . 1934 // Tests the chrome.identity API implemented by custom JS bindings .
1844 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { 1935 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) {
1845 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; 1936 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_;
1846 } 1937 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698