mirror of
https://github.com/servo/servo.git
synced 2025-10-18 01:09:16 +01:00
160 lines
6.3 KiB
HTML
160 lines
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<meta charset=utf-8>
|
|
<title>Web NFC: NFCReader 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 NFCReaderOptionTests =
|
|
[
|
|
{
|
|
desc: "Test that reading data succeed when NFCScanOptions'" +
|
|
" recordType is set to 'empty'.",
|
|
scanOptions: {recordType: "empty"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createRecord('empty', '')])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NFCScanOptions'" +
|
|
" recordType is set to 'json'.",
|
|
scanOptions: {recordType: "json"},
|
|
unmatchedScanOptions: {recordType: "url"},
|
|
message: createMessage([createJsonRecord(test_json_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NFCScanOptions'" +
|
|
" recordType is set to 'opaque'.",
|
|
scanOptions: {recordType: "opaque"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NFCScanOptions'" +
|
|
" recordType is set to 'text'.",
|
|
scanOptions: {recordType: "text"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that reading data succeed when NFCScanOptions'" +
|
|
" recordType is set to 'url'.",
|
|
scanOptions: {recordType: "url"},
|
|
unmatchedScanOptions: {recordType: "json"},
|
|
message: createMessage([createUrlRecord(test_url_data)])
|
|
},
|
|
{
|
|
desc: "Test that the url of NFCScanOptions 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 NFCScanOptions filters relevant data" +
|
|
" sources correctly.",
|
|
scanOptions: {mediaType: "application/octet-stream"},
|
|
unmatchedScanOptions: {mediaType: "application/json"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)])
|
|
},
|
|
{
|
|
desc: "Test that the compatibility of NFCScanOptions filters relevant data" +
|
|
" sources correctly.",
|
|
scanOptions: {compatibility: "vendor"},
|
|
unmatchedScanOptions: {compatibility: "nfc-forum"},
|
|
message: createMessage([createTextRecord(test_text_data)]),
|
|
}
|
|
];
|
|
|
|
const ReadMultiMessagesTests =
|
|
[
|
|
{
|
|
desc: "Test that filtering 'empty' record from different messages" +
|
|
" correctly with NFCScanOptions' 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 NFCScanOptions' 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 NFCScanOptions' recordType is set to 'opaque'.",
|
|
scanOptions: {recordType: "opaque"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'text' record from different messages" +
|
|
" correctly with NFCScanOptions' 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 NFCScanOptions' recordType is set to 'url'.",
|
|
scanOptions: {recordType: "url"},
|
|
message: createMessage([createUrlRecord(test_url_data)]),
|
|
unmatchedMessage: createMessage([createTextRecord(test_text_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'text' record from different messages" +
|
|
" correctly with NFCScanOptions' 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 NFCScanOptions' mediaType set.",
|
|
scanOptions: {mediaType: "application/octet-stream"},
|
|
message: createMessage([createOpaqueRecord(test_buffer_data)]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)])
|
|
},
|
|
{
|
|
desc: "Test that filtering 'text' record from different messages" +
|
|
" correctly with NFCScanOptions' compatibility set.",
|
|
scanOptions: {compatibility: "nfc-forum"},
|
|
message: createMessage([createTextRecord(test_text_data)]),
|
|
unmatchedMessage: createMessage([createJsonRecord(test_json_data)]),
|
|
unmatchedCompatibility: "vendor"
|
|
}
|
|
];
|
|
|
|
for (let NFCReaderOptionTest of NFCReaderOptionTests) {
|
|
testNFCScanOptions(
|
|
NFCReaderOptionTest.message,
|
|
NFCReaderOptionTest.scanOptions,
|
|
NFCReaderOptionTest.unmatchedScanOptions,
|
|
NFCReaderOptionTest.desc
|
|
);
|
|
}
|
|
|
|
for (let readMultiMessagesTest of ReadMultiMessagesTests) {
|
|
// Sets default message's associated compatibility
|
|
let unmatchedCompatibility = "nfc-forum";
|
|
if(readMultiMessagesTest.unmatchedCompatibility)
|
|
unmatchedCompatibility = readMultiMessagesTest.unmatchedCompatibility;
|
|
|
|
testReadingMultiMessages(
|
|
readMultiMessagesTest.message,
|
|
readMultiMessagesTest.scanOptions,
|
|
readMultiMessagesTest.unmatchedMessage,
|
|
unmatchedCompatibility,
|
|
readMultiMessagesTest.desc
|
|
);
|
|
}
|
|
</script>
|