From 68486219bd1a5f435c1d6fc55a426b9096de8109 Mon Sep 17 00:00:00 2001 From: Adam Rice Date: Thu, 11 Feb 2021 16:48:18 +0000 Subject: [PATCH] Bug 1691862 [wpt PR 27561] - Make responsexml-document-properties.htm timezone correct, a=testonly Automatic update from web-platform-tests Make responsexml-document-properties.htm timezone correct The web platform test responsexml-document-properties.htm was flaky, apparently due to incorrect handling of timezones. Make the timezone handling robust to fix the flakiness. BUG=1144537 Change-Id: Ib338d7b9e87415a4900963782fde218b0d3ec6b0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2684076 Reviewed-by: Yutaka Hirano Commit-Queue: Adam Rice Cr-Commit-Position: refs/heads/master@{#852607} -- wpt-commits: 4cf1a9640f6c87c31b21c115d8e4fce2cfffa427 wpt-pr: 27561 --- .../tests/xhr/resources/last-modified.py | 2 +- .../tests/xhr/responsexml-document-properties.htm | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/testing/web-platform/tests/xhr/resources/last-modified.py b/testing/web-platform/tests/xhr/resources/last-modified.py index 9d694817bf11..db08e4b16d78 100644 --- a/testing/web-platform/tests/xhr/resources/last-modified.py +++ b/testing/web-platform/tests/xhr/resources/last-modified.py @@ -3,7 +3,7 @@ from wptserve.utils import isomorphic_decode, isomorphic_encode def main(request, response): import datetime, os srcpath = os.path.join(os.path.dirname(isomorphic_decode(__file__)), u"well-formed.xml") - srcmoddt = datetime.datetime.fromtimestamp(os.path.getmtime(srcpath)) + srcmoddt = datetime.datetime.utcfromtimestamp(os.path.getmtime(srcpath)) response.headers.set(b"Last-Modified", isomorphic_encode(srcmoddt.strftime(u"%a, %d %b %Y %H:%M:%S GMT"))) response.headers.set(b"Content-Type", b"application/xml") return open(srcpath, u"r").read() diff --git a/testing/web-platform/tests/xhr/responsexml-document-properties.htm b/testing/web-platform/tests/xhr/responsexml-document-properties.htm index cb2edb777ddb..a9f14f8212a4 100644 --- a/testing/web-platform/tests/xhr/responsexml-document-properties.htm +++ b/testing/web-platform/tests/xhr/responsexml-document-properties.htm @@ -46,6 +46,14 @@ }, name) } + // Parse a "lastModified" value and convert it to a Date. + // See https://html.spec.whatwg.org/multipage/dom.html#dom-document-lastmodified + function parseLastModified(value) { + const [undefined, month, day, year, hours, minutes, seconds] = + /^(\d\d)\/(\d\d)\/(\d+) (\d\d):(\d\d):(\d\d)$/.exec(value); + return new Date(year, month - 1, day, hours, minutes, seconds); + } + async_test(t => { const client = new XMLHttpRequest(); client.open("GET", "resources/redirect.py?location=well-formed.xml"); @@ -79,7 +87,7 @@ }, "Test document URL properties of document with after redirect"); test(function() { - var lastModified = Math.floor(new Date(client.responseXML.lastModified).getTime() / 1000); + var lastModified = Math.floor(parseLastModified(client.responseXML.lastModified).getTime() / 1000); var now = Math.floor(new Date().getTime(new Date().getTime() + 3000) / 1000); // three seconds from now, in case there's clock drift assert_greater_than_equal(lastModified, timePreXHR); assert_less_than_equal(lastModified, now); @@ -89,7 +97,7 @@ var client2 = new XMLHttpRequest() client2.open("GET", "resources/last-modified.py", false) client2.send(null) - assert_equals((new Date(client2.getResponseHeader('Last-Modified'))).getTime(), (new Date(client2.responseXML.lastModified)).getTime()) + assert_equals((new Date(client2.getResponseHeader('Last-Modified'))).getTime(), (parseLastModified(client2.responseXML.lastModified)).getTime()) }, 'lastModified set to related HTTP header if provided') test(function() {