MCPcopy Index your code
hub / github.com/ampproject/amphtml / createIframePromise

Function createIframePromise

testing/iframe.js:215–294  ·  view source on GitHub ↗
(opt_runtimeOff, opt_beforeLayoutCallback)

Source from the content-addressed store, hash-verified

213 * }>}
214 */
215export 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();

Callers 15

getReplacementsFunction · 0.90
expandUrlAsyncFunction · 0.90
getWinFunction · 0.90
test-ad-helper.jsFile · 0.90
getPreconnectIframeFunction · 0.90
test-aduptech.jsFile · 0.90
test-ssp.jsFile · 0.90

Calls 15

installDocServiceFunction · 0.90
installExtensionsServiceFunction · 0.90
installRuntimeServicesFunction · 0.90
installAmpdocServicesFunction · 0.90
installStylesLegacyFunction · 0.85
onInsertFunction · 0.85
getSingleDocMethod · 0.80
buildInternalMethod · 0.80
createPlaceholderMethod · 0.80
resolveFunction · 0.50
ampInitCompleteMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected