chromium/third_party/blink/web_tests/fast/dom/geometry-interfaces-dom-quad.html

<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./resources/geometry-interfaces-test-helpers.js"></script>
<script>
test(() => {
  var p1 = new DOMPoint(0, 1, 3, 4);
  var p2 = new DOMPoint(5, 6, 7, 8);
  var p3 = new DOMPoint(9, 10, 11, 12);
  var p4 = new DOMPoint(13, 14, 15, 16);
  var quad = new DOMQuad(p1, p2, p3, p4);
  assert_dom_point_equals(quad.p1, p1);
  assert_dom_point_equals(quad.p2, p2);
  assert_dom_point_equals(quad.p3, p3);
  assert_dom_point_equals(quad.p4, p4);
}, "DOMQuad() constructor");

test(() => {
  var p1 = new DOMPoint(0, 1, 3, 4);
  var p2 = new DOMPoint(5, 6, 7, 8);
  var p3 = new DOMPoint(9, 10, 11, 12);
  var p4 = new DOMPoint(13, 14, 15, 16);
  var quad = new DOMQuad(p1, p2, p3, p4);
  assert_dom_point_equals(quad.toJSON().p1, p1, "p1");
  assert_dom_point_equals(quad.toJSON().p2, p2, "p2");
  assert_dom_point_equals(quad.toJSON().p3, p3, "p3");
  assert_dom_point_equals(quad.toJSON().p4, p4, "p4");
}, "DOMQuad() toJSON()");

test(() => {
  var expect_p1 = new DOMPoint(10, 20, 0, 1);
  var expect_p2 = new DOMPoint(90, 20, 0, 1);
  var expect_p3 = new DOMPoint(90, 70, 0, 1);
  var expect_p4 = new DOMPoint(10, 70, 0, 1);
  var quad = DOMQuad.fromRect({x: 10, y: 20, width: 80, height: 50});
  assert_dom_point_equals(quad.p1, expect_p1, "p1");
  assert_dom_point_equals(quad.p2, expect_p2, "p2");
  assert_dom_point_equals(quad.p3, expect_p3, "p3");
  assert_dom_point_equals(quad.p4, expect_p4, "p4");
}, "DOMQuad() fromRect");

test(() => {
  var expect_p1 = new DOMPoint(0, 1, 2, 3);
  var expect_p2 = new DOMPoint(4, 5, 6, 7);
  var expect_p3 = new DOMPoint(8, 9, 10, 11);
  var expect_p4 = new DOMPoint(12, 13, 14, 15);
  var quad = DOMQuad.fromQuad({p1: {x: 0, y: 1, z: 2, w: 3},
                                      p2: {x: 4, y: 5, z: 6, w: 7},
                                      p3: {x: 8, y: 9, z: 10, w: 11},
                                      p4: {x: 12, y: 13, z: 14, w: 15}});
  assert_dom_point_equals(quad.p1, expect_p1, "p1");
  assert_dom_point_equals(quad.p2, expect_p2, "p2");
  assert_dom_point_equals(quad.p3, expect_p3, "p3");
  assert_dom_point_equals(quad.p4, expect_p4, "p4");
}, "DOMQuad() fromQuad");

test(() => {
  var expect_p1 = new DOMPoint(0, 0, 0, 1);
  var expect_p2 = new DOMPoint(0, 0, 0, 1);
  var expect_p3 = new DOMPoint(0, 0, 0, 1);
  var expect_p4 = new DOMPoint(0, 0, 0, 1);
  var quad = DOMQuad.fromQuad({});
  assert_dom_point_equals(quad.p1, expect_p1, "p1");
  assert_dom_point_equals(quad.p2, expect_p2, "p2");
  assert_dom_point_equals(quad.p3, expect_p3, "p3");
  assert_dom_point_equals(quad.p4, expect_p4, "p4");
}, "DOMQuad() fromQuad - parameter of fromQuad function does not have any point.");

test(() => {
  var p1 = new DOMPoint(40, 25, 0, 1);
  var p2 = new DOMPoint(180, 8, 0, 1);
  var p3 = new DOMPoint(210, 150, 0, 1);
  var p4 = new DOMPoint(10, 180, 0, 1);
  var expect_rect = new DOMRect(10, 8, 200, 172);
  var quad = new DOMQuad(p1, p2, p3, p4);
  assert_dom_rect_equals(quad.getBounds(), expect_rect);
}, "DOMQuad() getBounds");

</script>