promise-job-entry.html (3214B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Entry settings object for promise jobs</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 the entry page, so window.open() should resolve relative to it, even inside promise jobs. --> 10 11 <iframe src="resources/promise-job-entry-incumbent.html"></iframe> 12 13 <script> 14 setup({ explicit_done: true }); 15 16 const relativeURL = "resources/window-to-open.html"; 17 const expectedURL = (new URL(relativeURL, location.href)).href; 18 19 const incumbentWindow = frames[0]; 20 21 window.onload = () => { 22 async_test(t => { 23 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 24 w.onload = t.step_func_done(() => { 25 t.add_cleanup(() => w.close()); 26 assert_equals(w.location.href, expectedURL); 27 }); 28 }, "Sanity check: this all works as expected with no promises involved"); 29 30 async_test(t => { 31 // No t.step_func because that could change the realms 32 Promise.resolve().then(() => { 33 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 34 w.onload = t.step_func_done(() => { 35 t.add_cleanup(() => w.close()); 36 assert_equals(w.location.href, expectedURL); 37 }); 38 }); 39 }, "Fulfillment handler on fulfilled promise"); 40 41 async_test(t => { 42 // No t.step_func because that could change the realms 43 Promise.reject().catch(() => { 44 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 45 w.onload = t.step_func_done(() => { 46 t.add_cleanup(() => w.close()); 47 assert_equals(w.location.href, expectedURL); 48 }); 49 }); 50 }, "Rejection handler on rejected promise"); 51 52 async_test(t => { 53 let resolve; 54 const p = new Promise(r => { resolve = r; }); 55 56 // No t.step_func because that could change the realms 57 p.then(() => { 58 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 59 w.onload = t.step_func_done(() => { 60 t.add_cleanup(() => w.close()); 61 assert_equals(w.location.href, expectedURL); 62 }); 63 }); 64 65 t.step_timeout(resolve, 0); 66 }, "Fulfillment handler on pending-then-fulfilled promise"); 67 68 async_test(t => { 69 let reject; 70 const p = new Promise((_, r) => { reject = r; }); 71 72 // No t.step_func because that could change the realms 73 p.catch(() => { 74 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 75 w.onload = t.step_func_done(() => { 76 t.add_cleanup(() => w.close()); 77 assert_equals(w.location.href, expectedURL); 78 }); 79 }); 80 81 t.step_timeout(reject, 0); 82 }, "Rejection handler on pending-then-rejected promise"); 83 84 async_test(t => { 85 const thenable = { 86 // No t.step_func because that could change the realms 87 then(f) { 88 const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); 89 w.onload = t.step_func_done(() => { 90 t.add_cleanup(() => w.close()); 91 assert_equals(w.location.href, expectedURL); 92 }); 93 } 94 }; 95 96 Promise.resolve(thenable); 97 }, "Thenable resolution"); 98 99 done(); 100 }; 101 </script>