Bug 1253225 - Remove GCLI commands not used in Firefox; r=jryans draft
authorJoe Walker <jwalker@mozilla.com>
Thu, 03 Mar 2016 12:52:15 +0000
changeset 362897 56ba922c54ff7c1d1fb1f3ac13d50f4194a7a09a
parent 362896 61396447a5cf0ea058e9e17f321fa12eca1b5025
child 519897 a35d38d016d711735742408ddb8b5ad32ccd1630
push id17056
push userbmo:jwalker@mozilla.com
push dateTue, 03 May 2016 14:16:44 +0000
reviewersjryans
bugs1253225
milestone49.0a1
Bug 1253225 - Remove GCLI commands not used in Firefox; r=jryans MozReview-Commit-ID: 5TmpY0yYJ7M
devtools/shared/gcli/source/lib/gcli/commands/connect.js
devtools/shared/gcli/source/lib/gcli/commands/exec.js
devtools/shared/gcli/source/lib/gcli/commands/global.js
devtools/shared/gcli/source/lib/gcli/commands/intro.js
devtools/shared/gcli/source/lib/gcli/commands/lang.js
devtools/shared/gcli/source/lib/gcli/commands/mocks.js
devtools/shared/gcli/source/lib/gcli/commands/moz.build
devtools/shared/gcli/source/lib/gcli/commands/test.js
devtools/shared/gcli/source/lib/gcli/util/host.js
deleted file mode 100644
--- a/devtools/shared/gcli/source/lib/gcli/commands/connect.js
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright 2012, Mozilla Foundation and contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var l10n = require('../util/l10n');
-var cli = require('../cli');
-var GcliFront = require('../connectors/remoted').GcliFront;
-
-/**
- * A lookup of the current connection
- */
-var fronts = {};
-
-/**
- * 'connection' type
- */
-var connection = {
-  item: 'type',
-  name: 'connection',
-  parent: 'selection',
-  lookup: function() {
-    return Object.keys(fronts).map(function(prefix) {
-      return { name: prefix, value: fronts[prefix] };
-    });
-  }
-};
-
-/**
- * 'connector' type
- */
-var connector = {
-  item: 'type',
-  name: 'connector',
-  parent: 'selection',
-  lookup: function(context) {
-    var connectors = context.system.connectors;
-    return connectors.getAll().map(function(connector) {
-      return { name: connector.name, value: connector };
-    });
-  }
-};
-
-/**
- * 'connect' command
- */
-var connect = {
-  item: 'command',
-  name: 'connect',
-  description: l10n.lookup('connectDesc'),
-  manual: l10n.lookup('connectManual'),
-  params: [
-    {
-      name: 'prefix',
-      type: 'string',
-      description: l10n.lookup('connectPrefixDesc')
-    },
-    {
-      name: 'method',
-      short: 'm',
-      type: 'connector',
-      description: l10n.lookup('connectMethodDesc'),
-      defaultValue: null,
-      option: true
-    },
-    {
-      name: 'url',
-      short: 'u',
-      type: 'string',
-      description: l10n.lookup('connectUrlDesc'),
-      defaultValue: null,
-      option: true
-    }
-  ],
-  returnType: 'string',
-
-  exec: function(args, context) {
-    if (fronts[args.prefix] != null) {
-      throw new Error(l10n.lookupFormat('connectDupReply', [ args.prefix ]));
-    }
-
-    args.method = args.method || context.system.connectors.get('xhr');
-
-    return GcliFront.create(args.method, args.url).then(function(front) {
-      // Nasty: stash the prefix on the front to help us tidy up
-      front.prefix = args.prefix;
-      fronts[args.prefix] = front;
-
-      return front.specs().then(function(specs) {
-        var remoter = this.createRemoter(args.prefix, front);
-        var commands = cli.getMapping(context).requisition.system.commands;
-        commands.addProxyCommands(specs, remoter, args.prefix, args.url);
-
-        // TODO: We should add type proxies here too
-
-        // commandSpecs doesn't include the parent command that we added
-        return l10n.lookupFormat('connectReply',
-                                 [ Object.keys(specs).length + 1 ]);
-      }.bind(this));
-    }.bind(this));
-  },
-
-  /**
-   * When we register a set of remote commands, we need to provide a proxy
-   * executor. This is that executor.
-   */
-  createRemoter: function(prefix, front) {
-    return function(cmdArgs, context) {
-      var typed = context.typed;
-
-      // If we've been called using a 'context' then there will be no prefix
-      // otherwise we need to remove it
-      if (typed.indexOf(prefix) === 0) {
-        typed = typed.substring(prefix.length).replace(/^ */, '');
-      }
-
-      return front.execute(typed).then(function(reply) {
-        var typedData = context.typedData(reply.type, reply.data);
-        if (!reply.error) {
-          return typedData;
-        }
-        else {
-          throw typedData;
-        }
-      });
-    }.bind(this);
-  }
-};
-
-/**
- * 'disconnect' command
- */
-var disconnect = {
-  item: 'command',
-  name: 'disconnect',
-  description: l10n.lookup('disconnectDesc2'),
-  manual: l10n.lookup('disconnectManual2'),
-  params: [
-    {
-      name: 'prefix',
-      type: 'connection',
-      description: l10n.lookup('disconnectPrefixDesc')
-    }
-  ],
-  returnType: 'string',
-
-  exec: function(args, context) {
-    var front = args.prefix;
-    return front.connection.disconnect().then(function() {
-      var commands = cli.getMapping(context).requisition.system.commands;
-      var removed = commands.removeProxyCommands(front.prefix);
-      delete fronts[front.prefix];
-      return l10n.lookupFormat('disconnectReply', [ removed.length ]);
-    });
-  }
-};
-
-exports.items = [ connection, connector, connect, disconnect ];
deleted file mode 100644
--- a/devtools/shared/gcli/source/lib/gcli/commands/exec.js
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2012, Mozilla Foundation and contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var host = require('../util/host');
-var l10n = require('../util/l10n');
-var cli = require('../cli');
-
-exports.items = [
-  {
-    // 'cd' command
-    item: 'command',
-    name: 'cd',
-    description: l10n.lookup('cdDesc'),
-    manual: l10n.lookup('cdManual'),
-    params: [
-      {
-        name: 'directory',
-        type: {
-          name: 'file',
-          filetype: 'directory',
-          existing: 'yes'
-        },
-        description: l10n.lookup('cdDirectoryDesc')
-      }
-    ],
-    returnType: 'string',
-    exec: function(args, context) {
-      context.shell.cwd = args.directory;
-      return l10n.lookupFormat('cdOutput', [ context.shell.cwd ]);
-    }
-  },
-  {
-    // 'exec' command
-    item: 'command',
-    name: 'exec',
-    description: l10n.lookup('execDesc'),
-    manual: l10n.lookup('execManual'),
-    params: [
-      {
-        name: 'command',
-        type: 'string',
-        description: l10n.lookup('execCommandDesc')
-      }
-    ],
-    returnType: 'output',
-    exec: function(args, context) {
-      var cmdArgs = cli.tokenize(args.command).map(function(arg) {
-        return arg.text;
-      });
-      var cmd = cmdArgs.shift();
-
-      var spawnSpec = {
-        cmd: cmd,
-        args: cmdArgs,
-        env: context.shell.env,
-        cwd: context.shell.cwd
-      };
-
-      return host.spawn(context, spawnSpec).then(function(output) {
-        if (output.code === 0) {
-          return output;
-        }
-
-        throw output.data;
-      }, function(output) {
-        throw output.data;
-      });
-    }
-  },
-  {
-    // How we display the output of a generic exec command: we have to assume
-    // that it is a string to be displayed in a monospaced font
-    item: 'converter',
-    from: 'output',
-    to: 'view',
-    exec: function(output, context) {
-      return {
-        html: '<pre>${output.data}</pre>',
-        data: { output: output }
-      };
-    }
-  },
-  {
-    item: 'converter',
-    from: 'output',
-    to: 'string',
-    exec: function(output, context) {
-      return output.data;
-    }
-  }
-];
deleted file mode 100644
--- a/devtools/shared/gcli/source/lib/gcli/commands/global.js
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2012, Mozilla Foundation and contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var l10n = require('../util/l10n');
-
-exports.items = [
-  {
-    // A type for selecting a known setting
-    item: 'type',
-    name: 'global',
-    parent: 'selection',
-    remote: true,
-    lookup: function(context) {
-      var knownWindows = context.environment.window == null ?
-                         [ ] : [ context.environment.window ];
-
-      this.last = findWindows(knownWindows).map(function(window) {
-        return { name: windowToString(window), value: window };
-      });
-
-      return this.last;
-    }
-  },
-  {
-    // A command to switch JS globals
-    item: 'command',
-    runAt: 'client',
-    name: 'global',
-    description: l10n.lookup('globalDesc'),
-    params: [
-      {
-        name: 'window',
-        type: 'global',
-        description: l10n.lookup('globalWindowDesc'),
-      }
-    ],
-    returnType: 'string',
-    exec: function(args, context) {
-      context.shell.global = args.window;
-      return l10n.lookupFormat('globalOutput', [ windowToString(args.window) ]);
-    }
-  }
-];
-
-function windowToString(win) {
-  return win.location ? win.location.href : 'NodeJS-Global';
-}
-
-function findWindows(knownWindows) {
-  knownWindows.forEach(function(window) {
-    addChildWindows(window, knownWindows);
-  });
-  return knownWindows;
-}
-
-function addChildWindows(win, knownWindows) {
-  var iframes = win.document.querySelectorAll('iframe');
-  [].forEach.call(iframes, function(iframe) {
-    var iframeWin = iframe.contentWindow;
-    if (knownWindows.indexOf(iframeWin) === -1) {
-      knownWindows.push(iframeWin);
-      addChildWindows(iframeWin, knownWindows);
-    }
-  });
-}
deleted file mode 100644
--- a/devtools/shared/gcli/source/lib/gcli/commands/intro.js
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012, Mozilla Foundation and contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var l10n = require('../util/l10n');
-var intro = require('../ui/intro');
-
-exports.items = [
-  {
-    item: 'converter',
-    from: 'intro',
-    to: 'view',
-    exec: intro.createView
-  },
-  {
-    item: 'command',
-    name: 'intro',
-    description: l10n.lookup('introDesc'),
-    manual: l10n.lookup('introManual'),
-    returnType: 'intro',
-    exec: function(args, context) {
-      // The intro command is pure formatting - no data
-    }
-  }
-];
deleted file mode 100644
--- a/devtools/shared/gcli/source/lib/gcli/commands/lang.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2012, Mozilla Foundation and contributors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-'use strict';
-
-var l10n = require('../util/l10n');
-var cli = require('../cli');
-
-exports.items = [
-  {
-    // A type that lists available languages
-    item: 'type',
-    name: 'language',
-    parent: 'selection',
-    lookup: function(context) {
-      return context.system.languages.getAll().map(function(language) {
-        return { name: language.name, value: language };
-      });
-    }
-  },
-  {
-    // A command to switch languages
-    item: 'command',
-    name: 'lang',
-    description: l10n.lookup('langDesc'),
-    params: [
-      {
-        name: 'language',
-        type: 'language'
-      }
-    ],
-    returnType: 'view',
-    exec: function(args, context) {
-      var terminal = cli.getMapping(context).terminal;
-
-      context.environment.window.setTimeout(function() {
-        terminal.switchLanguage(args.language);
-      }, 10);
-
-      return {
-        html:
-          '<div class="gcli-section ${style}">' +
-          '  ${langOutput}' +
-          '</div>',
-        data: {
-          langOutput: l10n.lookupFormat('langOutput', [ args.language.name ]),
-          style: args.language.proportionalFonts ? '' : 'gcli-row-script'
-        }
-      };
-    }
-  }
-];
--- a/devtools/shared/gcli/source/lib/gcli/commands/mocks.js
+++ b/devtools/shared/gcli/source/lib/gcli/commands/mocks.js
@@ -13,18 +13,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 'use strict';
 
 var cli = require('../cli');
 var mockCommands = require('../test/mockCommands');
+var mockFileCommands = require('../test/mockFileCommands');
 var mockSettings = require('../test/mockSettings');
-var mockDocument = require('../test/mockDocument');
+
+var isNode = (typeof(process) !== 'undefined' &&
+             process.title.indexOf('node') != -1);
 
 exports.items = [
   {
     item: 'command',
     name: 'mocks',
     description: 'Add/remove mock commands',
     params: [
       {
@@ -42,18 +45,24 @@ exports.items = [
       var requisition = cli.getMapping(context).requisition;
       this[args.included](requisition);
       return 'Mock commands are now ' + args.included;
     },
 
     on: function(requisition) {
       mockCommands.setup(requisition);
       mockSettings.setup(requisition.system);
-      mockDocument.setup(requisition);
+
+      if (isNode) {
+        mockFileCommands.setup(requisition);
+      }
     },
 
     off: function(requisition) {
       mockCommands.shutdown(requisition);
       mockSettings.shutdown(requisition.system);
-      mockDocument.shutdown(requisition);
+
+      if (isNode) {
+        mockFileCommands.shutdown(requisition);
+      }
     }
   }
 ];
--- a/devtools/shared/gcli/source/lib/gcli/commands/moz.build
+++ b/devtools/shared/gcli/source/lib/gcli/commands/moz.build
@@ -2,20 +2,15 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
     'clear.js',
     'commands.js',
-    'connect.js',
     'context.js',
-    'exec.js',
-    'global.js',
     'help.js',
-    'intro.js',
-    'lang.js',
     'mocks.js',
     'pref.js',
     'preflist.js',
     'test.js',
 )
--- a/devtools/shared/gcli/source/lib/gcli/commands/test.js
+++ b/devtools/shared/gcli/source/lib/gcli/commands/test.js
@@ -11,25 +11,29 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 'use strict';
 
-require('../test/suite');
-
 var examiner = require('../testharness/examiner');
 var stati = require('../testharness/status').stati;
 var helpers = require('../test/helpers');
+var suite = require('../test/suite');
 var cli = require('../cli');
 var Requisition = require('../cli').Requisition;
 var createRequisitionAutomator = require('../test/automators/requisition').createRequisitionAutomator;
 
+var isNode = (typeof(process) !== 'undefined' &&
+             process.title.indexOf('node') != -1);
+
+suite.init(isNode);
+
 exports.optionsContainer = [];
 
 exports.items = [
   {
     item: 'type',
     name: 'suite',
     parent: 'selection',
     cacheable: true,
@@ -64,22 +68,25 @@ exports.items = [
         throw new Error('Can\'t use --usehost without injected options');
       }
 
       var options;
       if (args.usehost) {
         options = exports.optionsContainer[0];
       }
       else {
+        var env = {
+          document: document,
+          window: window
+        };
         options = {
-          isNode: (typeof(process) !== 'undefined' &&
-                   process.title.indexOf('node') != -1),
+          isNode: isNode,
           isFirefox: false,
           isPhantomjs: false,
-          requisition: new Requisition(context.system)
+          requisition: new Requisition(context.system, { environment: env })
         };
         options.automator = createRequisitionAutomator(options.requisition);
       }
 
       var requisition = options.requisition;
       requisition.system.commands.get('mocks').on(requisition);
       helpers.resetResponseTimes();
       examiner.reset();
--- a/devtools/shared/gcli/source/lib/gcli/util/host.js
+++ b/devtools/shared/gcli/source/lib/gcli/util/host.js
@@ -55,23 +55,16 @@ Highlighter.prototype._unhighlightNode =
   // Enable when the highlighter rewrite is done
 };
 
 exports.Highlighter = Highlighter;
 
 /**
  * See docs in lib/gcli/util/host.js
  */
-exports.spawn = function(context, spawnSpec) {
-  throw new Error('Not supported');
-};
-
-/**
- * See docs in lib/gcli/util/host.js
- */
 exports.exec = function(task) {
   return Task.spawn(task);
 };
 
 /**
  * The URL API is new enough that we need specific platform help
  */
 exports.createUrl = function(uristr, base) {