| <!DOCTYPE html> |
| <meta charset="utf-8"> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script src="resources/callback-function-detached-frame-common.js"></script> |
| |
| <body> |
| |
| <div id="mutationObserverTestRoot" hidden></div> |
| |
| <script> |
| const IFRAME_SRC = "resources/callback-function-detached-frame-mutation-observer-iframe.html"; |
| |
| promise_test(async t => { |
| const iframe = await createIframe(t, IFRAME_SRC); |
| const mutationObserver = iframe.contentWindow.createMutationObserver(); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 0); |
| scheduleObservedMutation(); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 1); |
| }, "Callback function, originated in an <iframe>, is invoked if <iframe> is connected"); |
| |
| promise_test(async t => { |
| const iframe = await createIframe(t, IFRAME_SRC); |
| const mutationObserver = iframe.contentWindow.createMutationObserver(Function); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 0); |
| |
| iframe.remove(); |
| assert_equals(iframe.contentWindow, null); |
| |
| scheduleObservedMutation(); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 1); |
| }, "Callback function, originated in an <iframe> via main window's Function constructor, is invoked even if <iframe> is disconnected"); |
| |
| promise_test(async t => { |
| const iframe = await createIframe(t, IFRAME_SRC); |
| const mutationObserver = iframe.contentWindow.createMutationObserver(); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 0); |
| |
| iframe.remove(); |
| assert_equals(iframe.contentWindow, null); |
| |
| scheduleObservedMutation(); |
| |
| await sleep(100); |
| assert_equals(mutationObserver.callbackInvocations, 0); |
| }, "Callback function, originated in an <iframe>, is not invoked if <iframe> is disconnected"); |
| |
| function scheduleObservedMutation() { |
| mutationObserverTestRoot.append("foo"); |
| } |
| </script> |