promise-job-entry-different-function-realm.html (4043B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Entry settings object for promise jobs when the function realm is different from the test realm</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <!-- https://github.com/whatwg/html/pull/5212 --> 7 <!-- https://github.com/whatwg/html/issues/1426 --> 8 9 <!-- This is what would normally be considered the entry page. However, we use functions from the 10 resources/function/function.html realm. So window.open() should resolve relative to that realm 11 inside promise jobs. --> 12 13 <iframe src="resources/promise-job-entry-incumbent.html"></iframe> 14 <iframe src="resources/function/function.html" id="function-frame"></iframe> 15 16 <script> 17 setup({ explicit_done: true }); 18 19 const relativeURL = "resources/window-to-open.html"; 20 const expectedURL = (new URL(relativeURL, document.querySelector("#function-frame").src)).href; 21 22 const incumbentWindow = frames[0]; 23 const functionWindow = frames[1]; 24 const FunctionFromAnotherWindow = frames[1].Function; 25 26 window.onload = () => { 27 async_test(t => { 28 const func = FunctionFromAnotherWindow(` 29 const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0]; 30 31 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 32 w.onload = t.step_func_done(() => { 33 t.add_cleanup(() => w.close()); 34 assert_equals(w.location.href, expectedURL); 35 }); 36 `); 37 38 Promise.resolve([incumbentWindow, relativeURL, t, assert_equals, expectedURL]).then(func); 39 }, "Fulfillment handler on fulfilled promise"); 40 41 async_test(t => { 42 const func = FunctionFromAnotherWindow(` 43 const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0]; 44 45 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 46 w.onload = t.step_func_done(() => { 47 t.add_cleanup(() => w.close()); 48 assert_equals(w.location.href, expectedURL); 49 }); 50 `); 51 52 Promise.reject([incumbentWindow, relativeURL, t, assert_equals, expectedURL]).catch(func); 53 }, "Rejection handler on rejected promise"); 54 55 async_test(t => { 56 let resolve; 57 const p = new Promise(r => { resolve = r; }); 58 59 const func = FunctionFromAnotherWindow(` 60 const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0]; 61 62 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 63 w.onload = t.step_func_done(() => { 64 t.add_cleanup(() => w.close()); 65 assert_equals(w.location.href, expectedURL); 66 }); 67 `); 68 69 p.then(func); 70 t.step_timeout(() => resolve([incumbentWindow, relativeURL, t, assert_equals, expectedURL]), 0); 71 }, "Fulfillment handler on pending-then-fulfilled promise"); 72 73 async_test(t => { 74 let reject; 75 const p = new Promise((_, r) => { reject = r; }); 76 77 const func = FunctionFromAnotherWindow(` 78 const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = arguments[0]; 79 80 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 81 w.onload = t.step_func_done(() => { 82 t.add_cleanup(() => w.close()); 83 assert_equals(w.location.href, expectedURL); 84 }); 85 `); 86 87 p.catch(func); 88 t.step_timeout(() => reject([incumbentWindow, relativeURL, t, assert_equals, expectedURL]), 0); 89 }, "Rejection handler on pending-then-rejected promise"); 90 91 async_test(t => { 92 t.add_cleanup(() => { delete frames[1].args; }); 93 frames[1].args = [incumbentWindow, relativeURL, t, assert_equals, expectedURL]; 94 95 const func = FunctionFromAnotherWindow(` 96 const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = window.args; 97 98 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 99 w.onload = t.step_func_done(() => { 100 t.add_cleanup(() => w.close()); 101 assert_equals(w.location.href, expectedURL); 102 }); 103 `); 104 105 const thenable = { then: func }; 106 107 Promise.resolve(thenable); 108 }, "Thenable resolution"); 109 110 done(); 111 }; 112 </script>