Bug 1594347 [wpt PR 20112] - [webnfc] NDEFRecordInit#mediaType is only applicable for 'mime' records, a=testonly
authorLeon Han <leon.han@intel.com>
Mon, 25 Nov 2019 17:41:28 +0000
changeset 504469 6d6466cca7f789609489f7ec7c24ce767e51d27c
parent 504468 887502d04d1cb7e8ce0d631c1089ca18b9cc546c
child 504470 83f37687db83836ce619f9870cb30d1694207eb4
push id101897
push userwptsync@mozilla.com
push dateFri, 29 Nov 2019 11:10:32 +0000
treeherderautoland@47be1b3fdda6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1594347, 20112, 520391, 1900670, 714144
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1594347 [wpt PR 20112] - [webnfc] NDEFRecordInit#mediaType is only applicable for 'mime' records, a=testonly Automatic update from web-platform-tests [webnfc] NDEFRecordInit#mediaType is only applicable for 'mime' records mediaType does not make any sense for other record types. The spec change: https://github.com/w3c/web-nfc/pull/419 BUG=520391 Change-Id: Icf077c2fea64364f9a799a08d3aa630531590b7b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900670 Commit-Queue: Leon Han <leon.han@intel.com> Reviewed-by: Rijubrata Bhaumik <rijubrata.bhaumik@intel.com> Reviewed-by: Fran├žois Beaufort <beaufort.francois@gmail.com> Cr-Commit-Position: refs/heads/master@{#714144} -- wpt-commits: eaf583ff9cfe4ce36b517ae3519e114948ba10c3 wpt-pr: 20112
testing/web-platform/tests/resources/chromium/nfc-mock.js
testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.html
testing/web-platform/tests/web-nfc/NDEFReader_options.https.html
testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html
testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html
testing/web-platform/tests/web-nfc/NDEFWriter_push.https.html
testing/web-platform/tests/web-nfc/idlharness.https.window.js
testing/web-platform/tests/web-nfc/resources/nfc-helpers.js
--- a/testing/web-platform/tests/resources/chromium/nfc-mock.js
+++ b/testing/web-platform/tests/resources/chromium/nfc-mock.js
@@ -54,21 +54,21 @@ function toByteArray(data) {
 }
 
 // Compares NDEFRecords that were provided / received by the mock service.
 // TODO: Use different getters to get received record data,
 // see spec changes at https://github.com/w3c/web-nfc/pull/243.
 function compareNDEFRecords(providedRecord, receivedRecord) {
   assert_equals(providedRecord.recordType, receivedRecord.recordType);
 
-  // Compares media types without charset.
-  // Charset should be compared when watch method is implemented, in order
-  // to check that written and read strings are equal.
-  assert_equals(providedRecord.mediaType,
-      receivedRecord.mediaType.substring(0, providedRecord.mediaType.length));
+  if (providedRecord.mediaType === undefined) {
+    assert_equals(null, receivedRecord.mediaType);
+  } else {
+    assert_equals(providedRecord.mediaType, receivedRecord.mediaType);
+  }
 
   assert_not_equals(providedRecord.recordType, 'empty');
 
   assert_array_equals(toByteArray(providedRecord.data),
                       new Uint8Array(receivedRecord.data));
 }
 
 // Compares NDEFPushOptions structures that were provided to API and
--- a/testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.html
+++ b/testing/web-platform/tests/web-nfc/NDEFMessage_constructor.https.html
@@ -17,17 +17,17 @@
     assert_equals(message.records.length, 0, 'empty records');
   }, 'NDEFMessage constructor with null init dict');
 
   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, 'text/plain', 'mediaType');
+    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');
--- a/testing/web-platform/tests/web-nfc/NDEFReader_options.https.html
+++ b/testing/web-platform/tests/web-nfc/NDEFReader_options.https.html
@@ -12,17 +12,17 @@
 
 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', '')])
+      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)])
     },
@@ -54,18 +54,17 @@ const NDEFReaderOptionTests =
       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', 'application/octet-stream',
-            test_buffer_data)])
+      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)]}
@@ -80,17 +79,17 @@ const NDEFReaderOptionTests =
   ];
 
 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', '')]),
+      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)])
@@ -122,18 +121,17 @@ const ReadMultiMessagesTests =
       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', 'application/octet-stream',
-            test_buffer_data)]),
+      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)]},
--- a/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html
+++ b/testing/web-platform/tests/web-nfc/NDEFReader_scan.https.html
@@ -185,31 +185,31 @@ nfc_test(async (t, mockNFC) => {
 
 nfc_test(async (t, mockNFC) => {
   const reader = new NDEFReader();
   const controller = new AbortController();
   const readerWatcher = new EventWatcher(t, reader, ["reading", "error"]);
 
   const payloadMessage = createMessage([createTextRecord(test_text_data)]);
   const message = createMessage([createRecord('example.com:payloadIsMessage',
-          undefined, payloadMessage)]);
+          payloadMessage)]);
   mockNFC.setReadingMessage(message);
 
   reader.scan({signal : controller.signal});
   const event = await readerWatcher.wait_for("reading");
   controller.abort();
   assert_true(event instanceof NDEFReadingEvent);
   // The message contains only an external type record.
   assert_equals(event.message.records.length, 1);
   assert_equals(event.message.records[0].recordType, 'example.com:payloadIsMessage', 'recordType');
   // The external type record's payload is a message, which contains only a text record.
   const embeddedRecords = event.message.records[0].toRecords();
   assert_equals(embeddedRecords.length, 1);
   assert_equals(embeddedRecords[0].recordType, 'text', 'recordType');
-  assert_equals(embeddedRecords[0].mediaType, 'text/plain', 'mediaType');
+  assert_equals(embeddedRecords[0].mediaType, null, 'mediaType');
   const decoder = new TextDecoder();
   assert_equals(decoder.decode(embeddedRecords[0].data), test_text_data,
                   'data has the same content with the original dictionary');
 }, "NDEFRecord.toRecords returns its embedded records correctly.");
 
 test(() => {
   const reader = new NDEFReader();
   invalid_signals.forEach(invalid_signal => {
--- a/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html
+++ b/testing/web-platform/tests/web-nfc/NDEFRecord_constructor.https.html
@@ -12,59 +12,80 @@
   }, 'NDEFRecord constructor without init dict');
 
   test(() => {
     assert_throws(new TypeError, () => new NDEFRecord(null),
         'The record has neither type nor data.');
   }, 'NDEFRecord constructor with null init dict');
 
   test(() => {
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('empty', test_text_data, 'text/plain')),
+        'mediaType does not apply for empty record type.');
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('text', test_text_data, 'text/plain')),
+        'mediaType does not apply for text record type.');
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('url', test_url_data, 'text/plain')),
+        'mediaType does not apply for url record type.');
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('absolute-url', test_url_data, 'text/plain')),
+        'mediaType does not apply for absolute-url record type.');
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('unknown', test_buffer_data, 'application/octet-stream')),
+        'mediaType does not apply for unknown record type.');
+    assert_throws(new TypeError, () => new NDEFRecord(
+          createRecord('foo.example.com:bar', test_buffer_data, 'application/octet-stream')),
+        'mediaType does not apply for external record type.');
+  }, 'NDEFRecord constructor should only accept mediaType for mime record type');
+
+  test(() => {
     const record = new NDEFRecord(createTextRecord(test_text_data));
     assert_equals(record.recordType, 'text', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     assert_equals(record.encoding, 'utf-8', 'encoding');
     assert_equals(record.lang, 'en', 'lang');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_text_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with text record type and string data');
 
   test(() => {
     const encoder = new TextEncoder();
     const uint8Array = encoder.encode(test_text_data);
     const record = new NDEFRecord(createTextRecord(uint8Array.buffer));
     assert_equals(record.recordType, 'text', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     assert_equals(record.encoding, 'utf-8', 'encoding');
     assert_equals(record.lang, 'en', 'lang');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_text_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with text record type and arrayBuffer data');
 
   test(() => {
     const encoder = new TextEncoder();
     const uint8Array = encoder.encode(test_text_data);
     const record = new NDEFRecord(createTextRecord(uint8Array));
     assert_equals(record.recordType, 'text', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     assert_equals(record.encoding, 'utf-8', 'encoding');
     assert_equals(record.lang, 'en', 'lang');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_text_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with text record type and arrayBufferView data');
 
   test(() => {
     const encodings = ['utf-8', 'utf-16', 'utf-16be', 'utf-16le'];
     for (const encoding of encodings) {
       const lang = 'fr';
       const record = new NDEFRecord(createTextRecord(test_text_data, encoding, lang));
       assert_equals(record.recordType, 'text', 'recordType');
-      assert_equals(record.mediaType, 'text/plain', 'mediaType');
+      assert_equals(record.mediaType, null, 'mediaType');
       assert_equals(record.encoding, encoding, 'encoding');
       assert_equals(record.lang, lang, 'lang');
       const decoder = new TextDecoder();
       assert_equals(decoder.decode(record.data), test_text_data,
           'data has the same content with the original dictionary');
     }
   }, 'NDEFRecord constructor with text record type, encoding, and lang');
 
@@ -72,37 +93,37 @@
     const previous_lang = document.querySelector('html').getAttribute('lang');
     const test_lang = 'fr';
     document.querySelector('html').setAttribute('lang', test_lang);
     t.add_cleanup(() => {
       document.querySelector('html').setAttribute('lang', previous_lang);
     });
     const record = new NDEFRecord(createTextRecord(test_text_data));
     assert_equals(record.recordType, 'text', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     assert_equals(record.encoding, 'utf-8', 'encoding');
     assert_equals(record.lang, test_lang, 'lang');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_text_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with text record type and custom document language');
 
   test(() => {
     const record = new NDEFRecord(createUrlRecord(test_url_data));
     assert_equals(record.recordType, 'url', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_url_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with url record type');
 
   test(() => {
     const record = new NDEFRecord(createUrlRecord(test_url_data, true));
     assert_equals(record.recordType, 'absolute-url', 'recordType');
-    assert_equals(record.mediaType, 'text/plain', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     const decoder = new TextDecoder();
     assert_equals(decoder.decode(record.data), test_url_data,
         'data has the same content with the original dictionary');
   }, 'NDEFRecord constructor with absolute-url record type');
 
   test(() => {
     assert_throws(new TypeError, () => new NDEFRecord(
           createMimeRecord("A string is not a BufferSource")),
@@ -161,44 +182,42 @@
     }
   }, 'NDEFRecord constructor with unknown record type');
 
   test(() => {
     let buffer = new ArrayBuffer(4);
     let buffer_view = new Uint8Array(buffer);
     let original_data = new Uint8Array([1, 2, 3, 4]);
     buffer_view.set(original_data);
-    const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', undefined, buffer));
+    const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', buffer));
     assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
-    assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
+    assert_equals(record.mediaType, null, 'mediaType');
     assert_array_equals(new Uint8Array(record.data.buffer), original_data,
         'data has the same content with the original buffer');
   }, 'NDEFRecord constructor with external record type');
 
   test(() => {
     assert_throws(new TypeError, () => new NDEFRecord(createRecord('EMptY')),
         'Unknown record type.');
-    assert_throws(new TypeError, () => new NDEFRecord(createRecord('TeXt', '', test_text_data)),
+    assert_throws(new TypeError, () => new NDEFRecord(createRecord('TeXt', test_text_data)),
         'Unknown record type.');
-    assert_throws(new TypeError, () => new NDEFRecord(createRecord('uRL', '', test_url_data)),
+    assert_throws(new TypeError, () => new NDEFRecord(createRecord('uRL', test_url_data)),
         'Unknown record type.');
-    assert_throws(new TypeError, () => new NDEFRecord(createRecord('jSoN', '', test_json_data)),
+    assert_throws(new TypeError, () => new NDEFRecord(createRecord('Mime', test_buffer_data)),
         'Unknown record type.');
-    assert_throws(new TypeError, () => new NDEFRecord(createRecord('OpaQUE', '', test_buffer_data)),
-        'Unknown record type.');
-    assert_throws(new TypeError, () => new NDEFRecord(createRecord('sMart-PosTER', '', test_url_data)),
+    assert_throws(new TypeError, () => new NDEFRecord(createRecord('sMart-PosTER', test_url_data)),
         'Unknown record type.');
   }, 'NDEFRecord constructor with record type string being treated as case sensitive');
 
   test(() => {
     assert_throws(new TypeError, () => new NDEFRecord(createRecord(
-        ':xyz', '', test_buffer_data)), 'The domain should not be empty.');
+        ':xyz', test_buffer_data)), 'The domain should not be empty.');
     assert_throws(new TypeError, () => new NDEFRecord(createRecord(
-        '[:xyz', '', test_buffer_data)), '"[" is not a valid FQDN.');
+        '[:xyz', test_buffer_data)), '"[" is not a valid FQDN.');
     assert_throws(new TypeError, () => new NDEFRecord(createRecord(
-        'example.com:', '', test_buffer_data)), 'The type should not be empty.');
+        'example.com:', test_buffer_data)), 'The type should not be empty.');
     assert_throws(new TypeError, () => new NDEFRecord(createRecord(
-        'example.com:xyz~', '', test_buffer_data)), 'The type should not contain \'~\'.');
+        'example.com:xyz~', test_buffer_data)), 'The type should not contain \'~\'.');
     assert_throws(new TypeError, () => new NDEFRecord(createRecord(
-        'example.com:xyz/', '', test_buffer_data)), 'The type should not contain \'/\'.');
+        'example.com:xyz/', test_buffer_data)), 'The type should not contain \'/\'.');
   }, 'NDEFRecord constructor with invalid external record type');
 
 </script>
--- a/testing/web-platform/tests/web-nfc/NDEFWriter_push.https.html
+++ b/testing/web-platform/tests/web-nfc/NDEFWriter_push.https.html
@@ -71,35 +71,31 @@ const invalid_type_messages =
 
       // NDEFRecord.data for 'unknown' record must be BufferSource.
       createMessage([createUnknownRecord(test_text_data)]),
       createMessage([createUnknownRecord(test_number_data)]),
       createMessage([createUnknownRecord(test_json_data)]),
 
       // https://w3c.github.io/web-nfc/#dfn-map-external-data-to-ndef
       // NDEFRecord must have data.
-      createMessage([createRecord('w3.org:xyz', '', undefined)]),
+      createMessage([createRecord('w3.org:xyz')]),
 
       // NDEFRecord.data for external record must be ArrayBuffer.
-      createMessage([createRecord('w3.org:xyz', '', test_text_data)]),
-      createMessage([createRecord('w3.org:xyz', '', test_number_data)]),
-      createMessage([createRecord('w3.org:xyz', '', test_json_data)]),
+      createMessage([createRecord('w3.org:xyz', test_text_data)]),
+      createMessage([createRecord('w3.org:xyz', test_number_data)]),
+      createMessage([createRecord('w3.org:xyz', test_json_data)]),
 
       // https://w3c.github.io/web-nfc/#the-ndefrecordtype-string
       // The record type is neither a known type ('text', 'mime' etc.) nor a
       // valid custom type for an external type record.
-      createMessage([createRecord('unmatched_type', '', test_buffer_data)])
+      createMessage([createRecord('unmatched_type', test_buffer_data)])
     ];
 
 const invalid_syntax_messages =
     [
-      // NDEFRecord.mediaType for 'text' record must be 'text/*'.
-      createMessage([createRecord('text', 'application/json',
-          test_text_data)]),
-
       // Data for 'url' or 'absolute-url' record, must be a valid URL.
       createMessage([createUrlRecord('Invalid URL:// Data')]),
       createMessage([createUrlRecord('Invalid URL:// Data', true)]),
     ];
 
 const invalid_signals = [
   "string",
   123,
@@ -289,17 +285,17 @@ nfc_test(async () => {
 nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
   let message = createMessage([createTextRecord(test_text_data),
                                createMimeRecordFromJson(test_json_data),
                                createMimeRecord(test_buffer_data),
                                createUnknownRecord(test_buffer_data),
                                createUrlRecord(test_url_data),
                                createUrlRecord(test_url_data, true),
-                               createRecord('w3.org:xyz', '', test_buffer_data)],
+                               createRecord('w3.org:xyz', test_buffer_data)],
                                test_message_origin);
   await writer.push(message);
   assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
 }, "NDEFWriter.push NDEFMessage containing text, mime, unknown, url, absolute-url \
 and external records with default NDEFPushOptions.");
 
 nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
@@ -409,41 +405,24 @@ nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
   await writer.push({ records: [{ data: test_buffer_data}] });
   assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage());
 }, "Test that recordType should be set to 'mime' if NDEFRecordInit.record's \
 recordType is undefined and NDEFRecordInit.record's data is not DOMString.");
 
 nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
-  await writer.push({ records: [{ recordType: "text", data: test_text_data }] });
-  assertNDEFMessagesEqual(test_text_data, mockNFC.pushedMessage());
-}, "Test that mediaType should be set to 'text/plain' if NDEFRecordInit.record's \
-recordType is 'text' and NDEFRecordInit.record's mediaType is undefined.");
-
-nfc_test(async (t, mockNFC) => {
-  const writer = new NDEFWriter();
   await writer.push({ records: [{ recordType: "mime", data: test_buffer_data }] });
   assertNDEFMessagesEqual(test_buffer_data, mockNFC.pushedMessage());
 }, "Test that mediaType should be set to 'application/octet-stream' if \
 NDEFRecordInit.record's recordType is 'mime' and NDEFRecordInit.record's \
 mediaType is undefined.");
 
 nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
-  await writer.push({ records: [{ recordType: "w3.org:xyz", data: test_buffer_data }] });
-  const message = createMessage([createRecord('w3.org:xyz', 'application/octet-stream',
-      test_buffer_data)]);
-  assertNDEFMessagesEqual(message, mockNFC.pushedMessage());
-}, "Test that mediaType should be set to 'application/octet-stream' if \
-NDEFRecordInit.record's recordType is external type and NDEFRecordInit.record's \
-mediaType is undefined.");
-
-nfc_test(async (t, mockNFC) => {
-  const writer = new NDEFWriter();
   mockNFC.setIsNDEFTech(false);
   await promise_rejects(t, 'NotSupportedError', writer.push(test_text_data));
 }, "NDEFWriter.push should fail when the NFC device does not expose \
 NDEF technology.");
 
 nfc_test(async (t, mockNFC) => {
   const writer = new NDEFWriter();
   await writer.push(test_text_data, { overwrite: false });
--- a/testing/web-platform/tests/web-nfc/idlharness.https.window.js
+++ b/testing/web-platform/tests/web-nfc/idlharness.https.window.js
@@ -2,17 +2,16 @@
 // META: script=/resources/idlharness.js
 
 'use strict';
 
 // https://w3c.github.io/web-nfc/
 
 const record = {
   recordType: "text",
-  mediaType: "text/plain",
   data: "Hello World",
   id: "/custom/path"
 };
 const message = {
   url: "/custom/path",
   records: [record]
 };
 
--- a/testing/web-platform/tests/web-nfc/resources/nfc-helpers.js
+++ b/testing/web-platform/tests/web-nfc/resources/nfc-helpers.js
@@ -79,54 +79,54 @@ NFCHWStatus.DISABLED = NFCHWStatus.NOT_S
 function createMessage(records) {
   if (records !== undefined) {
     let message = {};
     message.records = records;
     return message;
   }
 }
 
-function createRecord(recordType, mediaType, data, encoding, lang) {
+function createRecord(recordType, data, mediaType, encoding, lang) {
   let record = {};
   if (recordType !== undefined)
     record.recordType = recordType;
   if (mediaType !== undefined)
     record.mediaType = mediaType;
   if (encoding !== undefined)
     record.encoding = encoding;
   if (lang !== undefined)
     record.lang = lang;
   if (data !== undefined)
     record.data = data;
   return record;
 }
 
 function createTextRecord(data, encoding, lang) {
-  return createRecord('text', 'text/plain', data, encoding, lang);
+  return createRecord('text', data, undefined, encoding, lang);
 }
 
 function createMimeRecordFromJson(json) {
   return createRecord(
-      'mime', 'application/json',
-      new TextEncoder('utf-8').encode(JSON.stringify(json)));
+      'mime', new TextEncoder('utf-8').encode(JSON.stringify(json)),
+      'application/json');
 }
 
 function createMimeRecord(buffer) {
-  return createRecord('mime', 'application/octet-stream', buffer);
+  return createRecord('mime', buffer, 'application/octet-stream');
 }
 
 function createUnknownRecord(buffer) {
-  return createRecord('unknown', '', buffer);
+  return createRecord('unknown', buffer);
 }
 
 function createUrlRecord(url, isAbsUrl) {
   if (isAbsUrl) {
-    return createRecord('absolute-url', 'text/plain', url);
+    return createRecord('absolute-url', url);
   }
-  return createRecord('url', 'text/plain', url);
+  return createRecord('url', url);
 }
 
 function createNDEFPushOptions(target, timeout, ignoreRead) {
   return {target, timeout, ignoreRead};
 }
 
 // Compares NDEFMessageSource that was provided to the API
 // (e.g. NDEFWriter.push), and NDEFMessage that was received by the