Update web-platform-tests to revision e3d0146264093a389148cc555ee9be69bd75719b

This commit is contained in:
WPT Sync Bot 2019-04-10 21:49:30 -04:00
parent dd2deeabca
commit 7e807a0d1e
37 changed files with 842 additions and 140 deletions

View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web NFC Test: NFCReader NFCReaderOptions mediaType test</title>
<link rel="author" title="Intel" href="http://www.intel.com"/>
<link rel="help" href="https://w3c.github.io/web-nfc/"/>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc_help.js"></script>
<meta name="flags" content="interact">
<p>Tap an NFC tag to the test device with NFC support.</p>
<p>Note: All the actions need to be done in 60 seconds, otherwise it will get TIMEOUT.</p>
<div id="log"></div>
<script>
"use strict";
setup({ explicit_timeout: true });
const desc = "Test that the mediaType of NFCReaderOptions filters relevant data sources correctly.";
const readOptions = {mediaType: "application/octet-stream"};
const unacceptableReadOptions = {mediaType: "application/json"};
const message = createMessage([createOpaqueRecord(test_buffer_data)]);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -21,14 +21,11 @@
setup({ explicit_timeout: true });
const desc = "Test that write and read data succeed when recordType is set to 'empty'.";
const readOptions = {
recordType: "empty",
mediaType: "",
url: ""
}
const desc = "Test that write and read data succeed when NFCReaderOptions's recordType is set to 'empty'.";
const readOptions = {recordType: "empty"};
const unacceptableReadOptions = {recordType: "json"};
const message = createMessage([createRecord('empty', '')]);
testNDEFMessage(message, readOptions, desc);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -21,14 +21,11 @@
setup({ explicit_timeout: true });
const desc = "Test that write and read data succeed when recordType is set to 'json'.";
const readOptions = {
recordType : "json",
mediaType : "application/json",
url : ""
}
const desc = "Test that write and read data succeed when NFCReaderOptions's recordType is set to 'json'.";
const readOptions = {recordType: "json"};
const unacceptableReadOptions = {recordType: "url"};
const message = createMessage([createJsonRecord(test_json_data)]);
testNDEFMessage(message, readOptions, desc);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -21,14 +21,11 @@
setup({ explicit_timeout: true });
const desc = "Test that write and read data succeed when recordType is set to 'opaque'."
const readOptions = {
recordType : "opaque",
mediaType : "application/octet-stream",
url : ""
}
const desc = "Test that write and read data succeed when NFCReaderOptions's recordType is set to 'opaque'.";
const readOptions = {recordType: "opaque"};
const unacceptableReadOptions = {recordType: "json"};
const message = createMessage([createOpaqueRecord(test_buffer_data)]);
testNDEFMessage(message, readOptions, desc);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -21,14 +21,11 @@
setup({ explicit_timeout: true });
const desc = "Test that write and read data succeed when recordType is set to 'text'."
const readOptions = {
recordType : "text",
mediaType : "text/plain",
url : ""
}
const desc = "Test that write and read data succeed when NFCReaderOptions's recordType is set to 'text'.";
const readOptions = {recordType: "text"};
const unacceptableReadOptions = {recordType: "json"};
const message = createMessage([createTextRecord(test_text_data)]);
testNDEFMessage(message, readOptions, desc);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -21,15 +21,11 @@
setup({ explicit_timeout: true });
const test_message_origin = window.location.href.origin;
const desc = "Test that write and read data succeed when recordType is set to 'url'.";
const readOptions = {
recordType: "url",
mediaType: "text/plain",
url: test_message_origin
}
const desc = "Test that write and read data succeed when NFCReaderOptions's recordType is set to 'url'.";
const readOptions = {recordType: "url"};
const unacceptableReadOptions = {recordType: "json"};
const message = createMessage([createUrlRecord(test_url_data)]);
testNDEFMessage(message, readOptions, desc);
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -6,6 +6,7 @@
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc_help.js"></script>
<meta name="flags" content="interact">
<p>Tap an NFC tag to the test device with NFC support.</p>
@ -20,25 +21,14 @@
setup({ explicit_timeout: true });
promise_test(async t => {
const writer = new NFCWriter();
const reader1 = new NFCReader({url: `${location.origin}/custom/invalid`});
const reader2 = new NFCReader({url: `${location.origin}/custom/path`});
await writer.push({
url: "/custom/path/update",
records: [{ recordType: "text", data: "valid" }]
});
const desc = "Test that the url of NFCReaderOptions filters relevant data sources correctly.";
const readOptions = {url: `${location.origin}/custom/path`};
const unacceptableReadOptions = {url: `${location.origin}/custom/invalid`};
const message = {
url: "/custom/path/update",
records: [createTextRecord(test_text_data)]
}
reader1.onreading = t.unreached_func("reading event should not be fired.");
reader1.start();
const readerWatcher = new EventWatcher(t, reader2, ["reading", "error"]);
reader2.start();
const event = await readerWatcher.wait_for("reading");
const message = event.message;
assert_equals(message.records[0].recordType, "text");
assert_equals(message.records[0].data, "valid");
assert_equals(message.url, `${location.origin}/custom/path/update`);
}, "Test that the url of NFCReaderOptions filters relevant data sources correctly.");
testNFCReaderOptions(message, readOptions, unacceptableReadOptions, desc);
</script>

View file

@ -48,6 +48,7 @@ function createUrlRecord(url) {
}
function assertWebNDEFMessagesEqual(a, b) {
if (b.url) assert_equals(a.url, `${location.origin}${b.url}`);
assert_equals(a.records.length, b.records.length);
for(let i in a.records) {
let recordA = a.records[i];
@ -59,21 +60,25 @@ function assertWebNDEFMessagesEqual(a, b) {
new Uint8Array(recordB.data));
} else if (typeof recordA.data === 'object') {
assert_object_equals(recordA.data, recordB.data);
}
if (typeof recordA.data === 'number'
} else if (typeof recordA.data === 'number'
|| typeof recordA.data === 'string') {
assert_true(recordA.data == recordB.data);
}
}
}
function testNDEFMessage(pushedMessage, readOptions, desc) {
function testNFCReaderOptions(pushedMessage, readOptions, unacceptableReadOptions, desc) {
promise_test(async t => {
const writer = new NFCWriter();
const reader = new NFCReader(readOptions);
const reader1 = new NFCReader(unacceptableReadOptions);
const reader2 = new NFCReader(readOptions);
await writer.push(pushedMessage);
const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
reader.start();
reader1.onreading = t.unreached_func("reading event should not be fired.");
reader1.start();
const readerWatcher = new EventWatcher(t, reader2, ["reading", "error"]);
reader2.start();
const event = await readerWatcher.wait_for("reading");
assertWebNDEFMessagesEqual(event.message, pushedMessage);
}, desc);