Beispiel #1
0
exports.getSystem = function(target) {
  const existingLinks = linksForTarget.get(target);
  if (existingLinks != null) {
    existingLinks.refs++;
    return existingLinks.promise;
  }

  const system = createSystem({ location: "client" });

  exports.addAllItemsByModule(system);

  // Load the client system
  const links = {
    refs: 1,
    system,
    promise: system.load().then(() => {
      return GcliFront.create(target).then(front => {
        links.front = front;
        return connectFront(system, front, customProperties).then(() => system);
      });
    })
  };

  linksForTarget.set(target, links);
  return links.promise;
};
Beispiel #2
0
  _getRequisition: function() {
    if (this._targetActor == null) {
      throw new Error("GcliActor used post-destroy");
    }

    if (this._requisitionPromise != null) {
      return this._requisitionPromise;
    }

    const Requisition = require("gcli/cli").Requisition;
    const targetActor = this._targetActor;

    this._system = createSystem({ location: "server" });
    this._system.commands.onCommandsChange.add(this._commandsChanged);

    const gcliInit = require("devtools/shared/gcli/commands/index");
    gcliInit.addAllItemsByModule(this._system);

    // this._requisitionPromise should be created synchronously with the call
    // to _getRequisition so that destroy can tell whether there is an async
    // init in progress
    this._requisitionPromise = this._system.load().then(() => {
      const environment = {
        get chromeWindow() {
          throw new Error("environment.chromeWindow is not available in runAt:server" +
            " commands");
        },

        get chromeDocument() {
          throw new Error("environment.chromeDocument is not available in runAt:server" +
            " commands");
        },

        get window() {
          return targetActor.window;
        },

        get document() {
          return targetActor.window && targetActor.window.document;
        }
      };

      return new Requisition(this._system, { environment: environment });
    });

    return this._requisitionPromise;
  },
function* spawnTest() {
  // Setup
  let options = yield helpers.openTab(TEST_URI);

  const { createSystem } = require("gcli/system");
  const system = createSystem({ location: "server" });

  const gcliInit = require("devtools/shared/gcli/commands/index");
  gcliInit.addAllItemsByModule(system);
  yield system.load();

  let settings = system.settings;

  let hideIntroEnabled = settings.get("devtools.gcli.hideIntro");
  let tabSize = settings.get("devtools.editor.tabsize");
  let remoteHost = settings.get("devtools.debugger.remote-host");

  let hideIntroOrig = prefBranch.getBoolPref("devtools.gcli.hideIntro");
  let tabSizeOrig = prefBranch.getIntPref("devtools.editor.tabsize");
  let remoteHostOrig = prefBranch.getStringPref(
          "devtools.debugger.remote-host");

  info("originally: devtools.gcli.hideIntro = " + hideIntroOrig);
  info("originally: devtools.editor.tabsize = " + tabSizeOrig);
  info("originally: devtools.debugger.remote-host = " + remoteHostOrig);

  // Actual tests
  is(hideIntroEnabled.value, hideIntroOrig, "hideIntroEnabled default");
  is(tabSize.value, tabSizeOrig, "tabSize default");
  is(remoteHost.value, remoteHostOrig, "remoteHost default");

  hideIntroEnabled.setDefault();
  tabSize.setDefault();
  remoteHost.setDefault();

  let hideIntroEnabledDefault = hideIntroEnabled.value;
  let tabSizeDefault = tabSize.value;
  let remoteHostDefault = remoteHost.value;

  hideIntroEnabled.value = false;
  tabSize.value = 42;
  remoteHost.value = "example.com";

  is(hideIntroEnabled.value, false, "hideIntroEnabled basic");
  is(tabSize.value, 42, "tabSize basic");
  is(remoteHost.value, "example.com", "remoteHost basic");

  function hideIntroEnabledCheck(ev) {
    is(ev.setting, hideIntroEnabled, "hideIntroEnabled event setting");
    is(ev.value, true, "hideIntroEnabled event value");
    is(ev.setting.value, true, "hideIntroEnabled event setting value");
  }
  hideIntroEnabled.onChange.add(hideIntroEnabledCheck);
  hideIntroEnabled.value = true;
  is(hideIntroEnabled.value, true, "hideIntroEnabled change");

  function tabSizeCheck(ev) {
    is(ev.setting, tabSize, "tabSize event setting");
    is(ev.value, 1, "tabSize event value");
    is(ev.setting.value, 1, "tabSize event setting value");
  }
  tabSize.onChange.add(tabSizeCheck);
  tabSize.value = 1;
  is(tabSize.value, 1, "tabSize change");

  function remoteHostCheck(ev) {
    is(ev.setting, remoteHost, "remoteHost event setting");
    is(ev.value, "y.com", "remoteHost event value");
    is(ev.setting.value, "y.com", "remoteHost event setting value");
  }
  remoteHost.onChange.add(remoteHostCheck);
  remoteHost.value = "y.com";
  is(remoteHost.value, "y.com", "remoteHost change");

  hideIntroEnabled.onChange.remove(hideIntroEnabledCheck);
  tabSize.onChange.remove(tabSizeCheck);
  remoteHost.onChange.remove(remoteHostCheck);

  function remoteHostReCheck(ev) {
    is(ev.setting, remoteHost, "remoteHost event reset");
    is(ev.value, null, "remoteHost event revalue");
    is(ev.setting.value, null, "remoteHost event setting revalue");
  }
  remoteHost.onChange.add(remoteHostReCheck);

  hideIntroEnabled.setDefault();
  tabSize.setDefault();
  remoteHost.setDefault();

  remoteHost.onChange.remove(remoteHostReCheck);

  is(hideIntroEnabled.value, hideIntroEnabledDefault, "hideIntroEnabled reset");
  is(tabSize.value, tabSizeDefault, "tabSize reset");
  is(remoteHost.value, remoteHostDefault, "remoteHost reset");

  // Cleanup
  prefBranch.setBoolPref("devtools.gcli.hideIntro", hideIntroOrig);
  prefBranch.setIntPref("devtools.editor.tabsize", tabSizeOrig);
  supportsString.data = remoteHostOrig;
  prefBranch.setComplexValue("devtools.debugger.remote-host",
          Components.interfaces.nsISupportsString,
          supportsString);

  yield helpers.closeTab(options);
}