DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<!DOCTYPE html>
<title>NDEFMessage constructor</title>
<link rel="help" href="https://w3c.github.io/web-nfc/#dom-ndefmessage">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc-helpers.js"></script>
<script>

  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');

</script>