Revision de23472d66fb6b1bff6b56586c5299c543bd71f5 authored by Emilio Cobos Álvarez on 11 April 2018, 12:15:02 UTC, committed by Emilio Cobos Álvarez on 13 April 2018, 20:20:17 UTC
This tests the resolution in https://github.com/w3c/csswg-drafts/issues/2149.
1 parent cb845c5
Raw File
nfc_watch.https.html
<!DOCTYPE html>
<meta charset=utf-8>
<title>Web NFC: nfc.watch tests</title>
<link rel="author" title="Intel" href="http://www.intel.com"/>
<link rel="help" href="https://w3c.github.io/web-nfc/"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/nfc_help.js"></script>

<div id="log"></div>

<script>

"use strict";

promise_test(t => {
  return promise_rejects(t, 'NotFoundError', navigator.nfc.cancelWatch(1));
}, "Test that nfc.cancelWatch fails if invalid watch ID is provided.");

promise_test(t => {
  return promise_rejects(t, 'NotFoundError', navigator.nfc.cancelWatch());
}, "Test that nfc.cancelWatch fails if there are no active watchers.");

promise_test(t => {
  return navigator.nfc.watch(noop).then(id => {
    assert_equals(typeof(id), "number");
    assert_greater_than(id, 0, "greater than zero");
  });
}, "Test that nfc watch success if NFC HW is enable.");

promise_test(t => {
  return navigator.nfc.watch(noop).
      then(id => navigator.nfc.cancelWatch(id));
}, "Test that nfc.cancelWatch succeeds if correct watch id is provided.");

promise_test(t => {
  return navigator.nfc.watch(noop).then(() => {
    navigator.nfc.cancelWatch();
  });
}, "Test that nfc.cancelWatch succeeds if there are active watchers.");

promise_test(t => {
  return promise_rejects(t, 'SyntaxError', navigator.nfc.watch(noop, {url:"www.a.com"}));
}, 'Test that nfc.watch fails if NFCWatchOptions.url is missing components.');

promise_test(t => {
  return promise_rejects(t, 'SyntaxError', navigator.nfc.watch(noop, {url:"invalid"}));
}, 'Test that nfc.watch fails if NFCWatchOptions.url is invalid.');

promise_test(t => {
  return promise_rejects(t, 'SyntaxError', navigator.nfc.watch(noop, {url:"http://a.com"}));
}, 'Test that nfc.watch fails if NFCWatchOptions.url has wrong protocol.');

promise_test(t => {
  return navigator.nfc.watch(noop, {url:"https://a.com"});
}, 'Test that nfc.watch succeeds if NFCWatchOptions.url is valid URL.');

promise_test(t => {
  return navigator.nfc.watch(noop, {url:"https://a.com/*"});
}, 'Test that nfc.watch succeeds if NFCWatchOptions.url is valid URL with "*"' +
   ' wildcard character in path.');

promise_test(t => {
  return navigator.nfc.watch(noop, {url:"https://a.com/*/bar"});
}, 'Test that nfc.watch succeeds if NFCWatchOptions.url is valid URL with "*"' +
   ' wildcard character in the beginning of path component followed by' +
   ' subpath.');

promise_test(t => {
  return navigator.nfc.watch(noop, {url:""});
}, 'Test that nfc.watch succeeds if NFCWatchOptions.url is empty.');

</script>
back to top