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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "components/signin/core/common/signin_pref_names.h" | 48 #include "components/signin/core/common/signin_pref_names.h" |
49 #include "components/signin/core/common/signin_switches.h" | 49 #include "components/signin/core/common/signin_switches.h" |
50 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
51 #include "content/public/browser/notification_source.h" | 51 #include "content/public/browser/notification_source.h" |
52 #include "content/public/test/test_utils.h" | 52 #include "content/public/test/test_utils.h" |
53 #include "extensions/browser/api_test_utils.h" | 53 #include "extensions/browser/api_test_utils.h" |
54 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" | 54 #include "extensions/common/manifest_handlers/oauth2_manifest_handler.h" |
55 #include "extensions/common/test_util.h" | 55 #include "extensions/common/test_util.h" |
56 #include "google_apis/gaia/google_service_auth_error.h" | 56 #include "google_apis/gaia/google_service_auth_error.h" |
57 #include "google_apis/gaia/oauth2_mint_token_flow.h" | 57 #include "google_apis/gaia/oauth2_mint_token_flow.h" |
58 #include "net/test/spawned_test_server/spawned_test_server.h" | 58 #include "net/test/embedded_test_server/embedded_test_server.h" |
59 #include "testing/gmock/include/gmock/gmock.h" | 59 #include "testing/gmock/include/gmock/gmock.h" |
60 #include "testing/gtest/include/gtest/gtest.h" | 60 #include "testing/gtest/include/gtest/gtest.h" |
61 #include "url/gurl.h" | 61 #include "url/gurl.h" |
62 | 62 |
63 using guest_view::GuestViewBase; | 63 using guest_view::GuestViewBase; |
64 using testing::_; | 64 using testing::_; |
65 using testing::Return; | 65 using testing::Return; |
66 using testing::ReturnRef; | 66 using testing::ReturnRef; |
67 | 67 |
68 namespace extensions { | 68 namespace extensions { |
(...skipping 1705 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { | 1774 class LaunchWebAuthFlowFunctionTest : public AsyncExtensionBrowserTest { |
1775 public: | 1775 public: |
1776 void SetUpCommandLine(base::CommandLine* command_line) override { | 1776 void SetUpCommandLine(base::CommandLine* command_line) override { |
1777 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); | 1777 AsyncExtensionBrowserTest::SetUpCommandLine(command_line); |
1778 // Reduce performance test variance by disabling background networking. | 1778 // Reduce performance test variance by disabling background networking. |
1779 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); | 1779 command_line->AppendSwitch(switches::kDisableBackgroundNetworking); |
1780 } | 1780 } |
1781 }; | 1781 }; |
1782 | 1782 |
1783 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { | 1783 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, UserCloseWindow) { |
1784 net::SpawnedTestServer https_server( | 1784 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
1785 net::SpawnedTestServer::TYPE_HTTPS, | 1785 https_server.ServeFilesFromSourceDirectory( |
1786 net::SpawnedTestServer::kLocalhost, | 1786 "chrome/test/data/extensions/api_test/identity"); |
1787 base::FilePath(FILE_PATH_LITERAL( | |
1788 "chrome/test/data/extensions/api_test/identity"))); | |
1789 ASSERT_TRUE(https_server.Start()); | 1787 ASSERT_TRUE(https_server.Start()); |
1790 GURL auth_url(https_server.GetURL("files/interaction_required.html")); | 1788 GURL auth_url(https_server.GetURL("/interaction_required.html")); |
1791 | 1789 |
1792 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1790 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
1793 new IdentityLaunchWebAuthFlowFunction()); | 1791 new IdentityLaunchWebAuthFlowFunction()); |
1794 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1792 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
1795 function->set_extension(empty_extension.get()); | 1793 function->set_extension(empty_extension.get()); |
1796 | 1794 |
1797 WaitForGURLAndCloseWindow popup_observer(auth_url); | 1795 WaitForGURLAndCloseWindow popup_observer(auth_url); |
1798 | 1796 |
1799 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1797 std::string args = "[{\"interactive\": true, \"url\": \"" + |
1800 auth_url.spec() + "\"}]"; | 1798 auth_url.spec() + "\"}]"; |
1801 RunFunctionAsync(function.get(), args); | 1799 RunFunctionAsync(function.get(), args); |
1802 | 1800 |
1803 popup_observer.Wait(); | 1801 popup_observer.Wait(); |
1804 popup_observer.CloseEmbedderWebContents(); | 1802 popup_observer.CloseEmbedderWebContents(); |
1805 | 1803 |
1806 EXPECT_EQ(std::string(errors::kUserRejected), WaitForError(function.get())); | 1804 EXPECT_EQ(std::string(errors::kUserRejected), WaitForError(function.get())); |
1807 } | 1805 } |
1808 | 1806 |
1809 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { | 1807 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, InteractionRequired) { |
1810 net::SpawnedTestServer https_server( | 1808 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
1811 net::SpawnedTestServer::TYPE_HTTPS, | 1809 https_server.ServeFilesFromSourceDirectory( |
1812 net::SpawnedTestServer::kLocalhost, | 1810 "chrome/test/data/extensions/api_test/identity"); |
1813 base::FilePath(FILE_PATH_LITERAL( | |
1814 "chrome/test/data/extensions/api_test/identity"))); | |
1815 ASSERT_TRUE(https_server.Start()); | 1811 ASSERT_TRUE(https_server.Start()); |
1816 GURL auth_url(https_server.GetURL("files/interaction_required.html")); | 1812 GURL auth_url(https_server.GetURL("/interaction_required.html")); |
1817 | 1813 |
1818 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1814 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
1819 new IdentityLaunchWebAuthFlowFunction()); | 1815 new IdentityLaunchWebAuthFlowFunction()); |
1820 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1816 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
1821 function->set_extension(empty_extension.get()); | 1817 function->set_extension(empty_extension.get()); |
1822 | 1818 |
1823 std::string args = "[{\"interactive\": false, \"url\": \"" + | 1819 std::string args = "[{\"interactive\": false, \"url\": \"" + |
1824 auth_url.spec() + "\"}]"; | 1820 auth_url.spec() + "\"}]"; |
1825 std::string error = | 1821 std::string error = |
1826 utils::RunFunctionAndReturnError(function.get(), args, browser()); | 1822 utils::RunFunctionAndReturnError(function.get(), args, browser()); |
1827 | 1823 |
1828 EXPECT_EQ(std::string(errors::kInteractionRequired), error); | 1824 EXPECT_EQ(std::string(errors::kInteractionRequired), error); |
1829 } | 1825 } |
1830 | 1826 |
1831 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, LoadFailed) { | 1827 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, LoadFailed) { |
1832 net::SpawnedTestServer https_server( | 1828 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
1833 net::SpawnedTestServer::TYPE_HTTPS, | 1829 https_server.ServeFilesFromSourceDirectory( |
1834 net::SpawnedTestServer::kLocalhost, | 1830 "chrome/test/data/extensions/api_test/identity"); |
1835 base::FilePath(FILE_PATH_LITERAL( | |
1836 "chrome/test/data/extensions/api_test/identity"))); | |
1837 ASSERT_TRUE(https_server.Start()); | 1831 ASSERT_TRUE(https_server.Start()); |
1838 GURL auth_url(https_server.GetURL("files/five_hundred.html")); | 1832 GURL auth_url(https_server.GetURL("/five_hundred.html")); |
1839 | 1833 |
1840 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1834 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
1841 new IdentityLaunchWebAuthFlowFunction()); | 1835 new IdentityLaunchWebAuthFlowFunction()); |
1842 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1836 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
1843 function->set_extension(empty_extension.get()); | 1837 function->set_extension(empty_extension.get()); |
1844 | 1838 |
1845 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1839 std::string args = "[{\"interactive\": true, \"url\": \"" + |
1846 auth_url.spec() + "\"}]"; | 1840 auth_url.spec() + "\"}]"; |
1847 std::string error = | 1841 std::string error = |
1848 utils::RunFunctionAndReturnError(function.get(), args, browser()); | 1842 utils::RunFunctionAndReturnError(function.get(), args, browser()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 browser())); | 1892 browser())); |
1899 | 1893 |
1900 std::string url; | 1894 std::string url; |
1901 EXPECT_TRUE(value->GetAsString(&url)); | 1895 EXPECT_TRUE(value->GetAsString(&url)); |
1902 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1896 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1903 url); | 1897 url); |
1904 } | 1898 } |
1905 | 1899 |
1906 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, | 1900 IN_PROC_BROWSER_TEST_F(LaunchWebAuthFlowFunctionTest, |
1907 DISABLED_InteractiveSecondNavigationSuccess) { | 1901 DISABLED_InteractiveSecondNavigationSuccess) { |
1908 net::SpawnedTestServer https_server( | 1902 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
1909 net::SpawnedTestServer::TYPE_HTTPS, | 1903 https_server.ServeFilesFromSourceDirectory( |
1910 net::SpawnedTestServer::kLocalhost, | 1904 "chrome/test/data/extensions/api_test/identity"); |
1911 base::FilePath(FILE_PATH_LITERAL( | |
1912 "chrome/test/data/extensions/api_test/identity"))); | |
1913 ASSERT_TRUE(https_server.Start()); | 1905 ASSERT_TRUE(https_server.Start()); |
1914 GURL auth_url(https_server.GetURL("files/redirect_to_chromiumapp.html")); | 1906 GURL auth_url(https_server.GetURL("/redirect_to_chromiumapp.html")); |
1915 | 1907 |
1916 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( | 1908 scoped_refptr<IdentityLaunchWebAuthFlowFunction> function( |
1917 new IdentityLaunchWebAuthFlowFunction()); | 1909 new IdentityLaunchWebAuthFlowFunction()); |
1918 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); | 1910 scoped_refptr<Extension> empty_extension(test_util::CreateEmptyExtension()); |
1919 function->set_extension(empty_extension.get()); | 1911 function->set_extension(empty_extension.get()); |
1920 | 1912 |
1921 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); | 1913 function->InitFinalRedirectURLPrefixForTest("abcdefghij"); |
1922 std::string args = "[{\"interactive\": true, \"url\": \"" + | 1914 std::string args = "[{\"interactive\": true, \"url\": \"" + |
1923 auth_url.spec() + "\"}]"; | 1915 auth_url.spec() + "\"}]"; |
1924 scoped_ptr<base::Value> value( | 1916 scoped_ptr<base::Value> value( |
1925 utils::RunFunctionAndReturnSingleResult(function.get(), args, browser())); | 1917 utils::RunFunctionAndReturnSingleResult(function.get(), args, browser())); |
1926 | 1918 |
1927 std::string url; | 1919 std::string url; |
1928 EXPECT_TRUE(value->GetAsString(&url)); | 1920 EXPECT_TRUE(value->GetAsString(&url)); |
1929 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), | 1921 EXPECT_EQ(std::string("https://abcdefghij.chromiumapp.org/callback#test"), |
1930 url); | 1922 url); |
1931 } | 1923 } |
1932 | 1924 |
1933 } // namespace extensions | 1925 } // namespace extensions |
1934 | 1926 |
1935 // Tests the chrome.identity API implemented by custom JS bindings . | 1927 // Tests the chrome.identity API implemented by custom JS bindings . |
1936 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { | 1928 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeIdentityJsBindings) { |
1937 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; | 1929 ASSERT_TRUE(RunExtensionTest("identity/js_bindings")) << message_; |
1938 } | 1930 } |
OLD | NEW |