bug 1540684: remote: write tests for Error.jsm's current behaviour; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Thu, 04 Apr 2019 09:57:29 +0000
changeset 467952 6fba6453b064f32ea55c774e3e6357ca4354832d
parent 467951 d10b57a89a73db612a1856bee1975e7cdcbe0e7b
child 467953 304f28818b0f9a9c1dbc11a9c517248e03c6b8d4
push id112667
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:12:45 +0000
treeherdermozilla-inbound@230bb363f2f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1540684
milestone68.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 1540684: remote: write tests for Error.jsm's current behaviour; r=ochameau remote/Error.jsm is completely untested and that is suboptimal. This commit adds tests for remote/Error.jsm's current behaviour. Note that the subsequent commits make some changes to this behaviour, but it's a conscious decision to have tests before making those behavioural changes. Differential Revision: https://phabricator.services.mozilla.com/D25607
remote/test/unit/test_Error.js
remote/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/remote/test/unit/test_Error.js
@@ -0,0 +1,103 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+/* eslint-disable no-tabs */
+
+const {
+  FatalError,
+  RemoteAgentError,
+  UnknownMethodError,
+  UnsupportedError,
+} = ChromeUtils.import("chrome://remote/content/Error.jsm");
+
+add_test(function test_RemoteAgentError_ctor() {
+  const e1 = new RemoteAgentError();
+  equal(e1.name, "RemoteAgentError");
+  equal(e1.message, "");
+  equal(e1.cause, e1.message);
+
+  const e2 = new RemoteAgentError("message");
+  equal(e2.message, "message");
+  equal(e2.cause, e2.message);
+
+  const e3 = new RemoteAgentError("message", "cause");
+  equal(e3.message, "message");
+  equal(e3.cause, "cause");
+
+  run_next_test();
+});
+
+add_test(function test_RemoteAgentError_notify() {
+  // nothing much we can test, except test that it doesn't throw
+  new RemoteAgentError().notify();
+
+  run_next_test();
+});
+
+add_test(function test_RemoteAgentError_toString() {
+  const e = new RemoteAgentError("message");
+  equal(e.toString(), RemoteAgentError.format(e));
+  equal(e.toString({stack: true}), RemoteAgentError.format(e, {stack: true}));
+
+  run_next_test();
+});
+
+add_test(function test_RemoteAgentError_format() {
+  const {format} = RemoteAgentError;
+
+  equal(format({name: "HippoError"}), "HippoError: ");
+  equal(format({name: "HorseError", message: "neigh"}), "HorseError: neigh:");
+
+  const dog = {
+    name: "DogError",
+    message: "woof",
+    stack: "  one\ntwo\nthree  ",
+  };
+  equal(format(dog), "DogError: woof:");
+  equal(format(dog, {stack: true}),
+`DogError: woof:
+	one
+	two
+	three`);
+
+  const cat = {
+    name: "CatError",
+    message: "meow",
+    stack: "four\nfive\nsix",
+    cause: dog,
+  };
+  equal(format(cat), "CatError: meow:");
+  equal(format(cat, {stack: true}),
+`CatError: meow:
+	four
+	five
+	six
+caused by: DogError: woof:
+	one
+	two
+	three`);
+
+  run_next_test();
+});
+
+// FatalError calls nsIAppStartup.quit(), but it's OK because this is an xpcshell test:
+add_test(function test_FatalError() {
+  const e = new FatalError();
+  ok(e instanceof RemoteAgentError);
+  e.notify();
+  equal(e.toString(), RemoteAgentError.format(e));
+  e.quit();
+
+  run_next_test();
+});
+
+add_test(function test_UnsupportedError() {
+  ok(new UnsupportedError() instanceof RemoteAgentError);
+  run_next_test();
+});
+
+add_test(function test_UnknownMethodError() {
+  ok(new UnknownMethodError() instanceof RemoteAgentError);
+  run_next_test();
+});
--- a/remote/test/unit/xpcshell.ini
+++ b/remote/test/unit/xpcshell.ini
@@ -1,9 +1,10 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 [DEFAULT]
 skip-if = appname == "thunderbird"
 
 [test_Domains.js]
+[test_Error.js]
 [test_Session.js]