11cb0ef41Sopenharmony_ci<!DOCTYPE html> 21cb0ef41Sopenharmony_ci<meta charset="utf-8"> 31cb0ef41Sopenharmony_ci<title>Incumbent settings object for host functions</title> 41cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script> 51cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script> 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci<!-- This is the entry page. --> 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci<iframe src="resources/incumbent-incumbent.html"></iframe> 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci<script> 121cb0ef41Sopenharmony_cisetup({ explicit_done: true }); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci// postMessage should pick the incumbent page as its .source value to set on the MessageEvent, even 151cb0ef41Sopenharmony_ci// inside host functions. 161cb0ef41Sopenharmony_ciconst expectedURL = (new URL("resources/incumbent-incumbent.html", location.href)).href; 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cilet testId = 0; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciwindow.onload = () => { 211cb0ef41Sopenharmony_ci const relevantWindow = frames[0].document.querySelector("#r").contentWindow; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci function setupTest(t) { 241cb0ef41Sopenharmony_ci ++testId; 251cb0ef41Sopenharmony_ci const thisTestId = testId; 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci relevantWindow.addEventListener("messagereceived", t.step_func(e => { 281cb0ef41Sopenharmony_ci const [receivedTestId, receivedSourceURL] = e.detail; 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci if (receivedTestId !== thisTestId) { 311cb0ef41Sopenharmony_ci return; 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci assert_equals(receivedSourceURL, expectedURL); 351cb0ef41Sopenharmony_ci t.done(); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci return thisTestId; 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci async_test(t => { 421cb0ef41Sopenharmony_ci const thisTestId = setupTest(t); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci frames[0].runWindowPostMessageVeryIndirectly(thisTestId, "*"); 451cb0ef41Sopenharmony_ci }, "Sanity check: this all works as expected synchronously"); 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci async_test(t => { 481cb0ef41Sopenharmony_ci const thisTestId = setupTest(t); 491cb0ef41Sopenharmony_ci frames[0].runWindowPostMessageVeryIndirectlyWithNoUserCode(thisTestId, "*"); 501cb0ef41Sopenharmony_ci }, "Start function"); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci done(); 531cb0ef41Sopenharmony_ci}; 541cb0ef41Sopenharmony_ci</script> 55