Update web-platform-tests to revision c26470dac73f2df9d4822a0d3482f7eb1ebf57d9

This commit is contained in:
Anthony Ramine 2018-01-10 14:28:20 +01:00
parent 7de87c487b
commit 4d3c932c47
648 changed files with 9014 additions and 4821 deletions

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<title>Fetch destination tests for resources with no load event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
let frame;
const kScope = 'resources/dummy.html?dest=document';
// Set up the service worker and the frame.
promise_test(t => {
const kScript = 'resources/fetch-destination-worker-iframe.js';
return service_worker_unregister_and_register(t, kScript, kScope)
.then(registration => {
add_completion_callback(() => {
registration.unregister();
});
return wait_for_state(t, registration.installing, 'activated');
});
}, 'Initialize global state');
var waitOnMessageFromSW = async t => {
await new Promise((resolve, reject) => {
navigator.serviceWorker.onmessage = t.step_func(event => {
if (event.data == "PASS") {
resolve();
} else {
reject();
}
});
}).catch(() => {;
assert_unreached("Wrong destination.");
});
t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; });
}
// Document destination
///////////////////////
promise_test(async t => {
var f = document.createElement('iframe');
frame = f;
f.className = 'test-iframe';
f.src = kScope;
document.body.appendChild(f);
await waitOnMessageFromSW(t);
add_completion_callback(() => { f.remove(); });
}, 'iframe fetches with a "document" Request.destination');
</script>

View file

@ -0,0 +1,124 @@
<!DOCTYPE html>
<title>Fetch destination tests for resources with no load event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
let frame;
// Set up the service worker and the frame.
promise_test(t => {
const kScope = 'resources/empty.https.html';
const kScript = 'resources/fetch-destination-worker-no-load-event.js';
return service_worker_unregister_and_register(t, kScript, kScope)
.then(registration => {
add_completion_callback(() => {
registration.unregister();
});
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => {
return with_iframe(kScope);
})
.then(f => {
frame = f;
add_completion_callback(() => { f.remove(); });
});
}, 'Initialize global state');
var waitOnMessageFromSW = async t => {
await new Promise((resolve, reject) => {
frame.contentWindow.navigator.serviceWorker.onmessage = t.step_func(event => {
if (event.data == "PASS") {
resolve();
} else {
reject();
}
});
}).catch(() => {;
assert_unreached("Wrong destination.");
});
t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; });
}
// Actual tests
// Image destination
////////////////////
// CSS background image - image destination
promise_test(async t => {
let node = frame.contentWindow.document.createElement("div");
node.style = "background-image: url(dummy.png?t=bg2&dest=image)";
frame.contentWindow.document.body.appendChild(node);
await waitOnMessageFromSW(t);
}, 'Background image fetches with an "image" Request.destination');
// Font destination
///////////////////
// Font loading API - font destination
promise_test(async t => {
let font = new frame.contentWindow.FontFace("foo", "url(dummy.ttf?t=api&dest=font)");
font.load();
await waitOnMessageFromSW(t);
}, 'Font loading API fetches with an "font" Request.destination');
// CSS font - font destination
promise_test(async t => {
let style = frame.contentWindow.document.createElement("style");
style.innerHTML = "@font-face { font-family: foo; src: url(dummy.ttf?t=css&dest=font); }";
style.innerHTML += "div {font-family: foo; }";
let div = frame.contentWindow.document.createElement("div");
div.innerHTML = "bar";
frame.contentWindow.document.body.appendChild(style);
frame.contentWindow.document.body.appendChild(div);
await waitOnMessageFromSW(t);
}, 'CSS font fetches with an "font" Request.destination');
// Empty string destination
///////////////////////////
// sendBeacon() - empty string destination
promise_test(async t => {
frame.contentWindow.navigator.sendBeacon("dummy?t=beacon&dest=", "foobar");
await waitOnMessageFromSW(t);
}, 'sendBeacon() fetches with an empty string Request.destination');
// Cache.add() - empty string destination
promise_test(async t => {
frame.contentWindow.caches.open("foo").then(cache => {
cache.add("dummy?t=cache&dest=");
});
await waitOnMessageFromSW(t);
}, 'Cache.add() fetches with an empty string Request.destination');
// script destination
/////////////////////
// importScripts() - script destination
promise_test(async t => {
let worker = new frame.contentWindow.Worker("importer.js");
await waitOnMessageFromSW(t);
}, 'importScripts() fetches with a "script" Request.destination');
// style destination
/////////////////////
// @import - style destination
promise_test(async t => {
let node = frame.contentWindow.document.createElement("style");
node.innerHTML = '@import url("dummy?t=import&dest=style")';
frame.contentWindow.document.body.appendChild(node);
await waitOnMessageFromSW(t);
}, '@import fetches with a "style" Request.destination');
</script>

View file

@ -0,0 +1,54 @@
<!DOCTYPE html>
<title>Fetch destination tests for resources with no load event</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<script>
let frame;
// Set up the service worker and the frame.
promise_test(t => {
const kScope = 'resources/dummy.html';
const kScript = 'resources/fetch-destination-worker-no-load-event.js';
return service_worker_unregister_and_register(t, kScript, kScope)
.then(registration => {
add_completion_callback(() => {
registration.unregister();
});
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => {
return with_iframe(kScope);
})
.then(f => {
frame = f;
add_completion_callback(() => { f.remove(); });
});
}, 'Initialize global state');
var waitOnMessageFromSW = async t => {
await new Promise((resolve, reject) => {
frame.contentWindow.navigator.serviceWorker.onmessage = t.step_func(event => {
if (event.data == "PASS") {
resolve();
} else {
reject();
}
});
}).catch(() => {;
assert_unreached("Wrong destination.");
});
t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; });
}
// worker destination
/////////////////////
promise_test(async t => {
// We can use an html file as we don't really care about the worker successfully loading.
let worker = new frame.contentWindow.Worker("dummy.html?t=worker&dest=worker");
await waitOnMessageFromSW(t);
}, 'Worker fetches with a "worker" Request.destination');
</script>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<title>Service Worker: the body of FetchEvent using XMLHttpRequest</title>
<title>Fetch destination tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
@ -31,10 +31,13 @@ promise_test(t => {
// Actual tests
// Image destination
////////////////////
// HTMLImageElement - image destination
promise_test(async t => {
await new Promise((resolve, reject) => {
var node = frame.contentWindow.document.createElement("img");
let node = frame.contentWindow.document.createElement("img");
node.onload = resolve;
node.onerror = reject;
node.src = "dummy.png?dest=image";
@ -43,17 +46,92 @@ promise_test(async t => {
});
}, 'HTMLImageElement fetches with an "image" Request.destination');
// HTMLImageElement with srcset attribute - image destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("img");
node.onload = resolve;
node.onerror = reject;
node.srcset = "dummy.png?t=srcset&dest=image";
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLImageElement with srcset attribute fetches with an "image" Request.destination');
// HTMLImageElement with srcset attribute - image destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let img = frame.contentWindow.document.createElement("img");
let picture = frame.contentWindow.document.createElement("picture");
let source = frame.contentWindow.document.createElement("source");
picture.appendChild(source);
picture.appendChild(img);
img.onload = resolve;
img.onerror = reject;
source.srcset = "dummy.png?t=picture&dest=image";
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLImageElement with a HTMLPictureElement parent attribute fetches with an "image" Request.destination');
// SVGImageElement - image destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let svg = frame.contentWindow.document.createElementNS('http://www.w3.org/2000/svg','svg');
svg.setAttributeNS('http://www.w3.org/2000/svg','xlink','http://www.w3.org/1999/xlink');
let svgimg = frame.contentWindow.document.createElementNS('http://www.w3.org/2000/svg','image');
svgimg.onload = resolve;
svgimg.onerror = reject;
svgimg.setAttributeNS('http://www.w3.org/1999/xlink','href','dummy.png?t=svg&dest=image');
svg.appendChild(svgimg);
frame.contentWindow.document.documentElement.appendChild(svg);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'SVGImageElement fetches with an "image" Request.destination');
// Empty string destination
///////////////////////////
// fetch() - empty string destination
promise_test(async t => {
let response = await frame.contentWindow.fetch("dummy?dest=");
assert_true(response.ok);
}, 'fetch() fetches with an empty string Request.destination');
// XMLHttpRequest - empty string destination
promise_test(async t => {
let xhr;
await new Promise((resolve, reject) => {
xhr = new frame.contentWindow.XMLHttpRequest();
xhr.onload = resolve;
xhr.onerror = reject;
xhr.open("GET", "dummy?t=xhr&dest=");
xhr.send();
}).catch(() => {
assert_unreached("Fetch errored.");
});
assert_equals(xhr.status, 200);
}, 'XMLHttpRequest() fetches with an empty string Request.destination');
// EventSource - empty string destination
promise_test(async t => {
let xhr;
await new Promise((resolve, reject) => {
eventSource = new frame.contentWindow.EventSource("dummy.es?t=eventsource&dest=");
eventSource.onopen = resolve;
eventSource.onerror = reject;
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'EventSource() fetches with an empty string Request.destination');
// HTMLAudioElement - audio destination
///////////////////////////////////////
promise_test(async t => {
await new Promise((resolve, reject) => {
var audioURL = getAudioURI("dummy_audio");
var node = frame.contentWindow.document.createElement("audio");
let audioURL = getAudioURI("dummy_audio");
let node = frame.contentWindow.document.createElement("audio");
node.onloadeddata = resolve;
node.onerror = reject;
node.src = audioURL + "?dest=audio";
@ -63,10 +141,11 @@ promise_test(async t => {
}, 'HTMLAudioElement fetches with an "audio" Request.destination');
// HTMLVideoElement - video destination
///////////////////////////////////////
promise_test(async t => {
await new Promise((resolve, reject) => {
var videoURL = getVideoURI("dummy_video");
var node = frame.contentWindow.document.createElement("video");
let videoURL = getVideoURI("dummy_video");
let node = frame.contentWindow.document.createElement("video");
node.onloadeddata = resolve;
node.onerror = reject;
node.src = videoURL + "?dest=video";
@ -75,10 +154,13 @@ promise_test(async t => {
});
}, 'HTMLVideoElement fetches with a "video" Request.destination');
// script destinations
//////////////////////
// HTMLScriptElement - script destination
promise_test(async t => {
await new Promise((resolve, reject) => {
var node = frame.contentWindow.document.createElement("script");
let node = frame.contentWindow.document.createElement("script");
node.onload = resolve;
node.onerror = reject;
node.src = "dummy?dest=script";
@ -88,10 +170,13 @@ promise_test(async t => {
});
}, 'HTMLScriptElement fetches with a "script" Request.destination');
// HTMLLinkElement with rel=stylesheet - script destination
// Style destination
////////////////////
// HTMLLinkElement with rel=stylesheet - style destination
promise_test(async t => {
await new Promise((resolve, reject) => {
var node = frame.contentWindow.document.createElement("link");
let node = frame.contentWindow.document.createElement("link");
node.rel = "stylesheet";
node.onload = resolve;
node.onerror = reject;
@ -102,12 +187,17 @@ promise_test(async t => {
});
}, 'HTMLLinkElement with rel=stylesheet fetches with a "style" Request.destination');
// Preload tests
////////////////
// HTMLLinkElement with rel=preload and as=fetch - empty string destination
promise_test(async t => {
await new Promise((resolve, reject) => {
var node = frame.contentWindow.document.createElement("link");
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "fetch";
if (node.as != "fetch") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?t=2&dest=";
@ -120,9 +210,12 @@ promise_test(async t => {
// HTMLLinkElement with rel=preload and as=style - style destination
promise_test(async t => {
await new Promise((resolve, reject) => {
var node = frame.contentWindow.document.createElement("link");
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "style";
if (node.as != "style") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?t=2&dest=style";
@ -131,4 +224,205 @@ promise_test(async t => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=style fetches with a "style" Request.destination');
// HTMLLinkElement with rel=preload and as=script - script destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "script";
if (node.as != "script") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?t=2&dest=script";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=script fetches with a "script" Request.destination');
// HTMLLinkElement with rel=preload and as=font - font destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "font";
if (node.as != "font") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?t=2&dest=font";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=font fetches with a "font" Request.destination');
// HTMLLinkElement with rel=preload and as=image - image destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "image";
if (node.as != "image") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy.png?t=2&dest=image";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=image fetches with a "image" Request.destination');
// HTMLLinkElement with rel=preload and as=audio - audio destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let audioURL = getAudioURI("dummy_audio");
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "audio";
if (node.as != "audio") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = audioURL + "?dest=audio";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=audio fetches with a "audio" Request.destination');
// HTMLLinkElement with rel=preload and as=video - video destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let videoURL = getVideoURI("dummy_video");
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "video";
if (node.as != "video") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = videoURL + "?dest=video";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=video fetches with a "video" Request.destination');
// HTMLLinkElement with rel=preload and as=track - track destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "track";
if (node.as != "track") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=track";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=track fetches with a "track" Request.destination');
// HTMLLinkElement with rel=preload and as=document - document destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "document";
if (node.as != "document") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=document";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=document fetches with a "document" Request.destination');
// HTMLLinkElement with rel=preload and as=worker - worker destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "worker";
if (node.as != "worker") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=worker";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=worker fetches with a "worker" Request.destination');
// HTMLLinkElement with rel=preload and as=sharedworker - sharedworker destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "sharedworker";
if (node.as != "sharedworker") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=sharedworker";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=sharedworker fetches with a "sharedworker" Request.destination');
// HTMLLinkElement with rel=preload and as=xslt - xslt destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "xslt";
if (node.as != "xslt") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=xslt";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=xslt fetches with a "xslt" Request.destination');
// HTMLLinkElement with rel=preload and as=manifest - manifest destination
promise_test(async t => {
await new Promise((resolve, reject) => {
let node = frame.contentWindow.document.createElement("link");
node.rel = "preload";
node.as = "manifest";
if (node.as != "manifest") {
resolve();
}
node.onload = resolve;
node.onerror = reject;
node.href = "dummy?dest=manifest";
frame.contentWindow.document.body.appendChild(node);
}).catch(() => {
assert_unreached("Fetch errored.");
});
}, 'HTMLLinkElement with rel=preload and as=manifest fetches with a "manifest" Request.destination');
</script>

View file

@ -0,0 +1 @@
Content-Type: text/event-stream

View file

@ -0,0 +1,20 @@
self.addEventListener('fetch', function(event) {
if (event.request.url.includes('dummy')) {
event.waitUntil(async function() {
let destination = new URL(event.request.url).searchParams.get("dest");
let clients = await self.clients.matchAll({"includeUncontrolled": true});
clients.forEach(function(client) {
if (client.url.includes("fetch-destination-iframe")) {
if (event.request.destination == destination) {
client.postMessage("PASS");
} else {
client.postMessage("FAIL");
}
}
})
}());
}
event.respondWith(fetch(event.request));
});

View file

@ -0,0 +1,16 @@
self.addEventListener('fetch', function(event) {
if (event.request.url.includes('dummy')) {
event.waitUntil(async function() {
let destination = new URL(event.request.url).searchParams.get("dest");
let client = await self.clients.get(event.clientId);
if (event.request.destination == destination) {
client.postMessage("PASS");
} else {
client.postMessage("FAIL");
}
}())
}
event.respondWith(fetch(event.request));
});

View file

@ -0,0 +1 @@
importScripts("dummy?t=importScripts&dest=script");