Bug 1387094 - Add noProxy support for manual proxy type. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 31 Aug 2017 17:49:36 +0200
changeset 656738 cc668e55f81f90605b796b1f3199459b6f687d91
parent 656737 c495a173ddf7dedd2fef721ae27cc5da6e1c9382
child 729223 00681134c01b732d0186089d528039ef914e3ef6
push id77301
push userbmo:hskupin@gmail.com
push dateThu, 31 Aug 2017 15:52:41 +0000
bugs1387094
milestone57.0a1
Bug 1387094 - Add noProxy support for manual proxy type. MozReview-Commit-ID: 1C9sFgrno4i
testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
testing/marionette/session.js
testing/marionette/test_session.js
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_proxy.py
@@ -73,16 +73,35 @@ class TestProxyCapabilities(MarionetteTe
         capabilities = {"proxy": {
             "proxyType": "manual",
             "socksProxy": proxy_host,
         }}
 
         with self.assertRaises(errors.SessionNotCreatedException):
             self.marionette.start_session(capabilities)
 
+    def test_proxy_type_manual_no_proxy_on(self):
+        capabilities = {"proxy": {
+            "proxyType": "manual",
+            "noProxy": ["foo", "bar"],
+        }}
+
+        self.marionette.start_session(capabilities)
+        self.assertEqual(self.marionette.session_capabilities["proxy"],
+                         capabilities["proxy"])
+
+    def test_proxy_type_manual_invalid_no_proxy_on(self):
+        capabilities = {"proxy": {
+            "proxyType": "manual",
+            "noProxy": "foo, bar",
+        }}
+
+        with self.assertRaises(errors.SessionNotCreatedException):
+            self.marionette.start_session(capabilities)
+
     def test_proxy_type_pac(self):
         pac_url = "http://marionette.test"
         capabilities = {"proxy": {"proxyType": "pac", "proxyAutoconfigUrl": pac_url}}
 
         self.marionette.start_session(capabilities)
         self.assertEqual(self.marionette.session_capabilities["proxy"],
                          capabilities["proxy"])
 
--- a/testing/marionette/session.js
+++ b/testing/marionette/session.js
@@ -109,16 +109,17 @@ session.PageLoadStrategy = {
 session.Proxy = class {
   /** @class */
   constructor() {
     this.proxyType = null;
     this.ftpProxy = null;
     this.ftpProxyPort = null;
     this.httpProxy = null;
     this.httpProxyPort = null;
+    this.noProxy = null;
     this.sslProxy = null;
     this.sslProxyPort = null;
     this.socksProxy = null;
     this.socksProxyPort = null;
     this.socksVersion = null;
     this.proxyAutoconfigUrl = null;
   }
 
@@ -168,16 +169,20 @@ session.Proxy = class {
           Preferences.set("network.proxy.socks", this.socksProxy);
           if (Number.isInteger(this.socksProxyPort)) {
             Preferences.set("network.proxy.socks_port", this.socksProxyPort);
           }
           if (this.socksVersion) {
             Preferences.set("network.proxy.socks_version", this.socksVersion);
           }
         }
+
+        if (this.noProxy && this.noProxy.length > 0) {
+          Preferences.set("network.proxy.no_proxies_on", this.noProxy.join(", "));
+        }
         return true;
 
       case "pac":
         Preferences.set("network.proxy.type", 2);
         Preferences.set(
             "network.proxy.autoconfig_url", this.proxyAutoconfigUrl);
         return true;
 
@@ -273,16 +278,23 @@ session.Proxy = class {
         }
         if (typeof json.sslProxy != "undefined") {
           [p.sslProxy, p.sslProxyPort] = fromHost("https", json.sslProxy);
         }
         if (typeof json.socksProxy != "undefined") {
           [p.socksProxy, p.socksProxyPort] = fromHost("socks", json.socksProxy);
           p.socksVersion = assert.positiveInteger(json.socksVersion);
         }
+        if (typeof json.noProxy != "undefined") {
+          let entries = assert.array(json.noProxy);
+          for (let entry of entries) {
+            assert.string(entry);
+          }
+          p.noProxy = entries;
+        }
         break;
 
       default:
         throw new InvalidArgumentError(
             `Invalid type of proxy: ${p.proxyType}`);
     }
 
     return p;
@@ -304,16 +316,17 @@ session.Proxy = class {
 
       return hostname;
     }
 
     return marshal({
       proxyType: this.proxyType,
       ftpProxy: toHost(this.ftpProxy, this.ftpProxyPort),
       httpProxy: toHost(this.httpProxy, this.httpProxyPort),
+      noProxy: this.noProxy,
       sslProxy: toHost(this.sslProxy, this.sslProxyPort),
       socksProxy: toHost(this.socksProxy, this.socksProxyPort),
       socksVersion: this.socksVersion,
       proxyAutoconfigUrl: this.proxyAutoconfigUrl,
     });
   }
 
   toString() { return "[object session.Proxy]"; }
--- a/testing/marionette/test_session.js
+++ b/testing/marionette/test_session.js
@@ -145,24 +145,26 @@ add_test(function test_Proxy_init() {
   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.proxyType = "manual";
+    p.noProxy = ["foo", "bar"];
     p[`${proxy}Proxy`] = "foo";
     p[`${proxy}ProxyPort`] = 42;
     if (proxy === "socks") {
       p[`${proxy}Version`] = 4;
     }
 
     ok(p.init());
     equal(Preferences.get("network.proxy.type"), 1);
+    equal(Preferences.get("network.proxy.no_proxies_on"), "foo, bar");
     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);
     }
   }
 
   run_next_test();
@@ -273,16 +275,30 @@ add_test(function test_Proxy_fromJSON() 
     }
   }
 
   // missing required socks version
   Assert.throws(() => session.Proxy.fromJSON(
       {proxyType: "manual", socksProxy: "foo:1234"}),
       InvalidArgumentError);
 
+  // invalid noProxy
+  for (let noProxy of [true, 42, {}, null, "foo",
+      [true], [42], [{}], [null]]) {
+    Assert.throws(() => session.Proxy.fromJSON(
+        {proxyType: "manual", noProxy: noProxy}),
+        InvalidArgumentError);
+  }
+
+  // valid noProxy
+  for (let noProxy of [[], ["foo"], ["foo", "bar"]]) {
+    let manual = {proxyType: "manual", "noProxy": noProxy}
+    deepEqual(manual, session.Proxy.fromJSON(manual).toJSON());
+  }
+
   run_next_test();
 });
 
 add_test(function test_Capabilities_ctor() {
   let caps = new session.Capabilities();
   ok(caps.has("browserName"));
   ok(caps.has("browserVersion"));
   ok(caps.has("platformName"));