browser/devtools/responsivedesign/test/head.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/responsivedesign/test/head.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +"use strict";
     1.8 +
     1.9 +let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
    1.10 +let TargetFactory = devtools.TargetFactory;
    1.11 +
    1.12 +// Import the GCLI test helper
    1.13 +let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
    1.14 +Services.scriptloader.loadSubScript(testDir + "../../../commandline/test/helpers.js", this);
    1.15 +
    1.16 +gDevTools.testing = true;
    1.17 +SimpleTest.registerCleanupFunction(() => {
    1.18 +  gDevTools.testing = false;
    1.19 +});
    1.20 +
    1.21 +/**
    1.22 + * Open the toolbox, with the inspector tool visible.
    1.23 + * @return a promise that resolves when the inspector is ready
    1.24 + */
    1.25 +let openInspector = Task.async(function*() {
    1.26 +  info("Opening the inspector");
    1.27 +  let target = TargetFactory.forTab(gBrowser.selectedTab);
    1.28 +
    1.29 +  let inspector, toolbox;
    1.30 +
    1.31 +  // Checking if the toolbox and the inspector are already loaded
    1.32 +  // The inspector-updated event should only be waited for if the inspector
    1.33 +  // isn't loaded yet
    1.34 +  toolbox = gDevTools.getToolbox(target);
    1.35 +  if (toolbox) {
    1.36 +    inspector = toolbox.getPanel("inspector");
    1.37 +    if (inspector) {
    1.38 +      info("Toolbox and inspector already open");
    1.39 +      return {
    1.40 +        toolbox: toolbox,
    1.41 +        inspector: inspector
    1.42 +      };
    1.43 +    }
    1.44 +  }
    1.45 +
    1.46 +  info("Opening the toolbox");
    1.47 +  toolbox = yield gDevTools.showToolbox(target, "inspector");
    1.48 +  yield waitForToolboxFrameFocus(toolbox);
    1.49 +  inspector = toolbox.getPanel("inspector");
    1.50 +
    1.51 +  info("Waiting for the inspector to update");
    1.52 +  yield inspector.once("inspector-updated");
    1.53 +
    1.54 +  return {
    1.55 +    toolbox: toolbox,
    1.56 +    inspector: inspector
    1.57 +  };
    1.58 +});
    1.59 +
    1.60 +/**
    1.61 + * Wait for the toolbox frame to receive focus after it loads
    1.62 + * @param {Toolbox} toolbox
    1.63 + * @return a promise that resolves when focus has been received
    1.64 + */
    1.65 +function waitForToolboxFrameFocus(toolbox) {
    1.66 +  info("Making sure that the toolbox's frame is focused");
    1.67 +  let def = promise.defer();
    1.68 +  let win = toolbox.frame.contentWindow;
    1.69 +  waitForFocus(def.resolve, win);
    1.70 +  return def.promise;
    1.71 +}
    1.72 +
    1.73 +/**
    1.74 + * Open the toolbox, with the inspector tool visible, and the sidebar that
    1.75 + * corresponds to the given id selected
    1.76 + * @return a promise that resolves when the inspector is ready and the sidebar
    1.77 + * view is visible and ready
    1.78 + */
    1.79 +let openInspectorSideBar = Task.async(function*(id) {
    1.80 +  let {toolbox, inspector} = yield openInspector();
    1.81 +
    1.82 +  if (!hasSideBarTab(inspector, id)) {
    1.83 +    info("Waiting for the " + id + " sidebar to be ready");
    1.84 +    yield inspector.sidebar.once(id + "-ready");
    1.85 +  }
    1.86 +
    1.87 +  info("Selecting the " + id + " sidebar");
    1.88 +  inspector.sidebar.select(id);
    1.89 +
    1.90 +  return {
    1.91 +    toolbox: toolbox,
    1.92 +    inspector: inspector,
    1.93 +    view: inspector.sidebar.getWindowForTab(id)[id].view
    1.94 +  };
    1.95 +});
    1.96 +
    1.97 +/**
    1.98 + * Checks whether the inspector's sidebar corresponding to the given id already
    1.99 + * exists
   1.100 + * @param {InspectorPanel}
   1.101 + * @param {String}
   1.102 + * @return {Boolean}
   1.103 + */
   1.104 +function hasSideBarTab(inspector, id) {
   1.105 +  return !!inspector.sidebar.getWindowForTab(id);
   1.106 +}
   1.107 +
   1.108 +/**
   1.109 + * Open the toolbox, with the inspector tool visible, and the computed-view
   1.110 + * sidebar tab selected.
   1.111 + * @return a promise that resolves when the inspector is ready and the computed
   1.112 + * view is visible and ready
   1.113 + */
   1.114 +function openComputedView() {
   1.115 +  return openInspectorSideBar("computedview");
   1.116 +}
   1.117 +
   1.118 +/**
   1.119 + * Open the toolbox, with the inspector tool visible, and the rule-view
   1.120 + * sidebar tab selected.
   1.121 + * @return a promise that resolves when the inspector is ready and the rule
   1.122 + * view is visible and ready
   1.123 + */
   1.124 +function openRuleView() {
   1.125 +  return openInspectorSideBar("ruleview");
   1.126 +}

mercurial