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 {
return media_type_;
}
String NDEFRecord::toText() const {
String NDEFRecord::text() const {
if (record_type_ == "empty")
return String();
......@@ -293,7 +293,7 @@ String NDEFRecord::toText() const {
return String::FromUTF8WithLatin1Fallback(data_.data(), data_.size());
}
DOMArrayBuffer* NDEFRecord::toArrayBuffer() const {
DOMArrayBuffer* NDEFRecord::arrayBuffer() const {
if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url") {
return nullptr;
......@@ -304,8 +304,8 @@ DOMArrayBuffer* NDEFRecord::toArrayBuffer() const {
return DOMArrayBuffer::Create(data_.data(), data_.size());
}
ScriptValue NDEFRecord::toJSON(ScriptState* script_state,
ExceptionState& exception_state) const {
ScriptValue NDEFRecord::json(ScriptState* script_state,
ExceptionState& exception_state) const {
if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url") {
return ScriptValue::CreateNull(script_state->GetIsolate());
......
......@@ -37,9 +37,9 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
const String& recordType() const;
const String& mediaType() const;
String toText() const;
DOMArrayBuffer* toArrayBuffer() const;
ScriptValue toJSON(ScriptState*, ExceptionState&) const;
String text() const;
DOMArrayBuffer* arrayBuffer() const;
ScriptValue json(ScriptState*, ExceptionState&) const;
const WTF::Vector<uint8_t>& data() const;
......
......@@ -13,7 +13,7 @@
] interface NDEFRecord {
readonly attribute NDEFRecordType recordType;
readonly attribute USVString mediaType;
USVString? toText();
[NewObject] ArrayBuffer? toArrayBuffer();
[CallWith=ScriptState, RaisesException] object? toJSON();
USVString? text();
[NewObject] ArrayBuffer? arrayBuffer();
[CallWith=ScriptState, RaisesException] object? json();
};
......@@ -21,9 +21,9 @@ interface NDEFRecord {
readonly attribute USVString mediaType;
readonly attribute USVString id;
USVString? toText();
[NewObject] ArrayBuffer? toArrayBuffer();
[NewObject] any toJSON();
USVString? text();
[NewObject] ArrayBuffer? arrayBuffer();
[NewObject] any json();
sequence<NDEFRecord> toRecords();
};
......
......@@ -23,13 +23,13 @@
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_true(typeof message.records[0].toText() === 'string');
assert_equals(message.records[0].toText(), test_text_data,
'toText() contains the same text content');
assert_equals(message.records[0].toArrayBuffer(), null,
'toArrayBuffer() returns null');
assert_equals(message.records[0].toJSON(), null,
'toJSON() returns null');
assert_true(typeof message.records[0].text() === 'string');
assert_equals(message.records[0].text(), test_text_data,
'text() contains the same text content');
assert_equals(message.records[0].arrayBuffer(), null,
'arrayBuffer() returns null');
assert_equals(message.records[0].json(), null,
'json() returns null');
}, 'NDEFMessage constructor with a text record');
</script>
......@@ -20,16 +20,16 @@
const record = new NDEFRecord(createTextRecord(test_text_data));
assert_equals(record.recordType, 'text', 'recordType');
assert_equals(record.mediaType, 'text/plain', 'mediaType');
assert_equals(record.toText(), test_text_data,
'toText() has the same content with the original dictionary');
assert_equals(record.text(), test_text_data,
'text() has the same content with the original dictionary');
}, 'NDEFRecord constructor with text record type');
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.toText(), test_url_data,
'toText() has the same content with the original dictionary');
assert_equals(record.text(), test_url_data,
'text() has the same content with the original dictionary');
}, 'NDEFRecord constructor with url record type');
test(() => {
......@@ -41,28 +41,28 @@
assert_equals(record.recordType, 'opaque', 'recordType');
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_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,
'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_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,
'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]);
const data_3 = record.toArrayBuffer();
const data_3 = record.arrayBuffer();
assert_true(data_3 instanceof ArrayBuffer);
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,
'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,
'Modifying the original buffer does not affect toArrayBuffer() content');
'Modifying the original buffer does not affect arrayBuffer() content');
}, 'NDEFRecord constructor with opaque record type');
test(() => {
......@@ -70,18 +70,18 @@
assert_equals(record.recordType, 'json', 'recordType');
assert_equals(record.mediaType, 'application/json', 'mediaType');
const data_1 = record.toJSON();
const data_1 = record.json();
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,
'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_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,
'toJSON() has the same content with the original dictionary');
'json() has the same content with the original dictionary');
}, 'NDEFRecord constructor with JSON record type');
test(() => {
......@@ -93,28 +93,28 @@
assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
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_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,
'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_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,
'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]);
const data_3 = record.toArrayBuffer();
const data_3 = record.arrayBuffer();
assert_true(data_3 instanceof ArrayBuffer);
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,
'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,
'Modifying the original buffer does not affect toArrayBuffer() content');
'Modifying the original buffer does not affect arrayBuffer() content');
}, 'NDEFRecord constructor with external record type');
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 validation
PASS NDEFMessage interface: existence and properties of interface object
......@@ -21,19 +21,18 @@ PASS NDEFRecord interface: existence and properties of interface prototype objec
PASS NDEFRecord interface: attribute recordType
PASS NDEFRecord interface: attribute mediaType
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 toArrayBuffer()
PASS NDEFRecord interface: operation toJSON()
PASS NDEFRecord interface: operation text()
PASS NDEFRecord interface: operation arrayBuffer()
PASS NDEFRecord interface: operation json()
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 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 "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
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 "toArrayBuffer()" 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
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
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 "arrayBuffer()" 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: 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 object length
......
......@@ -152,17 +152,17 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) {
assert_equals(record.mediaType, expectedRecord.mediaType);
// Compares record data
assert_equals(record.toText(), expectedRecord.toText());
assert_array_equals(new Uint8Array(record.toArrayBuffer()),
new Uint8Array(expectedRecord.toArrayBuffer()));
assert_equals(record.text(), expectedRecord.text());
assert_array_equals(new Uint8Array(record.arrayBuffer()),
new Uint8Array(expectedRecord.arrayBuffer()));
let json;
try {
json = record.toJSON();
json = record.json();
} catch (e) {
}
let expectedJson;
try {
expectedJson = expectedRecord.toJSON();
expectedJson = expectedRecord.json();
} catch (e) {
}
if (json === undefined || json === null)
......
......@@ -5120,10 +5120,10 @@ interface NDEFRecord
attribute @@toStringTag
getter mediaType
getter recordType
method arrayBuffer
method constructor
method toArrayBuffer
method toJSON
method toText
method json
method text
interface NFCErrorEvent : Event
attribute @@toStringTag
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