diff --git a/src/client/sandbox/iframe.ts b/src/client/sandbox/iframe.ts index 9b4f44b18..4de047961 100644 --- a/src/client/sandbox/iframe.ts +++ b/src/client/sandbox/iframe.ts @@ -3,7 +3,13 @@ import SandboxBase from './base'; import settings from '../settings'; import nativeMethods from '../sandbox/native-methods'; import DomProcessor from '../../processing/dom'; -import { isShadowUIElement, isIframeWithoutSrc, isIframeElement, isFrameElement } from '../utils/dom'; +import { + isShadowUIElement, + isIframeWithoutSrc, + isIframeElement, + isFrameElement, + isIframeWithSrcdoc, +} from '../utils/dom'; import { isFirefox, isWebKit, isIE } from '../utils/browser'; import NodeMutation from './node/mutation'; import CookieSandbox from './cookie'; @@ -153,6 +159,10 @@ export default class IframeSandbox extends SandboxBase { if (isShadowUIElement(el)) return; + // NOTE: the ready to init event will be raised by the self removing script + if (isIframeWithSrcdoc(el)) + return; + if (isIframeElement(el) && nativeMethods.contentWindowGetter.call(el) || isFrameElement(el) && nativeMethods.frameContentWindowGetter.call(el)) this._raiseReadyToInitEvent(el); diff --git a/test/client/fixtures/sandbox/iframe-test.js b/test/client/fixtures/sandbox/iframe-test.js index 30761b777..4b7ee912f 100644 --- a/test/client/fixtures/sandbox/iframe-test.js +++ b/test/client/fixtures/sandbox/iframe-test.js @@ -145,6 +145,38 @@ if (nativeMethods.iframeSrcdocGetter) { strictEqual(iframe.getAttribute('srcdoc'), html); strictEqual(nativeMethods.getAttribute.call(iframe, 'srcdoc'), htmlUtils.processHtml(html, { isPage: true }).replace(/(sessionId)/, '$1!i')); }); + + test('ready to init event should be raised after the document was initialized', function () { + var iframeLoadingEventRaised = false; + + var handler = function (iframe) { + iframeLoadingEventRaised = true; + + strictEqual(iframe.contentDocument.location.href, 'about:srcdoc'); + }; + + iframeSandbox.on(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler); + + var iframe = document.createElement('iframe'); + + iframe.setAttribute('srcdoc', '

simple markup

'); + iframe.id = 'test' + Date.now(); + + document.body.appendChild(iframe); + + return window.QUnitGlobals.wait(function () { + return true; + }) + .then(function () { + return window.QUnitGlobals.waitForIframe(iframe); + }) + .then(function () { + ok(iframeLoadingEventRaised); + + iframeSandbox.off(iframeSandbox.RUN_TASK_SCRIPT_EVENT, handler); + document.body.removeChild(iframe); + }); + }); } test('should not call the contentWindow getter while cloning iframe/frame from XMLDocument (GH-2554)', function () {