Skip to content

Commit

Permalink
Convert some tests to use idl_test (web-platform-tests#18677)
Browse files Browse the repository at this point in the history
  • Loading branch information
foolip authored and lukebjerring committed Aug 27, 2019
1 parent f283c90 commit a593c50
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 195 deletions.
29 changes: 12 additions & 17 deletions audio-output/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

'use strict';

promise_test(async () => {
const srcs = ['audio-output', 'dom', 'html'];
const [idl, dom, html] = await Promise.all(
srcs.map(i => fetch(`/interfaces/${i}.idl`).then(r => r.text())));

const idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_dependency_idls(dom);
self.audio = document.createElement('audio');
self.video = document.createElement('video');
idl_array.add_objects({
HTMLAudioElement: ['audio'],
HTMLVideoElement: ['video']
});
idl_array.test();
}, 'Test IDL implementation of audio-output API');
idl_test(
['audio-output'],
['html', 'dom'],
idl_array => {
self.audio = document.createElement('audio');
self.video = document.createElement('video');
idl_array.add_objects({
HTMLAudioElement: ['audio'],
HTMLVideoElement: ['video']
});
}
);
21 changes: 9 additions & 12 deletions beacon/idlharness.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

// https://w3c.github.io/beacon/

promise_test(async () => {
const idl = await fetch('/interfaces/beacon.idl').then(r => r.text());
const html = await fetch('/interfaces/html.idl').then(r => r.text());

const idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_objects({
Navigator: ['navigator'],
});
idl_array.test();
}, 'beacon interfaces');
idl_test(
['beacon'],
['html'],
idl_array => {
idl_array.add_objects({
Navigator: ['navigator'],
});
}
);
23 changes: 13 additions & 10 deletions encrypted-media/idlharness.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ <h1 class="instructions">Description</h1>
<script>
'use strict';

promise_test(async () => {
const idls = await fetch('/interfaces/encrypted-media.idl').then(r => r.text());
const html = await fetch('/interfaces/html.idl').then(r => r.text());
const dom = await fetch('/interfaces/dom.idl').then(r => r.text());
var idl_array = new IdlArray();
idl_array.add_idls(idls);
idl_array.add_dependency_idls(html);
idl_array.add_dependency_idls(dom);
idl_array.test();
}, 'Test encrypted-media IDL');
idl_test(
['encrypted-media'],
['html', 'dom'],
idl_array => {
self.audio = document.createElement('audio');
self.video = document.createElement('video');
idl_array.add_objects({
HTMLAudioElement: ['audio'],
HTMLVideoElement: ['video'],
Navigator: ['navigator'],
});
}
);
</script>
</body>
</html>
25 changes: 12 additions & 13 deletions geolocation-API/idlharness.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

// https://www.w3.org/TR/geolocation-API/

promise_test(async () => {
const idl = await fetch('/interfaces/geolocation-API.idl').then(r => r.text());
const html = await fetch('/interfaces/html.idl').then(r => r.text());

const idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_objects({
Navigator: ["navigator"],
Geolocation: ["navigator.geolocation"]
});
idl_array.test();
}, 'geolocation-API interfaces');
idl_test(
['geolocation-API'],
['html'],
idl_array => {
self.audio = document.createElement('audio');
self.video = document.createElement('video');
idl_array.add_objects({
Navigator: ['navigator'],
Geolocation: ['navigator.geolocation'],
});
}
);
18 changes: 8 additions & 10 deletions mediacapture-depth/idlharness.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset=utf-8>
<title>Media Capture Depth Stream Extensions IDL test</title>
<link rel="help" href="See https://w3c.github.io/mediacapture-depth/">
<link rel="help" href="https://w3c.github.io/mediacapture-depth/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/WebIDLParser.js"></script>
Expand All @@ -15,15 +15,13 @@
<script>
'use strict';

promise_test(async () => {
const idl = await fetch('/interfaces/mediacapture-depth.idl').then(r => r.text());
const main = await fetch('/interfaces/mediacapture-streams.idl').then(r => r.text());

var idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(main);
idl_array.test();
}, 'mediacapture-depth interfaces');
idl_test(
['mediacapture-depth'],
['mediacapture-streams'],
idl_array => {
// No objects, spec defines dictionaries only.
}
);
</script>
<div id="log"></div>
</body>
Expand Down
84 changes: 39 additions & 45 deletions mediacapture-streams/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,44 @@

// https://w3c.github.io/mediacapture-main/


promise_test(async () => {
const srcs = ['mediacapture-streams','dom','html'];
const [idl, dom, html] = await Promise.all(
srcs.map(i => fetch(`/interfaces/${i}.idl`).then(r => r.text())));

const idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_dependency_idls(dom);

const devices = [];
// Errors will be surfaced in idlharness.js's test_object below.
try {
const list = await navigator.mediaDevices.enumerateDevices();
for (const item of list) {
switch (item.kind) {
case 'audioinput':
case 'videoinput':
case 'audiooutput':
self[item.kind] = item;
devices.push(item.kind);
default:
assert_unreached(
'media.kind should be one of "audioinput", "videoinput", or "audiooutput".');
idl_test(
['mediacapture-streams'],
['dom', 'html'],
async idl_array => {
const inputDevices = [];
const outputDevices = [];
try {
const list = await navigator.mediaDevices.enumerateDevices();
for (const device of list) {
if (device.kind in self) {
continue;
}
assert_in_array(device.kind, ['audioinput', 'videoinput', 'audiooutput']);
self[device.kind] = device;
if (device.kind.endsWith('input')) {
inputDevices.push(device.kind);
} else {
outputDevices.push(device.kind);
}
}
}
} catch (e) {}

try {
self.stream = await navigator.mediaDevices.getUserMedia({audio: true});
self.track = stream.getTracks()[0];
self.trackEvent = new MediaStreamTrackEvent("type", {
track: track,
} catch (e) {}

try {
self.stream = await navigator.mediaDevices.getUserMedia({audio: true});
self.track = stream.getTracks()[0];
self.trackEvent = new MediaStreamTrackEvent("type", {
track: track,
});
} catch (e) {}

idl_array.add_objects({
InputDeviceInfo: inputDevices,
MediaStream: ['stream', 'new MediaStream()'],
Navigator: ['navigator'],
MediaDevices: ['navigator.mediaDevices'],
MediaDeviceInfo: outputDevices,
MediaStreamTrack: ['track'],
MediaStreamTrackEvent: ['trackEvent'],
});
} catch (e) { throw e}

idl_array.add_objects({
InputDeviceInfo: devices,
MediaStream: ['stream', 'new MediaStream()'],
Navigator: ['navigator'],
MediaDevices: ['navigator.mediaDevices'],
MediaStreamTrack: ['track'],
MediaStreamTrackEvent: ['trackEvent'],
});
idl_array.test();
}, 'mediacapture-streams interfaces.');
}
);
27 changes: 11 additions & 16 deletions orientation-event/idlharness.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@

'use strict';

promise_test(async () => {
const idl = await fetch('/interfaces/orientation-event.idl').then(r => r.text());
const dom = await fetch('/interfaces/dom.idl').then(r => r.text());
const html = await fetch('/interfaces/html.idl').then(r => r.text());

var idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_dependency_idls(dom);
idl_array.add_objects({
Window: ['window'],
DeviceOrientationEvent: ['new DeviceOrientationEvent("foo")'],
DeviceMotionEvent: ['new DeviceMotionEvent("foo")'],
});
idl_array.test();
}, 'orientation-event interfaces');
idl_test(
['orientation-event'],
['html', 'dom'],
idl_array => {
idl_array.add_objects({
Window: ['window'],
DeviceOrientationEvent: ['new DeviceOrientationEvent("foo")'],
DeviceMotionEvent: ['new DeviceMotionEvent("foo")'],
});
}
);
54 changes: 20 additions & 34 deletions permissions/interfaces.any.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js

"use strict";

if (self.importScripts) {
importScripts("/resources/testharness.js");
importScripts("/resources/WebIDLParser.js", "/resources/idlharness.js");
}

// https://w3c.github.io/permissions/#idl-index

promise_test(async () => {
const idl = await fetch("/interfaces/permissions.idl").then(r => r.text());
const dom = await fetch("/interfaces/dom.idl").then(r => r.text());
const html = await fetch("/interfaces/html.idl").then(r => r.text());

const idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(dom);
idl_array.add_dependency_idls(html);

try {
self.permissionStatus = await navigator.permissions.query({ name: "geolocation" });
self.permissionStatus = await navigator.permissions.query({ name: "background-fetch" });
} catch (e) {
// Will be surfaced in idlharness.js's test_object below.
}
"use strict";

if (self.GLOBAL.isWorker()) {
idl_array.add_objects({ WorkerNavigator: ['navigator'] });
} else {
idl_array.add_objects({ Navigator: ['navigator'] });
idl_test(
['permissions'],
['html', 'dom'],
async idl_array => {
try {
self.permissionStatus = await navigator.permissions.query({ name: "geolocation" });
} catch (e) {}

if (self.GLOBAL.isWorker()) {
idl_array.add_objects({ WorkerNavigator: ['navigator'] });
} else {
idl_array.add_objects({ Navigator: ['navigator'] });
}

idl_array.add_objects({
Permissions: ['navigator.permissions'],
PermissionStatus: ['permissionStatus']
});
}

idl_array.add_objects({
Permissions: ['navigator.permissions'],
PermissionStatus: ['permissionStatus']
});
idl_array.test();
}, "Test IDL implementation of Permissions API");
);
42 changes: 18 additions & 24 deletions requestidlecallback/idlharness.window.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
// META: script=/resources/WebIDLParser.js
// META: script=/resources/idlharness.js

async_test(function() {
const srcs = ['requestidlecallback', 'html', 'dom'];
Promise.all(srcs.map(i => fetch(`/interfaces/${i}.idl`).then(r => r.text())))
.then(([idl, html, dom]) => {
var idl_array = new IdlArray();
idl_array.add_idls(idl);
idl_array.add_dependency_idls(html);
idl_array.add_dependency_idls(dom);
idl_array.add_objects({Window: ['window']});
// https://w3c.github.io/requestidlecallback/

let deadline;
const execIDLTest = this.step_func_done(function() {
idl_array.add_objects({IdleDeadline: [deadline]});
idl_array.test();
});
'use strict';

if (!window.requestIdleCallback) {
execIDLTest();
} else {
const callback = this.step_func(d => {
deadline = d;
execIDLTest();
});
requestIdleCallback(callback, { timeout: 100 });
}
idl_test(
['requestidlecallback'],
['html', 'dom'],
async idl_array => {
idl_array.add_objects({
IdleDeadline: ['deadline'],
Window: ['window'],
});
}, 'IdleDeadline object setup');

await new Promise(resolve => {
requestIdleCallback(d => {
self.deadline = d;
resolve();
}, { timeout: 100 });
});
}
);
Loading

0 comments on commit a593c50

Please sign in to comment.