| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
| 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
| 7 | 7 |
| 8 #include "base/command_line.h" |
| 8 #include "chrome/browser/signin/signin_manager.h" | 9 #include "chrome/browser/signin/signin_manager.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/singleton_tabs.h" | 12 #include "chrome/browser/ui/singleton_tabs.h" |
| 12 #include "chrome/browser/ui/sync/sync_promo_ui.h" | 13 #include "chrome/browser/ui/sync/sync_promo_ui.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/content_switches.h" |
| 22 #include "google_apis/gaia/gaia_urls.h" | 24 #include "google_apis/gaia/gaia_urls.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 25 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 const char kNonSigninURL[] = "www.google.com"; | 28 const char kNonSigninURL[] = "www.google.com"; |
| 27 } | 29 } |
| 28 | 30 |
| 29 class SigninBrowserTest : public InProcessBrowserTest { | 31 class SigninBrowserTest : public InProcessBrowserTest { |
| 30 public: | 32 public: |
| 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 34 https_server_.reset(new net::SpawnedTestServer( |
| 35 net::SpawnedTestServer::TYPE_HTTPS, |
| 36 net::SpawnedTestServer::kLocalhost, |
| 37 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")))); |
| 38 ASSERT_TRUE(https_server_->Start()); |
| 39 |
| 40 // Add a host resolver rule to map all outgoing requests to the test server. |
| 41 // This allows us to use "real" hostnames in URLs, which we can use to |
| 42 // create arbitrary SiteInstances. |
| 43 command_line->AppendSwitchASCII( |
| 44 switches::kHostResolverRules, |
| 45 "MAP * " + https_server_->host_port_pair().ToString() + |
| 46 ",EXCLUDE localhost"); |
| 47 command_line->AppendSwitch(switches::kIgnoreCertificateErrors); |
| 48 } |
| 49 |
| 31 virtual void SetUp() OVERRIDE { | 50 virtual void SetUp() OVERRIDE { |
| 32 factory_.reset(new net::URLFetcherImplFactory()); | 51 factory_.reset(new net::URLFetcherImplFactory()); |
| 33 fake_factory_.reset(new net::FakeURLFetcherFactory(factory_.get())); | 52 fake_factory_.reset(new net::FakeURLFetcherFactory(factory_.get())); |
| 34 fake_factory_->SetFakeResponse( | 53 fake_factory_->SetFakeResponse( |
| 35 GaiaUrls::GetInstance()->service_login_url(), | 54 GaiaUrls::GetInstance()->service_login_url(), |
| 36 std::string(), | 55 std::string(), |
| 37 true); | 56 true); |
| 38 fake_factory_->SetFakeResponse(kNonSigninURL, std::string(), true); | 57 fake_factory_->SetFakeResponse(kNonSigninURL, std::string(), true); |
| 39 // Yield control back to the InProcessBrowserTest framework. | 58 // Yield control back to the InProcessBrowserTest framework. |
| 40 InProcessBrowserTest::SetUp(); | 59 InProcessBrowserTest::SetUp(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 factory_.reset(); | 71 factory_.reset(); |
| 53 InProcessBrowserTest::TearDown(); | 72 InProcessBrowserTest::TearDown(); |
| 54 } | 73 } |
| 55 | 74 |
| 56 private: | 75 private: |
| 57 // Fake URLFetcher factory used to mock out GAIA signin. | 76 // Fake URLFetcher factory used to mock out GAIA signin. |
| 58 scoped_ptr<net::FakeURLFetcherFactory> fake_factory_; | 77 scoped_ptr<net::FakeURLFetcherFactory> fake_factory_; |
| 59 | 78 |
| 60 // The URLFetcherImplFactory instance used to instantiate |fake_factory_|. | 79 // The URLFetcherImplFactory instance used to instantiate |fake_factory_|. |
| 61 scoped_ptr<net::URLFetcherImplFactory> factory_; | 80 scoped_ptr<net::URLFetcherImplFactory> factory_; |
| 81 |
| 82 scoped_ptr<net::SpawnedTestServer> https_server_; |
| 62 }; | 83 }; |
| 63 | 84 |
| 85 // If the one-click-signin feature is not enabled (e.g Chrome OS), we |
| 86 // never grant signin privileges to any renderer processes. |
| 87 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 88 const bool kOneClickSigninEnabled = true; |
| 89 #else |
| 90 const bool kOneClickSigninEnabled = false; |
| 91 #endif |
| 92 |
| 64 // Disabled on Windows due to flakiness. http://crbug.com/249055 | 93 // Disabled on Windows due to flakiness. http://crbug.com/249055 |
| 65 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
| 66 #define MAYBE_ProcessIsolation DISABLED_ProcessIsolation | 95 #define MAYBE_ProcessIsolation DISABLED_ProcessIsolation |
| 67 #else | 96 #else |
| 68 #define MAYBE_ProcessIsolation ProcessIsolation | 97 #define MAYBE_ProcessIsolation ProcessIsolation |
| 69 #endif | 98 #endif |
| 70 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, MAYBE_ProcessIsolation) { | 99 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, MAYBE_ProcessIsolation) { |
| 71 // If the one-click-signin feature is not enabled (e.g Chrome OS), we | |
| 72 // never grant signin privileges to any renderer processes. | |
| 73 #if defined(ENABLE_ONE_CLICK_SIGNIN) | |
| 74 const bool kOneClickSigninEnabled = true; | |
| 75 #else | |
| 76 const bool kOneClickSigninEnabled = false; | |
| 77 #endif | |
| 78 | |
| 79 SigninManager* signin = SigninManagerFactory::GetForProfile( | 100 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 80 browser()->profile()); | 101 browser()->profile()); |
| 81 EXPECT_FALSE(signin->HasSigninProcess()); | 102 EXPECT_FALSE(signin->HasSigninProcess()); |
| 82 | 103 |
| 83 ui_test_utils::NavigateToURL(browser(), SyncPromoUI::GetSyncPromoURL( | 104 ui_test_utils::NavigateToURL(browser(), SyncPromoUI::GetSyncPromoURL( |
| 84 SyncPromoUI::SOURCE_NTP_LINK, true)); | 105 SyncPromoUI::SOURCE_NTP_LINK, true)); |
| 85 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); | 106 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); |
| 86 | 107 |
| 87 // Navigating away should change the process. | 108 // Navigating away should change the process. |
| 88 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 109 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 111 EXPECT_EQ(active_tab, browser()->tab_strip_model()->GetActiveWebContents()); | 132 EXPECT_EQ(active_tab, browser()->tab_strip_model()->GetActiveWebContents()); |
| 112 EXPECT_EQ(kOneClickSigninEnabled, | 133 EXPECT_EQ(kOneClickSigninEnabled, |
| 113 signin->IsSigninProcess(active_tab_process_id)); | 134 signin->IsSigninProcess(active_tab_process_id)); |
| 114 | 135 |
| 115 // Navigating away should change the process. | 136 // Navigating away should change the process. |
| 116 ui_test_utils::NavigateToURL(browser(), GURL(kNonSigninURL)); | 137 ui_test_utils::NavigateToURL(browser(), GURL(kNonSigninURL)); |
| 117 EXPECT_FALSE(signin->IsSigninProcess( | 138 EXPECT_FALSE(signin->IsSigninProcess( |
| 118 active_tab->GetRenderProcessHost()->GetID())); | 139 active_tab->GetRenderProcessHost()->GetID())); |
| 119 } | 140 } |
| 120 | 141 |
| 142 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, NotTrustedAfterRedirect) { |
| 143 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 144 browser()->profile()); |
| 145 EXPECT_FALSE(signin->HasSigninProcess()); |
| 146 |
| 147 GURL url = SyncPromoUI::GetSyncPromoURL(SyncPromoUI::SOURCE_NTP_LINK, true); |
| 148 ui_test_utils::NavigateToURL(browser(), url); |
| 149 EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess()); |
| 150 |
| 151 // Navigating away should change the process. |
| 152 GURL redirect_url("https://accounts.google.com/server-redirect?" |
| 153 "https://foo.com?service=chromiumsync"); |
| 154 ui_test_utils::NavigateToURL(browser(), redirect_url); |
| 155 EXPECT_FALSE(signin->HasSigninProcess()); |
| 156 } |
| 157 |
| 121 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | 158 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ |
| OLD | NEW |