Serenity Operating System
at master 36 lines 1.5 kB view raw
1describe("currentScript", () => { 2 loadLocalPage("/res/html/misc/blank.html"); 3 4 beforeInitialPageLoad(page => { 5 expect(page.document.currentScript).toBeNull(); 6 }); 7 8 afterInitialPageLoad(page => { 9 test("reset to null even if currentScript is adopted into another document", () => { 10 const script = page.document.createElement("script"); 11 script.id = "test"; 12 script.innerText = ` 13 const newDocument = globalThis.pageObject.document.implementation.createHTMLDocument(); 14 const thisScript = globalThis.pageObject.document.getElementById("test"); 15 16 // currentScript should stay the same even across adoption. 17 expect(globalThis.pageObject.document.currentScript).toBe(thisScript); 18 newDocument.adoptNode(thisScript); 19 expect(globalThis.pageObject.document.currentScript).toBe(thisScript); 20 `; 21 22 // currentScript should be null before and after running the script on insertion. 23 expect(page.document.currentScript).toBeNull(); 24 expect(script.ownerDocument).toBe(page.document); 25 26 globalThis.pageObject = page; 27 page.document.body.appendChild(script); 28 globalThis.pageObject = undefined; 29 30 expect(page.document.currentScript).toBeNull(); 31 expect(script.ownerDocument).not.toBe(page.document); 32 }); 33 }); 34 35 waitForPageToLoad(); 36});