(opt_runtimeOff, opt_beforeLayoutCallback)
| 213 | * }>} |
| 214 | */ |
| 215 | export function createIframePromise(opt_runtimeOff, opt_beforeLayoutCallback) { |
| 216 | return new Promise(function (resolve, reject) { |
| 217 | const iframe = document.createElement('iframe'); |
| 218 | iframe.name = 'test_' + iframeCount++; |
| 219 | iframe.srcdoc = '<!doctype><html><head><body><div id=parent></div>'; |
| 220 | iframe.onload = function () { |
| 221 | // Flag as being a test window. |
| 222 | iframe.contentWindow.__AMP_TEST_IFRAME = true; |
| 223 | iframe.contentWindow.testLocation = new FakeLocation( |
| 224 | window.location.href, |
| 225 | iframe.contentWindow |
| 226 | ); |
| 227 | if (opt_runtimeOff) { |
| 228 | iframe.contentWindow.name = '__AMP__off=1'; |
| 229 | } |
| 230 | // Required for timer service, which now refers not to the global |
| 231 | // Promise but the passed in window Promise in it's constructor as |
| 232 | // it is an embedabble service. b\17733 |
| 233 | iframe.contentWindow.Promise = window.Promise; |
| 234 | installDocService(iframe.contentWindow, /* isSingleDoc */ true); |
| 235 | const ampdoc = Services.ampdocServiceFor( |
| 236 | iframe.contentWindow |
| 237 | ).getSingleDoc(); |
| 238 | installExtensionsService(iframe.contentWindow); |
| 239 | installRuntimeServices(iframe.contentWindow); |
| 240 | // The anonymous class parameter allows us to detect native classes vs |
| 241 | // transpiled classes. |
| 242 | installCustomElements(iframe.contentWindow, class {}); |
| 243 | installAmpdocServices(ampdoc); |
| 244 | Services.resourcesForDoc(ampdoc).ampInitComplete(); |
| 245 | // Act like no other elements were loaded by default. |
| 246 | installStylesLegacy( |
| 247 | iframe.contentWindow.document, |
| 248 | ampDocCss + ampSharedCss, |
| 249 | () => { |
| 250 | resolve({ |
| 251 | win: iframe.contentWindow, |
| 252 | doc: iframe.contentWindow.document, |
| 253 | ampdoc, |
| 254 | iframe, |
| 255 | addElement: function (element) { |
| 256 | const iWin = iframe.contentWindow; |
| 257 | const p = onInsert(iWin) |
| 258 | .then(() => { |
| 259 | return element.buildInternal(); |
| 260 | }) |
| 261 | .then(() => { |
| 262 | if (!element.getPlaceholder()) { |
| 263 | const placeholder = element.createPlaceholder(); |
| 264 | if (placeholder) { |
| 265 | element.appendChild(placeholder); |
| 266 | } |
| 267 | } |
| 268 | const resources = Services.resourcesForDoc(ampdoc); |
| 269 | const resource = |
| 270 | resources.getResourceForElementOptional(element); |
| 271 | if (resource) { |
| 272 | resource.measure(); |
no test coverage detected