mirror of
https://github.com/servo/servo.git
synced 2025-10-16 00:10:23 +01:00
183 lines
7.5 KiB
HTML
183 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset=utf-8>
|
|
<title>Web NFC: NDEFReader option 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 NDEFReaderOptionTests =
|
|
[
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'empty'.",
|
|
scanOptions: {recordType: "empty"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createRecord('empty', '')])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'json'.",
|
|
scanOptions: {recordType: "json"},
|
|
unmatchedScanOptions: {recordType: "url"},
|
|
message: createMessage([createJsonRecord(test_json_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'opaque'.",
|
|
scanOptions: {recordType: "opaque"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'unknown'.",
|
|
scanOptions: {recordType: "unknown"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createUnknownRecord(test_buffer_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'text'.",
|
|
scanOptions: {recordType: "text"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'url'.",
|
|
scanOptions: {recordType: "url"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createUrlRecord(test_url_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to 'absolute-url'.",
|
|
scanOptions: {recordType: "absolute-url"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createUrlRecord(test_url_data, true)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NDEFScanOptions'" +
|
|
" recordType is set to a custom type for external type records.",
|
|
scanOptions: {recordType: "w3.org:xyz"},
|
|
unmatchedScanOptions: {recordType: "opaque"},
|
|
message: createMessage([createRecord('w3.org:xyz', 'application/octet-stream',
|
|
test_buffer_data)])
|
|
},
|
|
{
|
|
desc: "Test that the url of NDEFScanOptions filters relevant data" +
|
|
" sources correctly.",
|
|
scanOptions: {url: `${location.origin}/custom/path`},
|
|
unmatchedScanOptions: {url: `${location.origin}/custom/invalid`},
|
|
message: {url: `${location.origin}/custom/path/update`,
|
|
records: [createTextRecord(test_text_data)]}
|
|
},
|
|
{
|
|
desc: "Test that the mediaType of NDEFScanOptions filters relevant data" +
|
|
" sources correctly.",
|
|
scanOptions: {mediaType: "application/octet-stream"},
|
|
unmatchedScanOptions: {mediaType: "application/json"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)])
|
|
}
|
|
];
|
|
|
|
const ReadMultiMessagesTests =
|
|
[
|
|
{
|
|
desc: "Test that filtering 'empty' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'empty'.",
|
|
scanOptions: {recordType: "empty"},
|
|
message: createMessage([createRecord('empty', '')]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]),
|
|
},
|
|
{
|
|
desc: "Test that filtering 'json' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'json'.",
|
|
scanOptions: {recordType: "json"},
|
|
message: createMessage([createJsonRecord(test_json_data)]),
|
|
unmatchedMessage: createMessage([createUrlRecord(test_url_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'opaque' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'opaque'.",
|
|
scanOptions: {recordType: "opaque"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'unknown' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'unknown'.",
|
|
scanOptions: {recordType: "unknown"},
|
|
message: createMessage([createUnknownRecord(test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createUrlRecord(test_url_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'text' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'text'.",
|
|
scanOptions: {recordType: "text"},
|
|
message: createMessage([createTextRecord(test_text_data)]),
|
|
unmatchedMessage: createMessage([createUrlRecord(test_url_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'url' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'url'.",
|
|
scanOptions: {recordType: "url"},
|
|
message: createMessage([createUrlRecord(test_url_data)]),
|
|
unmatchedMessage: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'absolute-url' record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to 'absolute-url'.",
|
|
scanOptions: {recordType: "absolute-url"},
|
|
message: createMessage([createUrlRecord(test_url_data, true)]),
|
|
unmatchedMessage: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering external record from different messages" +
|
|
" correctly with NDEFScanOptions' recordType is set to the custom type.",
|
|
scanOptions: {recordType: "w3.org:xyz"},
|
|
message: createMessage([createRecord('w3.org:xyz', 'application/octet-stream',
|
|
test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'text' record from different messages" +
|
|
" correctly with NDEFScanOptions' url set.",
|
|
scanOptions: {url: `${location.origin}/custom/path`},
|
|
message: {url: `${location.origin}/custom/path/update`,
|
|
records: [createTextRecord(test_text_data)]},
|
|
unmatchedMessage: {url: `${location.origin}/custom/invalid`,
|
|
records: [createUrlRecord(test_url_data)]}
|
|
},
|
|
{
|
|
desc: "Test that filtering 'opaque' record from different messages" +
|
|
" correctly with NDEFScanOptions' mediaType set.",
|
|
scanOptions: {mediaType: "application/octet-stream"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)])
|
|
}
|
|
];
|
|
|
|
for (let NDEFReaderOptionTest of NDEFReaderOptionTests) {
|
|
testNDEFScanOptions(
|
|
NDEFReaderOptionTest.message,
|
|
NDEFReaderOptionTest.scanOptions,
|
|
NDEFReaderOptionTest.unmatchedScanOptions,
|
|
NDEFReaderOptionTest.desc
|
|
);
|
|
}
|
|
|
|
for (let readMultiMessagesTest of ReadMultiMessagesTests) {
|
|
testReadingMultiMessages(
|
|
readMultiMessagesTest.message,
|
|
readMultiMessagesTest.scanOptions,
|
|
readMultiMessagesTest.unmatchedMessage,
|
|
readMultiMessagesTest.desc
|
|
);
|
|
}
|
|
</script>
|