mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Update web-platform-tests to revision a3dd2ad02c65588ad280ceac378d82e9250d1045
This commit is contained in:
parent
e26530341b
commit
15e68ad3d3
171 changed files with 2819 additions and 1841 deletions
194
tests/wpt/web-platform-tests/web-nfc/NDEFReader_scan.https.html
Normal file
194
tests/wpt/web-platform-tests/web-nfc/NDEFReader_scan.https.html
Normal file
|
@ -0,0 +1,194 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Web NFC: NDEFReader.scan tests</title>
|
||||
<link rel="author" title="Intel" href="http://www.intel.com"/>
|
||||
<link rel="help" href="https://w3c.github.io/web-nfc/"/>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="resources/nfc-helpers.js"></script>
|
||||
<script>
|
||||
|
||||
"use strict";
|
||||
|
||||
const invalid_signals = [
|
||||
"string",
|
||||
123,
|
||||
{},
|
||||
true,
|
||||
Symbol(),
|
||||
() => {},
|
||||
self
|
||||
];
|
||||
|
||||
function waitSyntaxErrorPromise(t, scan_options) {
|
||||
const reader = new NDEFReader();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
const promise = readerWatcher.wait_for("error").then(event => {
|
||||
assert_equals(event.error.name, 'SyntaxError');
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the syntax error event.
|
||||
reader.scan(scan_options);
|
||||
return promise;
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
await waitSyntaxErrorPromise(t, {url: "www.a.com"});
|
||||
}, "Test that NDEFReader.scan fails if NDEFScanOptions.url is missing \
|
||||
components.");
|
||||
|
||||
promise_test(async t => {
|
||||
await waitSyntaxErrorPromise(t, {url: "invalid"});
|
||||
}, "Test that NDEFReader.scan fails if NDEFScanOptions.url is invalid.");
|
||||
|
||||
promise_test(async t => {
|
||||
await waitSyntaxErrorPromise(t, {url: "http://a.com"});
|
||||
}, "Test that NDEFReader.scan fails if NDEFScanOptions.url has wrong \
|
||||
protocol.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
reader.scan();
|
||||
mockNFC.setHWStatus(NFCHWStatus.DISABLED);
|
||||
const event = await readerWatcher.wait_for("error");
|
||||
assert_equals(event.error.name, 'NotReadableError');
|
||||
}, "NDEFReader.scan should fail if NFC HW is disabled.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
reader.scan();
|
||||
mockNFC.setHWStatus(NFCHWStatus.NOT_SUPPORTED);
|
||||
const event = await readerWatcher.wait_for("error");
|
||||
assert_equals(event.error.name, 'NotSupportedError');
|
||||
}, "NDEFReader.scan should fail if NFC HW is not supported.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
const promise = readerWatcher.wait_for("reading").then(event => {
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
controller.abort();
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the reading event.
|
||||
reader.scan({signal : controller.signal});
|
||||
await promise;
|
||||
}, "Test that nfc watch success if NFC HW is enabled.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
const promise = readerWatcher.wait_for("reading").then(event => {
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
controller.abort();
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the reading event.
|
||||
reader.scan({signal : controller.signal, url: "https://a.com"});
|
||||
await promise;
|
||||
}, "Test that NDEFReader.scan succeeds if NDEFScanOptions.url is valid URL.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
const promise = readerWatcher.wait_for("reading").then(event => {
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
controller.abort();
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the reading event.
|
||||
reader.scan({signal : controller.signal, url: "https://a.com/*"});
|
||||
await promise;
|
||||
}, "Test that NDEFReader.scan succeeds if NDEFScanOptions.url is valid URL \
|
||||
with '*' wildcard character in path.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
const promise = readerWatcher.wait_for("reading").then(event => {
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
controller.abort();
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the reading event.
|
||||
reader.scan({signal : controller.signal, url: "https://a.com/*/bar"});
|
||||
await promise;
|
||||
}, "Test that NDEFReader.scan succeeds if NDEFScanOptions.url is valid URL \
|
||||
with '*' wildcard character in the beginning of path component followed by \
|
||||
subpath.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
const promise = readerWatcher.wait_for("reading").then(event => {
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
controller.abort();
|
||||
});
|
||||
// NDEFReader#scan() asynchronously dispatches the reading event.
|
||||
reader.scan({signal : controller.signal, url: ""});
|
||||
await promise;
|
||||
}, "Test that NDEFReader.scan succeeds if NDEFScanOptions.url is empty.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
|
||||
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
reader.scan({signal: controller.signal});
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
readerWatcher.wait_for("reading").then(event => {
|
||||
reject("reading event should not be fired.");
|
||||
});
|
||||
t.step_timeout(resolve, 100);
|
||||
});
|
||||
|
||||
}, "Test that NDEFReader.onreading should not be fired if NDEFScanOptions.signal \
|
||||
is aborted.");
|
||||
|
||||
nfc_test(async (t, mockNFC) => {
|
||||
const reader = new NDEFReader();
|
||||
const controller = new AbortController();
|
||||
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
|
||||
const message = createMessage([createTextRecord(test_text_data)]);
|
||||
|
||||
mockNFC.setReadingMessage(message);
|
||||
|
||||
reader.scan({signal: controller.signal});
|
||||
const event = await readerWatcher.wait_for("reading");
|
||||
assert_true(event instanceof NDEFReadingEvent);
|
||||
mockNFC.setReadingMessage(message);
|
||||
controller.abort();
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
readerWatcher.wait_for("reading").then(event => {
|
||||
reject("reading event should not be fired.");
|
||||
});
|
||||
t.step_timeout(resolve, 100);
|
||||
});
|
||||
|
||||
}, "Synchronously signaled abort.");
|
||||
|
||||
test(() => {
|
||||
const reader = new NDEFReader();
|
||||
invalid_signals.forEach(invalid_signal => {
|
||||
assert_throws(new TypeError(),
|
||||
() => { reader.scan({ signal: invalid_signal }); });
|
||||
});
|
||||
}, "NDEFReader.scan should fail if signal is not an AbortSignal.");
|
||||
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue