This source file includes following definitions.
- SetUpCommandLine
- SetUp
- TearDown
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- DidCommitProvisionalLoadForFrame
- IN_PROC_BROWSER_TEST_F
#ifndef CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_
#define CHROME_BROWSER_SIGNIN_SIGNIN_BROWSERTEST_H_
#include "base/command_line.h"
#include "chrome/browser/signin/chrome_signin_client.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_switches.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/http/http_status_code.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_request_status.h"
namespace {
const char kNonSigninURL[] = "www.google.com";
}
class SigninBrowserTest : public InProcessBrowserTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
https_server_.reset(new net::SpawnedTestServer(
net::SpawnedTestServer::TYPE_HTTPS,
net::SpawnedTestServer::kLocalhost,
base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))));
ASSERT_TRUE(https_server_->Start());
command_line->AppendSwitchASCII(
switches::kHostResolverRules,
"MAP * " + https_server_->host_port_pair().ToString() +
",EXCLUDE localhost");
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
command_line->AppendSwitch(switches::kEnableWebBasedSignin);
}
virtual void SetUp() OVERRIDE {
factory_.reset(new net::URLFetcherImplFactory());
fake_factory_.reset(new net::FakeURLFetcherFactory(factory_.get()));
fake_factory_->SetFakeResponse(
GaiaUrls::GetInstance()->service_login_url(), std::string(),
net::HTTP_OK, net::URLRequestStatus::SUCCESS);
fake_factory_->SetFakeResponse(
GURL(kNonSigninURL), std::string(), net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
InProcessBrowserTest::SetUp();
}
virtual void TearDown() OVERRIDE {
if (fake_factory_.get()) {
fake_factory_->ClearFakeResponses();
fake_factory_.reset();
}
net::URLFetcher::CancelAll();
factory_.reset();
InProcessBrowserTest::TearDown();
}
private:
scoped_ptr<net::FakeURLFetcherFactory> fake_factory_;
scoped_ptr<net::URLFetcherImplFactory> factory_;
scoped_ptr<net::SpawnedTestServer> https_server_;
};
#if defined(ENABLE_ONE_CLICK_SIGNIN)
const bool kOneClickSigninEnabled = true;
#else
const bool kOneClickSigninEnabled = false;
#endif
#if defined(OS_WIN)
#define MAYBE_ProcessIsolation DISABLED_ProcessIsolation
#else
#define MAYBE_ProcessIsolation ProcessIsolation
#endif
IN_PROC_BROWSER_TEST_F(SigninBrowserTest, MAYBE_ProcessIsolation) {
ChromeSigninClient* signin =
ChromeSigninClientFactory::GetForProfile(browser()->profile());
EXPECT_FALSE(signin->HasSigninProcess());
ui_test_utils::NavigateToURL(browser(), signin::GetPromoURL(
signin::SOURCE_NTP_LINK, true));
EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess());
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIOmniboxURL));
EXPECT_FALSE(signin->HasSigninProcess());
ui_test_utils::NavigateToURL(browser(), signin::GetPromoURL(
signin::SOURCE_NTP_LINK, true));
EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess());
content::WebContents* active_tab =
browser()->tab_strip_model()->GetActiveWebContents();
int active_tab_process_id =
active_tab->GetRenderProcessHost()->GetID();
EXPECT_EQ(kOneClickSigninEnabled,
signin->IsSigninProcess(active_tab_process_id));
EXPECT_EQ(0, active_tab->GetRenderViewHost()->GetEnabledBindings());
chrome::NavigateParams params(chrome::GetSingletonTabNavigateParams(
browser(),
GURL(signin::GetPromoURL(signin::SOURCE_NTP_LINK, false))));
params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
ShowSingletonTabOverwritingNTP(browser(), params);
EXPECT_EQ(active_tab, browser()->tab_strip_model()->GetActiveWebContents());
EXPECT_EQ(kOneClickSigninEnabled,
signin->IsSigninProcess(active_tab_process_id));
ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
EXPECT_FALSE(signin->IsSigninProcess(
active_tab->GetRenderProcessHost()->GetID()));
}
IN_PROC_BROWSER_TEST_F(SigninBrowserTest, NotTrustedAfterRedirect) {
ChromeSigninClient* signin =
ChromeSigninClientFactory::GetForProfile(browser()->profile());
EXPECT_FALSE(signin->HasSigninProcess());
GURL url = signin::GetPromoURL(signin::SOURCE_NTP_LINK, true);
ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess());
ui_test_utils::NavigateToURLWithDisposition(
browser(), GURL(kNonSigninURL), NEW_BACKGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess());
GURL redirect_url("https://accounts.google.com/server-redirect?"
"https://foo.com?service=chromiumsync");
ui_test_utils::NavigateToURL(browser(), redirect_url);
EXPECT_FALSE(signin->HasSigninProcess());
}
class BackOnNTPCommitObserver : public content::WebContentsObserver {
public:
explicit BackOnNTPCommitObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
}
virtual void DidCommitProvisionalLoadForFrame(
int64 frame_id,
const base::string16& frame_unique_name,
bool is_main_frame,
const GURL& url,
content::PageTransition transition_type,
content::RenderViewHost* render_view_host) OVERRIDE {
if (url == GURL(chrome::kChromeUINewTabURL) ||
url == GURL(chrome::kChromeSearchLocalNtpUrl)) {
content::WindowedNotificationObserver observer(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
web_contents()->GetController().GoBack();
observer.Wait();
}
}
private:
DISALLOW_COPY_AND_ASSIGN(BackOnNTPCommitObserver);
};
IN_PROC_BROWSER_TEST_F(SigninBrowserTest, SigninSkipForNowAndGoBack) {
GURL ntp_url(chrome::kChromeUINewTabURL);
GURL start_url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false);
GURL skip_url = signin::GetLandingURL("ntp", 1);
ChromeSigninClient* signin =
ChromeSigninClientFactory::GetForProfile(browser()->profile());
EXPECT_FALSE(signin->HasSigninProcess());
ui_test_utils::NavigateToURL(browser(), start_url);
EXPECT_EQ(kOneClickSigninEnabled, signin->HasSigninProcess());
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
chrome::NavigateParams navigate_params(browser(),
skip_url,
content::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&navigate_params);
BackOnNTPCommitObserver commit_observer(web_contents);
EXPECT_EQ(skip_url, web_contents->GetLastCommittedURL());
EXPECT_EQ(start_url, web_contents->GetVisibleURL());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
observer.Wait();
EXPECT_EQ(start_url, web_contents->GetLastCommittedURL());
}
#endif