dom/imptests/editing/selecttest/test_addRange.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!doctype html>
michael@0 2 <title>Selection.addRange() tests</title>
michael@0 3 <div id=log></div>
michael@0 4 <script src=/resources/testharness.js></script>
michael@0 5 <script src=/resources/testharnessreport.js></script>
michael@0 6 <script src=common.js></script>
michael@0 7 <script>
michael@0 8 "use strict";
michael@0 9
michael@0 10 function testAddRange(exception, range, endpoints, qualifier, testName) {
michael@0 11 test(function() {
michael@0 12 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 13
michael@0 14 selection.addRange(range);
michael@0 15
michael@0 16 assert_equals(range.startContainer, endpoints[0],
michael@0 17 "addRange() must not modify the startContainer of the Range it's given");
michael@0 18 assert_equals(range.startOffset, endpoints[1],
michael@0 19 "addRange() must not modify the startOffset of the Range it's given");
michael@0 20 assert_equals(range.endContainer, endpoints[2],
michael@0 21 "addRange() must not modify the endContainer of the Range it's given");
michael@0 22 assert_equals(range.endOffset, endpoints[3],
michael@0 23 "addRange() must not modify the endOffset of the Range it's given");
michael@0 24 }, testName + ": " + qualifier + " addRange() must not throw exceptions or modify the range it's given");
michael@0 25
michael@0 26 test(function() {
michael@0 27 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 28
michael@0 29 assert_equals(selection.rangeCount, 1, "rangeCount must be 1");
michael@0 30 }, testName + ": " + qualifier + " addRange() must result in rangeCount being 1");
michael@0 31
michael@0 32 // From here on out we check selection.getRangeAt(selection.rangeCount - 1)
michael@0 33 // so as not to double-fail Gecko.
michael@0 34
michael@0 35 test(function() {
michael@0 36 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 37 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
michael@0 38
michael@0 39 var newRange = selection.getRangeAt(selection.rangeCount - 1);
michael@0 40
michael@0 41 assert_not_equals(newRange, null,
michael@0 42 "getRangeAt(rangeCount - 1) must not return null");
michael@0 43 assert_equals(typeof newRange, "object",
michael@0 44 "getRangeAt(rangeCount - 1) must return an object");
michael@0 45
michael@0 46 assert_equals(newRange.startContainer, range.startContainer,
michael@0 47 "startContainer of the Selection's last Range must match the added Range");
michael@0 48 assert_equals(newRange.startOffset, range.startOffset,
michael@0 49 "startOffset of the Selection's last Range must match the added Range");
michael@0 50 assert_equals(newRange.endContainer, range.endContainer,
michael@0 51 "endContainer of the Selection's last Range must match the added Range");
michael@0 52 assert_equals(newRange.endOffset, range.endOffset,
michael@0 53 "endOffset of the Selection's last Range must match the added Range");
michael@0 54 }, testName + ": " + qualifier + " addRange() must result in the selection's last range having the specified endpoints");
michael@0 55
michael@0 56 test(function() {
michael@0 57 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 58 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
michael@0 59
michael@0 60 assert_equals(selection.getRangeAt(selection.rangeCount - 1), range,
michael@0 61 "getRangeAt(rangeCount - 1) must return the same object we added");
michael@0 62 }, testName + ": " + qualifier + " addRange() must result in the selection's last range being the same object we added");
michael@0 63
michael@0 64 // Let's not test many different modifications -- one should be enough.
michael@0 65 test(function() {
michael@0 66 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 67 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
michael@0 68
michael@0 69 if (range.startContainer == paras[0].firstChild
michael@0 70 && range.startOffset == 0
michael@0 71 && range.endContainer == paras[0].firstChild
michael@0 72 && range.endOffset == 2) {
michael@0 73 // Just in case . . .
michael@0 74 range.setStart(paras[0].firstChild, 1);
michael@0 75 } else {
michael@0 76 range.setStart(paras[0].firstChild, 0);
michael@0 77 range.setEnd(paras[0].firstChild, 2);
michael@0 78 }
michael@0 79
michael@0 80 var newRange = selection.getRangeAt(selection.rangeCount - 1);
michael@0 81
michael@0 82 assert_equals(newRange.startContainer, range.startContainer,
michael@0 83 "After mutating the " + qualifier + " added Range, startContainer of the Selection's last Range must match the added Range");
michael@0 84 assert_equals(newRange.startOffset, range.startOffset,
michael@0 85 "After mutating the " + qualifier + " added Range, startOffset of the Selection's last Range must match the added Range");
michael@0 86 assert_equals(newRange.endContainer, range.endContainer,
michael@0 87 "After mutating the " + qualifier + " added Range, endContainer of the Selection's last Range must match the added Range");
michael@0 88 assert_equals(newRange.endOffset, range.endOffset,
michael@0 89 "After mutating the " + qualifier + " added Range, endOffset of the Selection's last Range must match the added Range");
michael@0 90 }, testName + ": modifying the " + qualifier + " added range must modify the Selection's last Range");
michael@0 91
michael@0 92 // Now test the other way too.
michael@0 93 test(function() {
michael@0 94 assert_equals(exception, null, "Test setup must not throw exceptions");
michael@0 95 assert_not_equals(selection.rangeCount, 0, "Cannot proceed with tests if rangeCount is 0");
michael@0 96
michael@0 97 var newRange = selection.getRangeAt(selection.rangeCount - 1);
michael@0 98
michael@0 99 if (newRange.startContainer == paras[0].firstChild
michael@0 100 && newRange.startOffset == 4
michael@0 101 && newRange.endContainer == paras[0].firstChild
michael@0 102 && newRange.endOffset == 6) {
michael@0 103 newRange.setStart(paras[0].firstChild, 5);
michael@0 104 } else {
michael@0 105 newRange.setStart(paras[0].firstChild, 4);
michael@0 106 newRange.setStart(paras[0].firstChild, 6);
michael@0 107 }
michael@0 108
michael@0 109 assert_equals(newRange.startContainer, range.startContainer,
michael@0 110 "After " + qualifier + " addRange(), after mutating the Selection's last Range, startContainer of the Selection's last Range must match the added Range");
michael@0 111 assert_equals(newRange.startOffset, range.startOffset,
michael@0 112 "After " + qualifier + " addRange(), after mutating the Selection's last Range, startOffset of the Selection's last Range must match the added Range");
michael@0 113 assert_equals(newRange.endContainer, range.endContainer,
michael@0 114 "After " + qualifier + " addRange(), after mutating the Selection's last Range, endContainer of the Selection's last Range must match the added Range");
michael@0 115 assert_equals(newRange.endOffset, range.endOffset,
michael@0 116 "After " + qualifier + " addRange(), after mutating the Selection's last Range, endOffset of the Selection's last Range must match the added Range");
michael@0 117 }, testName + ": modifying the Selection's last Range must modify the " + qualifier + " added Range");
michael@0 118 }
michael@0 119
michael@0 120 // Do only n evals, not n^2
michael@0 121 var testRangesEvaled = testRanges.map(eval);
michael@0 122
michael@0 123 for (var i = 0; i < testRanges.length; i++) {
michael@0 124 for (var j = 0; j < testRanges.length; j++) {
michael@0 125 var testName = "Range " + i + " " + testRanges[i]
michael@0 126 + " followed by Range " + j + " " + testRanges[j];
michael@0 127
michael@0 128 var exception = null;
michael@0 129 try {
michael@0 130 selection.removeAllRanges();
michael@0 131
michael@0 132 var endpoints1 = testRangesEvaled[i];
michael@0 133 var range1 = ownerDocument(endpoints1[0]).createRange();
michael@0 134 range1.setStart(endpoints1[0], endpoints1[1]);
michael@0 135 range1.setEnd(endpoints1[2], endpoints1[3]);
michael@0 136
michael@0 137 if (range1.startContainer !== endpoints1[0]) {
michael@0 138 throw "Sanity check: the first Range we created must have the desired startContainer";
michael@0 139 }
michael@0 140 if (range1.startOffset !== endpoints1[1]) {
michael@0 141 throw "Sanity check: the first Range we created must have the desired startOffset";
michael@0 142 }
michael@0 143 if (range1.endContainer !== endpoints1[2]) {
michael@0 144 throw "Sanity check: the first Range we created must have the desired endContainer";
michael@0 145 }
michael@0 146 if (range1.endOffset !== endpoints1[3]) {
michael@0 147 throw "Sanity check: the first Range we created must have the desired endOffset";
michael@0 148 }
michael@0 149
michael@0 150 var endpoints2 = testRangesEvaled[j];
michael@0 151 var range2 = ownerDocument(endpoints2[0]).createRange();
michael@0 152 range2.setStart(endpoints2[0], endpoints2[1]);
michael@0 153 range2.setEnd(endpoints2[2], endpoints2[3]);
michael@0 154
michael@0 155 if (range2.startContainer !== endpoints2[0]) {
michael@0 156 throw "Sanity check: the second Range we created must have the desired startContainer";
michael@0 157 }
michael@0 158 if (range2.startOffset !== endpoints2[1]) {
michael@0 159 throw "Sanity check: the second Range we created must have the desired startOffset";
michael@0 160 }
michael@0 161 if (range2.endContainer !== endpoints2[2]) {
michael@0 162 throw "Sanity check: the second Range we created must have the desired endContainer";
michael@0 163 }
michael@0 164 if (range2.endOffset !== endpoints2[3]) {
michael@0 165 throw "Sanity check: the second Range we created must have the desired endOffset";
michael@0 166 }
michael@0 167 } catch (e) {
michael@0 168 exception = e;
michael@0 169 }
michael@0 170
michael@0 171 testAddRange(exception, range1, endpoints1, "first", testName);
michael@0 172 testAddRange(exception, range2, endpoints2, "second", testName);
michael@0 173 }
michael@0 174 }
michael@0 175
michael@0 176 testDiv.style.display = "none";
michael@0 177 </script>

mercurial