servo/tests/wpt/web-platform-tests/web-nfc/NDEFReader_options.https.html

167 lines
6.8 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: "mime"},
message: createMessage([createRecord('empty')])
},
{
desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'mime'.",
scanOptions: {recordType: "mime"},
unmatchedScanOptions: {recordType: "url"},
message: createMessage([createMimeRecord(test_buffer_data)])
},
{
desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'unknown'.",
scanOptions: {recordType: "unknown"},
unmatchedScanOptions: {recordType: "mime"},
message: createMessage([createUnknownRecord(test_buffer_data)])
},
{
desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'text'.",
scanOptions: {recordType: "text"},
unmatchedScanOptions: {recordType: "url"},
message: createMessage([createTextRecord(test_text_data)])
},
{
desc: "Test that reading data succeed when NDEFScanOptions'" +
" recordType is set to 'url'.",
scanOptions: {recordType: "url"},
unmatchedScanOptions: {recordType: "absolute-url"},
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: "url"},
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: "mime"},
message: createMessage([createRecord('w3.org:xyz', 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([createMimeRecord(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([createMimeRecordFromJson(test_json_data)]),
},
{
desc: "Test that filtering 'mime' record from different messages" +
" correctly with NDEFScanOptions' recordType is set to 'mime'.",
scanOptions: {recordType: "mime"},
message: createMessage([createMimeRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createUnknownRecord(test_buffer_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', 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 'mime' record from different messages" +
" correctly with NDEFScanOptions' mediaType set.",
scanOptions: {mediaType: "application/octet-stream"},
message: createMessage([createMimeRecord(test_buffer_data)]),
unmatchedMessage: createMessage([createMimeRecordFromJson(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>