mirror of
https://github.com/servo/servo.git
synced 2025-08-13 09:25:32 +01:00
Update web-platform-tests to revision e29e596073468910d8655a8ec23262f17543e147
This commit is contained in:
parent
e56db1f322
commit
5e2118728a
67 changed files with 1403 additions and 821 deletions
|
@ -0,0 +1,74 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>History restoration order test</title>
|
||||
<meta name="assert" content="https://html.spec.whatwg.org/multipage/browsing-the-web.html#history-traversal">
|
||||
<meta name="assert" content="Traversing history should restore scroll position after dispatching popstate and before dispatching hashchange">
|
||||
|
||||
<style>
|
||||
body {
|
||||
height: 200vh;
|
||||
width: 200vw;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
async_test(function(t) {
|
||||
window.addEventListener('load', t.step_func(function() {
|
||||
// Allow 1px epsilon for fractional scrolling.
|
||||
assert_array_approx_equals(scrollPosition(), [0, 0], 1);
|
||||
|
||||
history.pushState('#1', '', '#1');
|
||||
window.scrollTo(50, 100);
|
||||
assert_array_approx_equals(scrollPosition(), [50, 100], 1);
|
||||
|
||||
history.pushState('#2', '', '#2');
|
||||
window.scrollTo(100, 200);
|
||||
assert_array_approx_equals(scrollPosition(), [100, 200], 1);
|
||||
|
||||
setTimeout(t.step_func(function(){
|
||||
history.pushState(null, null, '#done');
|
||||
window.scrollTo(555, 555);
|
||||
assert_array_approx_equals(scrollPosition(), [555, 555], 1);
|
||||
// Kick off the verification.
|
||||
window.history.back();
|
||||
}), 0);
|
||||
}));
|
||||
|
||||
window.addEventListener('popstate', t.step_func(function() {
|
||||
// Verify that scroll position is *not* restored before popstate.
|
||||
const key = location.hash;
|
||||
const expected_scroll_position = expectedScrollPositionForKey(key);
|
||||
assert_not_equals(scrollPosition()[0], expected_scroll_position[0], `scroll is restored before popstate for ${key}`);
|
||||
assert_not_equals(scrollPosition()[1], expected_scroll_position[1], `scroll is restored before popstate for ${key}`);
|
||||
|
||||
if (key == '')
|
||||
t.done();
|
||||
else
|
||||
setTimeout(t.step_func(function(){ window.history.back(); }), 0);
|
||||
}));
|
||||
|
||||
window.addEventListener('hashchange', t.step_func(function() {
|
||||
// Verify that scroll position is restored before hashchange.
|
||||
var key = location.hash;
|
||||
const expected_scroll_position = expectedScrollPositionForKey(key);
|
||||
assert_array_approx_equals(scrollPosition(), expected_scroll_position, 1, `scroll is restored before hashchange for ${key}`);
|
||||
}));
|
||||
|
||||
function scrollPosition() {
|
||||
return [window.pageXOffset, window.pageYOffset];
|
||||
}
|
||||
|
||||
function expectedScrollPositionForKey(key) {
|
||||
switch (key) {
|
||||
case '#2': return [100, 200];
|
||||
case '#1': return [50, 100];
|
||||
case '' : return [0, 0];
|
||||
default: assert_unreached();
|
||||
}
|
||||
}
|
||||
|
||||
}, 'Traversing history should restore scroll position after dispatching popstate and before dispatching hashchange');
|
||||
</script>
|
|
@ -0,0 +1,37 @@
|
|||
<html manifest="resources/appcache-iframe.manifest">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
const initPromise = new Promise(resolve => {
|
||||
applicationCache.addEventListener('cached', resolve, false);
|
||||
applicationCache.addEventListener('noupdate', resolve, false);
|
||||
});
|
||||
|
||||
function with_iframe(url) {
|
||||
return new Promise(resolve => {
|
||||
let frame = document.createElement('iframe');
|
||||
frame.src = url;
|
||||
frame.onload = () => { resolve(frame); };
|
||||
document.body.appendChild(frame);
|
||||
add_result_callback(() => frame.remove());
|
||||
});
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
await initPromise;
|
||||
const frame =
|
||||
await with_iframe('resources/appcache-iframe.py?type=cached');
|
||||
const msgEvent = await new Promise(r => window.onmessage = r);
|
||||
assert_equals(msgEvent.data, 'Done: cached');
|
||||
}, 'iframe should be loaded from application caches.');
|
||||
|
||||
promise_test(async t => {
|
||||
await initPromise;
|
||||
const frame =
|
||||
await with_iframe('resources/appcache-iframe.py?type=fallingback');
|
||||
const msgEvent = await new Promise(r => window.onmessage = r);
|
||||
assert_equals(msgEvent.data, 'Done: fallbacked');
|
||||
}, 'iframe should be loaded from application caches for fallback.');
|
||||
|
||||
</script>
|
||||
</html>
|
|
@ -0,0 +1,5 @@
|
|||
def main(request, response):
|
||||
type = request.GET['type']
|
||||
if request.GET['type'] == 'fallingback':
|
||||
return 404, [('Content-Type', 'text/plain')], "Page not found"
|
||||
return [('Content-Type', 'text/plain')], type
|
|
@ -0,0 +1,8 @@
|
|||
CACHE MANIFEST
|
||||
|
||||
appcache-iframe.py?type=cached
|
||||
appcache-data.py?type=cached
|
||||
|
||||
FALLBACK:
|
||||
appcache-iframe.py?type=fallingback appcache-iframe.py?type=fallbacked
|
||||
appcache-data.py?type=fallingback appcache-data.py?type=fallbacked
|
|
@ -0,0 +1,43 @@
|
|||
script = '''
|
||||
<script>
|
||||
function fetchCachedFileTest() {
|
||||
return fetch('appcache-data.py?type=cached')
|
||||
.then(res => res.text(),
|
||||
_ => { throw new Error('Failed to fetch cached file'); })
|
||||
.then(text => {
|
||||
if (text != 'cached') {
|
||||
throw new Error('cached file missmatch');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function fetchNotInCacheFileTest() {
|
||||
return fetch('appcache-data.py?type=not-in-cache')
|
||||
.then(_ => { throw new Error('Fetching not-in-cache file must fail'); },
|
||||
_ => {});
|
||||
}
|
||||
|
||||
function fetchFallbackFileTest() {
|
||||
return fetch('appcache-data.py?type=fallingback')
|
||||
.then(res => res.text(),
|
||||
_ => { throw new Error('Failed to fetch fallingback file'); })
|
||||
.then(text => {
|
||||
if (text != 'fallbacked') {
|
||||
throw new Error('fallbacked file miss match');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fetchCachedFileTest()
|
||||
.then(fetchNotInCacheFileTest)
|
||||
.then(fetchFallbackFileTest)
|
||||
.then(_ => window.parent.postMessage('Done: %s'),
|
||||
error => window.parent.postMessage(error.toString()));
|
||||
</script>
|
||||
'''
|
||||
|
||||
def main(request, response):
|
||||
type = request.GET['type']
|
||||
if request.GET['type'] == 'fallingback':
|
||||
return 404, [('Content-Type', 'text/plain')], "Page not found"
|
||||
return [('Content-Type', 'text/html')], script % type
|
|
@ -91,6 +91,7 @@ initPromise
|
|||
.then(importFallbackScriptTest)
|
||||
.then(fetchCachedFileTest)
|
||||
.then(fetchNotInCacheFileTest)
|
||||
.then(fetchFallbackFileTest)
|
||||
.then(_ => postMessage('Done: %s'),
|
||||
error => postMessage(error.toString()));
|
||||
'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue