summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webidl/current-realm.html
blob: 29e07d1f79edc05d69ccc351247894984488ad92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!-- This tests the agreed upon outcome for https://www.w3.org/Bugs/Public/show_bug.cgi?id=24652
     that has not been reflected in the IDL standard yet due to lack of editing resources.

     TODO: https://github.com/w3c/webcrypto/issues/85 -->
<!DOCTYPE html>
<meta charset=utf-8>
<title>Current Realm</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<iframe srcdoc="<body test>"></iframe>
<script>
 setup({explicit_done:true})

 function isObjectFromGlobal(object, global) {
   return object instanceof global.Object;
 }
 function assert_global(obj) {
   assert_false(isObjectFromGlobal(obj, self), obj + " should not be from top-level Realm")
   assert_true(isObjectFromGlobal(obj, self[0]), obj + " should be from <iframe> Realm")
 }

 onload = function() {
   [["querySelectorAll", "test"],
    ["createElement", "x"],
    ["createElementNS", null, "x"],
    ["createDocumentFragment"],
    ["createTextNode", "test"],
    ["createComment", "test"],
    ["createProcessingInstruction", "x", "x"],
    ["createAttribute", "x"],
    ["createAttributeNS", "x", "x"],
    ["createEvent", "Event"],
    ["createRange"],
    ["createNodeIterator", document.head],
    ["createTreeWalker", document.head]].forEach(function(val) {
     test(function() {
       const method = val.shift();
       let obj = self[0].document[method](...val);
       assert_global(obj)

       obj = Document.prototype[method].call(self[0].document, ...val);
       assert_global(obj)
     }, val[0])
   })

   ;["Request", "Response"].forEach(val => {
     test(() => {
       const obj = new self[0][val]("about:blank");
       assert_global(obj);

       const cloneObj = obj.clone();
       assert_global(cloneObj);

       const involvedCloneObj = self[val].prototype["clone"].call(cloneObj);
       assert_global(cloneObj);
     }, val)
   })

   // Note: these are not [NewObject] and can be cached. But across globals?
   ;[["getElementsByTagName", "x"],
     ["getElementsByTagNameNS", null, "x"],
     ["getElementsByClassName", "x"]].forEach(function(val) {
     test(function() {
       const method = val.shift();
       const obj = self[0].document[method](...val);
       assert_global(obj)

       const obj2 = Document.prototype[method].call(self[0].document, ...val);
       assert_global(obj)

       assert_equals(obj, obj2) // XXX this might be controversial
     }, val[0])
   })

   ;[["createDocumentType", "x", "", ""],
     ["createDocument", null, "", null],
     ["createHTMLDocument", "x"]].forEach(function(val) {
     test(function() {
       const method = val.shift();
       let obj = self[0].document.implementation[method](...val);
       assert_global(obj)

       obj = DOMImplementation.prototype[method].call(self[0].document.implementation, ...val);
       assert_global(obj)
     }, val[0])
   })

   ;[["item", 0],
     ["getNamedItem", "test"],
     ["getNamedItemNS", null, "test"]].forEach(function(val) {
     test(function() {
       const method = val.shift();
       const obj = self[0].document.body.attributes[method](...val);
       assert_global(obj)

       const obj2 = NamedNodeMap.prototype[method].call(self[0].document.body.attributes, ...val);
       assert_global(obj)

       assert_equals(obj, obj2)
     }, "NamedNodeMap " + val[0])
   })

   test(function() {
     var c = self[0].document.createTextNode(""),
         obj = c.splitText(0)
     assert_global(obj)

     obj = Text.prototype.splitText.call(c, "")
     assert_global(obj)
   }, "splitText")

   ;["extractContents",
     "cloneContents",
     "cloneRange"].forEach(function(val) {
     test(function() {
       var c = self[0].document.createRange(),
           obj = c[val]()
       assert_global(obj)

       obj = Range.prototype[val].call(c)
       assert_global(obj)
     }, val)
   })

   ;["2d", "webgl"].forEach(function(val) {
     test(function() {
       var c = self[0].document.createElement("canvas"),
           obj = c.getContext(val)

       // WebGL might not be enabled in this environment
       if (!obj && val === "webgl") {
         return;
       }

       assert_global(obj)
       obj = HTMLCanvasElement.prototype.getContext.call(c, val)
       assert_global(obj)
     }, "getContext " + val)
   })

   ;[["createImageData", 5, 5],
     ["getImageData", 5, 5, 5, 5]].forEach(function(val) {
     test(function() {
       const method = val.shift();
       const c = self[0].document.createElement("canvas").getContext("2d");
       let obj = c[method](...val);
       assert_global(obj)
       assert_global(obj.data)

       obj = CanvasRenderingContext2D.prototype[method].call(c, ...val);
       assert_global(obj)
       assert_global(obj.data)
     }, val[0])
   })

   test(function() {
     var c = new self[0].FontFace("test", "about:blank"),
         obj = c.load()
     assert_global(obj)

     obj = FontFace.prototype.load.call(c)
     assert_global(obj)
   }, "FontFace's load()")

   done()
 }
</script>