Commit 102fd46d authored by shadi's avatar shadi Committed by Commit bot

Enable new sign in flow for E2E tests.

There are multiple possible login pages based on the Gaia server version
we hit in the E2E tests.

This change should not affect existing tests on the waterfall.

BUG=477157

Review URL: https://codereview.chromium.org/1102603003

Cr-Commit-Position: refs/heads/master@{#327133}
parent 17415122
...@@ -84,30 +84,87 @@ class SignInObserver : public SigninTracker::Observer { ...@@ -84,30 +84,87 @@ class SignInObserver : public SigninTracker::Observer {
namespace login_ui_test_utils { namespace login_ui_test_utils {
void WaitUntilUIReady(Browser* browser) { void WaitUntilUIReady(Browser* browser) {
content::DOMMessageQueue message_queue; std::string message;
ASSERT_TRUE(content::ExecuteScript( ASSERT_TRUE(content::ExecuteScriptAndExtractString(
browser->tab_strip_model()->GetActiveWebContents(), browser->tab_strip_model()->GetActiveWebContents(),
"if (!inline.login.getAuthExtHost())" "if (!inline.login.getAuthExtHost())"
" inline.login.initialize();" " inline.login.initialize();"
"var handler = function() {" "var handler = function() {"
" window.domAutomationController.setAutomationId(0);"
" window.domAutomationController.send('ready');" " window.domAutomationController.send('ready');"
"};" "};"
"if (inline.login.isAuthReady())" "if (inline.login.isAuthReady())"
" handler();" " handler();"
"else" "else"
" inline.login.getAuthExtHost().addEventListener('ready', handler);")); " inline.login.getAuthExtHost().addEventListener('ready', handler);",
&message));
ASSERT_EQ("ready", message);
}
void WaitUntilElementExistsInSigninFrame(Browser* browser,
const std::string& element_id) {
std::string message; std::string message;
do { std::string js =
ASSERT_TRUE(message_queue.WaitForMessage(&message)); "function WaitForElementById(elementId) {"
} while (message != "\"ready\""); " var retries = 10; /* 10 seconds. */"
" function CheckelementExists() {"
" if (document.getElementById(elementId) != null) {"
" window.domAutomationController.send('found');"
" } else if (retries > 0) { "
" retries--;"
" window.setTimeout(CheckelementExists, 1000);"
" } else {"
" window.domAutomationController.send('failed');"
" }"
" }"
" CheckelementExists();"
"}"
"WaitForElementById('" + element_id + "');";
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
InlineLoginUI::GetAuthFrame(web_contents, GURL(), "signin-frame"),
js, &message));
ASSERT_EQ("found", message) <<
"Failed to find element with id " << element_id;
} }
void ExecuteJsToSigninInSigninFrame(Browser* browser, bool ElementExistsInSigninFrame(Browser* browser,
const std::string& email, const std::string& element_id) {
const std::string& password) { content::WebContents* web_contents =
std::string js = browser->tab_strip_model()->GetActiveWebContents();
bool result = false;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
InlineLoginUI::GetAuthFrame(web_contents, GURL(), "signin-frame"),
"window.domAutomationController.send("
" document.getElementById('" + element_id + "') != null);",
&result));
return result;
}
void SigninInNewGaiaFlow(Browser* browser,
const std::string& email,
const std::string& password) {
std::string js = "document.getElementById('Email').value = '" + email + "';"
"document.getElementById('next').click();";
content::WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthFrame(
web_contents, GURL(), "signin-frame"), js));
WaitUntilElementExistsInSigninFrame(browser, "Passwd");
js = "document.getElementById('Passwd').value = '" + password + "';"
"document.getElementById('signIn').click();";
ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthFrame(
web_contents, GURL(), "signin-frame"), js));
}
void SigninInOldGaiaFlow(Browser* browser,
const std::string& email,
const std::string& password) {
std::string js =
"document.getElementById('Email').value = '" + email + "';" "document.getElementById('Email').value = '" + email + "';"
"document.getElementById('Passwd').value = '" + password + "';" "document.getElementById('Passwd').value = '" + password + "';"
"document.getElementById('signIn').click();"; "document.getElementById('signIn').click();";
...@@ -118,6 +175,16 @@ void ExecuteJsToSigninInSigninFrame(Browser* browser, ...@@ -118,6 +175,16 @@ void ExecuteJsToSigninInSigninFrame(Browser* browser,
web_contents, GURL(), "signin-frame"), js)); web_contents, GURL(), "signin-frame"), js));
} }
void ExecuteJsToSigninInSigninFrame(Browser* browser,
const std::string& email,
const std::string& password) {
WaitUntilElementExistsInSigninFrame(browser, "Email");
if (ElementExistsInSigninFrame(browser, "next"))
SigninInNewGaiaFlow(browser, email, password);
else
SigninInOldGaiaFlow(browser, email, password);
}
bool SignInWithUI(Browser* browser, bool SignInWithUI(Browser* browser,
const std::string& username, const std::string& username,
const std::string& password) { const std::string& password) {
......
...@@ -14,12 +14,31 @@ namespace login_ui_test_utils { ...@@ -14,12 +14,31 @@ namespace login_ui_test_utils {
// Blocks until the login UI is available and ready for authorization. // Blocks until the login UI is available and ready for authorization.
void WaitUntilUIReady(Browser* browser); void WaitUntilUIReady(Browser* browser);
// Blocks until an element with id |element_id| exists in the signin page.
void WaitUntilElementExistsInSigninFrame(Browser* browser,
const std::string& element_id);
// Returns whether an element with id |element_id| exists in the signin page.
bool ElementExistsInSigninFrame(Browser* browser,
const std::string& element_id);
// Executes JavaScript code to sign in a user with email and password to the // Executes JavaScript code to sign in a user with email and password to the
// auth iframe hosted by gaia_auth extension. // auth iframe hosted by gaia_auth extension. This function automatically
// detects the version of GAIA sign in page to use.
void ExecuteJsToSigninInSigninFrame(Browser* browser, void ExecuteJsToSigninInSigninFrame(Browser* browser,
const std::string& email, const std::string& email,
const std::string& password); const std::string& password);
// Executes JS to sign in the user in the new GAIA sign in flow.
void SigninInNewGaiaFlow(Browser* browser,
const std::string& email,
const std::string& password);
// Executes JS to sign in the user in the old GAIA sign in flow.
void SigninInOldGaiaFlow(Browser* browser,
const std::string& email,
const std::string& password);
// A function to sign in a user using Chrome sign-in UI interface. // A function to sign in a user using Chrome sign-in UI interface.
// This will block until a signin succeeded or failed notification is observed. // This will block until a signin succeeded or failed notification is observed.
bool SignInWithUI(Browser* browser, bool SignInWithUI(Browser* browser,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment