Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | |
| 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | |
| 7 | |
| 8 #include "chrome/browser/signin/signin_manager.h" | |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 12 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
| 14 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "chrome/test/base/in_process_browser_test.h" | |
| 17 #include "chrome/test/base/ui_test_utils.h" | |
| 18 #include "content/public/browser/render_process_host.h" | |
| 19 #include "content/public/browser/web_contents.h" | |
| 20 #include "google_apis/gaia/gaia_urls.h" | |
| 21 #include "net/url_request/test_url_fetcher_factory.h" | |
| 22 | |
| 23 namespace { | |
| 24 const char kNonSigninURL[] = "www.google.com"; | |
| 25 } | |
| 26 | |
| 27 class SigninBrowserTest : public InProcessBrowserTest { | |
| 28 public: | |
| 29 virtual void SetUp() OVERRIDE { | |
| 30 factory_.reset(new net::URLFetcherImplFactory()); | |
| 31 fake_factory_.reset(new net::FakeURLFetcherFactory(factory_.get())); | |
| 32 fake_factory_->SetFakeResponse( | |
| 33 GaiaUrls::GetInstance()->service_login_url(), | |
| 34 std::string(), | |
| 35 true); | |
| 36 fake_factory_->SetFakeResponse(kNonSigninURL, std::string(), true); | |
| 37 // Yield control back to the InProcessBrowserTest framework. | |
| 38 InProcessBrowserTest::SetUp(); | |
| 39 } | |
| 40 | |
| 41 virtual void TearDown() OVERRIDE { | |
| 42 if (fake_factory_.get()) { | |
| 43 fake_factory_->ClearFakeResponses(); | |
| 44 fake_factory_.reset(); | |
| 45 } | |
| 46 | |
| 47 // Cancel any outstanding URL fetches and destroy the URLFetcherImplFactory | |
| 48 // we created. | |
| 49 net::URLFetcher::CancelAll(); | |
| 50 factory_.reset(); | |
| 51 InProcessBrowserTest::TearDown(); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 // Fake URLFetcher factory used to mock out GAIA signin. | |
| 56 scoped_ptr<net::FakeURLFetcherFactory> fake_factory_; | |
| 57 | |
| 58 // The URLFetcherImplFactory instance used to instantiate |fake_factory_|. | |
| 59 scoped_ptr<net::URLFetcherImplFactory> factory_; | |
| 60 }; | |
| 61 | |
| 62 IN_PROC_BROWSER_TEST_F(SigninBrowserTest, ProcessIsolation) { | |
| 63 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
| 64 browser()->profile()); | |
| 65 EXPECT_FALSE(signin->HasSigninProcess()); | |
| 66 | |
| 67 // Starting from about:blank (or any normal renderer) won't result in us | |
| 68 // granting "signin" privileges to the process, because it is treated just | |
| 69 // as a normal navigation to that URL and normal renderers are suitable | |
| 70 // hosts. | |
| 71 ui_test_utils::NavigateToURL(browser(), SyncPromoUI::GetSyncPromoURL( | |
| 72 GURL(), SyncPromoUI::SOURCE_NTP_LINK, true)); | |
|
Charlie Reis
2013/03/04 19:22:24
nit: wrong indent
tim (not reviewing)
2013/03/04 23:40:19
Done.
| |
| 73 EXPECT_FALSE(signin->HasSigninProcess()); | |
| 74 | |
| 75 // A "privileged" signin renderer will only be created if the navigation | |
| 76 // is programatically initiated in a brand new tab or in a tab with an | |
| 77 // unsuitable host, such as a WebUI tab hosting the new tab page. | |
|
Charlie Reis
2013/03/04 19:22:24
I don't understand what this means. Won't we alwa
| |
| 78 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | |
| 79 EXPECT_FALSE(signin->HasSigninProcess()); | |
| 80 | |
| 81 ui_test_utils::NavigateToURL(browser(), SyncPromoUI::GetSyncPromoURL( | |
| 82 GURL(), SyncPromoUI::SOURCE_NTP_LINK, true)); | |
| 83 EXPECT_TRUE(signin->HasSigninProcess()); | |
| 84 | |
| 85 content::WebContents* active_tab = | |
| 86 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 87 int active_tab_process_id = | |
| 88 active_tab->GetRenderProcessHost()->GetID(); | |
| 89 EXPECT_TRUE(signin->IsSigninProcess(active_tab_process_id)); | |
|
Charlie Reis
2013/03/04 19:22:24
Can you add this line to verify that it doesn't ha
tim (not reviewing)
2013/03/04 23:40:19
Done.
| |
| 90 | |
| 91 // Entry points to signin request "SINGLETON_TAB" mode, so a new request | |
| 92 // shouldn't change anything. | |
| 93 LoginUIService* login = LoginUIServiceFactory::GetForProfile( | |
| 94 browser()->profile()); | |
| 95 login->ShowLoginPopup(); | |
| 96 EXPECT_EQ(active_tab, browser()->tab_strip_model()->GetActiveWebContents()); | |
| 97 EXPECT_TRUE(signin->IsSigninProcess(active_tab_process_id)); | |
| 98 | |
| 99 // Navigating away should change the process. | |
| 100 ui_test_utils::NavigateToURL(browser(), GURL(kNonSigninURL)); | |
| 101 EXPECT_FALSE(signin->IsSigninProcess( | |
| 102 active_tab->GetRenderProcessHost()->GetID())); | |
| 103 } | |
| 104 | |
| 105 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_ | |
| OLD | NEW |