mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Update web-platform-tests to revision e0875f70f4f33a92d8a935e8d0e09a67a45761e8
This commit is contained in:
parent
175c0d56ca
commit
b209ce8d5b
49 changed files with 712 additions and 137 deletions
|
@ -32,7 +32,7 @@ function toMojoNDEFRecord(record) {
|
|||
}
|
||||
|
||||
function toByteArray(data) {
|
||||
// Convert JS objects to byte array
|
||||
// Convert JS objects to byte array.
|
||||
let byteArray = new Uint8Array(0);
|
||||
let tmpData = data;
|
||||
|
||||
|
@ -49,7 +49,7 @@ 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
|
||||
// see spec changes at https://github.com/w3c/web-nfc/pull/243.
|
||||
function compareNDEFRecords(providedRecord, receivedRecord) {
|
||||
assert_equals(providedRecord.recordType, receivedRecord.recordType);
|
||||
|
||||
|
@ -105,7 +105,7 @@ function assertNFCReaderOptionsEqual(provided, received) {
|
|||
|
||||
// Checks whether NFCReaderOptions are matched with given message.
|
||||
function matchesWatchOptions(message, options) {
|
||||
// Filter by Web NFC id
|
||||
// Filter by Web NFC id.
|
||||
if (!matchesWebNfcId(message.url, options.url)) return false;
|
||||
|
||||
// Matches any record / media type.
|
||||
|
@ -114,7 +114,7 @@ function matchesWatchOptions(message, options) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Filter by mediaType and recordType
|
||||
// Filter by mediaType and recordType.
|
||||
for (let record of message.records) {
|
||||
if (options.mediaType != null && options.mediaType !== ""
|
||||
&& options.mediaType !== record.mediaType) {
|
||||
|
@ -175,14 +175,15 @@ var WebNFCTest = (() => {
|
|||
this.client_ = null;
|
||||
this.watchers_ = [];
|
||||
this.reading_messages_ = [];
|
||||
this.operations_suspended_ = false;
|
||||
}
|
||||
|
||||
// NFC delegate functions
|
||||
// NFC delegate functions.
|
||||
async push(message, options) {
|
||||
let error = this.getHWError();
|
||||
if (error)
|
||||
return error;
|
||||
// Cancel previous pending push operation
|
||||
// Cancel previous pending push operation.
|
||||
if (this.pending_promise_func_) {
|
||||
this.cancelPendingPushOperation();
|
||||
}
|
||||
|
@ -192,9 +193,12 @@ var WebNFCTest = (() => {
|
|||
|
||||
return new Promise(resolve => {
|
||||
this.pending_promise_func_ = resolve;
|
||||
if (options.timeout && options.timeout !== Infinity &&
|
||||
// Pend push operation if NFC operation is suspended.
|
||||
if (this.operations_suspended_) {
|
||||
// Do nothing, pends push operation.
|
||||
} else if (options.timeout && options.timeout !== Infinity &&
|
||||
!this.push_completed_) {
|
||||
// Resolve with TimeoutError, else pending push operation.
|
||||
// Resolve with TimeoutError, else pend push operation.
|
||||
if (this.push_should_timeout_) {
|
||||
resolve(
|
||||
createNFCError(device.mojom.NFCErrorType.TIMER_EXPIRED));
|
||||
|
@ -226,11 +230,14 @@ var WebNFCTest = (() => {
|
|||
}
|
||||
|
||||
this.watchers_.push({id: id, options: options});
|
||||
// Triggers onWatch if the new watcher matches existing messages
|
||||
for (let message of this.reading_messages_) {
|
||||
if (matchesWatchOptions(message, options)) {
|
||||
this.client_.onWatch(
|
||||
[id], fake_tag_serial_number, toMojoNDEFMessage(message));
|
||||
// Ignore reading if NFC operation is suspended.
|
||||
if(!this.operations_suspended_) {
|
||||
// Triggers onWatch if the new watcher matches existing messages.
|
||||
for (let message of this.reading_messages_) {
|
||||
if (matchesWatchOptions(message, options)) {
|
||||
this.client_.onWatch(
|
||||
[id], fake_tag_serial_number, toMojoNDEFMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,6 +297,7 @@ var WebNFCTest = (() => {
|
|||
this.push_completed_ = true;
|
||||
this.watchers_ = [];
|
||||
this.reading_messages_ = [];
|
||||
this.operations_suspended_ = false;
|
||||
this.cancelPendingPushOperation();
|
||||
this.bindingSet_.closeAllBindings();
|
||||
this.interceptor_.stop();
|
||||
|
@ -311,10 +319,12 @@ var WebNFCTest = (() => {
|
|||
// Sets message that is used to deliver NFC reading updates.
|
||||
setReadingMessage(message) {
|
||||
this.reading_messages_.push(message);
|
||||
// Ignore reading if NFCPushOptions.ignoreRead is true
|
||||
// Ignore reading if NFC operation is suspended.
|
||||
if(this.operations_suspended_) return;
|
||||
// Ignore reading if NFCPushOptions.ignoreRead is true.
|
||||
if(this.push_options_ && this.push_options_.ignoreRead)
|
||||
return;
|
||||
// Triggers onWatch if the new message matches existing watchers
|
||||
// Triggers onWatch if the new message matches existing watchers.
|
||||
for (let watcher of this.watchers_) {
|
||||
if (matchesWatchOptions(message, watcher.options)) {
|
||||
this.client_.onWatch(
|
||||
|
@ -327,6 +337,31 @@ var WebNFCTest = (() => {
|
|||
setPushShouldTimeout(result) {
|
||||
this.push_should_timeout_ = result;
|
||||
}
|
||||
|
||||
// Suspends all pending NFC operations. Could be used when web page
|
||||
// visibility is lost.
|
||||
suspendNFCOperations() {
|
||||
this.operations_suspended_ = true;
|
||||
}
|
||||
|
||||
// Resumes all suspended NFC operations.
|
||||
resumeNFCOperations() {
|
||||
this.operations_suspended_ = false;
|
||||
// Resumes pending NFC reading.
|
||||
for (let watcher of this.watchers_) {
|
||||
for (let message of this.reading_messages_) {
|
||||
if (matchesWatchOptions(message, watcher.options)) {
|
||||
this.client_.onWatch(
|
||||
[watcher.id], fake_tag_serial_number,
|
||||
toMojoNDEFMessage(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Resumes pending push operation.
|
||||
if (this.pending_promise_func_) {
|
||||
this.pending_promise_func_(createNFCError(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let testInternal = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue