Commit b4ef1f06 authored by gogag2's avatar gogag2 Committed by Commit bot

Rewrite the layout test for DOMRect interface.

For historical reasons, older tests are written using the js-test harness.
This harness is deprecated, and should not be used for new tests. So, rewrite
The layout test as following new tests guide[1].

[1] https://chromium.googlesource.com/chromium/src/+/master/docs/testing/writing_layout_tests.md#The-js_test_js-Legacy-Harness

BUG=678023

Review-Url: https://codereview.chromium.org/2611713002
Cr-Commit-Position: refs/heads/master@{#441405}
parent b81742a8
# DOMRect()
PASS rect.x is 0
PASS rect.y is 0
PASS rect.width is 0
PASS rect.height is 0
PASS rect.top is 0
PASS rect.right is 0
PASS rect.bottom is 0
PASS rect.left is 0
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRect(10)
PASS rect.x is 10
PASS rect.y is 0
PASS rect.width is 0
PASS rect.height is 0
PASS rect.top is 0
PASS rect.right is 10
PASS rect.bottom is 0
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRect(10, 20)
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is 0
PASS rect.height is 0
PASS rect.top is 20
PASS rect.right is 10
PASS rect.bottom is 20
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRect(10, 20, 80)
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is 80
PASS rect.height is 0
PASS rect.top is 20
PASS rect.right is 90
PASS rect.bottom is 20
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRect(10, 20, 80, 50)
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is 80
PASS rect.height is 50
PASS rect.top is 20
PASS rect.right is 90
PASS rect.bottom is 70
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRect setter
PASS rect.x is 30
PASS rect.left is 30
PASS rect.width is 80
PASS rect.right is 110
PASS rect.y is -10
PASS rect.top is -10
PASS rect.height is 50
PASS rect.bottom is 40
PASS rect.x is 30
PASS rect.left is 30
PASS rect.width is 20
PASS rect.right is 50
PASS rect.y is -10
PASS rect.top is -10
PASS rect.height is 40
PASS rect.bottom is 30
# DOMRect(10, 20, -80, -50) negative width and height
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is -80
PASS rect.height is -50
PASS rect.top is -30
PASS rect.right is 10
PASS rect.bottom is 20
PASS rect.left is -70
PASS rect.top is rect.y + rect.height
PASS rect.right is rect.x
PASS rect.bottom is rect.y
PASS rect.left is rect.x + rect.width
# DOMRectReadOnly(10, 20, 80, 50)
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is 80
PASS rect.height is 50
PASS rect.top is 20
PASS rect.right is 90
PASS rect.bottom is 70
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
# DOMRectReadOnly readonly test
PASS rect.x is 10
PASS rect.y is 20
PASS rect.width is 80
PASS rect.height is 50
PASS rect.top is 20
PASS rect.right is 90
PASS rect.bottom is 70
PASS rect.left is 10
PASS rect.top is rect.y
PASS rect.right is rect.x + rect.width
PASS rect.bottom is rect.y + rect.height
PASS rect.left is rect.x
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Geometry Interfaces: DOMRect</title>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<link rel="help" href="https://drafts.fxtf.org/geometry/#domrect">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./resources/geometry-interfaces-test-helpers.js"></script>
<script>
'use strict';
debug("# DOMRect()");
var rect = new DOMRect();
shouldBe("rect.x", "0");
shouldBe("rect.y", "0");
shouldBe("rect.width", "0");
shouldBe("rect.height", "0");
shouldBe("rect.top", "0");
shouldBe("rect.right", "0");
shouldBe("rect.bottom", "0");
shouldBe("rect.left", "0");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRect();
assert_dom_rect_equals(rect, [0, 0, 0, 0, 0, 0, 0, 0]);
}, 'DOMRect constructor without parameter');
debug("# DOMRect(10)");
rect = new DOMRect(10);
shouldBe("rect.x", "10");
shouldBe("rect.y", "0");
shouldBe("rect.width", "0");
shouldBe("rect.height", "0");
shouldBe("rect.top", "0");
shouldBe("rect.right", "10");
shouldBe("rect.bottom", "0");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRect(10);
assert_dom_rect_equals(rect, [10, 0, 0, 0, 0, 10, 0, 10]);
}, 'DOMRect constructor with x parameter');
debug("# DOMRect(10, 20)");
rect = new DOMRect(10, 20);
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "0");
shouldBe("rect.height", "0");
shouldBe("rect.top", "20");
shouldBe("rect.right", "10");
shouldBe("rect.bottom", "20");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRect(10, 20);
assert_dom_rect_equals(rect, [10, 20, 0, 0, 20, 10, 20, 10]);
}, 'DOMRect constructor with x, y parameters');
debug("# DOMRect(10, 20, 80)");
rect = new DOMRect(10, 20, 80);
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "80");
shouldBe("rect.height", "0");
shouldBe("rect.top", "20");
shouldBe("rect.right", "90");
shouldBe("rect.bottom", "20");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRect(10, 20, 80);
assert_dom_rect_equals(rect, [10, 20, 80, 0, 20, 90, 20, 10]);
}, 'DOMRect constructor with x, y, width parameters');
debug("# DOMRect(10, 20, 80, 50)");
rect = new DOMRect(10, 20, 80, 50);
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "80");
shouldBe("rect.height", "50");
shouldBe("rect.top", "20");
shouldBe("rect.right", "90");
shouldBe("rect.bottom", "70");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRect(10, 20, 80, 50);
assert_dom_rect_equals(rect, [10, 20, 80, 50, 20, 90, 70, 10]);
}, 'DOMRect constructor with x, y, width, height parameters');
debug("# DOMRect setter");
rect.x = 30;
shouldBe("rect.x", "30");
shouldBe("rect.left", "30");
shouldBe("rect.width", "80");
shouldBe("rect.right", "110");
rect.y = -10;
shouldBe("rect.y", "-10");
shouldBe("rect.top", "-10");
shouldBe("rect.height", "50");
shouldBe("rect.bottom", "40");
rect.width = 20;
shouldBe("rect.x", "30");
shouldBe("rect.left", "30");
shouldBe("rect.width", "20");
shouldBe("rect.right", "50");
rect.height = 40;
shouldBe("rect.y", "-10");
shouldBe("rect.top", "-10");
shouldBe("rect.height", "40");
shouldBe("rect.bottom", "30");
debug("");
test(() => {
var rect = new DOMRect(10, 20, -80, -50);
assert_dom_rect_equals(rect, [10, 20, -80, -50, -30, 10, 20, -70]);
}, 'DOMRect constructor with negative width and height parameters');
debug("# DOMRect(10, 20, -80, -50) negative width and height");
rect = new DOMRect(10, 20, -80, -50);
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "-80");
shouldBe("rect.height", "-50");
shouldBe("rect.top", "-30");
shouldBe("rect.right", "10");
shouldBe("rect.bottom", "20");
shouldBe("rect.left", "-70");
shouldBe("rect.top", "rect.y + rect.height");
shouldBe("rect.right", "rect.x");
shouldBe("rect.bottom", "rect.y");
shouldBe("rect.left", "rect.x + rect.width");
debug("");
test(() => {
var rect = new DOMRect(10, 20, 80, 50);
rect.x = 30;
assert_dom_rect_equals(rect, [30, 20, 80, 50, 20, 110, 70, 30]);
rect.y = -10;
assert_dom_rect_equals(rect, [30, -10, 80, 50, -10, 110, 40, 30]);
rect.width = 20;
assert_dom_rect_equals(rect, [30, -10, 20, 50, -10, 50, 40, 30]);
rect.height = 40;
assert_dom_rect_equals(rect, [30, -10, 20, 40, -10, 50, 30, 30]);
}, 'DOMRect setter');
debug("# DOMRectReadOnly(10, 20, 80, 50)");
rect = new DOMRectReadOnly(10, 20, 80, 50);
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "80");
shouldBe("rect.height", "50");
shouldBe("rect.top", "20");
shouldBe("rect.right", "90");
shouldBe("rect.bottom", "70");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRectReadOnly(10, 20, 80, 50);
assert_dom_rect_equals(rect, [10, 20, 80, 50, 20, 90, 70, 10]);
}, 'DOMRectReadOnly constructor with x, y, width, height parameters');
debug("# DOMRectReadOnly readonly test");
rect.x = 40;
rect.y = 90;
rect.width = 200;
rect.height = 200;
shouldBe("rect.x", "10");
shouldBe("rect.y", "20");
shouldBe("rect.width", "80");
shouldBe("rect.height", "50");
shouldBe("rect.top", "20");
shouldBe("rect.right", "90");
shouldBe("rect.bottom", "70");
shouldBe("rect.left", "10");
shouldBe("rect.top", "rect.y");
shouldBe("rect.right", "rect.x + rect.width");
shouldBe("rect.bottom", "rect.y + rect.height");
shouldBe("rect.left", "rect.x");
debug("");
test(() => {
var rect = new DOMRectReadOnly(10, 20, 80, 50);
assert_readonly(rect, 'x');
assert_readonly(rect, 'y');
assert_readonly(rect, 'width');
assert_readonly(rect, 'height');
}, 'DOMRectReadOnly readonly test');
</script>
</body>
</html>
......@@ -81,3 +81,29 @@ function assert_dom_point_equals(actual, expected) {
assert_unreached();
}
}
function assert_dom_rect_equals(actual, expected) {
assert_true(actual instanceof DOMRectReadOnly);
if(Array.isArray(expected)) {
assert_equals(expected.length, 8);
assert_equals(actual.x, expected[0], "rect equality: x differs");
assert_equals(actual.y, expected[1], "rect equality: y differs");
assert_equals(actual.width, expected[2], "rect equality: width differs");
assert_equals(actual.height, expected[3], "rect equality: height differs");
assert_equals(actual.top, expected[4], "rect equality: top differs");
assert_equals(actual.right, expected[5], "rect equality: right differs");
assert_equals(actual.bottom, expected[6], "rect equality: bottom differs");
assert_equals(actual.left, expected[7], "rect equality: left differs");
} else if(expected instanceof DOMRectReadOnly) {
assert_equals(actual.x, expected.x, "rect equality: x differs");
assert_equals(actual.y, expected.y, "rect equality: y differs");
assert_equals(actual.width, expected.width, "rect equality: width differs");
assert_equals(actual.height, expected.height, "rect equality: height differs");
assert_equals(actual.top, expected.top, "rect equality: top differs");
assert_equals(actual.right, expected.right, "rect equality: right differs");
assert_equals(actual.bottom, expected.bottom, "rect equality: bottom differs");
assert_equals(actual.left, expected.left, "poirectnt equality: left differs");
} else {
assert_unreached();
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment