Commit a6b95784 authored by bartfab@chromium.org's avatar bartfab@chromium.org

Fix race in locale changes during DeviceLocalAccountTest

OOBE shows the network selection screen first. This screen will change
the application locale when it finishes loading and once again when it
loses focus.

This CL ensures that tests wait until both events have happened before
proceeding so that locale switches initiated by the network selection
screen do not interfere with the locale switching code that is actually
under test.

BUG=214904,241790
TEST=DeviceLocalAccountTest.SelectLanguageAndKeyboardWithTermsOfService
R=pneubeck@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287350 0039d316-1c4b-4281-b951-d872f2087c98
parent 4753b9ec
...@@ -482,6 +482,19 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, ...@@ -482,6 +482,19 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait(); base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait();
} }
void GetWebContents(content::WebContents** contents) {
chromeos::LoginDisplayHostImpl* host =
reinterpret_cast<chromeos::LoginDisplayHostImpl*>(
chromeos::LoginDisplayHostImpl::default_host());
ASSERT_TRUE(host);
chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(web_ui_login_view);
content::WebUI* web_ui = web_ui_login_view->GetWebUI();
ASSERT_TRUE(web_ui);
*contents = web_ui->GetWebContents();
ASSERT_TRUE(*contents);
}
void WaitForLoginUI() { void WaitForLoginUI() {
// Wait for the login UI to be ready. // Wait for the login UI to be ready.
chromeos::LoginDisplayHostImpl* host = chromeos::LoginDisplayHostImpl* host =
...@@ -494,6 +507,26 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, ...@@ -494,6 +507,26 @@ class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest,
const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure()); const bool oobe_ui_ready = oobe_ui->IsJSReady(run_loop.QuitClosure());
if (!oobe_ui_ready) if (!oobe_ui_ready)
run_loop.Run(); run_loop.Run();
// The network selection screen changes the application locale on load and
// once again on blur. Wait for the screen to load and blur it so that any
// locale changes caused by this screen happen now and do not affect any
// subsequent parts of the test.
content::WebContents* contents = NULL;
ASSERT_NO_FATAL_FAILURE(GetWebContents(&contents));
bool done = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
contents,
"var languageSelect = document.getElementById('language-select');"
"var blurAndReportSuccess = function() {"
" languageSelect.blur();"
" domAutomationController.send(true);"
"};"
"if (document.activeElement == languageSelect)"
" blurAndReportSuccess();"
"else"
" languageSelect.addEventListener('focus', blurAndReportSuccess);",
&done));
} }
void StartLogin(const std::string& locale, void StartLogin(const std::string& locale,
...@@ -1244,16 +1277,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ...@@ -1244,16 +1277,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest,
wizard_controller->current_screen()->GetName()); wizard_controller->current_screen()->GetName());
// Wait for the Terms of Service to finish downloading. // Wait for the Terms of Service to finish downloading.
chromeos::LoginDisplayHostImpl* host = content::WebContents* contents = NULL;
reinterpret_cast<chromeos::LoginDisplayHostImpl*>( ASSERT_NO_FATAL_FAILURE(GetWebContents(&contents));
chromeos::LoginDisplayHostImpl::default_host());
ASSERT_TRUE(host);
chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(web_ui_login_view);
content::WebUI* web_ui = web_ui_login_view->GetWebUI();
ASSERT_TRUE(web_ui);
content::WebContents* contents = web_ui->GetWebContents();
ASSERT_TRUE(contents);
bool done = false; bool done = false;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(contents, ASSERT_TRUE(content::ExecuteScriptAndExtractBool(contents,
"var screenElement = document.getElementById('terms-of-service');" "var screenElement = document.getElementById('terms-of-service');"
...@@ -1334,16 +1359,8 @@ IN_PROC_BROWSER_TEST_P(TermsOfServiceDownloadTest, TermsOfServiceScreen) { ...@@ -1334,16 +1359,8 @@ IN_PROC_BROWSER_TEST_P(TermsOfServiceDownloadTest, TermsOfServiceScreen) {
// Wait for the Terms of Service to finish downloading, then get the status of // Wait for the Terms of Service to finish downloading, then get the status of
// the screen's UI elements. // the screen's UI elements.
chromeos::LoginDisplayHostImpl* host = content::WebContents* contents = NULL;
reinterpret_cast<chromeos::LoginDisplayHostImpl*>( ASSERT_NO_FATAL_FAILURE(GetWebContents(&contents));
chromeos::LoginDisplayHostImpl::default_host());
ASSERT_TRUE(host);
chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView();
ASSERT_TRUE(web_ui_login_view);
content::WebUI* web_ui = web_ui_login_view->GetWebUI();
ASSERT_TRUE(web_ui);
content::WebContents* contents = web_ui->GetWebContents();
ASSERT_TRUE(contents);
std::string json; std::string json;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents, ASSERT_TRUE(content::ExecuteScriptAndExtractString(contents,
"var screenElement = document.getElementById('terms-of-service');" "var screenElement = document.getElementById('terms-of-service');"
......
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