adoption.window.js (24995B)
1 // Target document has a global registry 2 3 test(t => { 4 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 5 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 6 const element = document.createElement('div'); 7 assert_equals(element.customElementRegistry, customElements); 8 9 contentDocument.body.appendChild(element); 10 assert_equals(element.customElementRegistry, contentDocument.customElementRegistry); 11 }, "Adoption with global registry"); 12 13 test(t => { 14 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 15 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 16 const element = document.createElement('div', { customElementRegistry: customElements }); 17 assert_equals(element.customElementRegistry, customElements); 18 19 contentDocument.body.appendChild(element); 20 assert_equals(element.customElementRegistry, contentDocument.customElementRegistry); 21 }, "Adoption with explicit global registry"); 22 23 test(t => { 24 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 25 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 26 const scoped = new CustomElementRegistry(); 27 const element = document.createElement('div', { customElementRegistry: scoped }); 28 assert_equals(element.customElementRegistry, scoped); 29 30 contentDocument.body.appendChild(element); 31 assert_equals(element.customElementRegistry, scoped); 32 }, "Adoption with scoped registry"); 33 34 test(t => { 35 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 36 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 37 const element = document.createElement('div'); 38 assert_equals(element.customElementRegistry, customElements); 39 40 const scoped = new CustomElementRegistry(); 41 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 42 contentDocument.body.appendChild(scopedElement); 43 assert_equals(scopedElement.customElementRegistry, scoped); 44 scopedElement.appendChild(element); 45 assert_equals(element.customElementRegistry, contentDocument.customElementRegistry); 46 }, "Adoption with global registry into a scoped registry"); 47 48 test(t => { 49 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 50 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 51 const element = document.createElement('div', { customElementRegistry: customElements }); 52 assert_equals(element.customElementRegistry, customElements); 53 54 const scoped = new CustomElementRegistry(); 55 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 56 contentDocument.body.appendChild(scopedElement); 57 assert_equals(scopedElement.customElementRegistry, scoped); 58 scopedElement.appendChild(element); 59 assert_equals(element.customElementRegistry, contentDocument.customElementRegistry); 60 }, "Adoption with explicit global registry into a scoped registry"); 61 62 test(t => { 63 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 64 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 65 const scoped = new CustomElementRegistry(); 66 const element = document.createElement('div', { customElementRegistry: scoped }); 67 assert_equals(element.customElementRegistry, scoped); 68 69 const scoped2 = new CustomElementRegistry(); 70 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 71 contentDocument.body.appendChild(scopedElement); 72 assert_equals(scopedElement.customElementRegistry, scoped2); 73 scopedElement.appendChild(element); 74 assert_equals(element.customElementRegistry, scoped); 75 }, "Adoption with scoped registry into a scoped registry"); 76 77 test(t => { 78 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 79 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 80 const element = document.createElement('div'); 81 const elementShadow = element.attachShadow({ mode: "closed" }); 82 assert_equals(elementShadow.customElementRegistry, customElements); 83 84 contentDocument.body.appendChild(element); 85 // In certain implementations touching element.customElementRegistry can poison the results so we 86 // don't do that here. 87 assert_equals(elementShadow.customElementRegistry, contentDocument.customElementRegistry); 88 }, "Adoption including shadow root with global registry"); 89 90 test(t => { 91 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 92 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 93 const element = document.createElement('div'); 94 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 95 assert_equals(elementShadow.customElementRegistry, customElements); 96 97 contentDocument.body.appendChild(element); 98 assert_equals(elementShadow.customElementRegistry, contentDocument.customElementRegistry); 99 }, "Adoption including shadow root with explicit global registry"); 100 101 test(t => { 102 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 103 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 104 const element = document.createElement('div'); 105 const scoped = new CustomElementRegistry(); 106 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 107 assert_equals(elementShadow.customElementRegistry, scoped); 108 109 contentDocument.body.appendChild(element); 110 assert_equals(elementShadow.customElementRegistry, scoped); 111 }, "Adoption including shadow root with scoped registry"); 112 113 test(t => { 114 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 115 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 116 const element = document.createElement('div'); 117 const elementShadow = element.attachShadow({ mode: "closed" }); 118 assert_equals(elementShadow.customElementRegistry, customElements); 119 120 const scoped = new CustomElementRegistry(); 121 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 122 contentDocument.body.appendChild(scopedElement); 123 assert_equals(scopedElement.customElementRegistry, scoped); 124 scopedElement.appendChild(element); 125 assert_equals(elementShadow.customElementRegistry, contentDocument.customElementRegistry); 126 }, "Adoption including shadow root with global registry into a scoped registry"); 127 128 test(t => { 129 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 130 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 131 const element = document.createElement('div'); 132 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 133 assert_equals(elementShadow.customElementRegistry, customElements); 134 135 const scoped = new CustomElementRegistry(); 136 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 137 contentDocument.body.appendChild(scopedElement); 138 assert_equals(scopedElement.customElementRegistry, scoped); 139 scopedElement.appendChild(element); 140 assert_equals(elementShadow.customElementRegistry, contentDocument.customElementRegistry); 141 }, "Adoption including shadow root with explicit global registry into a scoped registry"); 142 143 test(t => { 144 const contentDocument = document.body.appendChild(document.createElement('iframe')).contentDocument; 145 t.add_cleanup(() => contentDocument.defaultView.frameElement.remove()); 146 const element = document.createElement('div'); 147 const scoped = new CustomElementRegistry(); 148 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 149 assert_equals(elementShadow.customElementRegistry, scoped); 150 151 const scoped2 = new CustomElementRegistry(); 152 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 153 contentDocument.body.appendChild(scopedElement); 154 assert_equals(scopedElement.customElementRegistry, scoped2); 155 scopedElement.appendChild(element); 156 assert_equals(elementShadow.customElementRegistry, scoped); 157 }, "Adoption including shadow root with scoped registry into a scoped registry"); 158 159 160 // Target document has a null registry 161 162 test(t => { 163 const contentDocument = document.implementation.createHTMLDocument(); 164 const element = document.createElement('div'); 165 assert_equals(element.customElementRegistry, customElements); 166 167 contentDocument.body.appendChild(element); 168 assert_equals(element.customElementRegistry, null); 169 }, "Adoption with global registry (null registry target)"); 170 171 test(t => { 172 const contentDocument = document.implementation.createHTMLDocument(); 173 const element = document.createElement('div', { customElementRegistry: customElements }); 174 assert_equals(element.customElementRegistry, customElements); 175 176 contentDocument.body.appendChild(element); 177 assert_equals(element.customElementRegistry, null); 178 }, "Adoption with explicit global registry (null registry target)"); 179 180 test(t => { 181 const contentDocument = document.implementation.createHTMLDocument(); 182 const scoped = new CustomElementRegistry(); 183 const element = document.createElement('div', { customElementRegistry: scoped }); 184 assert_equals(element.customElementRegistry, scoped); 185 186 contentDocument.body.appendChild(element); 187 assert_equals(element.customElementRegistry, scoped); 188 }, "Adoption with scoped registry (null registry target)"); 189 190 test(t => { 191 const contentDocument = document.implementation.createHTMLDocument(); 192 const element = document.createElement('div'); 193 assert_equals(element.customElementRegistry, customElements); 194 195 const scoped = new CustomElementRegistry(); 196 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 197 contentDocument.body.appendChild(scopedElement); 198 assert_equals(scopedElement.customElementRegistry, scoped); 199 scopedElement.appendChild(element); 200 assert_equals(element.customElementRegistry, null); 201 }, "Adoption with global registry into a scoped registry (null registry target)"); 202 203 test(t => { 204 const contentDocument = document.implementation.createHTMLDocument(); 205 const element = document.createElement('div', { customElementRegistry: customElements }); 206 assert_equals(element.customElementRegistry, customElements); 207 208 const scoped = new CustomElementRegistry(); 209 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 210 contentDocument.body.appendChild(scopedElement); 211 assert_equals(scopedElement.customElementRegistry, scoped); 212 scopedElement.appendChild(element); 213 assert_equals(element.customElementRegistry, null); 214 }, "Adoption with explicit global registry into a scoped registry (null registry target)"); 215 216 test(t => { 217 const contentDocument = document.implementation.createHTMLDocument(); 218 const scoped = new CustomElementRegistry(); 219 const element = document.createElement('div', { customElementRegistry: scoped }); 220 assert_equals(element.customElementRegistry, scoped); 221 222 const scoped2 = new CustomElementRegistry(); 223 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 224 contentDocument.body.appendChild(scopedElement); 225 assert_equals(scopedElement.customElementRegistry, scoped2); 226 scopedElement.appendChild(element); 227 assert_equals(element.customElementRegistry, scoped); 228 }, "Adoption with scoped registry into a scoped registry (null registry target)"); 229 230 test(t => { 231 const contentDocument = document.implementation.createHTMLDocument(); 232 const element = document.createElement('div'); 233 const elementShadow = element.attachShadow({ mode: "closed" }); 234 assert_equals(elementShadow.customElementRegistry, customElements); 235 236 contentDocument.body.appendChild(element); 237 // In certain implementations touching element.customElementRegistry can poison the results so we 238 // don't do that here. 239 assert_equals(elementShadow.customElementRegistry, null); 240 }, "Adoption including shadow root with global registry (null registry target)"); 241 242 test(t => { 243 const contentDocument = document.implementation.createHTMLDocument(); 244 const element = document.createElement('div'); 245 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 246 assert_equals(elementShadow.customElementRegistry, customElements); 247 248 contentDocument.body.appendChild(element); 249 assert_equals(elementShadow.customElementRegistry, null); 250 }, "Adoption including shadow root with explicit global registry (null registry target)"); 251 252 test(t => { 253 const contentDocument = document.implementation.createHTMLDocument(); 254 const element = document.createElement('div'); 255 const scoped = new CustomElementRegistry(); 256 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 257 assert_equals(elementShadow.customElementRegistry, scoped); 258 259 contentDocument.body.appendChild(element); 260 assert_equals(elementShadow.customElementRegistry, scoped); 261 }, "Adoption including shadow root with scoped registry (null registry target)"); 262 263 test(t => { 264 const contentDocument = document.implementation.createHTMLDocument(); 265 const element = document.createElement('div'); 266 const elementShadow = element.attachShadow({ mode: "closed" }); 267 assert_equals(elementShadow.customElementRegistry, customElements); 268 269 const scoped = new CustomElementRegistry(); 270 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 271 contentDocument.body.appendChild(scopedElement); 272 assert_equals(scopedElement.customElementRegistry, scoped); 273 scopedElement.appendChild(element); 274 assert_equals(elementShadow.customElementRegistry, null); 275 }, "Adoption including shadow root with global registry into a scoped registry (null registry target)"); 276 277 test(t => { 278 const contentDocument = document.implementation.createHTMLDocument(); 279 const element = document.createElement('div'); 280 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 281 assert_equals(elementShadow.customElementRegistry, customElements); 282 283 const scoped = new CustomElementRegistry(); 284 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 285 contentDocument.body.appendChild(scopedElement); 286 assert_equals(scopedElement.customElementRegistry, scoped); 287 scopedElement.appendChild(element); 288 assert_equals(elementShadow.customElementRegistry, null); 289 }, "Adoption including shadow root with explicit global registry into a scoped registry (null registry target)"); 290 291 test(t => { 292 const contentDocument = document.implementation.createHTMLDocument(); 293 const element = document.createElement('div'); 294 const scoped = new CustomElementRegistry(); 295 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 296 assert_equals(elementShadow.customElementRegistry, scoped); 297 298 const scoped2 = new CustomElementRegistry(); 299 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 300 contentDocument.body.appendChild(scopedElement); 301 assert_equals(scopedElement.customElementRegistry, scoped2); 302 scopedElement.appendChild(element); 303 assert_equals(elementShadow.customElementRegistry, scoped); 304 }, "Adoption including shadow root with scoped registry into a scoped registry (null registry target)"); 305 306 307 // Target document has a scoped registry 308 309 test(t => { 310 const documentRegistry = new CustomElementRegistry(); 311 const contentDocument = document.implementation.createHTMLDocument(); 312 documentRegistry.initialize(contentDocument); 313 assert_equals(contentDocument.customElementRegistry, documentRegistry); 314 const element = document.createElement('div'); 315 assert_equals(element.customElementRegistry, customElements); 316 317 contentDocument.body.appendChild(element); 318 assert_equals(element.customElementRegistry, null); 319 }, "Adoption with global registry (scoped registry target)"); 320 321 test(t => { 322 const documentRegistry = new CustomElementRegistry(); 323 const contentDocument = document.implementation.createHTMLDocument(); 324 documentRegistry.initialize(contentDocument); 325 assert_equals(contentDocument.customElementRegistry, documentRegistry); 326 327 const element = document.createElement('div', { customElementRegistry: customElements }); 328 assert_equals(element.customElementRegistry, customElements); 329 330 contentDocument.body.appendChild(element); 331 assert_equals(element.customElementRegistry, null); 332 }, "Adoption with explicit global registry (scoped registry target)"); 333 334 test(t => { 335 const documentRegistry = new CustomElementRegistry(); 336 const contentDocument = document.implementation.createHTMLDocument(); 337 documentRegistry.initialize(contentDocument); 338 assert_equals(contentDocument.customElementRegistry, documentRegistry); 339 340 const scoped = new CustomElementRegistry(); 341 const element = document.createElement('div', { customElementRegistry: scoped }); 342 assert_equals(element.customElementRegistry, scoped); 343 344 contentDocument.body.appendChild(element); 345 assert_equals(element.customElementRegistry, scoped); 346 }, "Adoption with scoped registry (scoped registry target)"); 347 348 test(t => { 349 const documentRegistry = new CustomElementRegistry(); 350 const contentDocument = document.implementation.createHTMLDocument(); 351 documentRegistry.initialize(contentDocument); 352 assert_equals(contentDocument.customElementRegistry, documentRegistry); 353 354 const element = document.createElement('div'); 355 assert_equals(element.customElementRegistry, customElements); 356 357 const scoped = new CustomElementRegistry(); 358 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 359 contentDocument.body.appendChild(scopedElement); 360 assert_equals(scopedElement.customElementRegistry, scoped); 361 scopedElement.appendChild(element); 362 assert_equals(element.customElementRegistry, null); 363 }, "Adoption with global registry into a scoped registry (scoped registry target)"); 364 365 test(t => { 366 const documentRegistry = new CustomElementRegistry(); 367 const contentDocument = document.implementation.createHTMLDocument(); 368 documentRegistry.initialize(contentDocument); 369 assert_equals(contentDocument.customElementRegistry, documentRegistry); 370 371 const element = document.createElement('div', { customElementRegistry: customElements }); 372 assert_equals(element.customElementRegistry, customElements); 373 374 const scoped = new CustomElementRegistry(); 375 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 376 contentDocument.body.appendChild(scopedElement); 377 assert_equals(scopedElement.customElementRegistry, scoped); 378 scopedElement.appendChild(element); 379 assert_equals(element.customElementRegistry, null); 380 }, "Adoption with explicit global registry into a scoped registry (scoped registry target)"); 381 382 test(t => { 383 const documentRegistry = new CustomElementRegistry(); 384 const contentDocument = document.implementation.createHTMLDocument(); 385 documentRegistry.initialize(contentDocument); 386 assert_equals(contentDocument.customElementRegistry, documentRegistry); 387 388 const scoped = new CustomElementRegistry(); 389 const element = document.createElement('div', { customElementRegistry: scoped }); 390 assert_equals(element.customElementRegistry, scoped); 391 392 const scoped2 = new CustomElementRegistry(); 393 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 394 contentDocument.body.appendChild(scopedElement); 395 assert_equals(scopedElement.customElementRegistry, scoped2); 396 scopedElement.appendChild(element); 397 assert_equals(element.customElementRegistry, scoped); 398 }, "Adoption with scoped registry into a scoped registry (scoped registry target)"); 399 400 test(t => { 401 const documentRegistry = new CustomElementRegistry(); 402 const contentDocument = document.implementation.createHTMLDocument(); 403 documentRegistry.initialize(contentDocument); 404 assert_equals(contentDocument.customElementRegistry, documentRegistry); 405 406 const element = document.createElement('div'); 407 const elementShadow = element.attachShadow({ mode: "closed" }); 408 assert_equals(elementShadow.customElementRegistry, customElements); 409 410 contentDocument.body.appendChild(element); 411 // In certain implementations touching element.customElementRegistry can poison the results so we 412 // don't do that here. 413 assert_equals(elementShadow.customElementRegistry, null); 414 }, "Adoption including shadow root with global registry (scoped registry target)"); 415 416 test(t => { 417 const documentRegistry = new CustomElementRegistry(); 418 const contentDocument = document.implementation.createHTMLDocument(); 419 documentRegistry.initialize(contentDocument); 420 assert_equals(contentDocument.customElementRegistry, documentRegistry); 421 422 const element = document.createElement('div'); 423 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 424 assert_equals(elementShadow.customElementRegistry, customElements); 425 426 contentDocument.body.appendChild(element); 427 assert_equals(elementShadow.customElementRegistry, null); 428 }, "Adoption including shadow root with explicit global registry (scoped registry target)"); 429 430 test(t => { 431 const documentRegistry = new CustomElementRegistry(); 432 const contentDocument = document.implementation.createHTMLDocument(); 433 documentRegistry.initialize(contentDocument); 434 assert_equals(contentDocument.customElementRegistry, documentRegistry); 435 436 const element = document.createElement('div'); 437 const scoped = new CustomElementRegistry(); 438 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 439 assert_equals(elementShadow.customElementRegistry, scoped); 440 441 contentDocument.body.appendChild(element); 442 assert_equals(elementShadow.customElementRegistry, scoped); 443 }, "Adoption including shadow root with scoped registry (scoped registry target)"); 444 445 test(t => { 446 const documentRegistry = new CustomElementRegistry(); 447 const contentDocument = document.implementation.createHTMLDocument(); 448 documentRegistry.initialize(contentDocument); 449 assert_equals(contentDocument.customElementRegistry, documentRegistry); 450 451 const element = document.createElement('div'); 452 const elementShadow = element.attachShadow({ mode: "closed" }); 453 assert_equals(elementShadow.customElementRegistry, customElements); 454 455 const scoped = new CustomElementRegistry(); 456 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 457 contentDocument.body.appendChild(scopedElement); 458 assert_equals(scopedElement.customElementRegistry, scoped); 459 scopedElement.appendChild(element); 460 assert_equals(elementShadow.customElementRegistry, null); 461 }, "Adoption including shadow root with global registry into a scoped registry (scoped registry target)"); 462 463 test(t => { 464 const documentRegistry = new CustomElementRegistry(); 465 const contentDocument = document.implementation.createHTMLDocument(); 466 documentRegistry.initialize(contentDocument); 467 assert_equals(contentDocument.customElementRegistry, documentRegistry); 468 const element = document.createElement('div'); 469 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: customElements }); 470 assert_equals(elementShadow.customElementRegistry, customElements); 471 472 const scoped = new CustomElementRegistry(); 473 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped }); 474 contentDocument.body.appendChild(scopedElement); 475 assert_equals(scopedElement.customElementRegistry, scoped); 476 scopedElement.appendChild(element); 477 assert_equals(elementShadow.customElementRegistry, null); 478 }, "Adoption including shadow root with explicit global registry into a scoped registry (scoped registry target)"); 479 480 test(t => { 481 const documentRegistry = new CustomElementRegistry(); 482 const contentDocument = document.implementation.createHTMLDocument(); 483 documentRegistry.initialize(contentDocument); 484 assert_equals(contentDocument.customElementRegistry, documentRegistry); 485 const element = document.createElement('div'); 486 const scoped = new CustomElementRegistry(); 487 const elementShadow = element.attachShadow({ mode: "closed", customElementRegistry: scoped }); 488 assert_equals(elementShadow.customElementRegistry, scoped); 489 490 const scoped2 = new CustomElementRegistry(); 491 const scopedElement = contentDocument.createElement('div', { customElementRegistry: scoped2 }); 492 contentDocument.body.appendChild(scopedElement); 493 assert_equals(scopedElement.customElementRegistry, scoped2); 494 scopedElement.appendChild(element); 495 assert_equals(elementShadow.customElementRegistry, scoped); 496 }, "Adoption including shadow root with scoped registry into a scoped registry (scoped registry target)");