Bug 1321623 - WPT tests for DOM Selection.setBaseAndExtent(). r=smaug
authorMats Palmgren <mats@mozilla.com>
Mon, 19 Dec 2016 16:48:37 +0100 (2016-12-19)
changeset 326427 ddfcb1823adcf22da5d4ac3b600eda2a0d6aa0a5
parent 326426 c389436be671d5b6a328d3ca32eede9e0b157c86
child 326428 b551aebe8076de5cb6389d2648b8754bb559b3f1
push id84949
push usermpalmgren@mozilla.com
push dateMon, 19 Dec 2016 15:48:47 +0000 (2016-12-19)
treeherdermozilla-inbound@ddfcb1823adc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1321623
milestone53.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 1321623 - WPT tests for DOM Selection.setBaseAndExtent(). r=smaug
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/selection/setBaseAndExtent.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -39556,16 +39556,22 @@
           }
         ],
         "html/semantics/forms/the-select-element/select-validity.html": [
           {
             "path": "html/semantics/forms/the-select-element/select-validity.html",
             "url": "/html/semantics/forms/the-select-element/select-validity.html"
           }
         ],
+        "selection/setBaseAndExtent.html": [
+          {
+            "path": "selection/setBaseAndExtent.html",
+            "url": "/selection/setBaseAndExtent.html"
+          }
+        ],
         "uievents/order-of-events/focus-events/focus-automated-blink-webkit.html": [
           {
             "path": "uievents/order-of-events/focus-events/focus-automated-blink-webkit.html",
             "url": "/uievents/order-of-events/focus-events/focus-automated-blink-webkit.html"
           }
         ],
         "web-animations/animation-model/animation-types/spacing-keyframes-filters.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/selection/setBaseAndExtent.html
@@ -0,0 +1,120 @@
+<!doctype html>
+<title>Selection.setBaseAndExtent() tests</title>
+<div id=log></div>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=common.js></script>
+<script>
+"use strict";
+
+for (var i = 0; i < testRanges.length; i++) {
+    test(function() {
+        var data = eval(testRanges[i]);
+        selection.setBaseAndExtent(data[0], data[1], data[2], data[3]);
+        assert_equals(selection.rangeCount, 1,
+                      "selection.rangeCount must equal 1");
+        assert_equals(selection.anchorNode, data[0],
+                      "anchorNode must equal the requested anchor node");
+        assert_equals(selection.anchorOffset, data[1],
+                      "anchorOffset must equal the requested anchor offset");
+        assert_equals(selection.focusNode, data[2],
+                      "focusNode must equal the requested focus node");
+        assert_equals(selection.focusOffset, data[3],
+                      "focusOffset must equal the requested focus offset");
+    }, "Range " + i + " " + testRanges[i] + " setBaseAndExtent()");
+
+    test(function() {
+        var data = eval(testRanges[i]);
+        selection.setBaseAndExtent(data[2], data[3], data[0], data[1]);
+        assert_equals(selection.rangeCount, 1,
+                      "selection.rangeCount must equal 1");
+        assert_equals(selection.anchorNode, data[2],
+                      "anchorNode must equal the requested focus node");
+        assert_equals(selection.anchorOffset, data[3],
+                      "anchorOffset must equal the requested focus offset");
+        assert_equals(selection.focusNode, data[0],
+                      "focusNode must equal the requested anchor node");
+        assert_equals(selection.focusOffset, data[1],
+                      "focusOffset must equal the requested anchor offset");
+    }, "Reverse range " + i + " " + testRanges[i] + " setBaseAndExtent()");
+}
+
+test(function() {
+    var title = document.getElementsByTagName('title')[0];
+    try {
+        selection.setBaseAndExtent(title, 0, title, 99);
+        assert_true(false, "focus offset, must throw an IndexSizeError exception")
+    } catch (e) {
+        assert_equals(e.name, "IndexSizeError", "focus offset, got an IndexSizeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(title, 99, title, 0);
+        assert_true(false, "anchor offset, must throw an IndexSizeError exception")
+    } catch (e) {
+        assert_equals(e.name, "IndexSizeError", "anchor offset, got an IndexSizeError exception")
+    }
+}, "setBaseAndExtent() with index larger than length");
+
+test(function() {
+    var title = document.getElementsByTagName('title')[0];
+    try {
+        selection.setBaseAndExtent(title, 0, title, -1);
+        assert_true(false, "focus offset, must throw an IndexSizeError exception")
+    } catch (e) {
+        assert_equals(e.name, "IndexSizeError", "focus offset, got an IndexSizeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(title, -1, title, 0);
+        assert_true(false, "anchor offset, must throw an IndexSizeError exception")
+    } catch (e) {
+        assert_equals(e.name, "IndexSizeError", "anchor offset, got an IndexSizeError exception")
+    }
+}, "setBaseAndExtent() with negative index");
+
+test(function() {
+    var title = document.getElementsByTagName('title')[0];
+    try {
+        selection.setBaseAndExtent(title, 0, null, 0);
+        assert_true(false, "focus node, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "focus node, got an TypeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(null, 0, title, 0);
+        assert_true(false, "anchor node, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "anchor node, got an TypeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(null, 0, null, 0);
+        assert_true(false, "both nodes, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "both nodes, got an TypeError exception")
+    }
+}, "setBaseAndExtent() with null nodes");
+
+test(function() {
+    var title = document.getElementsByTagName('title')[0];
+    try {
+        selection.setBaseAndExtent(title, 0, title);
+        assert_true(false, "focus offset, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "focus offset, got an TypeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(title, 0);
+        assert_true(false, "focus node, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "focus node, got an TypeError exception")
+    }
+    try {
+        selection.setBaseAndExtent(title);
+        assert_true(false, "anchor offset, must throw an TypeError exception")
+    } catch (e) {
+        assert_equals(e.name, "TypeError", "anchor offset, got an TypeError exception")
+    }
+}, "setBaseAndExtent() with too few params");
+
+testDiv.style.display = "none";
+
+</script>