MCPcopy Create free account
hub / github.com/ampproject/amphtml / setup

Method setup

testing/describes.js:602–669  ·  view source on GitHub ↗

@override

(env)

Source from the content-addressed store, hash-verified

600
601 /** @override */
602 setup(env) {
603 const {spec} = this;
604 return new Promise((resolve, reject) => {
605 const iframe = document.createElement('iframe');
606 env.iframe = iframe;
607 iframe.name = 'test_' + iframeCount++;
608 iframe.srcdoc =
609 '<!doctype html><html><head>' +
610 '<style>.i-amphtml-element {display: block;}</style>' +
611 '<body style="margin:0"><div id=parent></div>';
612 iframe.onload = function () {
613 const win = iframe.contentWindow;
614 env.win = win;
615
616 // Flag as being a test window.
617 win.__AMP_TEST_IFRAME = true;
618 // Set the testLocation on iframe to parent's location since location of
619 // the test iframe is about:srcdoc.
620 // Unfortunately location object is not configurable, so we have to
621 // define a new property.
622 win.testLocation = new FakeLocation(window.location.href, win);
623
624 if (!spec.allowExternalResources) {
625 doNotLoadExternalResourcesInTest(win, env.sandbox);
626 }
627
628 // Install AMP CSS if requested.
629 if (spec.ampCss) {
630 installRuntimeStylesPromise(win);
631 }
632
633 // Install AMP AD CSS if requested.
634 if (spec.ampAdCss) {
635 installAmpAdStylesPromise(win);
636 }
637
638 if (spec.fakeRegisterElement) {
639 const customElements = new FakeCustomElements(win);
640 Object.defineProperty(win, 'customElements', {
641 get: () => customElements,
642 });
643 } else if (!spec.skipCustomElementsPolyfill) {
644 // The anonymous class parameter allows us to detect native classes
645 // vs transpiled classes.
646 installCustomElements(win, class {});
647 }
648
649 // Install IntersectionObserver polyfill.
650 installIntersectionObserver(win);
651 installResizeObserver(win);
652
653 // Intercept event listeners
654 interceptEventListeners(win);
655 interceptEventListeners(win.document);
656 interceptEventListeners(win.document.documentElement);
657 interceptEventListeners(win.document.body);
658 env.interceptEventListeners = interceptEventListeners;
659

Callers

nothing calls this directly

Calls 7

interceptEventListenersFunction · 0.90
installResizeObserverFunction · 0.85
attachFetchMockFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected