diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js')
-rw-r--r-- | testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js b/testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js new file mode 100644 index 0000000000..f4d9a441b4 --- /dev/null +++ b/testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.window.js @@ -0,0 +1,42 @@ +// META: script=resources/nfc-helpers.js + +'use strict'; + +test(() => { + assert_equals(NDEFMessage.length, 1); + assert_throws_js(TypeError, () => new NDEFMessage()); +}, 'NDEFMessage constructor without init dict'); + +test(() => { + assert_throws_js( + TypeError, () => new NDEFMessage(null), + 'NDEFMessageInit#records is a required field.'); +}, 'NDEFMessage constructor with null init dict'); + +test(() => { + assert_throws_js( + TypeError, () => new NDEFMessage({dummy_key: 'dummy_value'}), + 'NDEFMessageInit#records is a required field.'); +}, 'NDEFMessage constructor without NDEFMessageInit#records field'); + +test(() => { + assert_throws_js( + TypeError, () => new NDEFMessage({records: []}), + 'NDEFMessageInit#records should not be empty.'); +}, 'NDEFMessage constructor with NDEFMessageInit#records being empty'); + +test(() => { + const message = + new NDEFMessage(createMessage([createTextRecord(test_text_data)])); + assert_equals(message.records.length, 1, 'one text record'); + assert_equals(message.records[0].recordType, 'text', 'messageType'); + assert_equals(message.records[0].mediaType, null, 'mediaType'); + assert_equals(message.records[0].encoding, 'utf-8', 'encoding'); + assert_equals(message.records[0].lang, 'en', 'lang'); + assert_true( + message.records[0].data instanceof DataView, 'data returns a DataView'); + const decoder = new TextDecoder(); + assert_equals( + decoder.decode(message.records[0].data), test_text_data, + 'data contains the same text content'); +}, 'NDEFMessage constructor with a text record'); |