Commit d9f7ec5d authored by Leon Han's avatar Leon Han Committed by Commit Bot

[webnfc] Remove NDEFRecord#{text,json,arrayBuffer}()

As we have NDEFRecord#data now with which users can do whatever they
want, so we just remove these helper getters for simplication.

The spec change:
https://github.com/w3c/web-nfc/pull/384

BUG=520391

Change-Id: I054b521b474433e81b4e8fd93dad0772698ac8a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1897480Reviewed-by: default avatarFrançois Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#712411}
parent f8a69f3b
......@@ -364,48 +364,6 @@ DOMDataView* NDEFRecord::data() const {
return DOMDataView::Create(dom_buffer, 0, payload_data_.size());
}
String NDEFRecord::text() const {
if (record_type_ == "empty")
return String();
// TODO(https://crbug.com/520391): Support utf-16 decoding for 'TEXT' record
// as described at
// http://w3c.github.io/web-nfc/#dfn-convert-ndefrecord-payloaddata-bytes.
return String::FromUTF8WithLatin1Fallback(payload_data_.data(),
payload_data_.size());
}
DOMArrayBuffer* NDEFRecord::arrayBuffer() const {
if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url" || record_type_ == "absolute-url") {
return nullptr;
}
DCHECK(record_type_ == "mime" || record_type_ == "unknown" ||
!ValidateCustomRecordType(record_type_).IsNull());
return DOMArrayBuffer::Create(payload_data_.data(), payload_data_.size());
}
ScriptValue NDEFRecord::json(ScriptState* script_state,
ExceptionState& exception_state) const {
if (record_type_ == "empty" || record_type_ == "text" ||
record_type_ == "url" || record_type_ == "absolute-url") {
return ScriptValue::CreateNull(script_state->GetIsolate());
}
DCHECK(record_type_ == "mime" || record_type_ == "unknown" ||
!ValidateCustomRecordType(record_type_).IsNull());
ScriptState::Scope scope(script_state);
v8::Local<v8::Value> json_object =
FromJSONString(script_state->GetIsolate(), script_state->GetContext(),
String::FromUTF8WithLatin1Fallback(payload_data_.data(),
payload_data_.size()),
exception_state);
if (exception_state.HadException())
return ScriptValue::CreateNull(script_state->GetIsolate());
return ScriptValue(script_state->GetIsolate(), json_object);
}
const WTF::Vector<uint8_t>& NDEFRecord::payloadData() const {
return payload_data_;
}
......
......@@ -15,12 +15,10 @@
namespace blink {
class DOMArrayBuffer;
class DOMDataView;
class ExceptionState;
class ExecutionContext;
class NDEFRecordInit;
class ScriptState;
class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
......@@ -50,9 +48,6 @@ class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
const String& encoding() const;
const String& lang() const;
DOMDataView* data() const;
String text() const;
DOMArrayBuffer* arrayBuffer() const;
ScriptValue json(ScriptState*, ExceptionState&) const;
const WTF::Vector<uint8_t>& payloadData() const;
......
......@@ -18,7 +18,4 @@
readonly attribute USVString? encoding;
readonly attribute USVString? lang;
readonly attribute DataView? data;
USVString? text();
[NewObject] ArrayBuffer? arrayBuffer();
[CallWith=ScriptState, RaisesException] object? json();
};
This is a testharness.js-based test.
PASS NDEFMessage constructor without init dict
PASS NDEFMessage constructor with null init dict
FAIL NDEFMessage constructor with a text record assert_true: arrayBuffer() returns an ArrayBuffer expected true got false
Harness: the test ran to completion.
......@@ -30,13 +30,6 @@
const decoder = new TextDecoder();
assert_equals(decoder.decode(message.records[0].data), test_text_data,
'data contains the same text content');
assert_true(typeof message.records[0].text() === 'string');
assert_equals(message.records[0].text(), test_text_data,
'text() contains the same text content');
assert_true(message.records[0].arrayBuffer() instanceof ArrayBuffer,
'arrayBuffer() returns an ArrayBuffer');
assert_equals(message.records[0].json(), null,
'json() returns null');
}, 'NDEFMessage constructor with a text record');
</script>
......@@ -92,8 +92,6 @@
const decoder = new TextDecoder();
assert_equals(decoder.decode(record.data), test_url_data,
'data 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(() => {
......@@ -103,8 +101,6 @@
const decoder = new TextDecoder();
assert_equals(decoder.decode(record.data), test_url_data,
'data 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 absolute-url record type');
test(() => {
......@@ -113,56 +109,32 @@
'Only BufferSource is allowed to be the record data.');
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(createMimeRecord(buffer));
assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
assert_array_equals(new Uint8Array(record.data.buffer), original_data,
'data has the same content with the original buffer');
const data_1 = record.arrayBuffer();
assert_true(data_1 instanceof ArrayBuffer);
assert_not_equals(data_1, buffer, 'arrayBuffer() returns a new object');
assert_array_equals(new Uint8Array(data_1), original_data,
'arrayBuffer() has the same content with the original buffer');
const data_2 = record.arrayBuffer();
assert_true(data_2 instanceof ArrayBuffer);
assert_not_equals(data_2, data_1,
'arrayBuffer() again returns another new object');
assert_array_equals(new Uint8Array(data_2), original_data,
'arrayBuffer() has the same content with the original buffer');
buffer_view.set([4, 3, 2, 1]);
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 arrayBuffer() content');
assert_array_equals(new Uint8Array(data_2), original_data,
'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 arrayBuffer() content');
new Uint8Array(buffer).set([1, 2, 3, 4]);
// Feed ArrayBuffer.
{
const record = new NDEFRecord(createMimeRecord(buffer));
assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
assert_array_equals(new Uint8Array(record.data.buffer), [1, 2, 3, 4],
'data has the same content with the original buffer');
}
// Feed ArrayBufferView.
{
let buffer_view = new Uint8Array(buffer, 1);
const record = new NDEFRecord(createMimeRecord(buffer_view));
assert_equals(record.recordType, 'mime', 'recordType');
assert_array_equals(new Uint8Array(record.data.buffer), [2, 3, 4],
'data has the same content with the original buffer view');
}
}, 'NDEFRecord constructor with mime record type and stream data');
test(() => {
const record = new NDEFRecord(createMimeRecordFromJson(test_json_data));
assert_equals(record.recordType, 'mime', 'recordType');
assert_equals(record.mediaType, 'application/json', 'mediaType');
const data_1 = record.json();
assert_true(typeof data_1 === 'object');
assert_not_equals(data_1, test_json_data, 'json() returns a new object');
assert_object_equals(data_1, test_json_data,
'json() has the same content with the original dictionary');
const data_2 = record.json();
assert_true(typeof data_2 === 'object');
assert_not_equals(data_2, data_1,
'json() again returns another new object');
assert_object_equals(data_2, test_json_data,
'json() has the same content with the original dictionary');
assert_object_equals(JSON.parse(new TextDecoder().decode(record.data)),
test_json_data,
'data has the same content with the original json');
}, 'NDEFRecord constructor with mime record type and json data');
test(() => {
......@@ -197,29 +169,8 @@
const record = new NDEFRecord(createRecord('foo.eXamPle.coM:bAr*-', undefined, buffer));
assert_equals(record.recordType, 'foo.example.com:bAr*-', 'recordType');
assert_equals(record.mediaType, 'application/octet-stream', 'mediaType');
const data_1 = record.arrayBuffer();
assert_true(data_1 instanceof ArrayBuffer);
assert_not_equals(data_1, buffer, 'arrayBuffer() returns a new object');
assert_array_equals(new Uint8Array(data_1), original_data,
'arrayBuffer() has the same content with the original buffer');
const data_2 = record.arrayBuffer();
assert_true(data_2 instanceof ArrayBuffer);
assert_not_equals(data_2, data_1,
'arrayBuffer() again returns another new object');
assert_array_equals(new Uint8Array(data_2), original_data,
'arrayBuffer() has the same content with the original buffer');
buffer_view.set([4, 3, 2, 1]);
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 arrayBuffer() content');
assert_array_equals(new Uint8Array(data_2), original_data,
'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 arrayBuffer() content');
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(() => {
......
......@@ -168,23 +168,6 @@ function assertWebNDEFMessagesEqual(message, expectedMessage) {
// Compares record data
assert_array_equals(new Uint8Array(record.data),
new Uint8Array(expectedRecord.data));
assert_equals(record.text(), expectedRecord.text());
assert_array_equals(new Uint8Array(record.arrayBuffer()),
new Uint8Array(expectedRecord.arrayBuffer()));
let json;
try {
json = record.json();
} catch (e) {
}
let expectedJson;
try {
expectedJson = expectedRecord.json();
} catch (e) {
}
if (json === undefined || json === null)
assert_equals(json, expectedJson);
else
assert_object_equals(json, expectedJson);
}
}
......
......@@ -5098,10 +5098,7 @@ interface NDEFRecord
getter lang
getter mediaType
getter recordType
method arrayBuffer
method constructor
method json
method text
interface NDEFWriter
attribute @@toStringTag
method constructor
......
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