tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

NDEFReader_scan_iframe.https.html (1613B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>NDEFReader.scan with an focused iframe</title>
      4 <link rel="help" href="https://w3c.github.io/web-nfc/"/>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="resources/nfc-helpers.js"></script>
      8 <body>
      9 <script>
     10 
     11 nfc_test(async (t, mockNFC) => {
     12  const ndef = new NDEFReader();
     13  const controller = new AbortController();
     14  const ndefWatcher = new EventWatcher(t, ndef, ["reading", "readingerror"]);
     15 
     16  const promise = ndefWatcher.wait_for("reading").then(event => {
     17    assert_true(event instanceof NDEFReadingEvent);
     18    controller.abort();
     19  });
     20  await ndef.scan({ signal: controller.signal });
     21 
     22  const iframe = document.createElement('iframe');
     23  iframe.src = 'resources/support-iframe.html';
     24 
     25  const iframeLoadWatcher = new EventWatcher(t, iframe, 'load');
     26  document.body.appendChild(iframe);
     27  await iframeLoadWatcher.wait_for('load');
     28  // Focus on iframe.
     29  iframe.contentWindow.document.getElementById('foo').focus();
     30  assert_true(iframe.contentDocument.hasFocus(), 'iframe gains the focus');
     31  // Suspend NFC operations is async in blink, use setTimeout as a workaround.
     32  // TODO(wanming.lin@intel.com): find a good way to eliminate this race
     33  // condition.
     34  await new Promise(resolve => t.step_timeout(resolve, 0));
     35  mockNFC.setReadingMessage(createMessage([createTextRecord(test_text_data)]));
     36  await promise;
     37 
     38  // Remove iframe from main document.
     39  iframe.parentNode.removeChild(iframe);
     40 }, 'Test that NDEFReader.scan is not suspended if iframe gains focus.');
     41 
     42 </script>
     43 </body>