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 <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#852607}

--

wpt-commits: 4cf1a9640f6c87c31b21c115d8e4fce2cfffa427
wpt-pr: 27561
This commit is contained in:
Adam Rice 2021-02-11 16:48:18 +00:00 коммит произвёл moz-wptsync-bot
Родитель b1aaaa0a76
Коммит 68486219bd
2 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -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()

Просмотреть файл

@ -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 <base> 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() {