Bug 1405240 - Fix test_cookie.js unit test assertions r=ato
authorPeter Major <peter.major@forgerock.com>
Tue, 03 Oct 2017 16:28:17 +0100
changeset 384440 2b4e006bc55a
parent 384439 83d470577ac4
child 384441 d508870ea425
push id52633
push useratolfsen@mozilla.com
push dateWed, 04 Oct 2017 13:58:07 +0000
treeherderautoland@2b4e006bc55a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1405240
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 1405240 - Fix test_cookie.js unit test assertions r=ato When verifying error messages, the second parameter of Assert.throws has to be a regular expression. MozReview-Commit-ID: LJ6Iif8ORTs
testing/marionette/test_cookie.js
--- a/testing/marionette/test_cookie.js
+++ b/testing/marionette/test_cookie.js
@@ -59,85 +59,85 @@ cookie.manager = {
 add_test(function test_fromJSON() {
   // object
   for (let invalidType of ["foo", 42, true, [], null, undefined]) {
     Assert.throws(() => cookie.fromJSON(invalidType), /Expected cookie object/);
   }
 
   // name and value
   for (let invalidType of [42, true, [], {}, null, undefined]) {
-    Assert.throws(() => cookie.fromJSON({name: invalidType}), "Cookie name must be string");
-    Assert.throws(() => cookie.fromJSON({value: invalidType}), "Cookie value must be string");
+    Assert.throws(() => cookie.fromJSON({name: invalidType}), /Cookie name must be string/);
+    Assert.throws(() => cookie.fromJSON({name: "foo", value: invalidType}), /Cookie value must be string/);
   }
 
   // domain
   for (let invalidType of [42, true, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       domain: invalidType
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie domain must be string");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie domain must be string/);
   }
   let test = {
     name: "foo",
     value: "bar",
     domain: "domain"
   };
   let parsedCookie = cookie.fromJSON(test);
   equal(parsedCookie.domain, ".domain");
 
   // path
   for (let invalidType of [42, true, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       path: invalidType,
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie path must be string");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie path must be string/);
   }
 
   // secure
   for (let invalidType of ["foo", 42, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       secure: invalidType,
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie secure flag must be boolean");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie secure flag must be boolean/);
   }
 
   // httpOnly
   for (let invalidType of ["foo", 42, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       httpOnly: invalidType,
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie httpOnly flag must be boolean");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie httpOnly flag must be boolean/);
   }
 
   // session
   for (let invalidType of ["foo", 42, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       session: invalidType,
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie session flag must be boolean");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie session flag must be boolean/);
   }
 
   // expiry
   for (let invalidType of ["foo", true, [], {}, null]) {
     let test = {
       name: "foo",
       value: "bar",
       expiry: invalidType,
     };
-    Assert.throws(() => cookie.fromJSON(test), "Cookie expiry must be a positive integer");
+    Assert.throws(() => cookie.fromJSON(test), /Cookie expiry must be a positive integer/);
   }
 
   // bare requirements
   let bare = cookie.fromJSON({name: "name", value: "value"});
   equal("name", bare.name);
   equal("value", bare.value);
   for (let missing of ["path", "secure", "httpOnly", "session", "expiry"]) {
     ok(!bare.hasOwnProperty(missing));
@@ -166,27 +166,24 @@ add_test(function test_fromJSON() {
   run_next_test();
 });
 
 add_test(function test_add() {
   cookie.manager.cookies = [];
 
   for (let invalidType of [42, true, [], {}, null, undefined]) {
     Assert.throws(
-        () => cookie.add(invalidType),
-        "Cookie must have string name");
-    Assert.throws(
         () => cookie.add({name: invalidType}),
-        "Cookie must have string name");
+        /Cookie name must be string/);
     Assert.throws(
         () => cookie.add({name: "name", value: invalidType}),
-        "Cookie must have string value");
+        /Cookie value must be string/);
     Assert.throws(
         () => cookie.add({name: "name", value: "value", domain: invalidType}),
-        "Cookie must have string domain");
+        /Cookie domain must be string/);
   }
 
   cookie.add({
     name: "name",
     value: "value",
     domain: "domain",
   });
   equal(1, cookie.manager.cookies.length);
@@ -201,17 +198,17 @@ add_test(function test_add() {
     value: "value2",
     domain: "domain2",
   });
   equal(2, cookie.manager.cookies.length);
 
   Assert.throws(() => {
     let biscuit = {name: "name3", value: "value3", domain: "domain3"};
     cookie.add(biscuit, {restrictToHost: "other domain"});
-  }, "Cookies may only be set for the current domain");
+  }, /Cookies may only be set for the current domain/);
 
   cookie.add({
     name: "name4",
     value: "value4",
     domain: "my.domain:1234",
   });
   equal("my.domain", cookie.manager.cookies[2].host);