current-realm.html (5041B)
1 <!-- This tests the agreed upon outcome for https://www.w3.org/Bugs/Public/show_bug.cgi?id=24652 2 that has not been reflected in the IDL standard yet due to lack of editing resources. 3 4 TODO: https://github.com/w3c/webcrypto/issues/85 --> 5 <!DOCTYPE html> 6 <meta charset=utf-8> 7 <title>Current Realm</title> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <div id="log"></div> 11 <iframe srcdoc="<body test>"></iframe> 12 <script> 13 setup({explicit_done:true}) 14 15 function isObjectFromGlobal(object, global) { 16 return object instanceof global.Object; 17 } 18 function assert_global(obj) { 19 assert_false(isObjectFromGlobal(obj, self), obj + " should not be from top-level Realm") 20 assert_true(isObjectFromGlobal(obj, self[0]), obj + " should be from <iframe> Realm") 21 } 22 23 onload = function() { 24 [["querySelectorAll", "test"], 25 ["createElement", "x"], 26 ["createElementNS", null, "x"], 27 ["createDocumentFragment"], 28 ["createTextNode", "test"], 29 ["createComment", "test"], 30 ["createProcessingInstruction", "x", "x"], 31 ["createAttribute", "x"], 32 ["createAttributeNS", "x", "x"], 33 ["createEvent", "Event"], 34 ["createRange"], 35 ["createNodeIterator", document.head], 36 ["createTreeWalker", document.head]].forEach(function(val) { 37 test(function() { 38 const method = val.shift(); 39 let obj = self[0].document[method](...val); 40 assert_global(obj) 41 42 obj = Document.prototype[method].call(self[0].document, ...val); 43 assert_global(obj) 44 }, val[0]) 45 }) 46 47 ;["Request", "Response"].forEach(val => { 48 test(() => { 49 const obj = new self[0][val]("about:blank"); 50 assert_global(obj); 51 52 const cloneObj = obj.clone(); 53 assert_global(cloneObj); 54 55 const involvedCloneObj = self[val].prototype["clone"].call(cloneObj); 56 assert_global(cloneObj); 57 }, val) 58 }) 59 60 // Note: these are not [NewObject] and can be cached. But across globals? 61 ;[["getElementsByTagName", "x"], 62 ["getElementsByTagNameNS", null, "x"], 63 ["getElementsByClassName", "x"]].forEach(function(val) { 64 test(function() { 65 const method = val.shift(); 66 const obj = self[0].document[method](...val); 67 assert_global(obj) 68 69 const obj2 = Document.prototype[method].call(self[0].document, ...val); 70 assert_global(obj) 71 72 assert_equals(obj, obj2) // XXX this might be controversial 73 }, val[0]) 74 }) 75 76 ;[["createDocumentType", "x", "", ""], 77 ["createDocument", null, "", null], 78 ["createHTMLDocument", "x"]].forEach(function(val) { 79 test(function() { 80 const method = val.shift(); 81 let obj = self[0].document.implementation[method](...val); 82 assert_global(obj) 83 84 obj = DOMImplementation.prototype[method].call(self[0].document.implementation, ...val); 85 assert_global(obj) 86 }, val[0]) 87 }) 88 89 ;[["item", 0], 90 ["getNamedItem", "test"], 91 ["getNamedItemNS", null, "test"]].forEach(function(val) { 92 test(function() { 93 const method = val.shift(); 94 const obj = self[0].document.body.attributes[method](...val); 95 assert_global(obj) 96 97 const obj2 = NamedNodeMap.prototype[method].call(self[0].document.body.attributes, ...val); 98 assert_global(obj) 99 100 assert_equals(obj, obj2) 101 }, "NamedNodeMap " + val[0]) 102 }) 103 104 test(function() { 105 var c = self[0].document.createTextNode(""), 106 obj = c.splitText(0) 107 assert_global(obj) 108 109 obj = Text.prototype.splitText.call(c, "") 110 assert_global(obj) 111 }, "splitText") 112 113 ;["extractContents", 114 "cloneContents", 115 "cloneRange"].forEach(function(val) { 116 test(function() { 117 var c = self[0].document.createRange(), 118 obj = c[val]() 119 assert_global(obj) 120 121 obj = Range.prototype[val].call(c) 122 assert_global(obj) 123 }, val) 124 }) 125 126 ;["2d", "webgl"].forEach(function(val) { 127 test(function() { 128 var c = self[0].document.createElement("canvas"), 129 obj = c.getContext(val) 130 131 // WebGL might not be enabled in this environment 132 if (!obj && val === "webgl") { 133 return; 134 } 135 136 assert_global(obj) 137 obj = HTMLCanvasElement.prototype.getContext.call(c, val) 138 assert_global(obj) 139 }, "getContext " + val) 140 }) 141 142 ;[["createImageData", 5, 5], 143 ["getImageData", 5, 5, 5, 5]].forEach(function(val) { 144 test(function() { 145 const method = val.shift(); 146 const c = self[0].document.createElement("canvas").getContext("2d"); 147 let obj = c[method](...val); 148 assert_global(obj) 149 assert_global(obj.data) 150 151 obj = CanvasRenderingContext2D.prototype[method].call(c, ...val); 152 assert_global(obj) 153 assert_global(obj.data) 154 }, val[0]) 155 }) 156 157 test(function() { 158 var c = new self[0].FontFace("test", "about:blank"), 159 obj = c.load() 160 assert_global(obj) 161 162 obj = FontFace.prototype.load.call(c) 163 assert_global(obj) 164 }, "FontFace's load()") 165 166 done() 167 } 168 </script>