Skip to content

Commit

Permalink
Fix more DOMRect constructor tests and add new tests
Browse files Browse the repository at this point in the history
Follow-up to w3c#834. I overlooked some tests that needed fixing, and extended the coverage a bit.
  • Loading branch information
tschneidereit committed Aug 28, 2015
1 parent 1284adb commit 6be1506
Showing 1 changed file with 97 additions and 5 deletions.
102 changes: 97 additions & 5 deletions geometry-1/DOMRect-001.html
Expand Up @@ -60,7 +60,7 @@
},'testConstructorNegativeWidthHeight');
test(function() {
checkDOMRect(new DOMRect(0, 0, undefined, 4),
{ x: 0, y: 0, width: NaN, height: 4, top: 0, right: 0, bottom: 4, left: 0 });
{ x: 0, y: 0, width: 0, height: 4, top: 0, right: 0, bottom: 4, left: 0 });
},'testConstructorUndefined1');
test(function() {
checkDOMRect(new DOMRect(NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, null),
Expand All @@ -75,11 +75,57 @@
{ x: NaN, y: NaN, width: NaN, height: NaN, top: NaN, right: NaN, bottom: NaN, left: NaN });
},'testConstructorString2');
test(function() {
assert_throws(new TypeError(), function() { new DOMRectReadOnly(); });
},'testConstructorIllegal1');
checkDOMRect(new DOMRectReadOnly(),
{ x: 0, y: 0, width: 0, height: 0, top: 0, right: 0, bottom: 0, left: 0 });
},'testReadOnlyConstructor0');
test(function() {
checkDOMRect(new DOMRectReadOnly(1),
{ x: 1, y: 0, width: 0, height: 0, top: 0, right: 1, bottom: 0, left: 1 });
},'testReadOnlyConstructor1');
test(function() {
checkDOMRect(new DOMRectReadOnly(1, 2),
{ x: 1, y: 2, width: 0, height: 0, top: 2, right: 1, bottom: 2, left: 1 });
},'testReadOnlyConstructor2');
test(function() {
checkDOMRect(new DOMRectReadOnly(1, 2, 3),
{ x: 1, y: 2, width: 3, height: 0, top: 2, right: 4, bottom: 2, left: 1 });
},'testReadOnlyConstructor3');
test(function() {
checkDOMRect(new DOMRectReadOnly(1, 2, 3, 4),
{ x: 1, y: 2, width: 3, height: 4, top: 2, right: 4, bottom: 6, left: 1 });
},'testReadOnlyConstructor4');
test(function() {
checkDOMRect(new DOMRectReadOnly(1, 2, 3, 4, 5),
{ x: 1, y: 2, width: 3, height: 4, top: 2, right: 4, bottom: 6, left: 1 });
},'testReadOnlyConstructor5');
test(function() {
assert_throws(new TypeError(), function() { new DOMRectReadOnly(1, 2, 3, 4); });
},'testConstructorIllegal2');
checkDOMRect(new DOMRectReadOnly(2, 2, -4, 4),
{ x: 2, y: 2, width: -4, height: 4, top: 2, right: 2, bottom: 6, left: -2 });
},'testReadOnlyConstructorNegativeWidth');
test(function() {
checkDOMRect(new DOMRectReadOnly(2, 2, 4, -4),
{ x: 2, y: 2, width: 4, height: -4, top: -2, right: 6, bottom: 2, left: 2 });
},'testReadOnlyConstructorNegativeHeight');
test(function() {
checkDOMRect(new DOMRectReadOnly(2, 2, -4, -4),
{ x: 2, y: 2, width: -4, height: -4, top: -2, right: 2, bottom: 2, left: -2 });
},'testReadOnlyConstructorNegativeWidthHeight');
test(function() {
checkDOMRect(new DOMRectReadOnly(0, 0, undefined, 4),
{ x: 0, y: 0, width: 0, height: 4, top: 0, right: 0, bottom: 4, left: 0 });
},'testReadOnlyConstructorUndefined1');
test(function() {
checkDOMRect(new DOMRectReadOnly(NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY, null),
{ x: NaN, y: -Infinity, width: Infinity, height: 0, top: -Infinity, right: NaN, bottom: -Infinity, left: NaN });
},'testReadOnlyConstructorUndefined2');
test(function() {
checkDOMRect(new DOMRectReadOnly("1", "2", "3", "4"),
{ x: 1, y: 2, width: 3, height: 4, top: 2, right: 4, bottom: 6, left: 1 });
},'testReadOnlyConstructorString1');
test(function() {
checkDOMRect(new DOMRectReadOnly("a", "b", "c", "d"),
{ x: NaN, y: NaN, width: NaN, height: NaN, top: NaN, right: NaN, bottom: NaN, left: NaN });
},'testReadOnlyConstructorString2');
test(function() {
var r = new DOMRect();
r.top = 5;
Expand All @@ -95,13 +141,59 @@
var r = new DOMRect();
r.x = 5;
assert_equals(r.x, 5, "Expected value for x is 5");
assert_equals(r.left, 5, "Expected value for left is 5");
assert_equals(r.right, 5, "Expected value for right is 5");
r.y = 5;
assert_equals(r.y, 5, "Expected value for y is 5");
assert_equals(r.top, 5, "Expected value for top is 5");
assert_equals(r.bottom, 5, "Expected value for bottom is 5");
r.width = 5;
assert_equals(r.width, 5, "Expected value for width is 5");
assert_equals(r.left, 5, "Expected value for left is 5");
assert_equals(r.right, 10, "Expected value for right is 10");
r.height = 5;
assert_equals(r.height, 5, "Expected value for height is 5");
assert_equals(r.top, 5, "Expected value for top is 5");
assert_equals(r.bottom, 10, "Expected value for bottom is 10");
},'testSetAttributes');
test(function() {
var r = new DOMRectReadOnly();
r.top = 5;
assert_equals(r.top, 0, "Expected value for top is 0");
assert_equals(r.y, 0, "Expected value for y is 0");
assert_equals(r.bottom, 0, "Expected value for bottom is 0");
r.right = 5;
assert_equals(r.right, 0, "Expected value for right is 0");
assert_equals(r.x, 0, "Expected value for x is 0");
assert_equals(r.left, 0, "Expected value for left is 0");
r.bottom = 5;
assert_equals(r.bottom, 0, "Expected value for bottom is 0");
assert_equals(r.y, 0, "Expected value for y is 0");
assert_equals(r.top, 0, "Expected value for top is 0");
r.left = 5;
assert_equals(r.left, 0, "Expected value for left is 0");
assert_equals(r.x, 0, "Expected value for x is 0");
assert_equals(r.right, 0, "Expected value for right is 0");
},'testReadOnlySetReadOnlyAttributes');
test(function() {
var r = new DOMRectReadOnly();
r.x = 0;
assert_equals(r.x, 0, "Expected value for x is 0");
assert_equals(r.left, 0, "Expected value for left is 0");
assert_equals(r.right, 0, "Expected value for right is 0");
r.y = 0;
assert_equals(r.y, 0, "Expected value for y is 0");
assert_equals(r.top, 0, "Expected value for top is 0");
assert_equals(r.bottom, 0, "Expected value for bottom is 0");
r.width = 0;
assert_equals(r.width, 0, "Expected value for width is 0");
assert_equals(r.x, 0, "Expected value for x is 0");
assert_equals(r.right, 0, "Expected value for right is 0");
r.height = 0;
assert_equals(r.height, 0, "Expected value for height is 0");
assert_equals(r.y, 0, "Expected value for y is 0");
assert_equals(r.bottom, 0, "Expected value for bottom is 0");
},'testReadOnlySetAttributes');

function checkDOMRect(r, exp) {
assert_equals(r.x, exp.x, "Expected value for x is " + exp.x);
Expand Down

0 comments on commit 6be1506

Please sign in to comment.