-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebIDL tests #271
base: master
Are you sure you want to change the base?
WebIDL tests #271
Changes from all commits
ba4eff3
a26923c
7322280
b74950d
696d45b
e189021
de6410f
38fd370
72fc51c
344cb88
8653de8
786a43f
1eac35a
1de9a40
6d7e539
ab78405
5b23c68
9f96e65
649663e
bcf2feb
3554ba2
afc90dd
986a5a2
635afe2
7ba167f
2988507
ff5c57a
e1ec191
19140ef
dc4b916
9b02611
3a766fb
a08c7c7
82d9dd2
2499540
8066f7a
84dde23
96605bf
0fe989c
eda1c49
642f753
b0f3023
6428241
f72443e
6769487
d78c8ac
233eb4c
ce5adff
4b1c515
e024e13
6191896
8a40a50
38bb727
2b54eff
5c44e1f
f48ba58
972a729
3d93ad3
2a34d4e
0f4ca25
18edb03
b49422d
5090995
5957d1b
18d8c7b
9fbe321
27d9dd8
206d746
3ee0722
b6c4f2f
f6b1769
a15b3ec
00f1b72
c970b79
478b74e
ccf8ee0
4664876
93d340d
14dd0ba
874a4d9
c2e1721
356900c
d8d5d64
47255a8
76568eb
3564cdf
0bab1a9
15f4185
b05c366
93eb4fd
cf13916
86d4680
8cbc70a
6b337e7
1c488e5
8b014c4
ef41733
b6a7a5d
f61b625
6f14cb7
acfeea4
072a889
d04911e
a1d7326
f04cfd5
0a18201
6b44bed
5d3d946
a01b082
c9bc35b
e354483
3af6949
072456b
eb91331
8514dcc
c1c6cd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<title>[ArrayClass]</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.5.3 Interface prototype object | ||
// | ||
// [ArrayClass] on an interface means that its [[Prototype]] is Array.prototype. | ||
|
||
// feature: NodeList (interface) (with [ArrayClass]) | ||
|
||
test(function() { | ||
assert_true(NodeList.prototype == Array.prototype, "NodeList.prototype == Array.prototype"); | ||
}, "NodeList being [ArrayClass] implies NodeList.prototype == Array.prototype"); | ||
|
||
test(function() { | ||
var a = document.childNodes.concat(); | ||
assert_true(Object.getPrototypeOf(a) == Array.prototype, "nodeList.concat() returns an Array"); | ||
assert_array_equals(document.childNodes, a); | ||
}, "nodeList.concat() works"); | ||
</script> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<title>[Clamp] on operation arguments</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.2.5 octet | ||
// | ||
// When [Clamp] is on an operation argument whose type is an integer type, then | ||
// values outside the range of the integer will be clamped to be valid. | ||
|
||
// feature: Uint8ClampedArray (indexed property setter) (with [Clamp]) | ||
|
||
test(function() { | ||
var a = new Uint8ClampedArray(1); | ||
a[0] = 128; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You forgot to follow this line with the assert_equals(a[0], 127); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a line has to be added, it should be assert_equals(a[0], 128); then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
a[0] = -1; | ||
assert_equals(a[0], 0); | ||
a[0] = 256; | ||
assert_equals(a[0], 255); | ||
a[0] = -0.1; | ||
assert_equals(a[0], 0); | ||
a[0] = 255.1; | ||
assert_equals(a[0], 255); | ||
a[0] = -Infinity; | ||
assert_equals(a[0], 0); | ||
a[0] = Infinity; | ||
assert_equals(a[0], 255); | ||
a[0] = -0; | ||
assert_true(a[0] == 0 && 1 / a[0] > 0); | ||
a[0] = 2.5; | ||
assert_equals(a[0], 2); | ||
a[0] = 5.5; | ||
assert_equals(a[0], 6); | ||
a[0] = NaN; | ||
assert_equals(a[0], 0); | ||
}, "correct conversion of Number values to a [Clamp]ed octet"); | ||
|
||
// feature: WebSocket.close (operation) (with [Clamp] on an argument) | ||
|
||
test(function() { | ||
var ws = new WebSocket("wss://test.invalid"); | ||
|
||
// valid code, should not throw | ||
ws.close(1000); | ||
|
||
// invalid code, should throw | ||
assert_throws({ name: "InvalidAccessError" }, function() { ws.close(500); }); | ||
|
||
// invalid code, as it should clamp to 65535, rather than wrap to 1000 | ||
assert_throws({ name: "InvalidAccessError" }, function() { ws.close(66536); }); | ||
}, "correct conversion of Number values to a [Clamp]ed unsigned short"); | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than the missing assert, noted above, this file (Clamp-001) looks great. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<!DOCTYPE html> | ||
<title>[Constructor]</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.5.1.1 Interface object [[Call]] method | ||
// | ||
// Interfaces with [Constructor] have a [[Call]] method that invokes the | ||
// constructor behavior. If it didn't have [Constructor], a TypeError is | ||
// thrown. The returned object must implement the interface. There must | ||
// also be a "length" property on the interface object. | ||
|
||
// feature: Element (interface) (without [Constructor]) | ||
|
||
test(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate this test, but instead of "new Element();" simply invoke Element as a method call: "Element();". Both cases should throw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
assert_throws(new TypeError(), function() { new Element(); }, "new Element()"); | ||
}, "Calling new on an interface object whose interface does not have [Constructor]") | ||
|
||
// feature: Event (interface) (with [Constructor]) | ||
|
||
test(function() { | ||
assert_true(new Event("test") instanceof Event, "new Event(...) instanceof Event"); | ||
}, "Event constructor returns an object that is instanceof Event"); | ||
|
||
test(function() { | ||
assert_true(Event("test") instanceof Event, "Event(...) instanceof Event"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this test is OK, given we don't yet have consensus on what to do about Bug 22808 (https://www.w3.org/Bugs/Public/show_bug.cgi?id=22808). Currently IE/Firefox would pass this test, Chrome would not (but IE won't pass it because it does not support Event constructors in general yet). |
||
}, "Event constructor called as a function returns an object that is instanceof Event"); | ||
|
||
// feature: XMLHttpRequest (interface) (with [Constructor]) | ||
|
||
test(function() { | ||
assert_true(new XMLHttpRequest() instanceof XMLHttpRequest, "new XMLHttpRequest() instanceof XMLHttpRequest"); | ||
}, "XMLHttpRequest constructor returns an object that is instanceof XMLHttpRequest"); | ||
|
||
test(function() { | ||
assert_true(XMLHttpRequest() instanceof XMLHttpRequest, "XMLHttpRequest() instanceof XMLHttpRequest"); | ||
}, "XMLHttpRequest constructor called as a function returns an object that is instanceof XMLHttpRequest"); | ||
|
||
var lengthProperties = [ | ||
"Event", 1, | ||
"XMLHttpRequest", 0 | ||
]; | ||
|
||
for (var i = 0; i < lengthProperties.length; i += 2) { | ||
var intf = lengthProperties[i]; | ||
var val = lengthProperties[i + 1]; | ||
|
||
test(function() { | ||
assert_property(window[intf], "length", { writable: false, enumerable: false, configurable: false, value: val }, intf + ".length"); | ||
}, intf + " has correct length property"); | ||
} | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One test addition requested; otherwise the rest looks good. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<title>Invoking constructors without overloading or optional arguments</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.5.1.1 Interface object [[Call]] method | ||
// | ||
// In this test we're invoking simple constructors -- ones that do not use | ||
// overloading or optional arguments. When too few arguments are passed, | ||
// a TypeError is thrown. When too many arguments are passed, the extra | ||
// ones are ignored. Argument types are not used to eliminate the single | ||
// entry in the effective overload set. | ||
|
||
// feature: ArrayBuffer (interface) (with [Constructor], and no overloading or optional arguments) | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new ArrayBuffer(); }); | ||
}, "passing too few arguments to ArrayBuffer constructor throws"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(undefined); | ||
assert_equals(buffer.byteLength, 0); | ||
}, "passing undefined to ArrayBuffer constructor succeeds"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(10, 20); | ||
assert_equals(buffer.byteLength, 10); | ||
}, "additional arguments passed to ArrayBuffer constructor are ignored"); | ||
|
||
// feature: Range (interface) (with [Constructor], and no overloading or optional arguments) | ||
|
||
test(function() { | ||
var range = new Range("test"); | ||
assert_true(!!range); | ||
}, "additional arguments passed to Range constructor are ignored"); | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests in Constructor-002 are all good. (The ArrayBuffer(undefined) threw me at first, as I read through overload resolution, which seemed to say throw TypeError, since there wasn't an optional overload, but then ArrayBuffer has no overloads, so this is really just "undefined" -> "unsigned long" conversion, which is +0. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<title>Invoking constructors without overloading but with optional arguments</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.5.1.1 Interface object [[Call]] method | ||
// | ||
// In this test we're invoking constructors with no overloading but which | ||
// do have optional arguments. When too few arguments are passed, a TypeError | ||
// is thrown. When too many arguments are passed, the extra ones are ignored. | ||
// Argument types are not used to eliminate the single entry in the effective | ||
// overload set that remains after discarding others due to incorrect argument | ||
// list length. Optional argument default values are also filled in for | ||
// trailing missing arguments. | ||
|
||
// feature: Event (interface) (with [Constructor] and optional arguments) | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new Event(); }); | ||
}, "passing too few arguments to Event constructor throws"); | ||
|
||
test(function() { | ||
var e1 = new Event("click"); | ||
var e2 = new Event("click", { }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It helped me when going through 4.2.19's conversion algorithm, to note a third test case here: |
||
assert_equals(e1.bubbles, e2.bubbles); | ||
assert_equals(e1.cancelable, e2.cancelable); | ||
}, "passing one argument to Event constructor will use the default argument value"); | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new Event("click", false); }); | ||
}, "passing a bad type as the Event constructor optional argument value throws an exception"); | ||
|
||
test(function() { | ||
var e = new Event("click", { }, "ignored"); | ||
assert_true(!!e); | ||
}, "extra arguments passed to Event constructor are ignored"); | ||
|
||
// feature: WebSocket (interface) (with [Constructor] and optional arguments) | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new WebSocket(); }); | ||
}, "passing too few arguments to WebSocket constructor throws"); | ||
|
||
test(function() { | ||
var ws = new WebSocket("wss://test.invalid"); | ||
assert_true(!!ws); | ||
}, "omitting an optional argument in the WebSocket constructor works"); | ||
|
||
test(function() { | ||
var ws = new WebSocket("wss://test.invalid", "protocol", "ignored"); | ||
assert_true(!!ws); | ||
}, "additional arguments passed to the WebSocket constructor are ignored"); | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test looks good (Constructor-003). It would be nice to add the extra test case mentioned above as well. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<!DOCTYPE html> | ||
<title>Invoking constructors with overloading</title> | ||
<script src="http://w3c-test.org/resources/testharness.js"></script> | ||
<script src="http://w3c-test.org/resources/testharnessreport.js"></script> | ||
<script src="utils.js"></script> | ||
<div id="log"></div> | ||
|
||
<script> | ||
// 4.5.1.1 Interface object [[Call]] method | ||
// | ||
// In this test we're invoking constructors with overloading. When too few | ||
// arguments are passed, a TypeError is thrown. When too many arguments are | ||
// passed, the extra ones are ignored. Candidate overloads are first chosen | ||
// based on how many arguments were passed. Then, a specific argument is used | ||
// as the one that distinguishes between the different candidate overloads. | ||
// Values before this distinguishing argument are converted to IDL values before | ||
// the distinguishing argument is inspected. Looking at the distinguishing | ||
// argument might then cause the call to fail (and a TypeError to be thrown) if | ||
// there is not an appropriate value passed in that position. | ||
// | ||
// With both Uint8Array and Blob, the two interfaces we are using in this test, | ||
// it's not possible to test the "arguments before the distinguishing argument | ||
// are converted before possibly throwing due to an invalid value in that | ||
// argument position" since the distinguishing argument index is < 1. | ||
|
||
// feature Uint8Array (interface) (with [Constructor] and overloading) | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new Uint8Array(); }); | ||
}, "passing too few arguments to Uint8Array constructor throws"); | ||
|
||
test(function() { | ||
var a = new Uint8Array(3); | ||
assert_equals(a.length, 3); | ||
}, "passing a Number as the only argument to the Uint8Array constructor selects the (unsigned long) overload"); | ||
|
||
test(function() { | ||
var a1 = new Uint8Array(4); | ||
var a2 = new Uint8Array(a1); | ||
assert_equals(a2.length, 4); | ||
}, "passing a Uint8Array as the only argument to the Uint8Array constructor selects the (Uint8Array) overload"); | ||
|
||
test(function() { | ||
var a = new Uint8Array([9, 9, 9]); | ||
assert_equals(a.length, 3); | ||
assert_equals(a[0], 9); | ||
}, "passing an Array as the only argument to the Uint8Array constructor selects the (octet[]) overload"); | ||
|
||
test(function() { | ||
var a = new Uint8Array({ length: 3, "0": 9 }); | ||
assert_equals(a.length, 3); | ||
assert_equals(a[0], 9); | ||
}, "passing { length: 3, \"0\": 9 } as the only argument to the Uint8Array constructor selects the (octet[]) overload"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(5); | ||
var a = new Uint8Array(buffer); | ||
assert_equals(a.length, 5); | ||
}, "passing an ArrayBuffer as the only argument to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload"); | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new Uint8Array(3, "extra"); }); | ||
}, "passing (Number, String) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload, and then throws due to the conversion of the Number to an ArrayBuffer"); | ||
|
||
test(function() { | ||
var a1 = new Uint8Array(4); | ||
assert_throws(new TypeError(), function() { new Uint8Array(a1, "extra"); }); | ||
}, "passing (Uint8Array, String) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload, and then throws due to the conversion of the Uint8Array to an ArrayBuffer"); | ||
|
||
test(function() { | ||
assert_throws(new TypeError(), function() { new Uint8Array([9, 9, 9], "extra"); }); | ||
}, "passing (Array, String) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload, and then throws due to the conversion of the Array to an ArrayBuffer"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(5); | ||
var a1 = new Uint8Array(buffer); | ||
a1[0] = 123; | ||
var a2 = new Uint8Array(buffer, "hello"); // the "hello" converts to 0 | ||
assert_equals(a2[0], 123); | ||
}, "passing (ArrayBuffer, String) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(5); | ||
var a = new Uint8Array(buffer, 0, { valueOf: function() { return 2; } }); | ||
assert_equals(a.length, 2); | ||
}, "passing (ArrayBuffer, Number, { valueOf }) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(5); | ||
var a = new Uint8Array(buffer, 0, 2, "extra"); | ||
assert_equals(a.length, 2); | ||
}, "passing (ArrayBuffer, Number, Number, String) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload"); | ||
|
||
test(function() { | ||
var buffer = new ArrayBuffer(5); | ||
var a = new Uint8Array(buffer, undefined, undefined); | ||
assert_equals(a.length, 5); | ||
}, "passing (ArrayBuffer, undefined, undefined) to the Uint8Array constructor selects the (ArrayBuffer, optional unsigned long, optional unsigned long) overload with three arguments and treats the undefineds as missing arguments"); | ||
|
||
|
||
// feature Blob (interface) (with [Constructor] and overloading) | ||
|
||
test(function() { | ||
var b = new Blob(); | ||
assert_equals(b.size, 0); | ||
}, "passing no arguments to the Blob constructor selects the () overload"); | ||
|
||
test(function() { | ||
var b1 = new Blob([]); | ||
var b2 = new Blob([], { }); | ||
assert_equals(b1.size, 0); | ||
assert_equals(b1.type, b2.type); | ||
}, "passing an Array object as the only argument to the Blob constructor selects the (sequence<...>, optional BlobPropertyBag) overload"); | ||
|
||
test(function() { | ||
var b = new Blob({ length: 3, "0": "a" }); | ||
assert_equals(b.size, "aundefinedundefined".length); | ||
}, "passing { length: 3, \"0\": \"a\" } as the only argument to the Blob constructor selects the (sequence<...>, optional BlobPropertyBag) overload"); | ||
|
||
test(function() { | ||
var b = new Blob(["abc"], { }, "extra"); | ||
assert_equals(b.size, 3); | ||
}, "passing ([\"abc\"], { }, \"extra\") to the Blob constructor selects the (sequence<...>, optional BlobPropertyBag) overload"); | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests are good (Constructor-004) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is good. Not sure if any browsers implement this correctly yet though :)