Commit ac8e37fa authored by Francois Beaufort's avatar Francois Beaufort Committed by Commit Bot

[WebNFC] Rename toText, toJSON, and toArrayBuffer NDEFRecord methods

This CL renames NDEFRecord methods "toText()" to "text()", "toJSON()" to
"json()", and "toArrayBuffer()", to "arrayBuffer() as decided at
https://github.com/w3c/web-nfc/pull/370

Change-Id: I8a540ee68b34863e09df562c2075e0d3c786462a
Bug: 520391
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855921Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#705531}
parent 4b5a4f4f
...@@ -283,7 +283,7 @@ const String& NDEFRecord::mediaType() const { ...@@ -283,7 +283,7 @@ const String& NDEFRecord::mediaType() const {
return media_type_; return media_type_;
} }
String NDEFRecord::toText() const { String NDEFRecord::text() const {
if (record_type_ == "empty") if (record_type_ == "empty")
return String(); return String();
...@@ -293,7 +293,7 @@ String NDEFRecord::toText() const { ...@@ -293,7 +293,7 @@ String NDEFRecord::toText() const {
return String::FromUTF8WithLatin1Fallback(data_.data(), data_.size()); return String::FromUTF8WithLatin1Fallback(data_.data(), data_.size());
} }
DOMArrayBuffer* NDEFRecord::toArrayBuffer() const { DOMArrayBuffer* NDEFRecord::arrayBuffer() const {
if (record_type_ == "empty" || record_type_ == "text" || if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url") { record_type_ == "url") {
return nullptr; return nullptr;
...@@ -304,8 +304,8 @@ DOMArrayBuffer* NDEFRecord::toArrayBuffer() const { ...@@ -304,8 +304,8 @@ DOMArrayBuffer* NDEFRecord::toArrayBuffer() const {
return DOMArrayBuffer::Create(data_.data(), data_.size()); return DOMArrayBuffer::Create(data_.data(), data_.size());
} }
ScriptValue NDEFRecord::toJSON(ScriptState* script_state, ScriptValue NDEFRecord::json(ScriptState* script_state,
ExceptionState& exception_state) const { ExceptionState& exception_state) const {
if (record_type_ == "empty" || record_type_ == "text" || if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url") { record_type_ == "url") {
return ScriptValue::CreateNull(script_state->GetIsolate()); return ScriptValue::CreateNull(script_state->GetIsolate());
......
...@@ -37,9 +37,9 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable { ...@@ -37,9 +37,9 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
const String& recordType() const; const String& recordType() const;
const String& mediaType() const; const String& mediaType() const;
String toText() const; String text() const;
DOMArrayBuffer* toArrayBuffer() const; DOMArrayBuffer* arrayBuffer() const;
ScriptValue toJSON(ScriptState*, ExceptionState&) const; ScriptValue json(ScriptState*, ExceptionState&) const;
const WTF::Vector<uint8_t>& data() const; const WTF::Vector<uint8_t>& data() const;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
] interface NDEFRecord { ] interface NDEFRecord {
readonly attribute NDEFRecordType recordType; readonly attribute NDEFRecordType recordType;
readonly attribute USVString mediaType; readonly attribute USVString mediaType;
USVString? toText(); USVString? text();
[NewObject] ArrayBuffer? toArrayBuffer(); [NewObject] ArrayBuffer? arrayBuffer();
[CallWith=ScriptState, RaisesException] object? toJSON(); [CallWith=ScriptState, RaisesException] object? json();
}; };
...@@ -21,9 +21,9 @@ interface NDEFRecord { ...@@ -21,9 +21,9 @@ interface NDEFRecord {
readonly attribute USVString mediaType; readonly attribute USVString mediaType;
readonly attribute USVString id; readonly attribute USVString id;
USVString? toText(); USVString? text();
[NewObject] ArrayBuffer? toArrayBuffer(); [NewObject] ArrayBuffer? arrayBuffer();
[NewObject] any toJSON(); [NewObject] any json();
sequence<NDEFRecord> toRecords(); sequence<NDEFRecord> toRecords();
}; };
......
...@@ -23,13 +23,13 @@ ...@@ -23,13 +23,13 @@
assert_equals(message.records.length, 1, 'one text record'); assert_equals(message.records.length, 1, 'one text record');
assert_equals(message.records[0].recordType, 'text', 'messageType'); assert_equals(message.records[0].recordType, 'text', 'messageType');
assert_equals(message.records[0].mediaType, 'text/plain', 'mediaType'); assert_equals(message.records[0].mediaType, 'text/plain', 'mediaType');
assert_true(typeof message.records[0].toText() === 'string'); assert_true(typeof message.records[0].text() === 'string');
assert_equals(message.records[0].toText(), test_text_data, assert_equals(message.records[0].text(), test_text_data,
'toText() contains the same text content'); 'text() contains the same text content');
assert_equals(message.records[0].toArrayBuffer(), null, assert_equals(message.records[0].arrayBuffer(), null,
'toArrayBuffer() returns null'); 'arrayBuffer() returns null');
assert_equals(message.records[0].toJSON(), null, assert_equals(message.records[0].json(), null,
'toJSON() returns null'); 'json() returns null');
}, 'NDEFMessage constructor with a text record'); }, 'NDEFMessage constructor with a text record');
</script> </script>
...@@ -20,16 +20,16 @@ ...@@ -20,16 +20,16 @@
const record = new NDEFRecord(createTextRecord(test_text_data)); const record = new NDEFRecord(createTextRecord(test_text_data));
assert_equals(record.recordType, 'text', 'recordType'); assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, 'text/plain', 'mediaType'); assert_equals(record.mediaType, 'text/plain', 'mediaType');
assert_equals(record.toText(), test_text_data, assert_equals(record.text(), test_text_data,
'toText() has the same content with the original dictionary'); 'text() has the same content with the original dictionary');
}, 'NDEFRecord constructor with text record type'); }, 'NDEFRecord constructor with text record type');
test(() => { test(() => {
const record = new NDEFRecord(createUrlRecord(test_url_data)); const record = new NDEFRecord(createUrlRecord(test_url_data));
assert_equals(record.recordType, 'url', 'recordType'); assert_equals(record.recordType, 'url', 'recordType');
assert_equals(record.mediaType, 'text/plain', 'mediaType'); assert_equals(record.mediaType, 'text/plain', 'mediaType');
assert_equals(record.toText(), test_url_data, assert_equals(record.text(), test_url_data,
'toText() has the same content with the original dictionary'); 'text() has the same content with the original dictionary');
}, 'NDEFRecord constructor with url record type'); }, 'NDEFRecord constructor with url record type');
test(() => { test(() => {
...@@ -41,28 +41,28 @@ ...@@ -41,28 +41,28 @@
assert_equals(record.recordType, 'opaque', 'recordType'); assert_equals(record.recordType, 'opaque', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType'); assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
const data_1 = record.toArrayBuffer(); const data_1 = record.arrayBuffer();
assert_true(data_1 instanceof ArrayBuffer); assert_true(data_1 instanceof ArrayBuffer);
assert_not_equals(data_1, buffer, 'toArrayBuffer() returns a new object'); assert_not_equals(data_1, buffer, 'arrayBuffer() returns a new object');
assert_array_equals(new Uint8Array(data_1), original_data, assert_array_equals(new Uint8Array(data_1), original_data,
'toArrayBuffer() has the same content with the original buffer'); 'arrayBuffer() has the same content with the original buffer');
const data_2 = record.toArrayBuffer(); const data_2 = record.arrayBuffer();
assert_true(data_2 instanceof ArrayBuffer); assert_true(data_2 instanceof ArrayBuffer);
assert_not_equals(data_2, data_1, assert_not_equals(data_2, data_1,
'toArrayBuffer() again returns another new object'); 'arrayBuffer() again returns another new object');
assert_array_equals(new Uint8Array(data_2), original_data, assert_array_equals(new Uint8Array(data_2), original_data,
'toArrayBuffer() has the same content with the original buffer'); 'arrayBuffer() has the same content with the original buffer');
buffer_view.set([4, 3, 2, 1]); buffer_view.set([4, 3, 2, 1]);
const data_3 = record.toArrayBuffer(); const data_3 = record.arrayBuffer();
assert_true(data_3 instanceof ArrayBuffer); assert_true(data_3 instanceof ArrayBuffer);
assert_array_equals(new Uint8Array(data_1), original_data, assert_array_equals(new Uint8Array(data_1), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
assert_array_equals(new Uint8Array(data_2), original_data, assert_array_equals(new Uint8Array(data_2), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
assert_array_equals(new Uint8Array(data_3), original_data, assert_array_equals(new Uint8Array(data_3), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
}, 'NDEFRecord constructor with opaque record type'); }, 'NDEFRecord constructor with opaque record type');
test(() => { test(() => {
...@@ -70,18 +70,18 @@ ...@@ -70,18 +70,18 @@
assert_equals(record.recordType, 'json', 'recordType'); assert_equals(record.recordType, 'json', 'recordType');
assert_equals(record.mediaType, 'application/json', 'mediaType'); assert_equals(record.mediaType, 'application/json', 'mediaType');
const data_1 = record.toJSON(); const data_1 = record.json();
assert_true(typeof data_1 === 'object'); assert_true(typeof data_1 === 'object');
assert_not_equals(data_1, test_json_data, 'toJSON() returns a new object'); assert_not_equals(data_1, test_json_data, 'json() returns a new object');
assert_object_equals(data_1, test_json_data, assert_object_equals(data_1, test_json_data,
'toJSON() has the same content with the original dictionary'); 'json() has the same content with the original dictionary');
const data_2 = record.toJSON(); const data_2 = record.json();
assert_true(typeof data_2 === 'object'); assert_true(typeof data_2 === 'object');
assert_not_equals(data_2, data_1, assert_not_equals(data_2, data_1,
'toJSON() again returns another new object'); 'json() again returns another new object');
assert_object_equals(data_2, test_json_data, assert_object_equals(data_2, test_json_data,
'toJSON() has the same content with the original dictionary'); 'json() has the same content with the original dictionary');
}, 'NDEFRecord constructor with JSON record type'); }, 'NDEFRecord constructor with JSON record type');
test(() => { test(() => {
...@@ -93,28 +93,28 @@ ...@@ -93,28 +93,28 @@
assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType'); assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType'); assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
const data_1 = record.toArrayBuffer(); const data_1 = record.arrayBuffer();
assert_true(data_1 instanceof ArrayBuffer); assert_true(data_1 instanceof ArrayBuffer);
assert_not_equals(data_1, buffer, 'toArrayBuffer() returns a new object'); assert_not_equals(data_1, buffer, 'arrayBuffer() returns a new object');
assert_array_equals(new Uint8Array(data_1), original_data, assert_array_equals(new Uint8Array(data_1), original_data,
'toArrayBuffer() has the same content with the original buffer'); 'arrayBuffer() has the same content with the original buffer');
const data_2 = record.toArrayBuffer(); const data_2 = record.arrayBuffer();
assert_true(data_2 instanceof ArrayBuffer); assert_true(data_2 instanceof ArrayBuffer);
assert_not_equals(data_2, data_1, assert_not_equals(data_2, data_1,
'toArrayBuffer() again returns another new object'); 'arrayBuffer() again returns another new object');
assert_array_equals(new Uint8Array(data_2), original_data, assert_array_equals(new Uint8Array(data_2), original_data,
'toArrayBuffer() has the same content with the original buffer'); 'arrayBuffer() has the same content with the original buffer');
buffer_view.set([4, 3, 2, 1]); buffer_view.set([4, 3, 2, 1]);
const data_3 = record.toArrayBuffer(); const data_3 = record.arrayBuffer();
assert_true(data_3 instanceof ArrayBuffer); assert_true(data_3 instanceof ArrayBuffer);
assert_array_equals(new Uint8Array(data_1), original_data, assert_array_equals(new Uint8Array(data_1), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
assert_array_equals(new Uint8Array(data_2), original_data, assert_array_equals(new Uint8Array(data_2), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
assert_array_equals(new Uint8Array(data_3), original_data, assert_array_equals(new Uint8Array(data_3), original_data,
'Modifying the original buffer does not affect toArrayBuffer() content'); 'Modifying the original buffer does not affect arrayBuffer() content');
}, 'NDEFRecord constructor with external record type'); }, 'NDEFRecord constructor with external record type');
test(() => { test(() => {
......
This is a testharness.js-based test. This is a testharness.js-based test.
Found 83 tests; 78 PASS, 5 FAIL, 0 TIMEOUT, 0 NOTRUN. Found 82 tests; 78 PASS, 4 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup PASS idl_test setup
PASS idl_test validation PASS idl_test validation
PASS NDEFMessage interface: existence and properties of interface object PASS NDEFMessage interface: existence and properties of interface object
...@@ -21,19 +21,18 @@ PASS NDEFRecord interface: existence and properties of interface prototype objec ...@@ -21,19 +21,18 @@ PASS NDEFRecord interface: existence and properties of interface prototype objec
PASS NDEFRecord interface: attribute recordType PASS NDEFRecord interface: attribute recordType
PASS NDEFRecord interface: attribute mediaType PASS NDEFRecord interface: attribute mediaType
FAIL NDEFRecord interface: attribute id assert_true: The prototype object must have a property "id" expected true got false FAIL NDEFRecord interface: attribute id assert_true: The prototype object must have a property "id" expected true got false
PASS NDEFRecord interface: operation toText() PASS NDEFRecord interface: operation text()
PASS NDEFRecord interface: operation toArrayBuffer() PASS NDEFRecord interface: operation arrayBuffer()
PASS NDEFRecord interface: operation toJSON() PASS NDEFRecord interface: operation json()
FAIL NDEFRecord interface: operation toRecords() assert_own_property: interface prototype object missing non-static operation expected property "toRecords" missing FAIL NDEFRecord interface: operation toRecords() assert_own_property: interface prototype object missing non-static operation expected property "toRecords" missing
PASS NDEFRecord must be primary interface of new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); PASS NDEFRecord must be primary interface of new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"});
PASS Stringification of new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); PASS Stringification of new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"});
PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "recordType" with the proper type PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "recordType" with the proper type
PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "mediaType" with the proper type PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "mediaType" with the proper type
FAIL NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "id" with the proper type assert_inherits: property "id" not found in prototype chain FAIL NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "id" with the proper type assert_inherits: property "id" not found in prototype chain
PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "toText()" with the proper type PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "text()" with the proper type
PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "toArrayBuffer()" with the proper type PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "arrayBuffer()" with the proper type
PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "toJSON()" with the proper type PASS NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "json()" with the proper type
FAIL NDEFRecord interface: toJSON operation on new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); assert_true: {"type":"return-type","extAttrs":[],"generic":"","nullable":false,"union":false,"idlType":"any"} is not an appropriate return value for the toJSON operation of NDEFRecord expected true got false
FAIL NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "toRecords()" with the proper type assert_inherits: property "toRecords" not found in prototype chain FAIL NDEFRecord interface: new NDEFRecord({"recordType":"text","mediaType":"text/plain","data":"Hello World","id":"/custom/path"}); must inherit property "toRecords()" with the proper type assert_inherits: property "toRecords" not found in prototype chain
PASS NFCWriter interface: existence and properties of interface object PASS NFCWriter interface: existence and properties of interface object
PASS NFCWriter interface object length PASS NFCWriter interface object length
......
...@@ -152,17 +152,17 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) { ...@@ -152,17 +152,17 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) {
assert_equals(record.mediaType, expectedRecord.mediaType); assert_equals(record.mediaType, expectedRecord.mediaType);
// Compares record data // Compares record data
assert_equals(record.toText(), expectedRecord.toText()); assert_equals(record.text(), expectedRecord.text());
assert_array_equals(new Uint8Array(record.toArrayBuffer()), assert_array_equals(new Uint8Array(record.arrayBuffer()),
new Uint8Array(expectedRecord.toArrayBuffer())); new Uint8Array(expectedRecord.arrayBuffer()));
let json; let json;
try { try {
json = record.toJSON(); json = record.json();
} catch (e) { } catch (e) {
} }
let expectedJson; let expectedJson;
try { try {
expectedJson = expectedRecord.toJSON(); expectedJson = expectedRecord.json();
} catch (e) { } catch (e) {
} }
if (json === undefined || json === null) if (json === undefined || json === null)
......
...@@ -5120,10 +5120,10 @@ interface NDEFRecord ...@@ -5120,10 +5120,10 @@ interface NDEFRecord
attribute @@toStringTag attribute @@toStringTag
getter mediaType getter mediaType
getter recordType getter recordType
method arrayBuffer
method constructor method constructor
method toArrayBuffer method json
method toJSON method text
method toText
interface NFCErrorEvent : Event interface NFCErrorEvent : Event
attribute @@toStringTag attribute @@toStringTag
getter error getter error
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment