Bug 1334088 Part 2: Add tests of Range.getClientRectsAndTexts. r=jfkthame
authorBrad Werth <bwerth@mozilla.com>
Thu, 23 Feb 2017 10:22:54 -0800
changeset 373547 88a7b28e2b714298493a1471c25925527c6d8409
parent 373546 22b0c9160df833f19740857f7e7d73439d235f26
child 373548 2aa2e92d394f993715cce84de22ba1bb9fc87047
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1334088
milestone54.0a1
Bug 1334088 Part 2: Add tests of Range.getClientRectsAndTexts. r=jfkthame MozReview-Commit-ID: 4VvrHSxR1ry
layout/base/tests/chrome/chrome.ini
layout/base/tests/chrome/test_getClientRectsAndTexts.html
--- a/layout/base/tests/chrome/chrome.ini
+++ b/layout/base/tests/chrome/chrome.ini
@@ -42,8 +42,9 @@ skip-if = (!debug) || (toolkit == "cocoa
 [test_no_clip_iframe.xul]
 [test_prerendered_transforms.html]
 [test_printpreview.xul]
 skip-if = os == "linux" && bits == 32 # Disabled on Linux32 for bug 1278957
 [test_printpreview_bug396024.xul]
 [test_printpreview_bug482976.xul]
 [test_scrolling_repaints.html]
 [test_will_change.html]
+[test_getClientRectsAndTexts.html]
new file mode 100644
--- /dev/null
+++ b/layout/base/tests/chrome/test_getClientRectsAndTexts.html
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <meta charset="utf-8">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<div id="div1" style="width:200px">Here is some text that <a href="#">will wrap</a> in <a href="#">this small</a>-ish container.</div>
+<div id="div2">Into another <a href="#">container</a></div>
+<div id="div3">A very <span>deep <span>deep <span>deep</span></span></span> bit of text.</div>
+
+<script>
+if (typeof(is) == "undefined") {
+  var is = function(a, b, m) {
+    if(a != b) {
+      window.console.log("Expected '" + b + "' but got '" + a + "': " + m);
+    }
+  };
+}
+
+if (typeof(todo_is) == "undefined") {
+  var todo_is = is;
+}
+
+function testRangeTexts(startNode, startOffset, endNode, endOffset, expectedText, todo) {
+  let r = new Range();
+  r.setStart(startNode, startOffset);
+  r.setEnd(endNode, endOffset);
+
+  let texts = r.getClientRectsAndTexts().textList;
+  let concatText = "";
+  for (let i = 0; i < texts.length; i++) {
+    concatText += texts[i];
+  }
+
+  if (todo) {
+    todo_is(concatText, expectedText, "Text matches.");
+  } else {
+    is(concatText, expectedText, "Text matches.");
+  }
+}
+
+let d1c1 = div1.firstChild;
+let d1c2 = d1c1.nextSibling;
+let d1c3 = d1c2.nextSibling;
+let d1c4 = d1c3.nextSibling;
+let d1c5 = d1c4.nextSibling;
+
+let link1 = d1c2.firstChild;
+let link2 = d1c4.firstChild;
+
+let d2c1 = div2.firstChild;
+let d2c2 = d2c1.nextSibling;
+
+let link3 = d2c2.firstChild;
+
+let d3c1 = div3.firstChild;
+let d3c2 = d3c1.nextSibling;
+let d3c3 = d3c2.nextSibling;
+
+let data = [
+  [d1c1, 0, d1c1, 0, ""],
+  [d1c1, 0, d1c1, 4, "Here"],
+  [d1c1, 4, d1c1, 7, " is"],
+  [d1c1, 22, link1, 0, " "],
+  [d1c1, 22, link1, 1, " w"],
+  [d1c1, 22, d1c3, 1, " will wrap "],
+  [link1, 2, link2, 3, "ll wrap in thi"],
+  [link2, 5, link3, 3, "small-ish container.Into another con"],
+  [d3c1, 3, d3c3, 4, "ery deep deep deep bit"],
+];
+
+data.forEach(function (d) { testRangeTexts.apply(null, d); });
+
+</script>
+
+</body>
+</html>