Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!doctype html> |
michael@0 | 2 | <title>Selection Document.open() 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> |
michael@0 | 7 | "use strict"; |
michael@0 | 8 | |
michael@0 | 9 | // This tests the HTML spec requirement "Replace the Document's singleton |
michael@0 | 10 | // objects with new instances of those objects. (This includes in particular |
michael@0 | 11 | // the Window, Location, History, ApplicationCache, and Navigator, objects, the |
michael@0 | 12 | // various BarProp objects, the two Storage objects, the various HTMLCollection |
michael@0 | 13 | // objects, and objects defined by other specifications, like Selection and the |
michael@0 | 14 | // document's UndoManager. It also includes all the Web IDL prototypes in the |
michael@0 | 15 | // JavaScript binding, including the Document object's prototype.)" in the |
michael@0 | 16 | // document.open() algorithm. |
michael@0 | 17 | |
michael@0 | 18 | var iframe = document.createElement("iframe"); |
michael@0 | 19 | var t = async_test("Selection must be replaced with a new object after document.open()"); |
michael@0 | 20 | iframe.onload = function() { |
michael@0 | 21 | t.step(function() { |
michael@0 | 22 | var originalSelection = iframe.contentWindow.getSelection(); |
michael@0 | 23 | assert_equals(originalSelection.rangeCount, 0, |
michael@0 | 24 | "Sanity check: rangeCount must be initially 0"); |
michael@0 | 25 | iframe.contentDocument.body.appendChild( |
michael@0 | 26 | iframe.contentDocument.createTextNode("foo")); |
michael@0 | 27 | var range = iframe.contentDocument.createRange(); |
michael@0 | 28 | range.selectNodeContents(iframe.contentDocument.body); |
michael@0 | 29 | iframe.contentWindow.getSelection().addRange(range); |
michael@0 | 30 | assert_equals(originalSelection.rangeCount, 1, |
michael@0 | 31 | "Sanity check: rangeCount must be 1 after adding a range"); |
michael@0 | 32 | |
michael@0 | 33 | iframe.contentDocument.open(); |
michael@0 | 34 | |
michael@0 | 35 | assert_not_equals(iframe.contentWindow.getSelection(), originalSelection, |
michael@0 | 36 | "After document.open(), the Selection object must no longer be the same"); |
michael@0 | 37 | assert_equals(iframe.contentWindow.getSelection().rangeCount, 0, |
michael@0 | 38 | "After document.open(), rangeCount must be 0 again"); |
michael@0 | 39 | }); |
michael@0 | 40 | t.done(); |
michael@0 | 41 | document.body.removeChild(iframe); |
michael@0 | 42 | }; |
michael@0 | 43 | document.body.appendChild(iframe); |
michael@0 | 44 | </script> |