tor-browser

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

browser_UITour_detach_tab.js (3425B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 /**
      5 * Detaching a tab to a new window shouldn't break the menu panel.
      6 */
      7 
      8 "use strict";
      9 
     10 var gTestTab;
     11 var gContentAPI;
     12 var gContentDoc;
     13 
     14 var detachedWindow;
     15 
     16 function test() {
     17  registerCleanupFunction(function () {
     18    gContentDoc = null;
     19  });
     20  UITourTest();
     21 }
     22 
     23 /**
     24 * When tab is changed we're tearing the tour down. So the UITour client has to always be aware of this
     25 * fact and therefore listens to pageshow events.
     26 * In particular this scenario happens for detaching the tab (ie. moving it to a new window).
     27 */
     28 var tests = [
     29  taskify(async function test_move_tab_to_new_window() {
     30    const myDocIdentifier =
     31      "Hello, I'm a unique expando to identify this document.";
     32 
     33    let highlight = document.getElementById("UITourHighlight");
     34 
     35    let browserStartupDeferred = Promise.withResolvers();
     36    Services.obs.addObserver(function onBrowserDelayedStartup(aWindow) {
     37      Services.obs.removeObserver(
     38        onBrowserDelayedStartup,
     39        "browser-delayed-startup-finished"
     40      );
     41      browserStartupDeferred.resolve(aWindow);
     42    }, "browser-delayed-startup-finished");
     43 
     44    await SpecialPowers.spawn(
     45      gBrowser.selectedBrowser,
     46      [myDocIdentifier],
     47      contentMyDocIdentifier => {
     48        let onPageShow = () => {
     49          if (!content.document.hidden) {
     50            let win = Cu.waiveXrays(content);
     51            win.Mozilla.UITour.showHighlight("appMenu");
     52          }
     53        };
     54        content.window.addEventListener("pageshow", onPageShow, {
     55          mozSystemGroup: true,
     56        });
     57        content.document.myExpando = contentMyDocIdentifier;
     58      }
     59    );
     60    gContentAPI.showHighlight("appMenu");
     61 
     62    await elementVisiblePromise(highlight, "old window highlight");
     63 
     64    detachedWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
     65    await browserStartupDeferred.promise;
     66 
     67    // This highlight should be shown thanks to the pageshow listener.
     68    let newWindowHighlight = UITour.getHighlightAndMaybeCreate(
     69      detachedWindow.document
     70    );
     71    await elementVisiblePromise(newWindowHighlight, "new window highlight");
     72 
     73    let selectedTab = detachedWindow.gBrowser.selectedTab;
     74    await SpecialPowers.spawn(
     75      selectedTab.linkedBrowser,
     76      [myDocIdentifier],
     77      contentMyDocIdentifier => {
     78        is(
     79          content.document.myExpando,
     80          contentMyDocIdentifier,
     81          "Document should be selected in new window"
     82        );
     83      }
     84    );
     85    ok(
     86      UITour.tourBrowsersByWindow &&
     87        UITour.tourBrowsersByWindow.has(detachedWindow),
     88      "Window should be known"
     89    );
     90    ok(
     91      UITour.tourBrowsersByWindow
     92        .get(detachedWindow)
     93        .has(selectedTab.linkedBrowser),
     94      "Selected browser should be known"
     95    );
     96 
     97    // Need this because gContentAPI in e10s land will try to use gTestTab to
     98    // spawn a content task, which doesn't work if the tab is dead, for obvious
     99    // reasons.
    100    gTestTab = detachedWindow.gBrowser.selectedTab;
    101 
    102    let shownPromise = promisePanelShown(detachedWindow);
    103    gContentAPI.showMenu("appMenu");
    104    await shownPromise;
    105 
    106    isnot(detachedWindow.PanelUI.panel.state, "closed", "Panel should be open");
    107    gContentAPI.hideHighlight();
    108    gContentAPI.hideMenu("appMenu");
    109    gTestTab = null;
    110 
    111    await BrowserTestUtils.closeWindow(detachedWindow);
    112  }),
    113 ];