Bug 1463673 - Add the expected argument to Assert.throws/rejects for various tests in toolkit/. r=mossop
authorMark Banner <standard8@mozilla.com>
Tue, 22 May 2018 19:25:34 +0100
changeset 420263 1350bcc2983eed6a9ed95586d9807ef1ec69dd9e
parent 420262 c9f558e4282c10db369642fbc989e975364797f0
child 420264 d73afee801c0c857899f86a58f9963234f761208
push id64576
push usermbanner@mozilla.com
push dateTue, 29 May 2018 17:46:42 +0000
treeherderautoland@d73afee801c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1463673
milestone62.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 1463673 - Add the expected argument to Assert.throws/rejects for various tests in toolkit/. r=mossop MozReview-Commit-ID: LsWlHC16145
toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
toolkit/components/mozintl/test/test_mozintl_getLocaleDisplayNames.js
toolkit/components/osfile/tests/xpcshell/test_remove.js
toolkit/components/passwordmgr/test/unit/test_logins_change.js
toolkit/components/utils/test/unit/test_Sampling.js
toolkit/modules/tests/xpcshell/test_Integration.js
toolkit/modules/tests/xpcshell/test_timer.js
--- a/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
+++ b/toolkit/components/crashes/tests/xpcshell/test_crash_manager.js
@@ -32,17 +32,17 @@ add_task(async function test_constructor
     storeDir: "/baz",
   });
   Assert.ok(m, "CrashManager can be created.");
 });
 
 add_task(async function test_constructor_invalid() {
   Assert.throws(() => {
     new CrashManager({foo: true});
-  });
+  }, /Required key not present in options/);
 });
 
 add_task(async function test_get_manager() {
   let m = await getManager();
   Assert.ok(m, "CrashManager obtained.");
 
   await m.createDummyDump(true);
   await m.createDummyDump(false);
@@ -648,9 +648,8 @@ add_task(async function test_telemetryHi
 
   // Check that we have the expected keys.
   let snap = h.snapshot();
   Assert.equal(Object.keys(snap).length, keysCount,
     "Some crash types have not been recorded, see the list in Histograms.json");
   Assert.deepEqual(Object.keys(snap).sort(), keys.sort(),
     "Some crash types do not match");
 });
-
--- a/toolkit/components/mozintl/test/test_mozintl_getLocaleDisplayNames.js
+++ b/toolkit/components/mozintl/test/test_mozintl_getLocaleDisplayNames.js
@@ -39,45 +39,45 @@ add_test(function test_other_subtags_ign
   deepEqual(gLocDN(["en-t-en-latn"]), ["English"]);
   deepEqual(gLocDN(["en-u-hc-h24"]), ["English"]);
   run_next_test();
 });
 
 add_test(function test_invalid_locales() {
   deepEqual(gLocDN(["2"]), ["2"]);
   deepEqual(gLocDN([""]), [""]);
-  Assert.throws(() => gLocDN([2]));
-  Assert.throws(() => gLocDN([{}]));
-  Assert.throws(() => gLocDN([true]));
+  Assert.throws(() => gLocDN([2]), /All locale codes must be strings/);
+  Assert.throws(() => gLocDN([{}]), /All locale codes must be strings/);
+  Assert.throws(() => gLocDN([true]), /All locale codes must be strings/);
   run_next_test();
 });
 
 add_test(function test_language_only() {
   deepEqual(gLangDN([]), []);
   deepEqual(gLangDN(["en"]), ["English"]);
   deepEqual(gLangDN(["und"]), ["und"]);
   run_next_test();
 });
 
 add_test(function test_invalid_languages() {
   deepEqual(gLangDN(["2"]), ["2"]);
   deepEqual(gLangDN([""]), [""]);
-  Assert.throws(() => gLangDN([2]));
-  Assert.throws(() => gLangDN([{}]));
-  Assert.throws(() => gLangDN([true]));
+  Assert.throws(() => gLangDN([2]), /All language codes must be strings/);
+  Assert.throws(() => gLangDN([{}]), /All language codes must be strings/);
+  Assert.throws(() => gLangDN([true]), /All language codes must be strings/);
   run_next_test();
 });
 
 add_test(function test_region_only() {
   deepEqual(gRegDN([]), []);
   deepEqual(gRegDN(["US"]), ["United States"]);
   deepEqual(gRegDN(["und"]), ["UND"]);
   run_next_test();
 });
 
 add_test(function test_invalid_regions() {
   deepEqual(gRegDN(["2"]), ["2"]);
   deepEqual(gRegDN([""]), [""]);
-  Assert.throws(() => gRegDN([2]));
-  Assert.throws(() => gRegDN([{}]));
-  Assert.throws(() => gRegDN([true]));
+  Assert.throws(() => gRegDN([2]), /All region codes must be strings/);
+  Assert.throws(() => gRegDN([{}]), /All region codes must be strings/);
+  Assert.throws(() => gRegDN([true]), /All region codes must be strings/);
   run_next_test();
 });
--- a/toolkit/components/osfile/tests/xpcshell/test_remove.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_remove.js
@@ -16,16 +16,17 @@ function run_test() {
   run_next_test();
 }
 
 add_task(async function test_ignoreAbsent() {
   let absent_file_name = "test_osfile_front_absent.tmp";
 
   // Removing absent files should throw if "ignoreAbsent" is true.
   await Assert.rejects(OS.File.remove(absent_file_name, {ignoreAbsent: false}),
+                       err => err.operation == "remove",
                        "OS.File.remove throws if there is no such file.");
 
   // Removing absent files should not throw if "ignoreAbsent" is true or not
   // defined.
   let exception = null;
   try {
     await OS.File.remove(absent_file_name, {ignoreAbsent: true});
     await OS.File.remove(absent_file_name);
@@ -35,16 +36,17 @@ add_task(async function test_ignoreAbsen
   Assert.ok(!exception, "OS.File.remove should not throw when not requested.");
 });
 
 add_task(async function test_ignoreAbsent_directory_missing() {
   let absent_file_name = OS.Path.join("absent_parent", "test.tmp");
 
   // Removing absent files should throw if "ignoreAbsent" is true.
   await Assert.rejects(OS.File.remove(absent_file_name, {ignoreAbsent: false}),
+                       err => err.operation == "remove",
                        "OS.File.remove throws if there is no such file.");
 
   // Removing files from absent directories should not throw if "ignoreAbsent"
   // is true or not defined.
   let exception = null;
   try {
     await OS.File.remove(absent_file_name, {ignoreAbsent: true});
     await OS.File.remove(absent_file_name);
--- a/toolkit/components/passwordmgr/test/unit/test_logins_change.js
+++ b/toolkit/components/passwordmgr/test/unit/test_logins_change.js
@@ -293,17 +293,17 @@ add_task(function test_modifyLogin_nsIPr
                 /No matching logins/);
 
   // It is also possible to provide no properties to be modified.
   Services.logins.modifyLogin(updatedLoginInfo, newPropertyBag());
 
   // Specifying a null property for a required value should throw.
   Assert.throws(() => Services.logins.modifyLogin(loginInfo, newPropertyBag({
     usernameField: null,
-  })));
+  })), /No matching logins/);
 
   // The login can be changed to have a different type and hostname.
   Services.logins.modifyLogin(updatedLoginInfo, differentLoginProperties);
   LoginTestUtils.checkLogins([differentLoginInfo]);
 
   // It is now possible to add a login with the old type and hostname.
   Services.logins.addLogin(loginInfo);
   LoginTestUtils.checkLogins([loginInfo, differentLoginInfo]);
--- a/toolkit/components/utils/test/unit/test_Sampling.js
+++ b/toolkit/components/utils/test/unit/test_Sampling.js
@@ -20,17 +20,18 @@ add_task(async function testBucketSample
 
   // Known samples. The numbers are nonces to make the tests pass
   equal(await Sampling.bucketSample("test-0", 0, 5, 10), true, "bucketSample returns true for known matching sample");
   equal(await Sampling.bucketSample("test-1", 0, 5, 10), false, "bucketSample returns false for known non-matching sample");
 });
 
 add_task(async function testRatioSample() {
   // Invalid input
-  Assert.rejects(Sampling.ratioSample("test", []), "ratioSample rejects for a list with no ratios");
+  await Assert.rejects(Sampling.ratioSample("test", []), /ratios must be at least 1 element long/,
+                       "ratioSample rejects for a list with no ratios");
 
   // Absolute samples
   equal(await Sampling.ratioSample("test", [1]), 0, "ratioSample returns 0 for a list with only 1 ratio");
   equal(
     await Sampling.ratioSample("test", [0, 0, 1, 0]),
     2,
     "ratioSample returns the only non-zero bucket if all other buckets are zero"
   );
--- a/toolkit/modules/tests/xpcshell/test_Integration.js
+++ b/toolkit/modules/tests/xpcshell/test_Integration.js
@@ -201,17 +201,17 @@ add_task(async function test_state_prese
  * This is limited by the fact that interfaces with the "[function]" annotation,
  * for example nsIObserver, do not call the QueryInterface implementation.
  */
 add_task(async function test_xpcom_throws() {
   let combined = Integration.testModule.getCombined(TestIntegration);
 
   // This calls QueryInterface because it looks for nsISupportsWeakReference.
   Assert.throws(() => Services.obs.addObserver(combined, "test-topic", true),
-                "NS_NOINTERFACE");
+                /NS_NOINTERFACE/);
 });
 
 /**
  * Checks that getters defined by defineModuleGetter are able to retrieve the
  * latest version of the combined integration object.
  */
 add_task(async function test_defineModuleGetter() {
   let objectForGetters = {};
--- a/toolkit/modules/tests/xpcshell/test_timer.js
+++ b/toolkit/modules/tests/xpcshell/test_timer.js
@@ -97,25 +97,25 @@ add_task(async function test_setInterval
       }
       calls++;
     }, 100, target, 15, "hola");
   });
 });
 
 add_task(async function test_setTimeoutNonFunction() {
   Assert.throws(() => { imported.setTimeout({}, 0); },
-                "callback is not a function in setTimeout");
+                /callback is not a function in setTimeout/);
 });
 
 add_task(async function test_setIntervalNonFunction() {
   Assert.throws(() => { imported.setInterval({}, 0); },
-                "callback is not a function in setInterval");
+                /callback is not a function in setInterval/);
 });
 
 add_task(async function test_setTimeoutWithTargetNonFunction() {
   Assert.throws(() => { imported.setTimeoutWithTarget({}, 0); },
-                "callback is not a function in setTimeout");
+                /callback is not a function in setTimeout/);
 });
 
 add_task(async function test_setIntervalWithTargetNonFunction() {
   Assert.throws(() => { imported.setIntervalWithTarget({}, 0); },
-                "callback is not a function in setInterval");
+                /callback is not a function in setInterval/);
 });