Bug 1470646 - Modularise capabilities module. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Tue, 26 Jun 2018 17:15:28 +0100
changeset 813590 afe03fe50083e4e9da978015177f5e849f66ec4f
parent 813589 c6069faeb7f561ce677a2efc134ab4834acec254
child 813591 b64402b1ccbfa8ef68375a1732f117d513543f93
push id114929
push userbmo:ato@sny.no
push dateTue, 03 Jul 2018 11:58:17 +0000
reviewerswhimboo
bugs1470646
milestone63.0a1
Bug 1470646 - Modularise capabilities module. r?whimboo This removes the "session." prefixed global export type in favour of individually exported types. MozReview-Commit-ID: 3DHTrJsy2IN
testing/marionette/capabilities.js
testing/marionette/doc/internals/capabilities.rst
testing/marionette/driver.js
testing/marionette/listener.js
testing/marionette/test/unit/test_capabilities.js
--- a/testing/marionette/capabilities.js
+++ b/testing/marionette/capabilities.js
@@ -13,57 +13,55 @@ const {
   InvalidArgumentError,
 } = ChromeUtils.import("chrome://marionette/content/error.js", {});
 const {
   pprint,
 } = ChromeUtils.import("chrome://marionette/content/format.js", {});
 
 XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 
-this.EXPORTED_SYMBOLS = ["session"];
+this.EXPORTED_SYMBOLS = [
+  "Capabilities",
+  "PageLoadStrategy",
+  "Proxy",
+  "Timeouts",
+];
 
 // Enable testing this module, as Services.appinfo.* is not available
 // in xpcshell tests.
 const appinfo = {name: "<missing>", version: "<missing>"};
 try { appinfo.name = Services.appinfo.name.toLowerCase(); } catch (e) {}
 try { appinfo.version = Services.appinfo.version; } catch (e) {}
 
-/**
- * State associated with a WebDriver session.
- *
- * @namespace
- */
-this.session = {};
-
 /** Representation of WebDriver session timeouts. */
-session.Timeouts = class {
+class Timeouts {
   constructor() {
     // disabled
     this.implicit = 0;
     // five mintues
     this.pageLoad = 300000;
     // 30 seconds
     this.script = 30000;
   }
 
-  toString() { return "[object session.Timeouts]"; }
+  toString() { return "[object Timeouts]"; }
 
   /** Marshals timeout durations to a JSON Object. */
   toJSON() {
     return {
       implicit: this.implicit,
       pageLoad: this.pageLoad,
       script: this.script,
     };
   }
 
   static fromJSON(json) {
     assert.object(json,
         pprint`Expected "timeouts" to be an object, got ${json}`);
-    let t = new session.Timeouts();
+    let t = new Timeouts();
 
     for (let [type, ms] of Object.entries(json)) {
       switch (type) {
         case "implicit":
           t.implicit = assert.positiveInteger(ms,
               pprint`Expected ${type} to be a positive integer, got ${ms}`);
           break;
 
@@ -79,40 +77,40 @@ session.Timeouts = class {
 
         default:
           throw new InvalidArgumentError("Unrecognised timeout: " + type);
       }
     }
 
     return t;
   }
-};
+}
 
 /**
  * Enum of page loading strategies.
  *
  * @enum
  */
-session.PageLoadStrategy = {
+const PageLoadStrategy = {
   /** No page load strategy.  Navigation will return immediately. */
   None: "none",
   /**
    * Eager, causing navigation to complete when the document reaches
    * the <code>interactive</code> ready state.
    */
   Eager: "eager",
   /**
    * Normal, causing navigation to return when the document reaches the
    * <code>complete</code> ready state.
    */
   Normal: "normal",
 };
 
 /** Proxy configuration object representation. */
-session.Proxy = class {
+class Proxy {
   /** @class */
   constructor() {
     this.proxyType = null;
     this.ftpProxy = null;
     this.ftpProxyPort = null;
     this.httpProxy = null;
     this.httpProxyPort = null;
     this.noProxy = null;
@@ -252,17 +250,17 @@ session.Proxy = class {
           url.hash != "") {
         throw new InvalidArgumentError(
             `${host} was not of the form host[:port]`);
       }
 
       return [hostname, port];
     }
 
-    let p = new session.Proxy();
+    let p = new Proxy();
     if (typeof json == "undefined" || json === null) {
       return p;
     }
 
     assert.object(json, pprint`Expected "proxy" to be an object, got ${json}`);
 
     assert.in("proxyType", json,
         pprint`Expected "proxyType" in "proxy" object, got ${json}`);
@@ -351,33 +349,33 @@ session.Proxy = class {
       noProxy: excludes,
       sslProxy: toHost(this.sslProxy, this.sslProxyPort),
       socksProxy: toHost(this.socksProxy, this.socksProxyPort),
       socksVersion: this.socksVersion,
       proxyAutoconfigUrl: this.proxyAutoconfigUrl,
     });
   }
 
-  toString() { return "[object session.Proxy]"; }
-};
+  toString() { return "[object Proxy]"; }
+}
 
 /** WebDriver session capabilities representation. */
-session.Capabilities = class extends Map {
+class Capabilities extends Map {
   /** @class */
   constructor() {
     super([
       // webdriver
       ["browserName", appinfo.name],
       ["browserVersion", appinfo.version],
       ["platformName", Services.sysinfo.getProperty("name").toLowerCase()],
       ["platformVersion", Services.sysinfo.getProperty("version")],
-      ["pageLoadStrategy", session.PageLoadStrategy.Normal],
+      ["pageLoadStrategy", PageLoadStrategy.Normal],
       ["acceptInsecureCerts", false],
-      ["timeouts", new session.Timeouts()],
-      ["proxy", new session.Proxy()],
+      ["timeouts", new Timeouts()],
+      ["proxy", new Proxy()],
 
       // features
       ["rotatable", appinfo.name == "B2G"],
 
       // proprietary
       ["moz:accessibilityChecks", false],
       ["moz:headless", Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo).isHeadless],
       ["moz:processID", Services.appinfo.processID],
@@ -389,92 +387,91 @@ session.Capabilities = class extends Map
 
   /**
    * @param {string} key
    *     Capability key.
    * @param {(string|number|boolean)} value
    *     JSON-safe capability value.
    */
   set(key, value) {
-    if (key === "timeouts" && !(value instanceof session.Timeouts)) {
+    if (key === "timeouts" && !(value instanceof Timeouts)) {
       throw new TypeError();
-    } else if (key === "proxy" && !(value instanceof session.Proxy)) {
+    } else if (key === "proxy" && !(value instanceof Proxy)) {
       throw new TypeError();
     }
 
     return super.set(key, value);
   }
 
-  /** @return {string} */
-  toString() { return "[object session.Capabilities]"; }
+  toString() { return "[object Capabilities]"; }
 
   /**
    * JSON serialisation of capabilities object.
    *
    * @return {Object.<string, ?>}
    */
   toJSON() {
     return marshal(this);
   }
 
   /**
    * Unmarshal a JSON object representation of WebDriver capabilities.
    *
    * @param {Object.<string, *>=} json
    *     WebDriver capabilities.
    *
-   * @return {session.Capabilities}
+   * @return {Capabilities}
    *     Internal representation of WebDriver capabilities.
    */
   static fromJSON(json) {
     if (typeof json == "undefined" || json === null) {
       json = {};
     }
     assert.object(json,
         pprint`Expected "capabilities" to be an object, got ${json}"`);
 
-    return session.Capabilities.match_(json);
+    return Capabilities.match_(json);
   }
 
   // Matches capabilities as described by WebDriver.
   static match_(json = {}) {
-    let matched = new session.Capabilities();
+    let matched = new Capabilities();
 
     for (let [k, v] of Object.entries(json)) {
       switch (k) {
         case "acceptInsecureCerts":
           assert.boolean(v,
               pprint`Expected ${k} to be a boolean, got ${v}`);
           matched.set("acceptInsecureCerts", v);
           break;
 
         case "pageLoadStrategy":
           if (v === null) {
-            matched.set("pageLoadStrategy", session.PageLoadStrategy.Normal);
+            matched.set("pageLoadStrategy", PageLoadStrategy.Normal);
           } else {
             assert.string(v,
                 pprint`Expected ${k} to be a string, got ${v}`);
 
-            if (Object.values(session.PageLoadStrategy).includes(v)) {
+            if (Object.values(PageLoadStrategy).includes(v)) {
               matched.set("pageLoadStrategy", v);
             } else {
               throw new InvalidArgumentError(
                   "Unknown page load strategy: " + v);
             }
           }
 
           break;
 
         case "proxy":
-          let proxy = session.Proxy.fromJSON(v);
+          let proxy = Proxy.fromJSON(v);
           matched.set("proxy", proxy);
           break;
 
         case "timeouts":
-          let timeouts = session.Timeouts.fromJSON(v);
+          let timeouts = Timeouts.fromJSON(v);
           matched.set("timeouts", timeouts);
           break;
 
         case "moz:accessibilityChecks":
           assert.boolean(v,
               pprint`Expected ${k} to be a boolean, got ${v}`);
           matched.set("moz:accessibilityChecks", v);
           break;
@@ -490,17 +487,22 @@ session.Capabilities = class extends Map
               pprint`Expected ${k} to be a boolean, got ${v}`);
           matched.set("moz:webdriverClick", v);
           break;
       }
     }
 
     return matched;
   }
-};
+}
+
+this.Capabilities = Capabilities;
+this.PageLoadStrategy = PageLoadStrategy;
+this.Proxy = Proxy;
+this.Timeouts = Timeouts;
 
 // Specialisation of |JSON.stringify| that produces JSON-safe object
 // literals, dropping empty objects and entries which values are undefined
 // or null.  Objects are allowed to produce their own JSON representations
 // by implementing a |toJSON| function.
 function marshal(obj) {
   let rv = Object.create(null);
 
--- a/testing/marionette/doc/internals/capabilities.rst
+++ b/testing/marionette/doc/internals/capabilities.rst
@@ -1,22 +1,22 @@
-session module
-==============
+capabilities module
+===================
 
 Timeouts
 --------
-.. js:autoclass:: session.Timeouts
+.. js:autoclass:: Timeouts
   :members:
 
 PageLoadStrategy
 ----------------
-.. js:autoclass:: session.PageLoadStrategy
+.. js:autoclass:: PageLoadStrategy
   :members:
 
 Proxy
 -----
-.. js:autoclass:: session.Proxy
+.. js:autoclass:: Proxy
   :members:
 
 Capabilities
 ------------
-.. js:autoclass:: session.Capabilities
+.. js:autoclass:: Capabilities
   :members:
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -12,16 +12,20 @@ ChromeUtils.import("chrome://marionette/
 const {Addon} = ChromeUtils.import("chrome://marionette/content/addon.js", {});
 ChromeUtils.import("chrome://marionette/content/assert.js");
 ChromeUtils.import("chrome://marionette/content/atom.js");
 const {
   browser,
   Context,
   WindowState,
 } = ChromeUtils.import("chrome://marionette/content/browser.js", {});
+const {
+  Capabilities,
+  Timeouts,
+} = ChromeUtils.import("chrome://marionette/content/capabilities.js", {});
 ChromeUtils.import("chrome://marionette/content/capture.js");
 const {
   CertificateOverrideManager,
   InsecureSweepingOverride,
 } = ChromeUtils.import("chrome://marionette/content/cert.js", {});
 ChromeUtils.import("chrome://marionette/content/cookie.js");
 const {
   ChromeWebElement,
@@ -46,17 +50,16 @@ const {pprint} = ChromeUtils.import("chr
 ChromeUtils.import("chrome://marionette/content/interaction.js");
 ChromeUtils.import("chrome://marionette/content/l10n.js");
 ChromeUtils.import("chrome://marionette/content/legacyaction.js");
 const {Log} = ChromeUtils.import("chrome://marionette/content/log.js", {});
 ChromeUtils.import("chrome://marionette/content/modal.js");
 const {MarionettePrefs} = ChromeUtils.import("chrome://marionette/content/prefs.js", {});
 ChromeUtils.import("chrome://marionette/content/proxy.js");
 ChromeUtils.import("chrome://marionette/content/reftest.js");
-ChromeUtils.import("chrome://marionette/content/session.js");
 const {
   PollPromise,
   TimedPromise,
 } = ChromeUtils.import("chrome://marionette/content/sync.js", {});
 
 XPCOMUtils.defineLazyGetter(this, "logger", Log.get);
 XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 
@@ -139,17 +142,17 @@ this.GeckoDriver = function(appId, serve
   this._browserIds = new WeakMap();
 
   // Use content context by default
   this.context = Context.Content;
 
   this.sandboxes = new Sandboxes(() => this.getCurrentWindow());
   this.legacyactions = new legacyaction.Chain();
 
-  this.capabilities = new session.Capabilities();
+  this.capabilities = new Capabilities();
 
   this.mm = globalMessageManager;
   this.listener = proxy.toListener(
       this.sendAsync.bind(this), () => this.curBrowser);
 
   // points to an alert instance if a modal dialog is present
   this.dialog = null;
   this.dialogHandler = this.globalModalDialogHandler.bind(this);
@@ -698,17 +701,17 @@ GeckoDriver.prototype.listeningPromise =
  */
 GeckoDriver.prototype.newSession = async function(cmd) {
   if (this.sessionID) {
     throw new SessionNotCreatedError("Maximum number of active sessions");
   }
   this.sessionID = WebElement.generateUUID();
 
   try {
-    this.capabilities = session.Capabilities.fromJSON(cmd.parameters);
+    this.capabilities = Capabilities.fromJSON(cmd.parameters);
 
     if (!this.secureTLS) {
       logger.warn("TLS certificate errors will be ignored for this session");
       let acceptAllCerts = new InsecureSweepingOverride();
       CertificateOverrideManager.install(acceptAllCerts);
     }
 
     if (this.proxy.init()) {
@@ -1867,17 +1870,17 @@ GeckoDriver.prototype.getTimeouts = func
  *
  * @throws {InvalidArgumentError}
  *     If timeout type key is unknown, or the value provided with it is
  *     not an integer.
  */
 GeckoDriver.prototype.setTimeouts = function(cmd) {
   // merge with existing timeouts
   let merged = Object.assign(this.timeouts.toJSON(), cmd.parameters);
-  this.timeouts = session.Timeouts.fromJSON(merged);
+  this.timeouts = Timeouts.fromJSON(merged);
 };
 
 /** Single tap. */
 GeckoDriver.prototype.singleTap = async function(cmd) {
   assert.open(this.getCurrentWindow());
 
   let {id, x, y} = cmd.parameters;
   let webEl = WebElement.fromUUID(id, this.context);
@@ -2850,17 +2853,17 @@ GeckoDriver.prototype.deleteSession = fu
   }
 
   modal.removeHandler(this.dialogHandler);
 
   this.sandboxes.clear();
   CertificateOverrideManager.uninstall();
 
   this.sessionID = null;
-  this.capabilities = new session.Capabilities();
+  this.capabilities = new Capabilities();
 };
 
 /**
  * Takes a screenshot of a web element, current frame, or viewport.
  *
  * The screen capture is returned as a lossless PNG image encoded as
  * a base 64 string.
  *
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -12,16 +12,20 @@ const winUtil = content.QueryInterface(C
 
 ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.import("chrome://marionette/content/accessibility.js");
 ChromeUtils.import("chrome://marionette/content/action.js");
 ChromeUtils.import("chrome://marionette/content/atom.js");
+const {
+  Capabilities,
+  PageLoadStrategy,
+} = ChromeUtils.import("chrome://marionette/content/capabilities.js", {});
 ChromeUtils.import("chrome://marionette/content/capture.js");
 const {
   element,
   WebElement,
 } = ChromeUtils.import("chrome://marionette/content/element.js", {});
 const {
   ElementNotInteractableError,
   InsecureCertificateError,
@@ -36,17 +40,16 @@ ChromeUtils.import("chrome://marionette/
 ChromeUtils.import("chrome://marionette/content/event.js");
 const {ContentEventObserverService} = ChromeUtils.import("chrome://marionette/content/dom.js", {});
 const {pprint, truncate} = ChromeUtils.import("chrome://marionette/content/format.js", {});
 ChromeUtils.import("chrome://marionette/content/interaction.js");
 ChromeUtils.import("chrome://marionette/content/legacyaction.js");
 const {Log} = ChromeUtils.import("chrome://marionette/content/log.js", {});
 ChromeUtils.import("chrome://marionette/content/navigate.js");
 ChromeUtils.import("chrome://marionette/content/proxy.js");
-ChromeUtils.import("chrome://marionette/content/session.js");
 
 XPCOMUtils.defineLazyGetter(this, "logger", () => Log.getWithPrefix(outerWindowID));
 XPCOMUtils.defineLazyGlobalGetters(this, ["URL"]);
 
 let {outerWindowID} = winUtil;
 let curContainer = {frame: content, shadowRoot: null};
 
 // Listen for click event to indicate one click has happened, so actions
@@ -65,17 +68,17 @@ const SUPPORTED_STRATEGIES = new Set([
   element.Strategy.PartialLinkText,
   element.Strategy.TagName,
   element.Strategy.XPath,
 ]);
 
 Object.defineProperty(this, "capabilities", {
   get() {
     let payload = sendSyncMessage("Marionette:WebDriver:GetCapabilities");
-    return session.Capabilities.fromJSON(payload[0]);
+    return Capabilities.fromJSON(payload[0]);
   },
   configurable: true,
 });
 
 let legacyactions = new legacyaction.Chain();
 
 // last touch for each fingerId
 let multiLast = {};
@@ -273,18 +276,17 @@ const loadListener = {
           finished = true;
 
         // Return early with a page load strategy of eager, and also
         // special-case about:blocked pages which should be treated as
         // non-error pages but do not raise a pageshow event. about:blank
         // is also treaded specifically here, because it gets temporary
         // loaded for new content processes, and we only want to rely on
         // complete loads for it.
-        } else if ((capabilities.get("pageLoadStrategy") ===
-            session.PageLoadStrategy.Eager &&
+        } else if ((capabilities.get("pageLoadStrategy") === PageLoadStrategy.Eager &&
             documentURI != "about:blank") ||
             /about:blocked\?/.exec(documentURI)) {
           this.stop();
           sendOk(this.commandID);
           finished = true;
         }
 
         break;
@@ -392,18 +394,17 @@ const loadListener = {
    * @param {string=} url
    *     Optional URL, which is used to check if a page load is expected.
    */
   navigate(trigger, commandID, timeout, loadEventExpected = true,
       useUnloadTimer = false) {
 
     // Only wait if the page load strategy is not `none`
     loadEventExpected = loadEventExpected &&
-        (capabilities.get("pageLoadStrategy") !==
-        session.PageLoadStrategy.None);
+        (capabilities.get("pageLoadStrategy") !== PageLoadStrategy.None);
 
     if (loadEventExpected) {
       let startTime = new Date().getTime();
       this.start(commandID, timeout, startTime, true);
     }
 
     return (async () => {
       await trigger();
--- a/testing/marionette/test/unit/test_capabilities.js
+++ b/testing/marionette/test/unit/test_capabilities.js
@@ -3,101 +3,106 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Preferences.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 const {InvalidArgumentError} = ChromeUtils.import("chrome://marionette/content/error.js", {});
-ChromeUtils.import("chrome://marionette/content/session.js");
+const {
+  Capabilities,
+  PageLoadStrategy,
+  Proxy,
+  Timeouts,
+} = ChromeUtils.import("chrome://marionette/content/capabilities.js", {});
 
 add_test(function test_Timeouts_ctor() {
-  let ts = new session.Timeouts();
+  let ts = new Timeouts();
   equal(ts.implicit, 0);
   equal(ts.pageLoad, 300000);
   equal(ts.script, 30000);
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_toString() {
-  equal(new session.Timeouts().toString(), "[object session.Timeouts]");
+  equal(new Timeouts().toString(), "[object Timeouts]");
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_toJSON() {
-  let ts = new session.Timeouts();
+  let ts = new Timeouts();
   deepEqual(ts.toJSON(), {"implicit": 0, "pageLoad": 300000, "script": 30000});
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_fromJSON() {
   let json = {
     implicit: 10,
     pageLoad: 20,
     script: 30,
   };
-  let ts = session.Timeouts.fromJSON(json);
+  let ts = Timeouts.fromJSON(json);
   equal(ts.implicit, json.implicit);
   equal(ts.pageLoad, json.pageLoad);
   equal(ts.script, json.script);
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_fromJSON_unrecognised_field() {
   let json = {
     sessionId: "foobar",
     script: 42,
   };
   try {
-    session.Timeouts.fromJSON(json);
+    Timeouts.fromJSON(json);
   } catch (e) {
     equal(e.name, InvalidArgumentError.name);
     equal(e.message, "Unrecognised timeout: sessionId");
   }
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_fromJSON_invalid_type() {
   try {
-    session.Timeouts.fromJSON({script: "foobar"});
+    Timeouts.fromJSON({script: "foobar"});
   } catch (e) {
     equal(e.name, InvalidArgumentError.name);
     equal(e.message, "Expected [object String] \"script\" to be a positive integer, got [object String] \"foobar\"");
   }
 
   run_next_test();
 });
 
 add_test(function test_Timeouts_fromJSON_bounds() {
   try {
-    session.Timeouts.fromJSON({script: -42});
+    Timeouts.fromJSON({script: -42});
   } catch (e) {
     equal(e.name, InvalidArgumentError.name);
     equal(e.message, "Expected [object String] \"script\" to be a positive integer, got [object Number] -42");
   }
 
   run_next_test();
 });
 
 add_test(function test_PageLoadStrategy() {
-  equal(session.PageLoadStrategy.None, "none");
-  equal(session.PageLoadStrategy.Eager, "eager");
-  equal(session.PageLoadStrategy.Normal, "normal");
+  equal(PageLoadStrategy.None, "none");
+  equal(PageLoadStrategy.Eager, "eager");
+  equal(PageLoadStrategy.Normal, "normal");
 
   run_next_test();
 });
 
 add_test(function test_Proxy_ctor() {
-  let p = new session.Proxy();
+  let p = new Proxy();
   let props = [
     "proxyType",
     "httpProxy",
     "sslProxy",
     "ftpProxy",
     "socksProxy",
     "socksVersion",
     "proxyAutoconfigUrl",
@@ -106,52 +111,52 @@ add_test(function test_Proxy_ctor() {
     ok(prop in p, `${prop} in ${JSON.stringify(props)}`);
     equal(p[prop], null);
   }
 
   run_next_test();
 });
 
 add_test(function test_Proxy_init() {
-  let p = new session.Proxy();
+  let p = new Proxy();
 
   // no changed made, and 5 (system) is default
   equal(p.init(), false);
   equal(Preferences.get("network.proxy.type"), 5);
 
   // pac
   p.proxyType = "pac";
   p.proxyAutoconfigUrl = "http://localhost:1234";
   ok(p.init());
 
   equal(Preferences.get("network.proxy.type"), 2);
   equal(Preferences.get("network.proxy.autoconfig_url"),
       "http://localhost:1234");
 
   // direct
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "direct";
   ok(p.init());
   equal(Preferences.get("network.proxy.type"), 0);
 
   // autodetect
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "autodetect";
   ok(p.init());
   equal(Preferences.get("network.proxy.type"), 4);
 
   // system
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "system";
   ok(p.init());
   equal(Preferences.get("network.proxy.type"), 5);
 
   // manual
   for (let proxy of ["ftp", "http", "ssl", "socks"]) {
-    p = new session.Proxy();
+    p = new Proxy();
     p.proxyType = "manual";
     p.noProxy = ["foo", "bar"];
     p[`${proxy}Proxy`] = "foo";
     p[`${proxy}ProxyPort`] = 42;
     if (proxy === "socks") {
       p[`${proxy}Version`] = 4;
     }
 
@@ -161,50 +166,50 @@ add_test(function test_Proxy_init() {
     equal(Preferences.get(`network.proxy.${proxy}`), "foo");
     equal(Preferences.get(`network.proxy.${proxy}_port`), 42);
     if (proxy === "socks") {
       equal(Preferences.get(`network.proxy.${proxy}_version`), 4);
     }
   }
 
   // empty no proxy should reset default exclustions
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
   p.noProxy = [];
   ok(p.init());
   equal(Preferences.get("network.proxy.no_proxies_on"), "");
 
   run_next_test();
 });
 
 add_test(function test_Proxy_toString() {
-  equal(new session.Proxy().toString(), "[object session.Proxy]");
+  equal(new Proxy().toString(), "[object Proxy]");
 
   run_next_test();
 });
 
 add_test(function test_Proxy_toJSON() {
-  let p = new session.Proxy();
+  let p = new Proxy();
   deepEqual(p.toJSON(), {});
 
   // autoconfig url
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "pac";
   p.proxyAutoconfigUrl = "foo";
   deepEqual(p.toJSON(), {proxyType: "pac", proxyAutoconfigUrl: "foo"});
 
   // manual proxy
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
   deepEqual(p.toJSON(), {proxyType: "manual"});
 
   for (let proxy of ["ftpProxy", "httpProxy", "sslProxy", "socksProxy"]) {
     let expected = {proxyType: "manual"};
 
-    p = new session.Proxy();
+    p = new Proxy();
     p.proxyType = "manual";
 
     if (proxy == "socksProxy") {
       p.socksVersion = 5;
       expected.socksVersion = 5;
     }
 
     // without port
@@ -226,69 +231,69 @@ add_test(function test_Proxy_toJSON() {
     p[proxy] = "2001:db8::1";
     p[`${proxy}Port`] = 42;
     expected[proxy] = "foo:42";
     expected[proxy] = "[2001:db8::1]:42";
     deepEqual(p.toJSON(), expected);
   }
 
   // noProxy: add brackets for IPv6 address
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
   p.noProxy = ["2001:db8::1"];
   let expected = {proxyType: "manual", noProxy: "[2001:db8::1]"};
   deepEqual(p.toJSON(), expected);
 
   run_next_test();
 });
 
 add_test(function test_Proxy_fromJSON() {
-  let p = new session.Proxy();
-  deepEqual(p, session.Proxy.fromJSON(undefined));
-  deepEqual(p, session.Proxy.fromJSON(null));
+  let p = new Proxy();
+  deepEqual(p, Proxy.fromJSON(undefined));
+  deepEqual(p, Proxy.fromJSON(null));
 
   for (let typ of [true, 42, "foo", []]) {
-    Assert.throws(() => session.Proxy.fromJSON(typ), /InvalidArgumentError/);
+    Assert.throws(() => Proxy.fromJSON(typ), /InvalidArgumentError/);
   }
 
   // must contain a valid proxyType
-  Assert.throws(() => session.Proxy.fromJSON({}), /InvalidArgumentError/);
-  Assert.throws(() => session.Proxy.fromJSON({proxyType: "foo"}),
+  Assert.throws(() => Proxy.fromJSON({}), /InvalidArgumentError/);
+  Assert.throws(() => Proxy.fromJSON({proxyType: "foo"}),
       /InvalidArgumentError/);
 
   // autoconfig url
   for (let url of [true, 42, [], {}]) {
-    Assert.throws(() => session.Proxy.fromJSON(
+    Assert.throws(() => Proxy.fromJSON(
         {proxyType: "pac", proxyAutoconfigUrl: url}), /InvalidArgumentError/);
   }
 
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "pac";
   p.proxyAutoconfigUrl = "foo";
   deepEqual(p,
-      session.Proxy.fromJSON({proxyType: "pac", proxyAutoconfigUrl: "foo"}));
+      Proxy.fromJSON({proxyType: "pac", proxyAutoconfigUrl: "foo"}));
 
   // manual proxy
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
-  deepEqual(p, session.Proxy.fromJSON({proxyType: "manual"}));
+  deepEqual(p, Proxy.fromJSON({proxyType: "manual"}));
 
   for (let proxy of ["httpProxy", "sslProxy", "ftpProxy", "socksProxy"]) {
     let manual = {proxyType: "manual"};
 
     // invalid hosts
     for (let host of [true, 42, [], {}, null, "http://foo",
       "foo:-1", "foo:65536", "foo/test", "foo#42", "foo?foo=bar",
       "2001:db8::1"]) {
       manual[proxy] = host;
-      Assert.throws(() => session.Proxy.fromJSON(manual),
+      Assert.throws(() => Proxy.fromJSON(manual),
           /InvalidArgumentError/);
     }
 
-    p = new session.Proxy();
+    p = new Proxy();
     p.proxyType = "manual";
     if (proxy == "socksProxy") {
       manual.socksVersion = 5;
       p.socksVersion = 5;
     }
 
     let host_map = {
       "foo:1": {hostname: "foo", port: 1},
@@ -302,17 +307,17 @@ add_test(function test_Proxy_fromJSON() 
 
     // valid proxy hosts with port
     for (let host in host_map) {
       manual[proxy] = host;
 
       p[`${proxy}`] = host_map[host].hostname;
       p[`${proxy}Port`] = host_map[host].port;
 
-      deepEqual(p, session.Proxy.fromJSON(manual));
+      deepEqual(p, Proxy.fromJSON(manual));
     }
 
     // Without a port the default port of the scheme is used
     for (let host of ["foo", "foo:"]) {
       manual[proxy] = host;
 
       // For socks no default port is available
       p[proxy] = `foo`;
@@ -320,82 +325,82 @@ add_test(function test_Proxy_fromJSON() 
         p[`${proxy}Port`] = null;
       } else {
         let default_ports = {"ftpProxy": 21, "httpProxy": 80,
           "sslProxy": 443};
 
         p[`${proxy}Port`] = default_ports[proxy];
       }
 
-      deepEqual(p, session.Proxy.fromJSON(manual));
+      deepEqual(p, Proxy.fromJSON(manual));
     }
   }
 
   // missing required socks version
-  Assert.throws(() => session.Proxy.fromJSON(
+  Assert.throws(() => Proxy.fromJSON(
       {proxyType: "manual", socksProxy: "foo:1234"}),
       /InvalidArgumentError/);
 
   // noProxy: invalid settings
   for (let noProxy of [true, 42, {}, null, "foo",
       [true], [42], [{}], [null]]) {
-    Assert.throws(() => session.Proxy.fromJSON(
+    Assert.throws(() => Proxy.fromJSON(
         {proxyType: "manual", noProxy}),
         /InvalidArgumentError/);
   }
 
   // noProxy: valid settings
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
   for (let noProxy of [[], ["foo"], ["foo", "bar"], ["127.0.0.1"]]) {
     let manual = {proxyType: "manual", "noProxy": noProxy};
     p.noProxy = noProxy;
-    deepEqual(p, session.Proxy.fromJSON(manual));
+    deepEqual(p, Proxy.fromJSON(manual));
   }
 
   // noProxy: IPv6 needs brackets removed
-  p = new session.Proxy();
+  p = new Proxy();
   p.proxyType = "manual";
   p.noProxy = ["2001:db8::1"];
   let manual = {proxyType: "manual", "noProxy": ["[2001:db8::1]"]};
-  deepEqual(p, session.Proxy.fromJSON(manual));
+  deepEqual(p, Proxy.fromJSON(manual));
 
   run_next_test();
 });
 
 add_test(function test_Capabilities_ctor() {
-  let caps = new session.Capabilities();
+  let caps = new Capabilities();
   ok(caps.has("browserName"));
   ok(caps.has("browserVersion"));
   ok(caps.has("platformName"));
   ok(caps.has("platformVersion"));
-  equal(session.PageLoadStrategy.Normal, caps.get("pageLoadStrategy"));
+  equal(PageLoadStrategy.Normal, caps.get("pageLoadStrategy"));
   equal(false, caps.get("acceptInsecureCerts"));
-  ok(caps.get("timeouts") instanceof session.Timeouts);
-  ok(caps.get("proxy") instanceof session.Proxy);
+  ok(caps.get("timeouts") instanceof Timeouts);
+  ok(caps.get("proxy") instanceof Proxy);
 
   ok(caps.has("rotatable"));
 
   equal(false, caps.get("moz:accessibilityChecks"));
   ok(caps.has("moz:processID"));
   ok(caps.has("moz:profile"));
   equal(false, caps.get("moz:useNonSpecCompliantPointerOrigin"));
   equal(true, caps.get("moz:webdriverClick"));
 
   run_next_test();
 });
 
 add_test(function test_Capabilities_toString() {
-  equal("[object session.Capabilities]", new session.Capabilities().toString());
+  equal("[object Capabilities]", new Capabilities().toString());
 
   run_next_test();
 });
 
 add_test(function test_Capabilities_toJSON() {
-  let caps = new session.Capabilities();
+  let caps = new Capabilities();
   let json = caps.toJSON();
 
   equal(caps.get("browserName"), json.browserName);
   equal(caps.get("browserVersion"), json.browserVersion);
   equal(caps.get("platformName"), json.platformName);
   equal(caps.get("platformVersion"), json.platformVersion);
   equal(caps.get("pageLoadStrategy"), json.pageLoadStrategy);
   equal(caps.get("acceptInsecureCerts"), json.acceptInsecureCerts);
@@ -410,36 +415,36 @@ add_test(function test_Capabilities_toJS
   equal(caps.get("moz:useNonSpecCompliantPointerOrigin"),
       json["moz:useNonSpecCompliantPointerOrigin"]);
   equal(caps.get("moz:webdriverClick"), json["moz:webdriverClick"]);
 
   run_next_test();
 });
 
 add_test(function test_Capabilities_fromJSON() {
-  const {fromJSON} = session.Capabilities;
+  const {fromJSON} = Capabilities;
 
   // plain
   for (let typ of [{}, null, undefined]) {
     ok(fromJSON(typ).has("browserName"));
   }
   for (let typ of [true, 42, "foo", []]) {
     Assert.throws(() => fromJSON(typ), /InvalidArgumentError/);
   }
 
   // matching
-  let caps = new session.Capabilities();
+  let caps = new Capabilities();
 
   caps = fromJSON({acceptInsecureCerts: true});
   equal(true, caps.get("acceptInsecureCerts"));
   caps = fromJSON({acceptInsecureCerts: false});
   equal(false, caps.get("acceptInsecureCerts"));
   Assert.throws(() => fromJSON({acceptInsecureCerts: "foo"}), InvalidArgumentError);
 
-  for (let strategy of Object.values(session.PageLoadStrategy)) {
+  for (let strategy of Object.values(PageLoadStrategy)) {
     caps = fromJSON({pageLoadStrategy: strategy});
     equal(strategy, caps.get("pageLoadStrategy"));
   }
   Assert.throws(() => fromJSON({pageLoadStrategy: "foo"}), InvalidArgumentError);
 
   let proxyConfig = {proxyType: "manual"};
   caps = fromJSON({proxy: proxyConfig});
   equal("manual", caps.get("proxy").proxyType);
@@ -469,39 +474,39 @@ add_test(function test_Capabilities_from
   caps = fromJSON({"moz:webdriverClick": false});
   equal(false, caps.get("moz:webdriverClick"));
   Assert.throws(() => fromJSON({"moz:webdriverClick": "foo"}), InvalidArgumentError);
   Assert.throws(() => fromJSON({"moz:webdriverClick": 1}), InvalidArgumentError);
 
   run_next_test();
 });
 
-// use session.Proxy.toJSON to test marshal
+// use Proxy.toJSON to test marshal
 add_test(function test_marshal() {
-  let proxy = new session.Proxy();
+  let proxy = new Proxy();
 
   // drop empty fields
   deepEqual({}, proxy.toJSON());
   proxy.proxyType = "manual";
   deepEqual({proxyType: "manual"}, proxy.toJSON());
   proxy.proxyType = null;
   deepEqual({}, proxy.toJSON());
   proxy.proxyType = undefined;
   deepEqual({}, proxy.toJSON());
 
   // iterate over object literals
   proxy.proxyType = {foo: "bar"};
   deepEqual({proxyType: {foo: "bar"}}, proxy.toJSON());
 
   // iterate over complex object that implement toJSON
-  proxy.proxyType = new session.Proxy();
+  proxy.proxyType = new Proxy();
   deepEqual({}, proxy.toJSON());
   proxy.proxyType.proxyType = "manual";
   deepEqual({proxyType: {proxyType: "manual"}}, proxy.toJSON());
 
   // drop objects with no entries
   proxy.proxyType = {foo: {}};
   deepEqual({}, proxy.toJSON());
-  proxy.proxyType = {foo: new session.Proxy()};
+  proxy.proxyType = {foo: new Proxy()};
   deepEqual({}, proxy.toJSON());
 
   run_next_test();
 });