Commit d5f0058a authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Fix and re-enable browser_tests SetTimeDialogBrowserTest.All

The test failures were caused by a real bug. For the set-time-dialog
element, the keys of the prevValues_ object are HTML element IDs
("dateInput" and "timeInput"), not "date" and "time". I broke this
when I changed the element IDs during the Material Design conversion
of this dialog in March 2019.

The failures were flaky because we didn't have an explicit test for
reverting the input elements to their previous values. The occasional
failures we say were due to element blur() events during test teardown
that apparently depend on timing.

Fix the bug and add an explicit test for reverting values.

Bug: 996000
Test: browser_tests

Change-Id: Ic0a286858e0563d32351da06536c881e541b1273
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1773541
Commit-Queue: James Cook <jamescook@chromium.org>
Auto-Submit: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690921}
parent 4ef7a591
......@@ -159,10 +159,11 @@ Polymer({
},
/**
* Values for reverting inputs when the user's date/time is invalid.
* @private {?Object}
* Values for reverting inputs when the user's date/time is invalid. The
* keys are element ids.
* @private {{dateInput: string, timeInput: string}}
*/
prevValues_: null,
prevValues_: {dateInput: '', timeInput: ''},
/**
* ID of the setTimeout() used to refresh the current time.
......@@ -175,7 +176,6 @@ Polymer({
/** @override */
created: function() {
this.prevValues_ = {};
this.browserProxy_ = settime.SetTimeBrowserProxyImpl.getInstance();
},
......@@ -265,8 +265,8 @@ Polymer({
if (document.activeElement.id != 'dateInput' &&
document.activeElement.id != 'timeInput') {
const htmlValues = dateToHtmlValues(newTime);
this.prevValues_.date = this.$.dateInput.value = htmlValues.date;
this.prevValues_.time = this.$.timeInput.value = htmlValues.time;
this.prevValues_.dateInput = this.$.dateInput.value = htmlValues.date;
this.prevValues_.timeInput = this.$.timeInput.value = htmlValues.time;
}
if (this.timeTimeoutId_) {
......
......@@ -22,9 +22,7 @@ SetTimeDialogBrowserTest.prototype = {
],
};
// Fails on linux-chromeos-google-rel, flaky on other bots.
// https://crbug.com/996000
TEST_F('SetTimeDialogBrowserTest', 'DISABLED_All', function() {
TEST_F('SetTimeDialogBrowserTest', 'All', function() {
suite('SetTimeDialog', function() {
let setTimeElement = null;
let testBrowserProxy = null;
......@@ -133,6 +131,16 @@ TEST_F('SetTimeDialogBrowserTest', 'DISABLED_All', function() {
});
});
test('Revert invalid date on blur', () => {
const dateInput = setTimeElement.$$('#dateInput');
dateInput.focus();
dateInput.value = '9999-99-99';
dateInput.blur();
// The exact value isn't important (it depends on the current date, and
// the date could change in the middle of the test).
assertNotEquals('9999-99-99', dateInput.value);
});
test('SystemTimezoneChanged', () => {
const timezoneSelect = setTimeElement.$$('#timezoneSelect');
assertTrue(!!timezoneSelect);
......
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