gecko-dev/dom/mobilemessage/tests/test_smsfilter.html

91 строка
3.1 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test SmsFilter</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<iframe></iframe>
</div>
<pre id="test">
<script type="application/javascript">
/** Test SmsFilter **/
function throwingCheck(aFilter, aProperty, disallowedValue)
{
disallowedValue.forEach(function(v) {
var exception = false;
try {
aFilter[aProperty] = v;
} catch (e) {
exception = true;
}
ok(exception, "An exception should have been thrown");
});
}
var filter = new MozSmsFilter();
isnot(filter, null, "filter should be set");
is(filter.startDate, null, "Parameters shouldn't be initialized");
is(filter.endDate, null, "Parameters shouldn't be initialized");
is(filter.numbers, null, "Parameters shouldn't be initialized");
is(filter.delivery, null, "Parameters shouldn't be initialized");
is(filter.read, null, "Parameters shouldn't be initialized");
is(filter.threadId, null, "Parameters shouldn't be initialized");
var date = new Date();
filter.startDate = date;
is(filter.startDate, "" + date, "Setters and getters should work!");
filter.startDate = null;
is(filter.startDate, null, "null should revert the value to default");
throwingCheck(filter, 'startDate', [ "foo", 42, [1, 2], function () {}, undefined ]);
filter.endDate = date;
is(filter.endDate, "" + date, "Setters and getters should work!");
filter.endDate = null;
is(filter.endDate, null, "null should revert the value to default");
throwingCheck(filter, 'endDate', [ "foo", 42, [1, 2], function () {}, undefined ]);
var numbers = [ "foo", "bar" ];
filter.numbers = numbers;
is(filter.numbers, "" + numbers, "Setters and getters should work!");
filter.numbers = null;
is(filter.numbers, null, "null should revert the value to default");
throwingCheck(filter, 'numbers', [ "foo", 42, function () {}, new Date(), undefined ]);
filter.delivery = "sent";
is(filter.delivery, "sent", "Setters and getters should work!");
filter.delivery = "received";
is(filter.delivery, "received", "Setters and getters should work!");
filter.delivery = "";
is(filter.delivery, null, "The empty string should revert the value to default.");
filter.delivery = null;
is(filter.delivery, null, "'null' should revert the value to default.");
throwingCheck(filter, 'delivery', [ "foo", 42, [1, 2], function () {}, new Date(), undefined ]);
filter.read = true;
is(filter.read, true, "Setters and getters should work!");
filter.read = false;
is(filter.read, false, "Setters and getters should work!");
filter.read = null;
is(filter.read, null, "'null' should revert the value to default");
throwingCheck(filter, 'read', [ "foo", 0, [1, 2], function () {}, new Date(), undefined ]);
filter.threadId = 1;
is(filter.threadId, 1, "Setters and getters should work!");
filter.threadId = null;
is(filter.threadId, null, "'null' should revert the value to default");
throwingCheck(filter, 'threadId', [ "foo", 0, 1.5, [1, 2], function () {}, new Date(), undefined ]);
</script>
</pre>
</body>
</html>