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 (491b05117886)

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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<!DOCTYPE html>
<title>NDEFReadingEvent constructor</title>
<link rel="help" href="https://w3c.github.io/web-nfc/#dom-ndefreadingevent">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc-helpers.js"></script>
<script>

  test(() => {
    assert_equals(NDEFReadingEvent.length, 2);
    assert_throws(new TypeError, () => new NDEFReadingEvent('message'));
  }, 'NDEFReadingEvent constructor without init dict');

  test(() => {
    const message = createMessage([createMimeRecordFromJson(test_buffer_data)]);
    const event = new NDEFReadingEvent('type', {serialNumber: null, message: message});
    assert_equals(event.serialNumber, '', 'serialNumber');
  }, 'NDEFReadingEvent constructor with null serialNumber');

  test(() => {
    const message = createMessage([createMimeRecordFromJson(test_buffer_data)]);
    const event = new NDEFReadingEvent('type', {message: message});
    assert_equals(event.serialNumber, '', 'serialNumber');
  }, 'NDEFReadingEvent constructor with serialNumber not present');

  test(() => {
    const event = new NDEFReadingEvent('type', {serialNumber: '', message: null});
    assert_equals(0, event.message.records.length, 'no records');
    assert_equals(0, event.message.url.length, 'empty url');
  }, 'NDEFReadingEvent constructor with null message');

  test(() => {
    const message = createMessage([createMimeRecord(test_buffer_data)]);
    const event = new NDEFReadingEvent('type', {serialNumber: '', message: message});
    assert_equals(event.type, 'type', 'type');
    assert_equals(event.serialNumber, '', 'serialNumber');
    assertWebNDEFMessagesEqual(event.message, new NDEFMessage(message));
  }, 'NDEFReadingEvent constructor with valid parameters');

  test(() => {
    const record_init = createTextRecord(test_text_data);
    const event = new NDEFReadingEvent('type',
        {serialNumber: '', message: createMessage([record_init])});
    assert_equals(event.type, 'type', 'type');
    assert_equals(event.serialNumber, '', 'serialNumber');
    assert_equals(1, event.message.records.length, 'only 1 record');

    const record = new NDEFRecord(record_init);
    assert_equals(record.recordType, 'text', 'recordType');
    assert_equals(record.mediaType, null, 'mediaType');
    assert_equals(record.encoding, 'utf-8', 'encoding');
    assert_equals(record.lang, 'en', 'lang');

    assert_equals(event.message.records[0].recordType, 'text', 'recordType');
    assert_equals(event.message.records[0].mediaType, null, 'mediaType');
    assert_equals(event.message.records[0].encoding, 'utf-8', 'encoding');
    assert_equals(event.message.records[0].lang, null, 'lang is not set');
  }, 'NDEFReadingEvent constructor does not set NDEFRecord#lang for any text records it embeds');

</script>