2016-11-01 01:00:21 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
2018-04-11 22:26:53 +03:00
|
|
|
/* eslint-disable no-array-constructor, no-new-object */
|
2016-11-01 01:00:21 +03:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("chrome://marionette/content/assert.js");
|
2018-04-11 22:26:53 +03:00
|
|
|
const {
|
|
|
|
InvalidArgumentError,
|
|
|
|
InvalidSessionIDError,
|
|
|
|
JavaScriptError,
|
|
|
|
NoSuchWindowError,
|
|
|
|
SessionNotCreatedError,
|
|
|
|
UnexpectedAlertOpenError,
|
|
|
|
UnsupportedOperationError,
|
|
|
|
} = ChromeUtils.import("chrome://marionette/content/error.js", {});
|
2016-11-01 01:00:21 +03:00
|
|
|
|
2017-11-24 21:21:03 +03:00
|
|
|
add_test(function test_acyclic() {
|
|
|
|
assert.acyclic({});
|
|
|
|
assert.acyclic(new Object());
|
|
|
|
assert.acyclic([]);
|
|
|
|
assert.acyclic(new Array());
|
|
|
|
|
|
|
|
// object
|
|
|
|
Assert.throws(() => {
|
|
|
|
let obj = {};
|
|
|
|
obj.reference = obj;
|
|
|
|
assert.acyclic(obj);
|
|
|
|
}, JavaScriptError);
|
|
|
|
|
|
|
|
// array
|
|
|
|
Assert.throws(() => {
|
|
|
|
let arr = [];
|
|
|
|
arr.push(arr);
|
|
|
|
assert.acyclic(arr);
|
|
|
|
}, JavaScriptError);
|
|
|
|
|
|
|
|
// array in object
|
|
|
|
Assert.throws(() => {
|
|
|
|
let arr = [];
|
|
|
|
arr.push(arr);
|
|
|
|
assert.acyclic({arr});
|
|
|
|
}, JavaScriptError);
|
|
|
|
|
|
|
|
// object in array
|
|
|
|
Assert.throws(() => {
|
|
|
|
let obj = {};
|
|
|
|
obj.reference = obj;
|
|
|
|
assert.acyclic([obj]);
|
|
|
|
}, JavaScriptError);
|
|
|
|
|
|
|
|
// custom message
|
|
|
|
let cyclic = {};
|
|
|
|
cyclic.reference = cyclic;
|
|
|
|
Assert.throws(() => assert.acyclic(cyclic, "", RangeError), RangeError);
|
|
|
|
Assert.throws(() => assert.acyclic(cyclic, "foo"), /JavaScriptError: foo/);
|
|
|
|
Assert.throws(() => assert.acyclic(cyclic, "bar", RangeError), /RangeError: bar/);
|
|
|
|
|
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2017-02-02 19:09:14 +03:00
|
|
|
add_test(function test_session() {
|
2017-08-04 22:32:19 +03:00
|
|
|
assert.session({sessionID: "foo"});
|
2017-02-02 19:09:14 +03:00
|
|
|
for (let typ of [null, undefined, ""]) {
|
2017-02-10 21:36:52 +03:00
|
|
|
Assert.throws(() => assert.session({sessionId: typ}), InvalidSessionIDError);
|
2017-02-02 19:09:14 +03:00
|
|
|
}
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.session({sessionId: null}, "custom"), /custom/);
|
|
|
|
|
2017-02-02 19:09:14 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
add_test(function test_platforms() {
|
|
|
|
// at least one will fail
|
|
|
|
let raised;
|
2017-05-03 17:40:37 +03:00
|
|
|
for (let fn of [assert.firefox, assert.fennec]) {
|
2016-11-01 01:00:21 +03:00
|
|
|
try {
|
|
|
|
fn();
|
|
|
|
} catch (e) {
|
|
|
|
raised = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(raised instanceof UnsupportedOperationError);
|
|
|
|
|
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
add_test(function test_noUserPrompt() {
|
|
|
|
assert.noUserPrompt(null);
|
|
|
|
assert.noUserPrompt(undefined);
|
|
|
|
Assert.throws(() => assert.noUserPrompt({}), UnexpectedAlertOpenError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.noUserPrompt({}, "custom"), /custom/);
|
|
|
|
|
2017-04-20 20:00:46 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
add_test(function test_defined() {
|
|
|
|
assert.defined({});
|
|
|
|
Assert.throws(() => assert.defined(undefined), InvalidArgumentError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.noUserPrompt({}, "custom"), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2017-02-20 18:38:05 +03:00
|
|
|
add_test(function test_number() {
|
|
|
|
assert.number(1);
|
|
|
|
assert.number(0);
|
|
|
|
assert.number(-1);
|
|
|
|
assert.number(1.2);
|
|
|
|
for (let i of ["foo", "1", {}, [], NaN, Infinity, undefined]) {
|
|
|
|
Assert.throws(() => assert.number(i), InvalidArgumentError);
|
|
|
|
}
|
2017-06-12 20:18:48 +03:00
|
|
|
|
|
|
|
Assert.throws(() => assert.number("foo", "custom"), /custom/);
|
|
|
|
|
2017-02-20 18:38:05 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2017-02-10 22:28:51 +03:00
|
|
|
add_test(function test_callable() {
|
2018-04-11 22:26:53 +03:00
|
|
|
assert.callable(function() {});
|
2017-02-10 22:28:51 +03:00
|
|
|
assert.callable(() => {});
|
|
|
|
|
|
|
|
for (let typ of [undefined, "", true, {}, []]) {
|
|
|
|
Assert.throws(() => assert.callable(typ), InvalidArgumentError);
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.callable("foo", "custom"), /custom/);
|
|
|
|
|
2017-02-10 22:28:51 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
add_test(function test_integer() {
|
|
|
|
assert.integer(1);
|
|
|
|
assert.integer(0);
|
|
|
|
assert.integer(-1);
|
|
|
|
Assert.throws(() => assert.integer("foo"), InvalidArgumentError);
|
2017-02-20 18:38:05 +03:00
|
|
|
Assert.throws(() => assert.integer(1.2), InvalidArgumentError);
|
2016-11-01 01:00:21 +03:00
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.integer("foo", "custom"), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_test(function test_positiveInteger() {
|
|
|
|
assert.positiveInteger(1);
|
|
|
|
assert.positiveInteger(0);
|
|
|
|
Assert.throws(() => assert.positiveInteger(-1), InvalidArgumentError);
|
|
|
|
Assert.throws(() => assert.positiveInteger("foo"), InvalidArgumentError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.positiveInteger("foo", "custom"), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_test(function test_boolean() {
|
|
|
|
assert.boolean(true);
|
|
|
|
assert.boolean(false);
|
|
|
|
Assert.throws(() => assert.boolean("false"), InvalidArgumentError);
|
|
|
|
Assert.throws(() => assert.boolean(undefined), InvalidArgumentError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.boolean(undefined, "custom"), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_test(function test_string() {
|
|
|
|
assert.string("foo");
|
|
|
|
assert.string(`bar`);
|
|
|
|
Assert.throws(() => assert.string(42), InvalidArgumentError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.string(42, "custom"), /custom/);
|
|
|
|
|
2017-03-28 22:10:06 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2018-01-12 17:25:30 +03:00
|
|
|
add_test(function test_open() {
|
|
|
|
assert.open({closed: false});
|
2017-03-28 22:10:06 +03:00
|
|
|
|
2017-06-13 19:08:22 +03:00
|
|
|
for (let typ of [null, undefined, {closed: true}]) {
|
2018-01-12 17:25:30 +03:00
|
|
|
Assert.throws(() => assert.open(typ), NoSuchWindowError);
|
2017-03-28 22:10:06 +03:00
|
|
|
}
|
|
|
|
|
2018-01-12 17:25:30 +03:00
|
|
|
Assert.throws(() => assert.open(null, "custom"), /custom/);
|
2017-05-31 17:44:49 +03:00
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
|
|
|
add_test(function test_object() {
|
|
|
|
assert.object({});
|
|
|
|
assert.object(new Object());
|
2016-12-30 14:21:27 +03:00
|
|
|
for (let typ of [42, "foo", true, null, undefined]) {
|
|
|
|
Assert.throws(() => assert.object(typ), InvalidArgumentError);
|
|
|
|
}
|
2016-11-01 01:00:21 +03:00
|
|
|
|
2017-06-12 20:02:39 +03:00
|
|
|
Assert.throws(() => assert.object(null, "custom"), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-12-30 14:39:22 +03:00
|
|
|
add_test(function test_in() {
|
|
|
|
assert.in("foo", {foo: 42});
|
|
|
|
for (let typ of [{}, 42, true, null, undefined]) {
|
|
|
|
Assert.throws(() => assert.in("foo", typ), InvalidArgumentError);
|
|
|
|
}
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.in("foo", {bar: 42}, "custom"), /custom/);
|
|
|
|
|
2016-12-30 14:39:22 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-12-30 14:30:05 +03:00
|
|
|
add_test(function test_array() {
|
|
|
|
assert.array([]);
|
|
|
|
assert.array(new Array());
|
|
|
|
Assert.throws(() => assert.array(42), InvalidArgumentError);
|
|
|
|
Assert.throws(() => assert.array({}), InvalidArgumentError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.array(42, "custom"), /custom/);
|
|
|
|
|
2016-12-30 14:30:05 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
add_test(function test_that() {
|
|
|
|
equal(1, assert.that(n => n + 1)(1));
|
|
|
|
Assert.throws(() => assert.that(() => false)());
|
|
|
|
Assert.throws(() => assert.that(val => val)(false));
|
|
|
|
Assert.throws(() => assert.that(val => val, "foo", SessionNotCreatedError)(false),
|
|
|
|
SessionNotCreatedError);
|
|
|
|
|
2017-06-12 20:18:48 +03:00
|
|
|
Assert.throws(() => assert.that(() => false, "custom")(), /custom/);
|
|
|
|
|
2016-11-01 01:00:21 +03:00
|
|
|
run_next_test();
|
|
|
|
});
|
2018-04-11 22:26:53 +03:00
|
|
|
|
|
|
|
/* eslint-enable no-array-constructor, no-new-object */
|