dom/imptests/editing/selecttest/test_Document-open.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/imptests/editing/selecttest/test_Document-open.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,44 @@
     1.4 +<!doctype html>
     1.5 +<title>Selection Document.open() tests</title>
     1.6 +<div id=log></div>
     1.7 +<script src=/resources/testharness.js></script>
     1.8 +<script src=/resources/testharnessreport.js></script>
     1.9 +<script>
    1.10 +"use strict";
    1.11 +
    1.12 +// This tests the HTML spec requirement "Replace the Document's singleton
    1.13 +// objects with new instances of those objects. (This includes in particular
    1.14 +// the Window, Location, History, ApplicationCache, and Navigator, objects, the
    1.15 +// various BarProp objects, the two Storage objects, the various HTMLCollection
    1.16 +// objects, and objects defined by other specifications, like Selection and the
    1.17 +// document's UndoManager. It also includes all the Web IDL prototypes in the
    1.18 +// JavaScript binding, including the Document object's prototype.)" in the
    1.19 +// document.open() algorithm.
    1.20 +
    1.21 +var iframe = document.createElement("iframe");
    1.22 +var t = async_test("Selection must be replaced with a new object after document.open()");
    1.23 +iframe.onload = function() {
    1.24 +	t.step(function() {
    1.25 +		var originalSelection = iframe.contentWindow.getSelection();
    1.26 +		assert_equals(originalSelection.rangeCount, 0,
    1.27 +			"Sanity check: rangeCount must be initially 0");
    1.28 +		iframe.contentDocument.body.appendChild(
    1.29 +			iframe.contentDocument.createTextNode("foo"));
    1.30 +		var range = iframe.contentDocument.createRange();
    1.31 +		range.selectNodeContents(iframe.contentDocument.body);
    1.32 +		iframe.contentWindow.getSelection().addRange(range);
    1.33 +		assert_equals(originalSelection.rangeCount, 1,
    1.34 +			"Sanity check: rangeCount must be 1 after adding a range");
    1.35 +
    1.36 +		iframe.contentDocument.open();
    1.37 +
    1.38 +		assert_not_equals(iframe.contentWindow.getSelection(), originalSelection,
    1.39 +			"After document.open(), the Selection object must no longer be the same");
    1.40 +		assert_equals(iframe.contentWindow.getSelection().rangeCount, 0,
    1.41 +			"After document.open(), rangeCount must be 0 again");
    1.42 +	});
    1.43 +	t.done();
    1.44 +	document.body.removeChild(iframe);
    1.45 +};
    1.46 +document.body.appendChild(iframe);
    1.47 +</script>

mercurial