OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>Selection Document.open() tests</title> |
| 3 <div id=log></div> |
| 4 <script src=/resources/testharness.js></script> |
| 5 <script src=/resources/testharnessreport.js></script> |
| 6 <script> |
| 7 "use strict"; |
| 8 |
| 9 // This tests the HTML spec requirement "Replace the Document's singleton |
| 10 // objects with new instances of those objects. (This includes in particular |
| 11 // the Window, Location, History, ApplicationCache, and Navigator, objects, the |
| 12 // various BarProp objects, the two Storage objects, the various HTMLCollection |
| 13 // objects, and objects defined by other specifications, like Selection and the |
| 14 // document's UndoManager. It also includes all the Web IDL prototypes in the |
| 15 // JavaScript binding, including the Document object's prototype.)" in the |
| 16 // document.open() algorithm. |
| 17 |
| 18 var iframe = document.createElement("iframe"); |
| 19 var t = async_test("Selection must be replaced with a new object after document.
open()"); |
| 20 iframe.onload = function() { |
| 21 t.step(function() { |
| 22 var originalSelection = iframe.contentWindow.getSelection(); |
| 23 assert_equals(originalSelection.rangeCount, 0, |
| 24 "Sanity check: rangeCount must be initially 0"); |
| 25 iframe.contentDocument.body.appendChild( |
| 26 iframe.contentDocument.createTextNode("foo")); |
| 27 var range = iframe.contentDocument.createRange(); |
| 28 range.selectNodeContents(iframe.contentDocument.body); |
| 29 iframe.contentWindow.getSelection().addRange(range); |
| 30 assert_equals(originalSelection.rangeCount, 1, |
| 31 "Sanity check: rangeCount must be 1 after adding a range"); |
| 32 |
| 33 iframe.contentDocument.open(); |
| 34 |
| 35 assert_not_equals(iframe.contentWindow.getSelection(), originalSelection
, |
| 36 "After document.open(), the Selection object must no longer be the s
ame"); |
| 37 assert_equals(iframe.contentWindow.getSelection().rangeCount, 0, |
| 38 "After document.open(), rangeCount must be 0 again"); |
| 39 }); |
| 40 t.done(); |
| 41 document.body.removeChild(iframe); |
| 42 }; |
| 43 document.body.appendChild(iframe); |
| 44 </script> |
OLD | NEW |