Bug 1405240 - Fix test_cookie.js unit test assertions r?ato, whimboo draft
authorPeter Major <peter.major@forgerock.com>
Tue, 03 Oct 2017 16:28:17 +0100
changeset 674517 a23212d948da
parent 674516 c97190c389c4
child 734360 ef12ab57b40c
push id82867
push userbmo:majorpetya@gmail.com
push dateTue, 03 Oct 2017 22:00:33 +0000
reviewersato, whimboo
bugs1405240
milestone58.0a1
Bug 1405240 - Fix test_cookie.js unit test assertions r?ato, whimboo 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);