browser/modules/test/browser_UITour_detach_tab.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/modules/test/browser_UITour_detach_tab.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Detaching a tab to a new window shouldn't break the menu panel.
     1.9 + */
    1.10 +
    1.11 +"use strict";
    1.12 +
    1.13 +let gTestTab;
    1.14 +let gContentAPI;
    1.15 +let gContentWindow;
    1.16 +let gContentDoc;
    1.17 +let highlight = document.getElementById("UITourHighlight");
    1.18 +let tooltip = document.getElementById("UITourTooltip");
    1.19 +
    1.20 +Components.utils.import("resource:///modules/UITour.jsm");
    1.21 +
    1.22 +function test() {
    1.23 +  registerCleanupFunction(function() {
    1.24 +    gContentDoc = null;
    1.25 +  });
    1.26 +  UITourTest();
    1.27 +}
    1.28 +
    1.29 +let tests = [
    1.30 +  function test_move_tab_to_new_window(done) {
    1.31 +    let gOpenedWindow;
    1.32 +    let onVisibilityChange = (aEvent) => {
    1.33 +      if (!document.hidden && window != UITour.getChromeWindow(aEvent.target)) {
    1.34 +        gContentAPI.showHighlight("appMenu");
    1.35 +      }
    1.36 +    };
    1.37 +    let onDOMWindowDestroyed = (aWindow, aTopic, aData) => {
    1.38 +      if (gOpenedWindow && aWindow == gOpenedWindow) {
    1.39 +        Services.obs.removeObserver(onDOMWindowDestroyed, "dom-window-destroyed", false);
    1.40 +        done();
    1.41 +      }
    1.42 +    };
    1.43 +    let onBrowserDelayedStartup = (aWindow, aTopic, aData) => {
    1.44 +      gOpenedWindow = aWindow;
    1.45 +      Services.obs.removeObserver(onBrowserDelayedStartup, "browser-delayed-startup-finished");
    1.46 +      try {
    1.47 +        let newWindowHighlight = gOpenedWindow.document.getElementById("UITourHighlight");
    1.48 +        let selectedTab = aWindow.gBrowser.selectedTab;
    1.49 +        is(selectedTab.linkedBrowser && selectedTab.linkedBrowser.contentDocument, gContentDoc, "Document should be selected in new window");
    1.50 +        ok(UITour.originTabs && UITour.originTabs.has(aWindow), "Window should be known");
    1.51 +        ok(UITour.originTabs.get(aWindow).has(selectedTab), "Tab should be known");
    1.52 +        waitForElementToBeVisible(newWindowHighlight, function checkHighlightIsThere() {
    1.53 +          let shownPromise = promisePanelShown(aWindow);
    1.54 +          gContentAPI.showMenu("appMenu");
    1.55 +          shownPromise.then(() => {
    1.56 +            isnot(aWindow.PanelUI.panel.state, "closed", "Panel should be open");
    1.57 +            ok(aWindow.PanelUI.contents.children.length > 0, "Panel contents should have children");
    1.58 +            gContentAPI.hideHighlight();
    1.59 +            gContentAPI.hideMenu("appMenu");
    1.60 +            gTestTab = null;
    1.61 +            aWindow.close();
    1.62 +          }).then(null, Components.utils.reportError);
    1.63 +        }, "Highlight should be shown in new window.");
    1.64 +      } catch (ex) {
    1.65 +        Cu.reportError(ex);
    1.66 +        ok(false, "An error occurred running UITour tab detach test.");
    1.67 +      } finally {
    1.68 +        gContentDoc.removeEventListener("visibilitychange", onVisibilityChange, false);
    1.69 +        Services.obs.addObserver(onDOMWindowDestroyed, "dom-window-destroyed", false);
    1.70 +      }
    1.71 +    };
    1.72 +
    1.73 +    Services.obs.addObserver(onBrowserDelayedStartup, "browser-delayed-startup-finished", false);
    1.74 +    // NB: we're using this rather than gContentWindow.document because the latter wouldn't
    1.75 +    // have an XRayWrapper, and we need to compare this to the doc we get using this method
    1.76 +    // later on...
    1.77 +    gContentDoc = gBrowser.selectedTab.linkedBrowser.contentDocument;
    1.78 +    gContentDoc.addEventListener("visibilitychange", onVisibilityChange, false);
    1.79 +    gContentAPI.showHighlight("appMenu");
    1.80 +    waitForElementToBeVisible(highlight, function checkForInitialHighlight() {
    1.81 +      gBrowser.replaceTabWithWindow(gBrowser.selectedTab);
    1.82 +    });
    1.83 +
    1.84 +  },
    1.85 +];
    1.86 +

mercurial