Bug 1355675 Part 4: Add tests of Element::getTransformTo... methods. r=mattwoodrow
authorBrad Werth <bwerth@mozilla.com>
Thu, 25 May 2017 16:01:06 -0700
changeset 412074 cb9066e8f9f379ccb3bdb341af87db369987b996
parent 412073 fcfd741290a439a04e5117237daeb8085e9575fe
child 412075 cb69c9d70a96df96f15f7f04305f6858e3b2df16
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1355675
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1355675 Part 4: Add tests of Element::getTransformTo... methods. r=mattwoodrow MozReview-Commit-ID: JQzJ3AZqNC
dom/tests/mochitest/chrome/chrome.ini
dom/tests/mochitest/chrome/test_getTransformTo.html
--- a/dom/tests/mochitest/chrome/chrome.ini
+++ b/dom/tests/mochitest/chrome/chrome.ini
@@ -58,16 +58,17 @@ skip-if = os == 'linux' && !debug # bug 
 [test_focus_docnav.xul]
 [test_focus_switchbinding.xul]
 [test_focused_link_scroll.xul]
 [test_fullscreen.xul]
 tags = fullscreen
 # disabled on linux for timeouts--bug-867745
 skip-if = os == 'linux'
 [test_geolocation.xul]
+[test_getTransformTo.html]
 [test_indexedSetter.html]
 [test_intlUtils_getDisplayNames.html]
 [test_intlUtils_getLocaleInfo.html]
 [test_moving_nodeList.xul]
 [test_moving_xhr.xul]
 [test_MozDomFullscreen_event.xul]
 tags = fullscreen
 # disabled on OS X for intermittent failures--bug-798848
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/chrome/test_getTransformTo.html
@@ -0,0 +1,117 @@
+<!doctype html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Test Element::getTransformToViewport</title>
+<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+<style>
+body {
+  margin: 0px;
+}
+.box {
+  background-color: red;
+  height: 20px;
+  width: 80px;
+}
+.a {
+  margin: 10px;
+}
+.b {
+  margin: 20px;
+}
+.c {
+  transform: translate(11px, -11px);
+}
+.d {
+  transform: skewx(-45deg);
+}
+
+</style>
+<script>
+'use strict';
+
+SimpleTest.waitForExplicitFinish();
+
+function testTransformToParent() {
+  let expectedData = [
+    ["boxA", "1,0,0,0,0,1,0,0,0,0,1,0,10,0,0,1"],
+    ["boxB", "1,0,0,0,0,1,0,0,0,0,1,0,20,0,0,1"],
+    ["boxC", "1,0,0,0,0,1,0,0,0,0,1,0,11,-11,0,1"],
+    ["boxD", "1,0,0,0,-1,1,0,0,0,0,1,0,10,0,0,1"],
+  ];
+
+  // Test transform to parent.
+  for (let i = 0; i < expectedData.length; ++i) {
+    let expected = expectedData[i];
+    let element = document.getElementById(expected[0]);
+
+    let transform = element.getTransformToParent();
+    let transformFloats = transform.toFloat32Array();
+    let transformString = transformFloats.toString();
+    is(transformString, expected[1], "Element " + expected[0] + " has expected transform to parent.");
+  }
+}
+
+function testTransformToAncestorAndViewport() {
+  let expectedData = [
+    ["boxA", "1,0,0,0,0,1,0,0,0,0,1,0,10,10,0,1"],
+    ["boxB", "1,0,0,0,0,1,0,0,0,0,1,0,20,50,0,1"],
+    ["boxC", "1,0,0,0,0,1,0,0,0,0,1,0,11,79,0,1"],
+  ];
+
+  // Test transform to document (an actual ancestor unchanged by embedding within the mochitest framework).
+  for (let i = 0; i < expectedData.length; ++i) {
+    let expected = expectedData[i];
+    let element = document.getElementById(expected[0]);
+
+    let transform = element.getTransformToAncestor(document.documentElement);
+    let transformFloats = transform.toFloat32Array();
+    let transformString = transformFloats.toString();
+    is(transformString, expected[1], "Element " + expected[0] + " has expected transform to ancestor.");
+  }
+
+  // Test transform to a non-ancestor is equivalent to transform to viewport.
+  let nonAncestorElement = document.getElementById("nonAncestor");
+  for (let i = 0; i < expectedData.length; ++i) {
+    let expected = expectedData[i];
+    let element = document.getElementById(expected[0]);
+
+    let transform = element.getTransformToAncestor(nonAncestorElement);
+    let transformFloats = transform.toFloat32Array();
+    let transformString = transformFloats.toString();
+
+    let transformToViewport = element.getTransformToViewport();
+    let transformToViewportFloats = transformToViewport.toFloat32Array();
+    let transformToViewportString = transformToViewportFloats.toString();
+    is(transformString, transformToViewportString, "Element " + expected[0] + " transform to non-ancestor is equivalent to transform to viewport.");
+  }
+}
+
+function runTests() {
+  testTransformToParent();
+  testTransformToAncestorAndViewport();
+
+  SimpleTest.finish();
+}
+</script>
+</head>
+<body onLoad="runTests();">
+
+<div id="boxAParent">
+  <div id="boxA" class="box a">boxA</div>
+</div>
+<div id="boxBParent">
+  <div id="boxB" class="box b">boxB</div>
+</div>
+<div id="boxCParent">
+  <div id="boxC" class="box c">boxC</div>
+</div>
+<div id="boxDParent">
+  <div id="boxD" class="box d">boxD</div>
+</div>
+
+<div id="nonAncestor">This div is not an ancestor of any of the boxes.</div>
+
+</body>
+</html>
\ No newline at end of file