tor-browser

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

browser_browsingContext_iframeWebProgress.js (1807B)


      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 file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 function getPageURL(domain) {
      6  // The iframe in file_browsingContext_iframeWebProgress.html is hardcoded to
      7  // point to example.com
      8  return (
      9    getRootDirectory(gTestPath).replace(
     10      "chrome://mochitests/content",
     11      `https://${domain}`
     12    ) + "file_browsingContext_iframeWebProgress.html"
     13  );
     14 }
     15 
     16 const SAME_ORIGIN_IFRAME_PAGE = getPageURL("example.com");
     17 const CROSS_ORIGIN_IFRAME_PAGE = getPageURL("example.org");
     18 
     19 add_task(async function testReloadCrossOriginIframePage() {
     20  await testReloadPageWithIframe(CROSS_ORIGIN_IFRAME_PAGE);
     21 });
     22 
     23 add_task(async function testReloadSameOriginIframePage() {
     24  await testReloadPageWithIframe(SAME_ORIGIN_IFRAME_PAGE);
     25 });
     26 
     27 async function testReloadPageWithIframe(url) {
     28  const tab = BrowserTestUtils.addTab(gBrowser, url);
     29 
     30  const browser = tab.linkedBrowser;
     31  await BrowserTestUtils.browserLoaded(browser, false, url);
     32 
     33  const onStateChangeEvents = [];
     34  const listener = {
     35    QueryInterface: ChromeUtils.generateQI([
     36      "nsIWebProgressListener",
     37      "nsISupportsWeakReference",
     38    ]),
     39    onStateChange(webProgress, request, flags) {
     40      if (flags & Ci.nsIWebProgressListener.STATE_START) {
     41        onStateChangeEvents.push(
     42          request.QueryInterface(Ci.nsIChannel).originalURI
     43        );
     44      }
     45    },
     46  };
     47  browser.browsingContext.webProgress.addProgressListener(
     48    listener,
     49    Ci.nsIWebProgress.NOTIFY_STATE_WINDOW
     50  );
     51  BrowserTestUtils.reloadTab(tab);
     52 
     53  await BrowserTestUtils.waitForCondition(
     54    () => onStateChangeEvents.length == 2
     55  );
     56  is(onStateChangeEvents.length, 2);
     57 
     58  gBrowser.removeTab(tab);
     59 }