tor-browser

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

browser_inspector_reload_iframe.js (2998B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 "use strict";
      5 
      6 // Check that the markup view selection is preserved even if the selection is
      7 // in an iframe.
      8 
      9 // We're loading an image that would take a few second to load so the iframe won't have
     10 // its readyState to "complete" (it should be "interactive").
     11 // That was causing some issue, see Bug 1733539.
     12 
     13 function getTestURI(delay) {
     14  const IMG_URL = `${URL_ROOT_COM_SSL}sjs_slow-loading-image.sjs?delay=${delay}`;
     15  const FRAME_URI =
     16    "data:text/html;charset=utf-8," +
     17    encodeURI(`
     18      <div id="in-frame">div in the iframe</div>
     19      <img src="${IMG_URL}"></img>
     20    `);
     21  const HTML = `
     22    <iframe src="${FRAME_URI}"></iframe>
     23  `;
     24 
     25  return "data:text/html;charset=utf-8," + encodeURI(HTML);
     26 }
     27 
     28 add_task(async function () {
     29  const { getSystemInfo } = require("resource://devtools/shared/system.js");
     30 
     31  const INSPECTOR_FIND_NODE_TIMEOUT = 1000 * getSystemInfo().timeoutMultiplier;
     32  const TEST_URI = getTestURI(INSPECTOR_FIND_NODE_TIMEOUT / 10);
     33  const SLOW_TEST_URI = getTestURI(INSPECTOR_FIND_NODE_TIMEOUT + 5000);
     34 
     35  const { inspector } = await openInspectorForURL(TEST_URI);
     36 
     37  await selectNodeInFrames(["iframe", "#in-frame"], inspector);
     38 
     39  let markupLoaded = inspector.once("markuploaded");
     40 
     41  info("Reloading page.");
     42  await navigateTo(TEST_URI);
     43 
     44  info("Waiting for markupview to load after reload.");
     45  await markupLoaded;
     46 
     47  const reloadedNodeFront = await getNodeFrontInFrames(
     48    ["iframe", "#in-frame"],
     49    inspector
     50  );
     51 
     52  is(
     53    inspector.selection.nodeFront,
     54    reloadedNodeFront,
     55    "#in-frame selected after reload."
     56  );
     57 
     58  info("Check that markup view is not blocked for a page with a slow iframe");
     59  await navigateTo(SLOW_TEST_URI);
     60  await selectNodeInFrames(["iframe", "#in-frame"], inspector);
     61 
     62  markupLoaded = inspector.once("markuploaded");
     63 
     64  info("Reloading page.");
     65  const onNavigate = navigateTo(SLOW_TEST_URI);
     66 
     67  info("Waiting for markupview to load after reload.");
     68  await markupLoaded;
     69 
     70  info("Check that the navigation is not done yet");
     71  ok(
     72    !(await hasPromiseResolved(onNavigate)),
     73    "Navigation to page with slow iframe is not done yet"
     74  );
     75 
     76  const bodyNodeFront = await getNodeFrontInFrames(["body"], inspector);
     77  is(
     78    inspector.selection.nodeFront,
     79    bodyNodeFront,
     80    "Iframe was too slow to load, the markup view selected body as fallback"
     81  );
     82 
     83  await onNavigate;
     84 });
     85 
     86 async function hasPromiseResolved(promise) {
     87  let resolved = false;
     88 
     89  // Note that the catch() is only here to avoid leaking promise rejections.
     90  // In all cases the resolved flag should be successfully flipped in finally().
     91  promise.finally(() => (resolved = true)).catch(() => {});
     92  // Make sure microtasks have time to run.
     93  await new Promise(resolve => Services.tm.dispatchToMainThread(resolve));
     94  return resolved;
     95 }