Esempio n. 1
0
      iframe.onload = function() {
        const win = iframe.contentWindow;
        env.win = win;

        // Flag as being a test window.
        win.AMP_TEST_IFRAME = true;

        doNotLoadExternalResourcesInTest(win);

        // Install AMP CSS if requested.
        if (spec.ampCss) {
          installRuntimeStylesPromise(win);
        }

        if (spec.fakeRegisterElement) {
          win.customElements = new FakeCustomElements(win);
        } else {
          installCustomElements(win);
        }

        // Intercept event listeners
        interceptEventListeners(win);
        interceptEventListeners(win.document);
        interceptEventListeners(win.document.documentElement);
        interceptEventListeners(win.document.body);
        env.interceptEventListeners = interceptEventListeners;

        resolve();
      };
Esempio n. 2
0
      iframe.onload = function() {
        const win = iframe.contentWindow;
        env.win = win;

        // Flag as being a test window.
        win.AMP_TEST_IFRAME = true;
        // Set the testLocation on iframe to parent's location since location of
        // the test iframe is about:srcdoc.
        // Unfortunately location object is not configurable, so we have to
        // define a new property.
        win.testLocation = new FakeLocation(window.location.href, win);

        if (!spec.allowExternalResources) {
          doNotLoadExternalResourcesInTest(win);
        }

        // Install AMP CSS if requested.
        if (spec.ampCss) {
          installRuntimeStylesPromise(win);
        }

        // Install AMP AD CSS if requested.
        if (spec.ampAdCss) {
          installAmpAdStylesPromise(win);
        }

        if (spec.fakeRegisterElement) {
          const customElements = new FakeCustomElements(win);
          Object.defineProperty(win, 'customElements', {
            get: () => customElements,
          });
        } else {
          installCustomElements(win);
        }

        // Intercept event listeners
        interceptEventListeners(win);
        interceptEventListeners(win.document);
        interceptEventListeners(win.document.documentElement);
        interceptEventListeners(win.document.body);
        env.interceptEventListeners = interceptEventListeners;

        if (spec.mockFetch !== false) {
          attachFetchMock(env);
        }

        resolve();
      };
Esempio n. 3
0
 iframe.onload = function() {
   // Flag as being a test window.
   iframe.contentWindow.AMP_TEST_IFRAME = true;
   if (opt_runtimeOff) {
     iframe.contentWindow.name = '__AMP__off=1';
   }
   const ampdocService = installDocService(iframe.contentWindow, true);
   const ampdoc = ampdocService.getAmpDoc(iframe.contentWindow.document);
   installExtensionsService(iframe.contentWindow);
   installRuntimeServices(iframe.contentWindow);
   installCustomElements(iframe.contentWindow);
   installAmpdocServices(ampdoc);
   registerForUnitTest(iframe.contentWindow);
   // Act like no other elements were loaded by default.
   iframe.contentWindow.ampExtendedElements = {};
   installStyles(iframe.contentWindow.document, cssText, () => {
     resolve({
       win: iframe.contentWindow,
       doc: iframe.contentWindow.document,
       ampdoc: ampdoc,
       iframe: iframe,
       addElement: function(element) {
         const iWin = iframe.contentWindow;
         const p = onInsert(iWin).then(() => {
           element.build(true);
           if (!element.getPlaceholder()) {
             const placeholder = element.createPlaceholder();
             if (placeholder) {
               element.appendChild(placeholder);
             }
           }
           if (element.layoutCount_ == 0) {
             if (opt_beforeLayoutCallback) {
               opt_beforeLayoutCallback(element);
             }
             return element.layoutCallback().then(() => {
               return element;
             });
           }
           return element;
         });
         iWin.document.getElementById('parent')
             .appendChild(element);
         return p;
       },
     });
   });
 };
Esempio n. 4
0
// Importing the document-register-element module has the side effect
// of installing the custom elements polyfill if necessary.
import installCustomElements from
  'document-register-element/build/document-register-element.node';
import {
  install as installDOMTokenListToggle,
} from './polyfills/domtokenlist-toggle';
import {install as installDocContains} from './polyfills/document-contains';
import {install as installMathSign} from './polyfills/math-sign';
import {install as installObjectAssign} from './polyfills/object-assign';
import {install as installPromise} from './polyfills/promise';
import {install as installArrayIncludes} from './polyfills/array-includes';
import {getMode} from './mode';

/**
  Only install in closure binary and not in babel/browserify binary, since in
  the closure binary we strip out the `document-register-element` install side
  effect so we can tree shake the dependency correctly and we have to make
  sure to not `install` it during dev since the `install` is done as a side
  effect in importing the module.
*/
if (!getMode().localDev) {
  installCustomElements(self, 'auto');
}
installDOMTokenListToggle(self);
installMathSign(self);
installObjectAssign(self);
installPromise(self);
installDocContains(self);
installArrayIncludes(self);
Esempio n. 5
0
/**
 * Install polyfills in the child window (friendly iframe).
 * @param {!Window} childWin
 */
function installPolyfillsInChildWindow(childWin) {
  installDocContains(childWin);
  installDOMTokenListToggle(childWin);
  installCustomElements(childWin);
}
Esempio n. 6
0
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Importing the document-register-element module has the side effect
// of installing the custom elements polyfill if necessary.
import installCustomElements from
    'document-register-element/build/document-register-element.node';
import {install as installDocContains} from './polyfills/document-contains';
import {install as installMathSign} from './polyfills/math-sign';
import {install as installObjectAssign} from './polyfills/object-assign';
import {install as installPromise} from './polyfills/promise';
import {getMode} from './mode';

/**
  Only install in closure binary and not in babel/browserify binary, since in
  the closure binary we strip out the `document-register-element` install side
  effect so we can tree shake the dependency correctly and we have to make
  sure to not `install` it during dev since the `install` is done as a side
  effect in importing the module.
*/
if (!getMode().localDev) {
  installCustomElements(self);
}
installMathSign(self);
installObjectAssign(self);
installPromise(self);
installDocContains(self);
Esempio n. 7
0
/**
 * Install polyfills in the child window (friendly iframe).
 * @param {!Window} childWin
 */
function installPolyfillsInChildWindow(childWin) {
  installDocContains(childWin);
  installCustomElements(childWin);
}