fune/testing/web-platform/tests/css/css-animations/animationevent-interface.js
Stephen McGruer c67612824c Bug 1610938 [wpt PR 21354] - Replace some "assert_throws(new FooError(), stuff)" calls with assert_throws_js, a=testonly
Automatic update from web-platform-tests
Replace some "assert_throws(new FooError(), stuff)" calls with assert_throws_js. (#21354)

This diff was generated by running:

  find . -type f -print0 | xargs -0 perl -pi -e 'BEGIN { $/ = undef; } s/assert_throws\(([ \n]*)new ([A-Za-z]*Error) *\(\) *(, *.)/assert_throws_js(\1\2\3/gs'

and then:

1) Manually adjusting fullscreen/rendering/fullscreen-pseudo-class-support.html
to test for the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

2) Manually adjusting performance-timeline/po-observe-type.any.js to test for
the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

3) Manually adjusting performance-timeline/po-observe.any.js to test for
the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

4) Manually adjusting user-timing/mark_exceptions.html to test for the right
sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError).

5) Manually adjusting user-timing/measure_syntax_err.any.js to test for the right
sort of exceptions ("SyntaxError" DOMException, not a JS SyntaxError).

6) Manually adjusting domxpath/lexical-structure.html to test for a
"SyntaxError" DOMException, since that's what all browsers throw and there is no
clear spec for this.

7) Manually adjusting workers/constructors/Worker/Worker-constructor.html to
test for the right sort of exceptions ("SyntaxError" DOMException, not a JS
SyntaxError).

8) Backing out the changes to resources/idlharness.js because some tests pass
objects from a different window to it, and we end up with the wrong TypeError
constructor in those cases.

This does affect indentation poorly in cases when the first arg was on the same
line as the assert_throws, there was a newline after the ',' after the first
arg, and the following args were lined up with the first arg.  Fixing that,
especially when there are multiple lines after the first arg, is not trivial
with a regexp.

Co-authored-by: Boris Zbarsky <bzbarsky@mit.edu>
Co-authored-by: Stephen McGruer <smcgruer@chromium.org>

--

wpt-commits: 2c5c3c4c27d27a419c1fdba3e9879c2d22037074
wpt-pr: 21354
2020-01-27 15:35:57 +00:00

220 lines
7.6 KiB
JavaScript

(function() {
test(function() {
var event = new AnimationEvent("");
assert_true(event instanceof window.AnimationEvent);
}, "the event is an instance of AnimationEvent");
test(function() {
var event = new AnimationEvent("");
assert_true(event instanceof window.Event);
}, "the event inherts from Event");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent();
}, 'First argument is required, so was expecting a TypeError.');
}, 'Missing type argument');
test(function() {
var event = new AnimationEvent("test");
assert_equals(event.type, "test");
}, "type argument is string");
test(function() {
var event = new AnimationEvent(null);
assert_equals(event.type, "null");
}, "type argument is null");
test(function() {
var event = new AnimationEvent(undefined);
assert_equals(event.type, "undefined");
}, "event type set to undefined");
test(function() {
var event = new AnimationEvent("test");
assert_equals(event.animationName, "");
}, "animationName has default value of empty string");
test(function() {
var event = new AnimationEvent("test");
assert_equals(event.elapsedTime, 0.0);
}, "elapsedTime has default value of 0.0");
test(function() {
var event = new AnimationEvent("test");
assert_readonly(event, "animationName", "readonly attribute value");
}, "animationName is readonly");
test(function() {
var event = new AnimationEvent("test");
assert_readonly(event, "elapsedTime", "readonly attribute value");
}, "elapsedTime is readonly");
test(function() {
var event = new AnimationEvent("test", null);
assert_equals(event.animationName, "");
assert_equals(event.elapsedTime, 0.0);
}, "animationEventInit argument is null");
test(function() {
var event = new AnimationEvent("test", undefined);
assert_equals(event.animationName, "");
assert_equals(event.elapsedTime, 0.0);
}, "animationEventInit argument is undefined");
test(function() {
var event = new AnimationEvent("test", {});
assert_equals(event.animationName, "");
assert_equals(event.elapsedTime, 0.0);
}, "animationEventInit argument is empty dictionary");
test(function() {
var event = new AnimationEvent("test", {pseudoElement: "::testPseudo"});
assert_equals(event.pseudoElement, "::testPseudo");
}, "AnimationEvent.pseudoElement initialized from the dictionary");
test(function() {
var event = new AnimationEvent("test", {animationName: "sample"});
assert_equals(event.animationName, "sample");
}, "animationName set to 'sample'");
test(function() {
var event = new AnimationEvent("test", {animationName: undefined});
assert_equals(event.animationName, "");
}, "animationName set to undefined");
test(function() {
var event = new AnimationEvent("test", {animationName: null});
assert_equals(event.animationName, "null");
}, "animationName set to null");
test(function() {
var event = new AnimationEvent("test", {animationName: false});
assert_equals(event.animationName, "false");
}, "animationName set to false");
test(function() {
var event = new AnimationEvent("test", {animationName: true});
assert_equals(event.animationName, "true");
}, "animationName set to true");
test(function() {
var event = new AnimationEvent("test", {animationName: 0.5});
assert_equals(event.animationName, "0.5");
}, "animationName set to a number");
test(function() {
var event = new AnimationEvent("test", {animationName: []});
assert_equals(event.animationName, "");
}, "animationName set to []");
test(function() {
var event = new AnimationEvent("test", {animationName: [1, 2, 3]});
assert_equals(event.animationName, "1,2,3");
}, "animationName set to [1, 2, 3]");
test(function() {
var event = new AnimationEvent("test", {animationName: {sample: 0.5}});
assert_equals(event.animationName, "[object Object]");
}, "animationName set to an object");
test(function() {
var event = new AnimationEvent("test",
{animationName: {valueOf: function () { return 'sample'; }}});
assert_equals(event.animationName, "[object Object]");
}, "animationName set to an object with a valueOf function");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: 0.5});
assert_equals(event.elapsedTime, 0.5);
}, "elapsedTime set to 0.5");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: -0.5});
assert_equals(event.elapsedTime, -0.5);
}, "elapsedTime set to -0.5");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: undefined});
assert_equals(event.elapsedTime, 0);
}, "elapsedTime set to undefined");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: null});
assert_equals(event.elapsedTime, 0);
}, "elapsedTime set to null");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: false});
assert_equals(event.elapsedTime, 0);
}, "elapsedTime set to false");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: true});
assert_equals(event.elapsedTime, 1);
}, "elapsedTime set to true");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: ""});
assert_equals(event.elapsedTime, 0);
}, "elapsedTime set to ''");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: []});
assert_equals(event.elapsedTime, 0);
}, "elapsedTime set to []");
test(function() {
var event = new AnimationEvent("test", {elapsedTime: [0.5]});
assert_equals(event.elapsedTime, 0.5);
}, "elapsedTime set to [0.5]");
test(function() {
var event = new AnimationEvent(
"test", {elapsedTime: { valueOf: function() { return 0.5; }}});
assert_equals(event.elapsedTime, 0.5);
}, "elapsedTime set to an object with a valueOf function");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: NaN});
}, 'elapsedTime cannot be NaN so was expecting a TypeError');
}, "elapsedTime cannot be set to NaN");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: Infinity});
}, 'elapsedTime cannot be Infinity so was expecting a TypeError');
}, "elapsedTime cannot be set to Infinity");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: -Infinity});
}, 'elapsedTime cannot be -Infinity so was expecting a TypeError');
}, "elapsedTime cannot be set to -Infinity");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: "sample"});
}, 'elapsedTime cannot be a string so was expecting a TypeError');
}, "elapsedTime cannot be set to 'sample'");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: [0.5, 1.0]});
}, 'elapsedTime cannot be a multi-element array so was expecting a TypeError');
}, "elapsedTime cannot be set to [0.5, 1.0]");
test(function() {
assert_throws_js(TypeError, function() {
new AnimationEvent("test", {elapsedTime: { sample: 0.5}});
}, 'elapsedTime cannot be an object so was expecting a TypeError');
}, "elapsedTime cannot be set to an object");
test(function() {
var eventInit = {animationName: "sample", elapsedTime: 0.5};
var event = new AnimationEvent("test", eventInit);
assert_equals(event.animationName, "sample");
assert_equals(event.elapsedTime, 0.5);
}, "AnimationEventInit properties set value");
})();