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

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

Issue 327403003: Identity API: add chrome.identity.getProfileUserInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add identity.email permission to stubs_app Created 6 years, 6 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 | Annotate | Revision Log
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/strings/string_util.h" 11 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/api/identity/identity_api.h" 15 #include "chrome/browser/extensions/api/identity/identity_api.h"
15 #include "chrome/browser/extensions/component_loader.h" 16 #include "chrome/browser/extensions/component_loader.h"
16 #include "chrome/browser/extensions/extension_apitest.h" 17 #include "chrome/browser/extensions/extension_apitest.h"
17 #include "chrome/browser/extensions/extension_browsertest.h" 18 #include "chrome/browser/extensions/extension_browsertest.h"
18 #include "chrome/browser/extensions/extension_function_test_utils.h" 19 #include "chrome/browser/extensions/extension_function_test_utils.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/guest_view/guest_view_base.h" 21 #include "chrome/browser/guest_view/guest_view_base.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 23 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
23 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 24 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
24 #include "chrome/browser/signin/fake_signin_manager.h" 25 #include "chrome/browser/signin/fake_signin_manager.h"
25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
26 #include "chrome/browser/signin/signin_manager_factory.h" 27 #include "chrome/browser/signin/signin_manager_factory.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/extensions/api/identity.h" 31 #include "chrome/common/extensions/api/identity.h"
31 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h" 32 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.h"
32 #include "chrome/test/base/in_process_browser_test.h" 33 #include "chrome/test/base/in_process_browser_test.h"
33 #include "chrome/test/base/test_switches.h" 34 #include "chrome/test/base/test_switches.h"
34 #include "components/signin/core/browser/signin_manager.h" 35 #include "components/signin/core/browser/signin_manager.h"
35 #include "components/signin/core/common/profile_management_switches.h" 36 #include "components/signin/core/common/profile_management_switches.h"
37 #include "components/signin/core/common/signin_pref_names.h"
36 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
38 #include "content/public/test/test_utils.h" 40 #include "content/public/test/test_utils.h"
39 #include "extensions/common/id_util.h" 41 #include "extensions/common/id_util.h"
40 #include "google_apis/gaia/google_service_auth_error.h" 42 #include "google_apis/gaia/google_service_auth_error.h"
41 #include "google_apis/gaia/oauth2_mint_token_flow.h" 43 #include "google_apis/gaia/oauth2_mint_token_flow.h"
42 #include "grit/browser_resources.h" 44 #include "grit/browser_resources.h"
43 #include "net/test/spawned_test_server/spawned_test_server.h" 45 #include "net/test/spawned_test_server/spawned_test_server.h"
44 #include "testing/gmock/include/gmock/gmock.h" 46 #include "testing/gmock/include/gmock/gmock.h"
45 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 576
575 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest, 577 IN_PROC_BROWSER_TEST_F(IdentityOldProfilesGetAccountsFunctionTest,
576 TwoAccountsSignedIn) { 578 TwoAccountsSignedIn) {
577 SetAccountState(CreateIds("primary@example.com", "1"), true); 579 SetAccountState(CreateIds("primary@example.com", "1"), true);
578 SetAccountState(CreateIds("secondary@example.com", "2"), true); 580 SetAccountState(CreateIds("secondary@example.com", "2"), true);
579 std::vector<std::string> only_primary; 581 std::vector<std::string> only_primary;
580 only_primary.push_back("1"); 582 only_primary.push_back("1");
581 EXPECT_TRUE(ExpectGetAccounts(only_primary)); 583 EXPECT_TRUE(ExpectGetAccounts(only_primary));
582 } 584 }
583 585
586 class IdentityGetProfileUserInfoFunctionTest : public ExtensionBrowserTest {
587 protected:
588 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfo() {
589 scoped_refptr<IdentityGetProfileUserInfoFunction> func(
590 new IdentityGetProfileUserInfoFunction);
591 func->set_extension(utils::CreateEmptyExtension(kExtensionId).get());
592 scoped_ptr<base::Value> value(
593 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser()));
594 return api::identity::ProfileUserInfo::FromValue(*value.get());
595 }
596 };
597
598 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, NotSignedIn) {
599 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo();
600 EXPECT_TRUE(info->email.empty());
601 EXPECT_TRUE(info->id.empty());
602 }
603
604 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, SignedIn) {
605 profile()->GetPrefs()
606 ->SetString(prefs::kGoogleServicesUsername, "president@example.com");
607 profile()->GetPrefs()
608 ->SetString(prefs::kGoogleServicesUserAccountId, "12345");
609
610 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo();
611 EXPECT_EQ("president@example.com", info->email);
612 EXPECT_EQ("12345", info->id);
613 }
614
584 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { 615 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest {
585 public: 616 public:
586 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 617 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
587 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); 618 AsyncExtensionBrowserTest::SetUpCommandLine(command_line);
588 command_line->AppendSwitch(switches::kExtensionsMultiAccount); 619 command_line->AppendSwitch(switches::kExtensionsMultiAccount);
589 } 620 }
590 621
591 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 622 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
592 AsyncExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 623 AsyncExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
593 624
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), 1777 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"),
1747 url); 1778 url);
1748 } 1779 }
1749 1780
1750 } // namespace extensions 1781 } // namespace extensions
1751 1782
1752 // Tests the chrome.identity API implemented by custom JS bindings . 1783 // Tests the chrome.identity API implemented by custom JS bindings .
1753 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { 1784 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) {
1754 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; 1785 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_;
1755 } 1786 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/identity/identity_api.cc ('k') | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698