dom/imptests/editing/selecttest/test_deleteFromDocument.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!doctype html>
     2 <title>Selection.deleteFromDocument() tests</title>
     3 <link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
     4 <p>To debug test failures, add a query parameter with the test id (like
     5 "?5").  Only that test will be run.  Then you can look at the resulting
     6 iframes in the DOM.
     7 <div id=log></div>
     8 <script src=/resources/testharness.js></script>
     9 <script src=/resources/testharnessreport.js></script>
    10 <script src=common.js></script>
    11 <script>
    12 "use strict";
    14 // We need to use explicit_done, because in Chrome 16 dev and Opera 12.00, the
    15 // second iframe doesn't block the load event -- even though it is added before
    16 // the load event.
    17 setup({explicit_done: true});
    19 // Specified by WebIDL
    20 test(function() {
    21 	assert_equals(Selection.prototype.deleteFromDocument.length, 0,
    22 		"Selection.prototype.deleteFromDocument.length must equal 0");
    23 }, "Selection.prototype.deleteFromDocument.length must equal 0");
    25 testDiv.parentNode.removeChild(testDiv);
    27 // Test an empty selection too
    28 testRanges.unshift("empty");
    30 var actualIframe = document.createElement("iframe");
    32 var expectedIframe = document.createElement("iframe");
    34 var referenceDoc = document.implementation.createHTMLDocument("");
    35 referenceDoc.removeChild(referenceDoc.documentElement);
    37 actualIframe.onload = function() {
    38 	expectedIframe.onload = function() {
    39 		for (var i = 0; i < testRanges.length; i++) {
    40 			if (location.search && i != Number(location.search)) {
    41 				continue;
    42 			}
    44 			test(function() {
    45 				initializeIframe(actualIframe, testRanges[i]);
    46 				initializeIframe(expectedIframe, testRanges[i]);
    48 				var actualRange = actualIframe.contentWindow.testRange;
    49 				var expectedRange = expectedIframe.contentWindow.testRange;
    51 				assert_equals(actualIframe.contentWindow.unexpectedException, null,
    52 					"Unexpected exception thrown when setting up Range for actual deleteFromDocument");
    53 				assert_equals(expectedIframe.contentWindow.unexpectedException, null,
    54 					"Unexpected exception thrown when setting up Range for simulated deleteFromDocument");
    56 				actualIframe.contentWindow.getSelection().removeAllRanges();
    57 				if (testRanges[i] != "empty") {
    58 					assert_equals(typeof actualRange, "object",
    59 						"Range produced in actual iframe must be an object");
    60 					assert_equals(typeof expectedRange, "object",
    61 						"Range produced in expected iframe must be an object");
    62 					assert_true(actualRange instanceof actualIframe.contentWindow.Range,
    63 						"Range produced in actual iframe must be instanceof Range");
    64 					assert_true(expectedRange instanceof expectedIframe.contentWindow.Range,
    65 						"Range produced in expected iframe must be instanceof Range");
    66 					actualIframe.contentWindow.getSelection().addRange(actualIframe.contentWindow.testRange);
    67 					expectedIframe.contentWindow.testRange.deleteContents();
    68 				}
    69 				actualIframe.contentWindow.getSelection().deleteFromDocument();
    71 				assertNodesEqual(actualIframe.contentDocument, expectedIframe.contentDocument, "DOM contents");
    72 			}, "Range " + i + ": " + testRanges[i]);
    73 		}
    74 		actualIframe.style.display = "none";
    75 		expectedIframe.style.display = "none";
    76 		done();
    77 	};
    78 	expectedIframe.src = "test-iframe.html";
    79 	document.body.appendChild(expectedIframe);
    80 	referenceDoc.appendChild(actualIframe.contentDocument.documentElement.cloneNode(true));
    81 };
    82 actualIframe.src = "test-iframe.html";
    83 document.body.appendChild(actualIframe);
    85 function initializeIframe(iframe, endpoints) {
    86 	while (iframe.contentDocument.firstChild) {
    87 		iframe.contentDocument.removeChild(iframe.contentDocument.lastChild);
    88 	}
    89 	iframe.contentDocument.appendChild(iframe.contentDocument.implementation.createDocumentType("html", "", ""));
    90 	iframe.contentDocument.appendChild(referenceDoc.documentElement.cloneNode(true));
    91 	iframe.contentWindow.setupRangeTests();
    92 	if (endpoints != "empty") {
    93 		iframe.contentWindow.testRangeInput = endpoints;
    94 		iframe.contentWindow.run();
    95 	}
    96 }
    97 </script>

mercurial