| 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 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 class IdentityGetProfileUserInfoFunctionTest : public ExtensionBrowserTest { | 588 class IdentityGetProfileUserInfoFunctionTest : public ExtensionBrowserTest { |
| 589 protected: | 589 protected: |
| 590 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfo() { | 590 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfo() { |
| 591 scoped_refptr<IdentityGetProfileUserInfoFunction> func( | 591 scoped_refptr<IdentityGetProfileUserInfoFunction> func( |
| 592 new IdentityGetProfileUserInfoFunction); | 592 new IdentityGetProfileUserInfoFunction); |
| 593 func->set_extension(utils::CreateEmptyExtension(kExtensionId).get()); | 593 func->set_extension(utils::CreateEmptyExtension(kExtensionId).get()); |
| 594 scoped_ptr<base::Value> value( | 594 scoped_ptr<base::Value> value( |
| 595 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); | 595 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 596 return api::identity::ProfileUserInfo::FromValue(*value.get()); | 596 return api::identity::ProfileUserInfo::FromValue(*value.get()); |
| 597 } | 597 } |
| 598 |
| 599 scoped_ptr<api::identity::ProfileUserInfo> RunGetProfileUserInfoWithEmail() { |
| 600 scoped_refptr<IdentityGetProfileUserInfoFunction> func( |
| 601 new IdentityGetProfileUserInfoFunction); |
| 602 func->set_extension(CreateExtensionWithEmailPermission()); |
| 603 scoped_ptr<base::Value> value( |
| 604 utils::RunFunctionAndReturnSingleResult(func.get(), "[]", browser())); |
| 605 return api::identity::ProfileUserInfo::FromValue(*value.get()); |
| 606 } |
| 607 |
| 608 private: |
| 609 scoped_refptr<Extension> CreateExtensionWithEmailPermission() { |
| 610 scoped_ptr<base::DictionaryValue> test_extension_value( |
| 611 utils::ParseDictionary( |
| 612 "{\"name\": \"Test\", \"version\": \"1.0\", " |
| 613 "\"permissions\": [\"identity.email\"]}")); |
| 614 return utils::CreateExtension(test_extension_value.get()); |
| 615 } |
| 598 }; | 616 }; |
| 599 | 617 |
| 600 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, NotSignedIn) { | 618 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, NotSignedIn) { |
| 601 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); | 619 scoped_ptr<api::identity::ProfileUserInfo> info = |
| 620 RunGetProfileUserInfoWithEmail(); |
| 602 EXPECT_TRUE(info->email.empty()); | 621 EXPECT_TRUE(info->email.empty()); |
| 603 EXPECT_TRUE(info->id.empty()); | 622 EXPECT_TRUE(info->id.empty()); |
| 604 } | 623 } |
| 605 | 624 |
| 606 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, SignedIn) { | 625 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, SignedIn) { |
| 607 profile()->GetPrefs() | 626 profile()->GetPrefs() |
| 608 ->SetString(prefs::kGoogleServicesUsername, "president@example.com"); | 627 ->SetString(prefs::kGoogleServicesUsername, "president@example.com"); |
| 609 profile()->GetPrefs() | 628 profile()->GetPrefs() |
| 610 ->SetString(prefs::kGoogleServicesUserAccountId, "12345"); | 629 ->SetString(prefs::kGoogleServicesUserAccountId, "12345"); |
| 611 | 630 |
| 631 scoped_ptr<api::identity::ProfileUserInfo> info = |
| 632 RunGetProfileUserInfoWithEmail(); |
| 633 EXPECT_EQ("president@example.com", info->email); |
| 634 EXPECT_EQ("12345", info->id); |
| 635 } |
| 636 |
| 637 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, |
| 638 NotSignedInNoEmail) { |
| 612 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); | 639 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); |
| 613 EXPECT_EQ("president@example.com", info->email); | 640 EXPECT_TRUE(info->email.empty()); |
| 641 EXPECT_TRUE(info->id.empty()); |
| 642 } |
| 643 |
| 644 IN_PROC_BROWSER_TEST_F(IdentityGetProfileUserInfoFunctionTest, |
| 645 SignedInNoEmail) { |
| 646 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 647 "president@example.com"); |
| 648 profile()->GetPrefs()->SetString(prefs::kGoogleServicesUserAccountId, |
| 649 "12345"); |
| 650 |
| 651 scoped_ptr<api::identity::ProfileUserInfo> info = RunGetProfileUserInfo(); |
| 652 EXPECT_TRUE(info->email.empty()); |
| 614 EXPECT_EQ("12345", info->id); | 653 EXPECT_EQ("12345", info->id); |
| 615 } | 654 } |
| 616 | 655 |
| 617 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { | 656 class GetAuthTokenFunctionTest : public AsyncExtensionBrowserTest { |
| 618 public: | 657 public: |
| 619 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 658 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 620 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); | 659 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); |
| 621 command_line->AppendSwitch(switches::kExtensionsMultiAccount); | 660 command_line->AppendSwitch(switches::kExtensionsMultiAccount); |
| 622 } | 661 } |
| 623 | 662 |
| (...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1889 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
| 1851 url); | 1890 url); |
| 1852 } | 1891 } |
| 1853 | 1892 |
| 1854 } // namespace extensions | 1893 } // namespace extensions |
| 1855 | 1894 |
| 1856 // Tests the chrome.identity API implemented by custom JS bindings . | 1895 // Tests the chrome.identity API implemented by custom JS bindings . |
| 1857 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1896 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
| 1858 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1897 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
| 1859 } | 1898 } |
| OLD | NEW |