Commit d5514f4c authored by alexander.shalamov's avatar alexander.shalamov Committed by Commit bot

[webnfc] Reject promise if passed timeout value is invalid

According to latest changes in specification [1,2], when invalid
NFCPushOptions.timeout is provided to nfc.push function, promise
must be rejected with TypeError.

[1] https://w3c.github.io/web-nfc/#dom-nfc-push
[2] https://github.com/w3c/web-nfc/issues/112

BUG=714035

Review-Url: https://codereview.chromium.org/2836813007
Cr-Commit-Position: refs/heads/master@{#467265}
parent 6e537c98
...@@ -83,6 +83,16 @@ nfc_test(nfc => { ...@@ -83,6 +83,16 @@ nfc_test(nfc => {
return navigator.nfc.push(test_text_data, { timeout: 1 }); return navigator.nfc.push(test_text_data, { timeout: 1 });
}, 'nfc.push should succeed when NFC HW is enabled'); }, 'nfc.push should succeed when NFC HW is enabled');
nfc_test(nfc => {
return assertRejectsWithError(
navigator.nfc.push(test_text_data, { timeout: 'invalid' }), 'TypeError');
}, 'nfc.push should fail when invalid timeout is provided');
nfc_test(nfc => {
return assertRejectsWithError(
navigator.nfc.push(test_text_data, { timeout: -1 }), 'TypeError');
}, 'nfc.push should fail when invalid negative timeout value is provided');
nfc_test(nfc => { nfc_test(nfc => {
nfc.mockNFC.setPendingPushCompleted(false); nfc.mockNFC.setPendingPushCompleted(false);
return assertRejectsWithError( return assertRejectsWithError(
......
...@@ -622,6 +622,18 @@ ScriptPromise NFC::push(ScriptState* script_state, ...@@ -622,6 +622,18 @@ ScriptPromise NFC::push(ScriptState* script_state,
"Invalid NFCPushMessage type was provided.")); "Invalid NFCPushMessage type was provided."));
} }
// https://w3c.github.io/web-nfc/#dom-nfc-push
// 9. If timeout value is NaN or negative, reject promise with "TypeError"
// and abort these steps.
if (options.hasTimeout() &&
(std::isnan(options.timeout()) || options.timeout() < 0)) {
return ScriptPromise::Reject(
script_state,
V8ThrowException::CreateTypeError(
script_state->GetIsolate(),
"Invalid NFCPushOptions.timeout value was provided."));
}
device::nfc::mojom::blink::NFCMessagePtr message = device::nfc::mojom::blink::NFCMessagePtr message =
device::nfc::mojom::blink::NFCMessage::From(push_message); device::nfc::mojom::blink::NFCMessage::From(push_message);
if (!message) if (!message)
......
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