dom/imptests/editing/selecttest/test_deleteFromDocument.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/imptests/editing/selecttest/test_deleteFromDocument.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +<!doctype html>
     1.5 +<title>Selection.deleteFromDocument() tests</title>
     1.6 +<link rel=author title="Aryeh Gregor" href=ayg@aryeh.name>
     1.7 +<p>To debug test failures, add a query parameter with the test id (like
     1.8 +"?5").  Only that test will be run.  Then you can look at the resulting
     1.9 +iframes in the DOM.
    1.10 +<div id=log></div>
    1.11 +<script src=/resources/testharness.js></script>
    1.12 +<script src=/resources/testharnessreport.js></script>
    1.13 +<script src=common.js></script>
    1.14 +<script>
    1.15 +"use strict";
    1.16 +
    1.17 +// We need to use explicit_done, because in Chrome 16 dev and Opera 12.00, the
    1.18 +// second iframe doesn't block the load event -- even though it is added before
    1.19 +// the load event.
    1.20 +setup({explicit_done: true});
    1.21 +
    1.22 +// Specified by WebIDL
    1.23 +test(function() {
    1.24 +	assert_equals(Selection.prototype.deleteFromDocument.length, 0,
    1.25 +		"Selection.prototype.deleteFromDocument.length must equal 0");
    1.26 +}, "Selection.prototype.deleteFromDocument.length must equal 0");
    1.27 +
    1.28 +testDiv.parentNode.removeChild(testDiv);
    1.29 +
    1.30 +// Test an empty selection too
    1.31 +testRanges.unshift("empty");
    1.32 +
    1.33 +var actualIframe = document.createElement("iframe");
    1.34 +
    1.35 +var expectedIframe = document.createElement("iframe");
    1.36 +
    1.37 +var referenceDoc = document.implementation.createHTMLDocument("");
    1.38 +referenceDoc.removeChild(referenceDoc.documentElement);
    1.39 +
    1.40 +actualIframe.onload = function() {
    1.41 +	expectedIframe.onload = function() {
    1.42 +		for (var i = 0; i < testRanges.length; i++) {
    1.43 +			if (location.search && i != Number(location.search)) {
    1.44 +				continue;
    1.45 +			}
    1.46 +
    1.47 +			test(function() {
    1.48 +				initializeIframe(actualIframe, testRanges[i]);
    1.49 +				initializeIframe(expectedIframe, testRanges[i]);
    1.50 +
    1.51 +				var actualRange = actualIframe.contentWindow.testRange;
    1.52 +				var expectedRange = expectedIframe.contentWindow.testRange;
    1.53 +
    1.54 +				assert_equals(actualIframe.contentWindow.unexpectedException, null,
    1.55 +					"Unexpected exception thrown when setting up Range for actual deleteFromDocument");
    1.56 +				assert_equals(expectedIframe.contentWindow.unexpectedException, null,
    1.57 +					"Unexpected exception thrown when setting up Range for simulated deleteFromDocument");
    1.58 +
    1.59 +				actualIframe.contentWindow.getSelection().removeAllRanges();
    1.60 +				if (testRanges[i] != "empty") {
    1.61 +					assert_equals(typeof actualRange, "object",
    1.62 +						"Range produced in actual iframe must be an object");
    1.63 +					assert_equals(typeof expectedRange, "object",
    1.64 +						"Range produced in expected iframe must be an object");
    1.65 +					assert_true(actualRange instanceof actualIframe.contentWindow.Range,
    1.66 +						"Range produced in actual iframe must be instanceof Range");
    1.67 +					assert_true(expectedRange instanceof expectedIframe.contentWindow.Range,
    1.68 +						"Range produced in expected iframe must be instanceof Range");
    1.69 +					actualIframe.contentWindow.getSelection().addRange(actualIframe.contentWindow.testRange);
    1.70 +					expectedIframe.contentWindow.testRange.deleteContents();
    1.71 +				}
    1.72 +				actualIframe.contentWindow.getSelection().deleteFromDocument();
    1.73 +
    1.74 +				assertNodesEqual(actualIframe.contentDocument, expectedIframe.contentDocument, "DOM contents");
    1.75 +			}, "Range " + i + ": " + testRanges[i]);
    1.76 +		}
    1.77 +		actualIframe.style.display = "none";
    1.78 +		expectedIframe.style.display = "none";
    1.79 +		done();
    1.80 +	};
    1.81 +	expectedIframe.src = "test-iframe.html";
    1.82 +	document.body.appendChild(expectedIframe);
    1.83 +	referenceDoc.appendChild(actualIframe.contentDocument.documentElement.cloneNode(true));
    1.84 +};
    1.85 +actualIframe.src = "test-iframe.html";
    1.86 +document.body.appendChild(actualIframe);
    1.87 +
    1.88 +function initializeIframe(iframe, endpoints) {
    1.89 +	while (iframe.contentDocument.firstChild) {
    1.90 +		iframe.contentDocument.removeChild(iframe.contentDocument.lastChild);
    1.91 +	}
    1.92 +	iframe.contentDocument.appendChild(iframe.contentDocument.implementation.createDocumentType("html", "", ""));
    1.93 +	iframe.contentDocument.appendChild(referenceDoc.documentElement.cloneNode(true));
    1.94 +	iframe.contentWindow.setupRangeTests();
    1.95 +	if (endpoints != "empty") {
    1.96 +		iframe.contentWindow.testRangeInput = endpoints;
    1.97 +		iframe.contentWindow.run();
    1.98 +	}
    1.99 +}
   1.100 +</script>

mercurial