| Index: chrome/browser/ui/webui/signin/login_ui_test_utils.cc
|
| diff --git a/chrome/browser/ui/webui/signin/login_ui_test_utils.cc b/chrome/browser/ui/webui/signin/login_ui_test_utils.cc
|
| index 7f5e2bfd5c25cbe19b176f0b25d2fffd74b77dd6..c5dde136ec5dbf03543a1572ba35fc411654a207 100644
|
| --- a/chrome/browser/ui/webui/signin/login_ui_test_utils.cc
|
| +++ b/chrome/browser/ui/webui/signin/login_ui_test_utils.cc
|
| @@ -104,10 +104,83 @@ void WaitUntilUIReady(Browser* browser) {
|
| } while (message != "\"ready\"");
|
| }
|
|
|
| -void ExecuteJsToSigninInSigninFrame(Browser* browser,
|
| - const std::string& email,
|
| - const std::string& password) {
|
| - std::string js =
|
| +void WaitUntilElementExistsInSigninFrame(Browser* browser,
|
| + const std::string& element_id) {
|
| + content::DOMMessageQueue message_queue;
|
| + std::string js =
|
| + "function WaitForElementById(elementId) {"
|
| + " var retries = 10; /* 10 seconds. */"
|
| + " function CheckelementExists() {"
|
| + " if (document.getElementById(elementId) != null) {"
|
| + " window.domAutomationController.setAutomationId(0);"
|
| + " window.domAutomationController.send('found');"
|
| + " } else if (retries > 0) { "
|
| + " retries--;"
|
| + " window.setTimeout(CheckelementExists, 1000);"
|
| + " } else {"
|
| + " window.domAutomationController.setAutomationId(0);"
|
| + " window.domAutomationController.send('failed');"
|
| + " }"
|
| + " }"
|
| + " CheckelementExists();"
|
| + "}"
|
| + "WaitForElementById('" + element_id + "');";
|
| + content::WebContents* web_contents =
|
| + browser->tab_strip_model()->GetActiveWebContents();
|
| + ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthFrame(
|
| + web_contents, GURL(), "signin-frame"), js));
|
| +
|
| + std::string message;
|
| + do {
|
| + ASSERT_TRUE(message_queue.WaitForMessage(&message));
|
| + if (message == "\"failed\"")
|
| + LOG(ERROR) << "Failed to find element with id " << element_id;
|
| + } while (message != "\"found\"");
|
| +}
|
| +
|
| +bool ElementExistsInSigninFrame(Browser* browser,
|
| + const std::string& element_id) {
|
| + content::DOMMessageQueue message_queue;
|
| + std::string js =
|
| + "window.domAutomationController.setAutomationId(0);"
|
| + "if (document.getElementById('" + element_id + "') != null) {"
|
| + " window.domAutomationController.send('found');"
|
| + "} else { "
|
| + " window.domAutomationController.send('not found');"
|
| + "}";
|
| + content::WebContents* web_contents =
|
| + browser->tab_strip_model()->GetActiveWebContents();
|
| + EXPECT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthFrame(
|
| + web_contents, GURL(), "signin-frame"), js));
|
| +
|
| + std::string message;
|
| + EXPECT_TRUE(message_queue.WaitForMessage(&message));
|
| + return message == "\"found\"";
|
| +}
|
| +
|
| +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('Passwd').value = '" + password + "';"
|
| "document.getElementById('signIn').click();";
|
| @@ -118,6 +191,16 @@ void ExecuteJsToSigninInSigninFrame(Browser* browser,
|
| 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,
|
| const std::string& username,
|
| const std::string& password) {
|
|
|