Bug 1406763 - Refactor xpcshell proxy tests for fromJson and toJson. r=ato
authorHenrik Skupin <mail@hskupin.info>
Wed, 11 Oct 2017 00:26:22 +0200
changeset 385928 d8337396947a7c762722cd67289635a9c0489f2b
parent 385927 97bf696997c5d08e717c92bcf6cf3d0e57435db0
child 385929 633b06e5fc74afd202a58c722ae732872e512bc2
push id32672
push userarchaeopteryx@coole-files.de
push dateFri, 13 Oct 2017 09:00:05 +0000
treeherdermozilla-central@3efcb26e5f37 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1406763
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1406763 - Refactor xpcshell proxy tests for fromJson and toJson. r=ato To ensure that both methods are working as expected, they cannot be used in combination for assertions. MozReview-Commit-ID: 57jYmPejEq0
testing/marionette/test_session.js
--- a/testing/marionette/test_session.js
+++ b/testing/marionette/test_session.js
@@ -182,108 +182,143 @@ add_test(function test_Proxy_toString() 
 
   run_next_test();
 });
 
 add_test(function test_Proxy_toJSON() {
   let p = new session.Proxy();
   deepEqual(p.toJSON(), {});
 
-  // manual
+  // autoconfig url
+  p = new session.Proxy();
+  p.proxyType = "pac";
+  p.proxyAutoconfigUrl = "foo";
+  deepEqual(p.toJSON(), {proxyType: "pac", proxyAutoconfigUrl: "foo"});
+
+  // manual proxy
   p = new session.Proxy();
   p.proxyType = "manual";
   deepEqual(p.toJSON(), {proxyType: "manual"});
 
   for (let proxy of ["ftpProxy", "httpProxy", "sslProxy", "socksProxy"]) {
     let expected = {proxyType: "manual"}
 
-    let manual = new session.Proxy();
-    manual.proxyType = "manual";
+    p = new session.Proxy();
+    p.proxyType = "manual";
 
     if (proxy == "socksProxy") {
-      manual.socksVersion = 5;
+      p.socksVersion = 5;
       expected.socksVersion = 5;
     }
 
     // without port
-    manual[proxy] = "foo";
+    p[proxy] = "foo";
     expected[proxy] = "foo"
-    deepEqual(manual.toJSON(), expected);
+    deepEqual(p.toJSON(), expected);
 
     // with port
-    manual[proxy] = "foo";
-    manual[`${proxy}Port`] = 0;
+    p[proxy] = "foo";
+    p[`${proxy}Port`] = 0;
     expected[proxy] = "foo:0";
-    deepEqual(manual.toJSON(), expected);
+    deepEqual(p.toJSON(), expected);
 
-    manual[`${proxy}Port`] = 42;
+    p[`${proxy}Port`] = 42;
     expected[proxy] = "foo:42"
-    deepEqual(manual.toJSON(), expected);
+    deepEqual(p.toJSON(), expected);
   }
 
   run_next_test();
 });
 
 add_test(function test_Proxy_fromJSON() {
-  deepEqual({}, session.Proxy.fromJSON(undefined).toJSON());
-  deepEqual({}, session.Proxy.fromJSON(null).toJSON());
+  let p = new session.Proxy();
+  deepEqual(p, session.Proxy.fromJSON(undefined));
+  deepEqual(p, session.Proxy.fromJSON(null));
 
   for (let typ of [true, 42, "foo", []]) {
     Assert.throws(() => session.Proxy.fromJSON(typ), InvalidArgumentError);
   }
 
   // must contain a valid proxyType
   Assert.throws(() => session.Proxy.fromJSON({}), InvalidArgumentError);
   Assert.throws(() => session.Proxy.fromJSON({proxyType: "foo"}),
       InvalidArgumentError);
 
-  // manual
-  session.Proxy.fromJSON({proxyType: "manual"});
+  // autoconfig url
+  for (let url of [true, 42, [], {}]) {
+    Assert.throws(() => session.Proxy.fromJSON(
+        {proxyType: "pac", proxyAutoconfigUrl: url}), /InvalidArgumentError/);
+  }
+
+  p = new session.Proxy();
+  p.proxyType = "pac";
+  p.proxyAutoconfigUrl = "foo";
+  deepEqual(p,
+      session.Proxy.fromJSON({proxyType: "pac", proxyAutoconfigUrl: "foo"}));
+
+  // manual proxy
+  p = new session.Proxy();
+  p.proxyType = "manual";
+  deepEqual(p, session.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),
           InvalidArgumentError);
     }
 
-    let expected = {"proxyType": "manual"};
+    p = new session.Proxy();
+    p.proxyType = "manual";
     if (proxy == "socksProxy") {
       manual.socksVersion = 5;
-      expected.socksVersion = 5;
+      p.socksVersion = 5;
     }
 
+    let host_map = {
+      "foo:1": {hostname: "foo", port: 1},
+      "foo:21": {hostname: "foo", port: 21},
+      "foo:80": {hostname: "foo", port: 80},
+      "foo:443": {hostname: "foo", port: 443},
+      "foo:65535": {hostname: "foo", port: 65535},
+      "127.0.0.1:42": {hostname: "127.0.0.1", port: 42},
+      "[2001:db8::1]:42": {hostname: "[2001:db8::1]", port: "42"},
+    };
+
     // valid proxy hosts with port
-    for (let host of ["foo:1", "foo:80", "foo:443", "foo:65535",
-        "127.0.0.1:42", "[2001:db8::1]:42"]) {
+    for (let host in host_map) {
       manual[proxy] = host;
-      expected[proxy] = host;
 
-      deepEqual(expected, session.Proxy.fromJSON(manual).toJSON());
+      p[`${proxy}`] = host_map[host]["hostname"];
+      p[`${proxy}Port`] = host_map[host]["port"];
+
+      deepEqual(p, session.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`;
       if (proxy === "socksProxy") {
-        expected[proxy] = `foo`;
+        p[`${proxy}Port`] = null;
       } else {
         let default_ports = {"ftpProxy": 21, "httpProxy": 80,
            "sslProxy": 443};
 
-        expected[proxy] = `foo:${default_ports[proxy]}`;
+        p[`${proxy}Port`] = default_ports[proxy];
       }
-      deepEqual(expected, session.Proxy.fromJSON(manual).toJSON());
+
+      deepEqual(p, session.Proxy.fromJSON(manual));
     }
   }
 
   // missing required socks version
   Assert.throws(() => session.Proxy.fromJSON(
       {proxyType: "manual", socksProxy: "foo:1234"}),
       InvalidArgumentError);
 
@@ -291,19 +326,23 @@ add_test(function test_Proxy_fromJSON() 
   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"]]) {
+  p = new session.Proxy();
+  p.proxyType = "manual";
+  for (let noProxy of [[], ["foo"], ["foo", "bar"],
+      ["127.0.0.1"], ["[2001:db8::1"]]) {
     let manual = {proxyType: "manual", "noProxy": noProxy}
-    deepEqual(manual, session.Proxy.fromJSON(manual).toJSON());
+    p.noProxy = noProxy;
+    deepEqual(p, session.Proxy.fromJSON(manual));
   }
 
   run_next_test();
 });
 
 add_test(function test_Capabilities_ctor() {
   let caps = new session.Capabilities();
   ok(caps.has("browserName"));