From b7ede7e39037f14e5abdd13d151a0ada9eafa939 Mon Sep 17 00:00:00 2001 From: Raghu Simha Date: Mon, 10 May 2021 23:18:31 -0400 Subject: [PATCH 1/3] Replace all top-level `describe` tests with a `describes.sandboxed` equivalent --- .../test/test-content-recommendation.js | 4 +- .../a4a/shared/test/test-url-builder.js | 2 +- .../test-line-delimited-response-handler.js | 2 +- .../a4a/test/test-traffic-experiments.js | 2 +- ads/google/a4a/test/test-utils.js | 2 +- ads/google/test/test-utils.js | 74 +++++----- build-system/test-configs/forbidden-terms.js | 129 ------------------ .../amp-a4a/0.1/test/test-a4a-integration.js | 2 +- .../amp-a4a/0.1/test/test-a4a-var-source.js | 2 +- .../amp-a4a/0.1/test/test-amp-ad-utils.js | 8 +- extensions/amp-a4a/0.1/test/test-refresh.js | 2 +- .../amp-access/0.1/test/test-access-expr.js | 2 +- .../0.1/test/test-amp-login-done-dialog.js | 2 +- extensions/amp-access/0.1/test/test-jwt.js | 6 +- .../test/integration/test-amp-accordion.js | 4 +- .../0.1/test/filters/test-click-delay.js | 2 +- .../amp-ad/0.1/test/test-amp-ad-3p-impl.js | 2 +- .../amp-ad/0.1/test/test-amp-ad-custom.js | 2 +- .../test-amp-ad-xorigin-iframe-handler.js | 2 +- .../0.1/test/addthis-utils/test-fragment.js | 2 +- .../0.1/test/addthis-utils/test-rot13.js | 2 +- .../0.1/test/test-iframe-transport-client.js | 2 +- .../0.1/test/test-linker-manager.js | 4 +- .../0.1/test/test-linker-reader.js | 2 +- .../amp-analytics/0.1/test/test-linker.js | 2 +- .../0.1/test/test-transport-serializers.js | 2 +- .../amp-auto-ads/0.1/test/test-attributes.js | 2 +- .../amp-bind/0.1/test/test-bind-evaluator.js | 2 +- .../amp-bind/0.1/test/test-bind-expression.js | 2 +- .../amp-bind/0.1/test/test-bind-validator.js | 4 +- .../test-amp-bodymovin-animation.js | 4 +- .../0.1/test/test-dynamic-classes.js | 2 +- .../test/integration/test-amp-fx-fly-in.js | 2 +- .../integration/test-amp-image-lightbox.js | 4 +- .../integration/test-amp-lightbox-gallery.js | 2 +- .../0.1/test/integration/test-amp-list.js | 2 +- .../amp-live-list/0.1/test/test-poller.js | 2 +- .../0.1/test/integration/test-amp-pan-zoom.js | 4 +- .../0.1/test/integration/test-amp-script.js | 4 +- .../0.1/test/unit/test-amp-script.js | 2 +- .../0.1/test/integration/test-amp-sidebar.js | 4 +- .../amp-sidebar/0.1/test/test-toolbar.js | 2 +- .../0.2/test/integration/test-amp-sidebar.js | 4 +- .../0.1/test/test-binary-search.js | 2 +- .../test-amp-viewer-integration.js | 4 +- .../0.1/test/test-findtext.js | 4 +- test/integration/test-3p-nameframe.js | 2 +- test/integration/test-amp-ad-3p.js | 2 +- test/integration/test-amp-ad-doubleclick.js | 4 +- test/integration/test-amp-analytics.js | 4 +- test/integration/test-amp-bind.js | 4 +- test/integration/test-amp-img.js | 8 +- test/integration/test-amp-pixel.js | 2 +- test/integration/test-amp-recaptcha-input.js | 4 +- test/integration/test-amp-skimlinks.js | 2 +- test/integration/test-boilerplates.js | 4 +- test/integration/test-configuration.js | 2 +- test/integration/test-css.js | 2 +- test/integration/test-double-loading.js | 4 +- test/integration/test-extensions-loading.js | 98 ++++++------- test/integration/test-released.js | 4 +- test/integration/test-shadow-dom-element.js | 8 +- test/integration/test-video-manager.js | 40 +++--- test/integration/test-video-players.js | 22 +-- test/unit/3p/test-3p-messaging.js | 2 +- test/unit/3p/test-recaptcha.js | 2 +- test/unit/ads/test-unruly.js | 2 +- test/unit/test-3p-environment.js | 2 +- test/unit/test-3p.js | 2 +- test/unit/test-action.js | 6 +- test/unit/test-activity.js | 4 +- test/unit/test-ad-helper.js | 2 +- test/unit/test-ads-config.js | 2 +- test/unit/test-alp-handler.js | 2 +- test/unit/test-amp-context.js | 2 +- test/unit/test-amp-inabox.js | 2 +- test/unit/test-animation.js | 2 +- test/unit/test-batched-json.js | 2 +- test/unit/test-callout-vendors.js | 2 +- test/unit/test-chunk.js | 8 +- test/unit/test-cid.js | 2 +- test/unit/test-curve.js | 2 +- test/unit/test-describes.js | 2 +- test/unit/test-document-info.js | 4 +- test/unit/test-document-ready.js | 2 +- test/unit/test-event-helper.js | 2 +- test/unit/test-experiments.js | 12 +- test/unit/test-exponential-backoff.js | 2 +- test/unit/test-finite-state-machine.js | 2 +- test/unit/test-focus-history.js | 2 +- test/unit/test-gesture-recognizers.js | 10 +- test/unit/test-gesture.js | 2 +- test/unit/test-get-html.js | 2 +- test/unit/test-ie-media-bug.js | 2 +- test/unit/test-iframe-helper.js | 4 +- test/unit/test-iframe-stub.js | 4 +- test/unit/test-input.js | 2 +- test/unit/test-integration.js | 2 +- .../test-intersection-observer-polyfill.js | 2 +- test/unit/test-json.js | 2 +- test/unit/test-layout-rect.js | 8 +- test/unit/test-layout.js | 2 +- test/unit/test-log.js | 2 +- test/unit/test-mode.js | 4 +- test/unit/test-motion.js | 4 +- test/unit/test-mustache.js | 2 +- test/unit/test-pass.js | 2 +- test/unit/test-platform.js | 2 +- test/unit/test-pull-to-refresh.js | 2 +- test/unit/test-purifier.js | 12 +- test/unit/test-render-delaying-services.js | 2 +- test/unit/test-resource.js | 2 +- test/unit/test-sanitizer.js | 2 +- test/unit/test-service.js | 2 +- test/unit/test-srcset.js | 2 +- test/unit/test-static-template.js | 2 +- test/unit/test-style-installer.js | 2 +- test/unit/test-style.js | 2 +- test/unit/test-task-queue.js | 2 +- test/unit/test-transition.js | 2 +- test/unit/test-types.js | 2 +- test/unit/test-url-rewrite.js | 4 +- test/unit/test-url.js | 40 +++--- test/unit/test-viewport.js | 4 +- test/unit/test-web-components.js | 2 +- test/unit/test-xhr.js | 4 +- test/unit/utils/test-base64.js | 4 +- test/unit/utils/test-bytes.js | 6 +- test/unit/web-worker/test-amp-worker.js | 2 +- 129 files changed, 331 insertions(+), 446 deletions(-) diff --git a/ads/google/a4a/shared/test/test-content-recommendation.js b/ads/google/a4a/shared/test/test-content-recommendation.js index 6058e6d7f268..ca5e4f4bf283 100644 --- a/ads/google/a4a/shared/test/test-content-recommendation.js +++ b/ads/google/a4a/shared/test/test-content-recommendation.js @@ -20,7 +20,7 @@ import { getPubControlConfig, } from '../content-recommendation.js'; -describe('getAutoConfig', function () { +describes.sandboxed('getAutoConfig', {}, function () { it('should use image_stacked on wide slots', function () { const runTest = (availableWidth, expectedWidth, expectedHeight) => { expect( @@ -164,7 +164,7 @@ describe('getAutoConfig', function () { }); }); -describe('getPubControlConfig', function () { +describes.sandboxed('getPubControlConfig', {}, function () { it('should use setting when only one provided', function () { const rawPubControlParams = { numberOfColumns: '4', diff --git a/ads/google/a4a/shared/test/test-url-builder.js b/ads/google/a4a/shared/test/test-url-builder.js index 6cfd67fd6806..f95ef55b6179 100644 --- a/ads/google/a4a/shared/test/test-url-builder.js +++ b/ads/google/a4a/shared/test/test-url-builder.js @@ -16,7 +16,7 @@ import {buildUrl} from '../url-builder'; -describe('buildUrl', () => { +describes.sandboxed('buildUrl', {}, () => { it('should build a simple URL', () => { expect( buildUrl('https://example.test', {'key': 'value'}, Infinity) diff --git a/ads/google/a4a/test/test-line-delimited-response-handler.js b/ads/google/a4a/test/test-line-delimited-response-handler.js index 9327181a8d3a..93e9a030788e 100644 --- a/ads/google/a4a/test/test-line-delimited-response-handler.js +++ b/ads/google/a4a/test/test-line-delimited-response-handler.js @@ -19,7 +19,7 @@ import { metaJsonCreativeGrouper, } from '../line-delimited-response-handler'; -describe('#line-delimited-response-handler', () => { +describes.sandboxed('#line-delimited-response-handler', {}, () => { let chunkHandlerStub; let slotData; let win; diff --git a/ads/google/a4a/test/test-traffic-experiments.js b/ads/google/a4a/test/test-traffic-experiments.js index 216e14dd7f4e..e7a93bc93189 100644 --- a/ads/google/a4a/test/test-traffic-experiments.js +++ b/ads/google/a4a/test/test-traffic-experiments.js @@ -22,7 +22,7 @@ import { validateExperimentIds, } from '../traffic-experiments'; -describe('all-traffic-experiments-tests', () => { +describes.sandboxed('all-traffic-experiments-tests', {}, () => { describe('#validateExperimentIds', () => { it('should return true for empty list', () => { expect(validateExperimentIds([])).to.be.true; diff --git a/ads/google/a4a/test/test-utils.js b/ads/google/a4a/test/test-utils.js index 2e720f4884f1..3f7d1f2c7187 100644 --- a/ads/google/a4a/test/test-utils.js +++ b/ads/google/a4a/test/test-utils.js @@ -90,7 +90,7 @@ function noopMethods( sandbox.stub(impl.element, 'offsetHeight').value(pageLayoutBox.height); } -describe('Google A4A utils', () => { +describes.sandboxed('Google A4A utils', {}, () => { //TODO: Add tests for other utils functions. describe('#additionalDimensions', () => { diff --git a/ads/google/test/test-utils.js b/ads/google/test/test-utils.js index a645d9dc3cea..831930661a26 100644 --- a/ads/google/test/test-utils.js +++ b/ads/google/test/test-utils.js @@ -23,7 +23,7 @@ import { getMultiSizeDimensions, } from '../utils'; -describe('#getMultiSizeDimensions', () => { +describes.sandboxed('#getMultiSizeDimensions', {}, () => { const multiSizes = [ [300, 300], [300, 250], @@ -143,35 +143,43 @@ describe('#getMultiSizeDimensions', () => { }); }); -describe('#getMatchedContentResponsiveHeightAndUpdatePubParams', () => { - it('should use auto logic when no pub params present', () => { - const element = document.createElement('div'); - expect( - getMatchedContentResponsiveHeightAndUpdatePubParams(400, element) - ).to.equal(1472); - expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('12'); - expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal('1'); - expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal( - LayoutType.MOBILE_BANNER_IMAGE_SIDEBYSIDE - ); - }); - - it('should use pub control logic when pub params present', () => { - const element = document.createElement('div'); - element.setAttribute(ExternalCorePubVars.ROWS_NUM, '1,2'); - element.setAttribute(ExternalCorePubVars.COLUMNS_NUM, '3,4'); - element.setAttribute( - ExternalCorePubVars.UI_TYPE, - `${LayoutType.IMAGE_SIDEBYSIDE},${LayoutType.IMAGE_STACKED}` - ); - - expect( - getMatchedContentResponsiveHeightAndUpdatePubParams(800, element) - ).to.equal(382); - expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('2'); - expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal('4'); - expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal( - LayoutType.PUB_CONTROL_IMAGE_STACKED - ); - }); -}); +describes.sandboxed( + '#getMatchedContentResponsiveHeightAndUpdatePubParams', + {}, + () => { + it('should use auto logic when no pub params present', () => { + const element = document.createElement('div'); + expect( + getMatchedContentResponsiveHeightAndUpdatePubParams(400, element) + ).to.equal(1472); + expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('12'); + expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal( + '1' + ); + expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal( + LayoutType.MOBILE_BANNER_IMAGE_SIDEBYSIDE + ); + }); + + it('should use pub control logic when pub params present', () => { + const element = document.createElement('div'); + element.setAttribute(ExternalCorePubVars.ROWS_NUM, '1,2'); + element.setAttribute(ExternalCorePubVars.COLUMNS_NUM, '3,4'); + element.setAttribute( + ExternalCorePubVars.UI_TYPE, + `${LayoutType.IMAGE_SIDEBYSIDE},${LayoutType.IMAGE_STACKED}` + ); + + expect( + getMatchedContentResponsiveHeightAndUpdatePubParams(800, element) + ).to.equal(382); + expect(element.getAttribute(ExternalCorePubVars.ROWS_NUM)).to.equal('2'); + expect(element.getAttribute(ExternalCorePubVars.COLUMNS_NUM)).to.equal( + '4' + ); + expect(element.getAttribute(ExternalCorePubVars.UI_TYPE)).to.equal( + LayoutType.PUB_CONTROL_IMAGE_STACKED + ); + }); + } +); diff --git a/build-system/test-configs/forbidden-terms.js b/build-system/test-configs/forbidden-terms.js index 7f9978f7c3f0..15186d001ef3 100644 --- a/build-system/test-configs/forbidden-terms.js +++ b/build-system/test-configs/forbidden-terms.js @@ -705,135 +705,6 @@ const forbiddenTermsGlobal = { 'validator/js/engine/parse-url_test.js', 'validator/js/engine/validator_test.js', 'validator/js/gulpjs/test/validate.js', - // Test files. TODO(#24144): Fix these and remove from the allowlist. - 'ads/google/a4a/shared/test/test-content-recommendation.js', - 'ads/google/a4a/shared/test/test-url-builder.js', - 'ads/google/a4a/test/test-line-delimited-response-handler.js', - 'ads/google/a4a/test/test-traffic-experiments.js', - 'ads/google/a4a/test/test-utils.js', - 'ads/google/test/test-utils.js', - 'extensions/amp-a4a/0.1/test/test-a4a-integration.js', - 'extensions/amp-a4a/0.1/test/test-a4a-var-source.js', - 'extensions/amp-a4a/0.1/test/test-amp-ad-utils.js', - 'extensions/amp-a4a/0.1/test/test-refresh.js', - 'extensions/amp-access/0.1/test/test-access-expr.js', - 'extensions/amp-access/0.1/test/test-amp-login-done-dialog.js', - 'extensions/amp-access/0.1/test/test-jwt.js', - 'extensions/amp-accordion/0.1/test/integration/test-amp-accordion.js', - 'extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js', - 'extensions/amp-ad/0.1/test/test-amp-ad-3p-impl.js', - 'extensions/amp-ad/0.1/test/test-amp-ad-custom.js', - 'extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js', - 'extensions/amp-addthis/0.1/test/addthis-utils/test-fragment.js', - 'extensions/amp-addthis/0.1/test/addthis-utils/test-rot13.js', - 'extensions/amp-analytics/0.1/test/test-iframe-transport-client.js', - 'extensions/amp-analytics/0.1/test/test-linker-manager.js', - 'extensions/amp-analytics/0.1/test/test-linker-reader.js', - 'extensions/amp-analytics/0.1/test/test-linker.js', - 'extensions/amp-analytics/0.1/test/test-transport-serializers.js', - 'extensions/amp-auto-ads/0.1/test/test-attributes.js', - 'extensions/amp-bind/0.1/test/test-bind-evaluator.js', - 'extensions/amp-bind/0.1/test/test-bind-expression.js', - 'extensions/amp-bind/0.1/test/test-bind-validator.js', - 'extensions/amp-bodymovin-animation/0.1/test/integration/test-amp-bodymovin-animation.js', - 'extensions/amp-dynamic-css-classes/0.1/test/test-dynamic-classes.js', - 'extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fly-in.js', - 'extensions/amp-image-lightbox/0.1/test/integration/test-amp-image-lightbox.js', - 'extensions/amp-lightbox-gallery/0.1/test/integration/test-amp-lightbox-gallery.js', - 'extensions/amp-list/0.1/test/integration/test-amp-list.js', - 'extensions/amp-live-list/0.1/test/test-poller.js', - 'extensions/amp-pan-zoom/0.1/test/integration/test-amp-pan-zoom.js', - 'extensions/amp-script/0.1/test/integration/test-amp-script.js', - 'extensions/amp-script/0.1/test/unit/test-amp-script.js', - 'extensions/amp-sidebar/0.1/test/integration/test-amp-sidebar.js', - 'extensions/amp-sidebar/0.1/test/test-toolbar.js', - 'extensions/amp-sidebar/0.2/test/integration/test-amp-sidebar.js', - 'extensions/amp-truncate-text/0.1/test/test-binary-search.js', - 'extensions/amp-viewer-integration/0.1/test/integration/test-amp-viewer-integration.js', - 'extensions/amp-viewer-integration/0.1/test/test-findtext.js', - 'test/integration/test-3p-nameframe.js', - 'test/integration/test-amp-ad-3p.js', - 'test/integration/test-amp-ad-doubleclick.js', - 'test/integration/test-amp-analytics.js', - 'test/integration/test-amp-bind.js', - 'test/integration/test-amp-img.js', - 'test/integration/test-amp-pixel.js', - 'test/integration/test-amp-recaptcha-input.js', - 'test/integration/test-amp-skimlinks.js', - 'test/integration/test-boilerplates.js', - 'test/integration/test-configuration.js', - 'test/integration/test-css.js', - 'test/integration/test-double-loading.js', - 'test/integration/test-extensions-loading.js', - 'test/integration/test-released.js', - 'test/integration/test-shadow-dom-element.js', - 'test/integration/test-video-manager.js', - 'test/integration/test-video-players.js', - 'test/unit/3p/test-3p-messaging.js', - 'test/unit/3p/test-recaptcha.js', - 'test/unit/ads/test-unruly.js', - 'test/unit/test-3p-environment.js', - 'test/unit/test-3p.js', - 'test/unit/test-action.js', - 'test/unit/test-activity.js', - 'test/unit/test-ad-helper.js', - 'test/unit/test-ads-config.js', - 'test/unit/test-alp-handler.js', - 'test/unit/test-amp-context.js', - 'test/unit/test-amp-inabox.js', - 'test/unit/test-animation.js', - 'test/unit/test-batched-json.js', - 'test/unit/test-callout-vendors.js', - 'test/unit/test-chunk.js', - 'test/unit/test-cid.js', - 'test/unit/test-curve.js', - 'test/unit/test-describes.js', - 'test/unit/test-document-info.js', - 'test/unit/test-document-ready.js', - 'test/unit/test-event-helper.js', - 'test/unit/test-experiments.js', - 'test/unit/test-exponential-backoff.js', - 'test/unit/test-finite-state-machine.js', - 'test/unit/test-focus-history.js', - 'test/unit/test-gesture-recognizers.js', - 'test/unit/test-gesture.js', - 'test/unit/test-get-html.js', - 'test/unit/test-ie-media-bug.js', - 'test/unit/test-iframe-helper.js', - 'test/unit/test-iframe-stub.js', - 'test/unit/test-input.js', - 'test/unit/test-integration.js', - 'test/unit/test-intersection-observer-polyfill.js', - 'test/unit/test-json.js', - 'test/unit/test-layout-rect.js', - 'test/unit/test-layout.js', - 'test/unit/test-log.js', - 'test/unit/test-mode.js', - 'test/unit/test-motion.js', - 'test/unit/test-mustache.js', - 'test/unit/test-pass.js', - 'test/unit/test-platform.js', - 'test/unit/test-pull-to-refresh.js', - 'test/unit/test-purifier.js', - 'test/unit/test-render-delaying-services.js', - 'test/unit/test-resource.js', - 'test/unit/test-sanitizer.js', - 'test/unit/test-service.js', - 'test/unit/test-srcset.js', - 'test/unit/test-static-template.js', - 'test/unit/test-style-installer.js', - 'test/unit/test-style.js', - 'test/unit/test-task-queue.js', - 'test/unit/test-transition.js', - 'test/unit/test-types.js', - 'test/unit/test-url-rewrite.js', - 'test/unit/test-url.js', - 'test/unit/test-viewport.js', - 'test/unit/test-web-components.js', - 'test/unit/test-xhr.js', - 'test/unit/utils/test-base64.js', - 'test/unit/utils/test-bytes.js', - 'test/unit/web-worker/test-amp-worker.js', ], checkInTestFolder: true, }, diff --git a/extensions/amp-a4a/0.1/test/test-a4a-integration.js b/extensions/amp-a4a/0.1/test/test-a4a-integration.js index 8b6580af86bd..12ecca17adcd 100644 --- a/extensions/amp-a4a/0.1/test/test-a4a-integration.js +++ b/extensions/amp-a4a/0.1/test/test-a4a-integration.js @@ -78,7 +78,7 @@ function expectRenderedInXDomainIframe(element, src) { expect(child, 'iframe child').to.be.visible; } -describe('integration test: a4a', () => { +describes.sandboxed('integration test: a4a', {}, () => { let fixture; let fetchMock; let adResponse; diff --git a/extensions/amp-a4a/0.1/test/test-a4a-var-source.js b/extensions/amp-a4a/0.1/test/test-a4a-var-source.js index 1632c71ea334..1b57acd8ea48 100644 --- a/extensions/amp-a4a/0.1/test/test-a4a-var-source.js +++ b/extensions/amp-a4a/0.1/test/test-a4a-var-source.js @@ -18,7 +18,7 @@ import {A4AVariableSource} from '../a4a-variable-source'; import {createIframePromise} from '../../../../testing/iframe'; import {installDocumentInfoServiceForDoc} from '../../../../src/service/document-info-impl'; -describe('A4AVariableSource', () => { +describes.sandboxed('A4AVariableSource', {}, () => { let varSource; beforeEach(async () => { diff --git a/extensions/amp-a4a/0.1/test/test-amp-ad-utils.js b/extensions/amp-a4a/0.1/test/test-amp-ad-utils.js index 882f30b5731d..faf50242d738 100644 --- a/extensions/amp-a4a/0.1/test/test-amp-ad-utils.js +++ b/extensions/amp-a4a/0.1/test/test-amp-ad-utils.js @@ -22,7 +22,7 @@ import { mergeExtensionsMetadata, } from '../amp-ad-utils'; -describe('getAmpAdMetadata', () => { +describes.sandboxed('getAmpAdMetadata', {}, () => { it('should parse metadata successfully', () => { const creativeMetadata = getAmpAdMetadata(data.reserialized); expect(creativeMetadata).to.be.ok; @@ -62,7 +62,7 @@ describe('getAmpAdMetadata', () => { }); }); -describe('mergeExtensionsMetadata', () => { +describes.sandboxed('mergeExtensionsMetadata', {}, () => { it('should add els that exist in customElementExtensions but not extensions', () => { const customElementExtensions = ['amp-analytics']; const extensions = []; @@ -95,7 +95,7 @@ describe('mergeExtensionsMetadata', () => { }); }); -describe('extensionsHasElement', () => { +describes.sandboxed('extensionsHasElement', {}, () => { it('should return true if containing extension', () => { const extensions = [ { @@ -122,7 +122,7 @@ describe('extensionsHasElement', () => { }); }); -describe('getExtensionsFromMetadata', () => { +describes.sandboxed('getExtensionsFromMetadata', {}, () => { it('should return extension name and version', () => { const metadata = { extensions: [ diff --git a/extensions/amp-a4a/0.1/test/test-refresh.js b/extensions/amp-a4a/0.1/test/test-refresh.js index c24655944bb3..969fa53d57fb 100644 --- a/extensions/amp-a4a/0.1/test/test-refresh.js +++ b/extensions/amp-a4a/0.1/test/test-refresh.js @@ -23,7 +23,7 @@ import { } from '../refresh-manager'; import {Services} from '../../../../src/services'; -describe('refresh', () => { +describes.sandboxed('refresh', {}, () => { let mockA4a; const config = { visiblePercentageMin: 50, diff --git a/extensions/amp-access/0.1/test/test-access-expr.js b/extensions/amp-access/0.1/test/test-access-expr.js index 35c3156cecde..a09f89c479bc 100644 --- a/extensions/amp-access/0.1/test/test-access-expr.js +++ b/extensions/amp-access/0.1/test/test-access-expr.js @@ -16,7 +16,7 @@ import {AmpAccessEvaluator} from '../access-expr'; -describe('evaluate', () => { +describes.sandboxed('evaluate', {}, () => { let evaluator; beforeEach(() => { evaluator = new AmpAccessEvaluator(); diff --git a/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js b/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js index 4d7285b46aae..cf21ebe702f9 100644 --- a/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js +++ b/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js @@ -16,7 +16,7 @@ import {LoginDoneDialog, buildLangSelector} from '../amp-login-done-dialog'; -describe('LoginDoneDialog', () => { +describes.sandboxed('LoginDoneDialog', {}, () => { let clock; let windowApi; let dialog; diff --git a/extensions/amp-access/0.1/test/test-jwt.js b/extensions/amp-access/0.1/test/test-jwt.js index a5c1c9a381ef..790434ec0da3 100644 --- a/extensions/amp-access/0.1/test/test-jwt.js +++ b/extensions/amp-access/0.1/test/test-jwt.js @@ -16,7 +16,7 @@ import {JwtHelper, pemToBytes} from '../jwt'; -describe('JwtHelper', () => { +describes.sandboxed('JwtHelper', {}, () => { // Generated from https://jwt.io/#debugger // Name deliberately changed from "John Doe" to "John ௵Z加䅌ਇ☎Èʘغޝ" to test // correct unicode handling on our part. @@ -250,10 +250,10 @@ describe('JwtHelper', () => { }); // TODO(amphtml, #25621): Cannot find atob / btoa on Safari. -describe +describes.sandboxed .configure() .skipSafari() - .run('pemToBytes', () => { + .run('pemToBytes', {}, () => { const PLAIN_TEXT = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd' + 'UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs' + diff --git a/extensions/amp-accordion/0.1/test/integration/test-amp-accordion.js b/extensions/amp-accordion/0.1/test/integration/test-amp-accordion.js index a58b88560a5d..6bea056bc7ca 100644 --- a/extensions/amp-accordion/0.1/test/integration/test-amp-accordion.js +++ b/extensions/amp-accordion/0.1/test/integration/test-amp-accordion.js @@ -14,10 +14,10 @@ * limitations under the License. */ -describe +describes.sandboxed .configure() .skipEdge() - .run('amp-accordion', function () { + .run('amp-accordion', {}, function () { this.timeout(10000); const extensions = ['amp-accordion']; const body = ` diff --git a/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js b/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js index 85d86f76fb9c..285af715f397 100644 --- a/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js +++ b/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js @@ -17,7 +17,7 @@ import {ClickDelayFilter} from '../../filters/click-delay'; import {FilterType} from '../../filters/filter'; -describe('click-delay', () => { +describes.sandboxed('click-delay', {}, () => { const DEFAULT_CONFIG = { type: FilterType.CLICK_DELAY, delay: 123, diff --git a/extensions/amp-ad/0.1/test/test-amp-ad-3p-impl.js b/extensions/amp-ad/0.1/test/test-amp-ad-3p-impl.js index 476167d84329..ff0141d29ef7 100644 --- a/extensions/amp-ad/0.1/test/test-amp-ad-3p-impl.js +++ b/extensions/amp-ad/0.1/test/test-amp-ad-3p-impl.js @@ -636,7 +636,7 @@ describes.realWin( } ); -describe('#getLayoutPriority', () => { +describes.sandboxed('#getLayoutPriority', {}, () => { describes.realWin( 'with shadow AmpDoc', { diff --git a/extensions/amp-ad/0.1/test/test-amp-ad-custom.js b/extensions/amp-ad/0.1/test/test-amp-ad-custom.js index 8973a4778a9e..67c6fe34869e 100644 --- a/extensions/amp-ad/0.1/test/test-amp-ad-custom.js +++ b/extensions/amp-ad/0.1/test/test-amp-ad-custom.js @@ -189,7 +189,7 @@ describes.realWin('Amp custom ad', {amp: true}, (env) => { }); // TODO(wg-monetization, #25726): This test fails when run by itself. -describe.skip('#getLayoutPriority', () => { +describes.sandboxed.skip('#getLayoutPriority', {}, () => { const url = '/examples/custom.ad.example.json'; const slot = 'myslot'; diff --git a/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js b/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js index dce2f1c4731f..c107acc56755 100644 --- a/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js +++ b/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js @@ -26,7 +26,7 @@ import { import {layoutRectLtwh} from '../../../../src/layout-rect'; import {toggleExperiment} from '../../../../src/experiments'; -describe('amp-ad-xorigin-iframe-handler', () => { +describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { let ampdoc; let adImpl; let signals; diff --git a/extensions/amp-addthis/0.1/test/addthis-utils/test-fragment.js b/extensions/amp-addthis/0.1/test/addthis-utils/test-fragment.js index 5451f1f3f343..48ffd24a214e 100644 --- a/extensions/amp-addthis/0.1/test/addthis-utils/test-fragment.js +++ b/extensions/amp-addthis/0.1/test/addthis-utils/test-fragment.js @@ -16,7 +16,7 @@ import {clearOurFragment} from '../../addthis-utils/fragment'; -describe('fragment', () => { +describes.sandboxed('fragment', {}, () => { it('clears AddThis fragments from an url', () => { let url = 'http://www.example.com/2012-07-25?utm_campaign=linkedin-Share-Web#at_pco=cfd-1.0'; diff --git a/extensions/amp-addthis/0.1/test/addthis-utils/test-rot13.js b/extensions/amp-addthis/0.1/test/addthis-utils/test-rot13.js index 15ad4148101f..b3d901224dd6 100644 --- a/extensions/amp-addthis/0.1/test/addthis-utils/test-rot13.js +++ b/extensions/amp-addthis/0.1/test/addthis-utils/test-rot13.js @@ -16,7 +16,7 @@ import {rot13Array} from '../../addthis-utils/rot13'; -describe('rot13', () => { +describes.sandboxed('rot13', {}, () => { it('should properly rotate alphabetical characters', () => { const expected = [ '', diff --git a/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js b/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js index b21c1fddb6d2..adba2ab1168c 100644 --- a/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js +++ b/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js @@ -28,7 +28,7 @@ function createUniqueId() { return String(++nextId); } -describe('iframe-transport-client', () => { +describes.sandboxed('iframe-transport-client', {}, () => { let iframeTransportClient; let sentinel; diff --git a/extensions/amp-analytics/0.1/test/test-linker-manager.js b/extensions/amp-analytics/0.1/test/test-linker-manager.js index c65d9dcd1c43..4472bacdcba6 100644 --- a/extensions/amp-analytics/0.1/test/test-linker-manager.js +++ b/extensions/amp-analytics/0.1/test/test-linker-manager.js @@ -1071,7 +1071,7 @@ describes.realWin('Linker Manager', {amp: true}, (env) => { }); }); -describe('areFriendlyDomains', () => { +describes.sandboxed('areFriendlyDomains', {}, () => { it('should work', () => { expect(areFriendlyDomains('amp.source.test', 'www.source.test')).to.be.true; expect(areFriendlyDomains('m.source.test', 'www.source.test')).to.be.true; @@ -1086,7 +1086,7 @@ describe('areFriendlyDomains', () => { }); }); -describe('wildcard matching', () => { +describes.sandboxed('wildcard matching', {}, () => { const testCases = [ { hostname: 'amp.foo.com', diff --git a/extensions/amp-analytics/0.1/test/test-linker-reader.js b/extensions/amp-analytics/0.1/test/test-linker-reader.js index 7a6f64313b9e..00d0c9d74187 100644 --- a/extensions/amp-analytics/0.1/test/test-linker-reader.js +++ b/extensions/amp-analytics/0.1/test/test-linker-reader.js @@ -20,7 +20,7 @@ import { } from '../linker-reader'; import {mockWindowInterface} from '../../../../testing/test-helper'; -describe('LinkerReader', () => { +describes.sandboxed('LinkerReader', {}, () => { let linkerReader; let mockWin; diff --git a/extensions/amp-analytics/0.1/test/test-linker.js b/extensions/amp-analytics/0.1/test/test-linker.js index 8bbdd31772d1..474edb4c9275 100644 --- a/extensions/amp-analytics/0.1/test/test-linker.js +++ b/extensions/amp-analytics/0.1/test/test-linker.js @@ -245,7 +245,7 @@ const createLinkerTests = [ }, ]; -describe('Linker', () => { +describes.sandboxed('Linker', {}, () => { let mockWin; beforeEach(() => { // Linker uses a timestamp value to generate checksum. diff --git a/extensions/amp-analytics/0.1/test/test-transport-serializers.js b/extensions/amp-analytics/0.1/test/test-transport-serializers.js index 90bb13e3b0fc..c69534ab9ec6 100644 --- a/extensions/amp-analytics/0.1/test/test-transport-serializers.js +++ b/extensions/amp-analytics/0.1/test/test-transport-serializers.js @@ -110,7 +110,7 @@ const SerializerTests = { /** * Real test. Plugin vendors don't need to modify */ -describe('Transport serializers', () => { +describes.sandboxed('Transport serializers', {}, () => { it('TransportSerializers sort in alphabetic order', () => { const keys = Object.keys(TransportSerializers); const sorted = Object.keys(TransportSerializers).sort(); diff --git a/extensions/amp-auto-ads/0.1/test/test-attributes.js b/extensions/amp-auto-ads/0.1/test/test-attributes.js index a0a1cf2ba2f2..d979924ceae7 100644 --- a/extensions/amp-auto-ads/0.1/test/test-attributes.js +++ b/extensions/amp-auto-ads/0.1/test/test-attributes.js @@ -16,7 +16,7 @@ import {Attributes, getAttributesFromConfigObj} from '../attributes'; -describe('attributes', () => { +describes.sandboxed('attributes', {}, () => { it('should ignore attributes field if an array', () => { const configObj = { attributes: ['val1', 'val2'], diff --git a/extensions/amp-bind/0.1/test/test-bind-evaluator.js b/extensions/amp-bind/0.1/test/test-bind-evaluator.js index af83959488b9..3371ccc6793e 100644 --- a/extensions/amp-bind/0.1/test/test-bind-evaluator.js +++ b/extensions/amp-bind/0.1/test/test-bind-evaluator.js @@ -17,7 +17,7 @@ import {BindEvaluator} from '../bind-evaluator'; import {BindExpression} from '../bind-expression'; -describe('BindEvaluator', () => { +describes.sandboxed('BindEvaluator', {}, () => { let evaluator; beforeEach(() => { diff --git a/extensions/amp-bind/0.1/test/test-bind-expression.js b/extensions/amp-bind/0.1/test/test-bind-expression.js index d0c5b9d0cfc3..4e507960956b 100644 --- a/extensions/amp-bind/0.1/test/test-bind-expression.js +++ b/extensions/amp-bind/0.1/test/test-bind-expression.js @@ -17,7 +17,7 @@ import {BindExpression} from '../bind-expression'; import {BindMacro} from '../bind-macro'; -describe('BindExpression', () => { +describes.sandboxed('BindExpression', {}, () => { const argumentTypeError = 'Unexpected argument type'; const unsupportedFunctionError = 'not a supported function'; const expressionSizeExceededError = 'exceeds max'; diff --git a/extensions/amp-bind/0.1/test/test-bind-validator.js b/extensions/amp-bind/0.1/test/test-bind-validator.js index 4ba30371b47f..23f20e24a127 100644 --- a/extensions/amp-bind/0.1/test/test-bind-validator.js +++ b/extensions/amp-bind/0.1/test/test-bind-validator.js @@ -16,7 +16,7 @@ import {BindValidator} from '../bind-validator'; -describe('BindValidator (allowUrlProperties=true)', () => { +describes.sandboxed('BindValidator (allowUrlProperties=true)', {}, () => { let val; beforeEach(() => { @@ -314,7 +314,7 @@ describe('BindValidator (allowUrlProperties=true)', () => { }); }); -describe('BindValidator (allowUrlProperties=false)', () => { +describes.sandboxed('BindValidator (allowUrlProperties=false)', {}, () => { let val; beforeEach(() => { diff --git a/extensions/amp-bodymovin-animation/0.1/test/integration/test-amp-bodymovin-animation.js b/extensions/amp-bodymovin-animation/0.1/test/integration/test-amp-bodymovin-animation.js index b2a4b8fc8e8a..c689a6595e3f 100644 --- a/extensions/amp-bodymovin-animation/0.1/test/integration/test-amp-bodymovin-animation.js +++ b/extensions/amp-bodymovin-animation/0.1/test/integration/test-amp-bodymovin-animation.js @@ -14,10 +14,10 @@ * limitations under the License. */ -describe +describes.sandboxed .configure() .ifChrome() - .run('amp-bodymovin-animation', function () { + .run('amp-bodymovin-animation', {}, function () { const extensions = ['amp-bodymovin-animation']; const bodymovinBody = ` { +describes.sandboxed('amp-dynamic-css-classes', {}, () => { describe('referrers_', () => { describe('when referrer is TLD-less', () => { const referrer = 'localhost'; diff --git a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fly-in.js b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fly-in.js index 9283f7cabd22..9cb8720d1ca9 100644 --- a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fly-in.js +++ b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fly-in.js @@ -16,7 +16,7 @@ import {isExperimentOn, toggleExperiment} from '../../../../../src/experiments'; -describe.skip('amp-fx-collection', function () { +describes.sandboxed.skip('amp-fx-collection', {}, function () { const css = ` .spacer { height: 100vh; diff --git a/extensions/amp-image-lightbox/0.1/test/integration/test-amp-image-lightbox.js b/extensions/amp-image-lightbox/0.1/test/integration/test-amp-image-lightbox.js index 851a94fc120c..c4213ccdb302 100644 --- a/extensions/amp-image-lightbox/0.1/test/integration/test-amp-image-lightbox.js +++ b/extensions/amp-image-lightbox/0.1/test/integration/test-amp-image-lightbox.js @@ -16,10 +16,10 @@ import {poll} from '../../../../../testing/iframe'; -describe +describes.sandboxed .configure() .skipFirefox() - .run('amp-image-lightbox', function () { + .run('amp-image-lightbox', {}, function () { this.timeout(5000); const extensions = ['amp-image-lightbox']; const imageLightboxBody = ` diff --git a/extensions/amp-lightbox-gallery/0.1/test/integration/test-amp-lightbox-gallery.js b/extensions/amp-lightbox-gallery/0.1/test/integration/test-amp-lightbox-gallery.js index ea58ebe1743b..9b5a9c8417bc 100644 --- a/extensions/amp-lightbox-gallery/0.1/test/integration/test-amp-lightbox-gallery.js +++ b/extensions/amp-lightbox-gallery/0.1/test/integration/test-amp-lightbox-gallery.js @@ -18,7 +18,7 @@ import * as analytics from '../../../../../src/analytics'; import {poll} from '../../../../../testing/iframe'; // TODO(cathyxz, #16822): This suite is flaky. -describe.configure().skip('amp-lightbox-gallery', function () { +describes.sandboxed.configure().skip('amp-lightbox-gallery', function () { this.timeout(10000); const extensions = ['amp-lightbox-gallery']; const body = ` diff --git a/extensions/amp-list/0.1/test/integration/test-amp-list.js b/extensions/amp-list/0.1/test/integration/test-amp-list.js index 561f443a1d3f..440403466d53 100644 --- a/extensions/amp-list/0.1/test/integration/test-amp-list.js +++ b/extensions/amp-list/0.1/test/integration/test-amp-list.js @@ -18,7 +18,7 @@ import {BrowserController} from '../../../../../testing/test-helper'; const TIMEOUT = 15000; -describe('amp-list (integration)', function () { +describes.sandboxed('amp-list (integration)', {}, function () { this.timeout(TIMEOUT); const basicBody = ` diff --git a/extensions/amp-live-list/0.1/test/test-poller.js b/extensions/amp-live-list/0.1/test/test-poller.js index ae5a45c0d897..f75a39796a0e 100644 --- a/extensions/amp-live-list/0.1/test/test-poller.js +++ b/extensions/amp-live-list/0.1/test/test-poller.js @@ -17,7 +17,7 @@ import {Poller} from '../poller'; import {Services} from '../../../../src/services'; -describe('Poller', () => { +describes.sandboxed('Poller', {}, () => { let clock; let poller; let workStub; diff --git a/extensions/amp-pan-zoom/0.1/test/integration/test-amp-pan-zoom.js b/extensions/amp-pan-zoom/0.1/test/integration/test-amp-pan-zoom.js index f27415705823..223ed7c875d9 100644 --- a/extensions/amp-pan-zoom/0.1/test/integration/test-amp-pan-zoom.js +++ b/extensions/amp-pan-zoom/0.1/test/integration/test-amp-pan-zoom.js @@ -18,10 +18,10 @@ import {AmpEvents} from '../../../../../src/core/constants/amp-events'; import {createFixtureIframe} from '../../../../../testing/iframe'; import {toggleExperiment} from '../../../../../src/experiments'; -describe +describes.sandboxed .configure() .ifChrome() - .run('amp-pan-zoom', function () { + .run('amp-pan-zoom', {}, function () { this.timeout(100000); let fixture; beforeEach(() => { diff --git a/extensions/amp-script/0.1/test/integration/test-amp-script.js b/extensions/amp-script/0.1/test/integration/test-amp-script.js index ca417f8fb5cc..d61b4d17d268 100644 --- a/extensions/amp-script/0.1/test/integration/test-amp-script.js +++ b/extensions/amp-script/0.1/test/integration/test-amp-script.js @@ -23,10 +23,10 @@ function poll(description, condition, opt_onError) { return classicPoll(description, condition, opt_onError, TIMEOUT); } -describe +describes.sandboxed .configure() .skipFirefox() - .run('amp-script', function () { + .run('amp-script', {}, function () { this.timeout(TIMEOUT); let browser, doc, element; diff --git a/extensions/amp-script/0.1/test/unit/test-amp-script.js b/extensions/amp-script/0.1/test/unit/test-amp-script.js index 1474bc06763f..95629e9d45d7 100644 --- a/extensions/amp-script/0.1/test/unit/test-amp-script.js +++ b/extensions/amp-script/0.1/test/unit/test-amp-script.js @@ -339,7 +339,7 @@ describes.repeated( } ); -describe('SanitizerImpl', () => { +describes.sandboxed('SanitizerImpl', {}, () => { let el; let win; let s; diff --git a/extensions/amp-sidebar/0.1/test/integration/test-amp-sidebar.js b/extensions/amp-sidebar/0.1/test/integration/test-amp-sidebar.js index 5095c674782a..c20f6591b609 100644 --- a/extensions/amp-sidebar/0.1/test/integration/test-amp-sidebar.js +++ b/extensions/amp-sidebar/0.1/test/integration/test-amp-sidebar.js @@ -16,11 +16,11 @@ import {poll} from '../../../../../testing/iframe'; -describe +describes.sandboxed .configure() .skipSafari() .skipEdge() - .run('amp-sidebar', function () { + .run('amp-sidebar', {}, function () { // Extend timeout slightly for flakes on Windows environments this.timeout(4000); const extensions = ['amp-sidebar']; diff --git a/extensions/amp-sidebar/0.1/test/test-toolbar.js b/extensions/amp-sidebar/0.1/test/test-toolbar.js index 0a8d80db6ccd..342fbf64047a 100644 --- a/extensions/amp-sidebar/0.1/test/test-toolbar.js +++ b/extensions/amp-sidebar/0.1/test/test-toolbar.js @@ -23,7 +23,7 @@ import {toArray} from '../../../../src/core/types/array'; adopt(window); -describe('amp-sidebar - toolbar', () => { +describes.sandboxed('amp-sidebar - toolbar', {}, () => { let timer; function getToolbars(options) { diff --git a/extensions/amp-sidebar/0.2/test/integration/test-amp-sidebar.js b/extensions/amp-sidebar/0.2/test/integration/test-amp-sidebar.js index 5095c674782a..c20f6591b609 100644 --- a/extensions/amp-sidebar/0.2/test/integration/test-amp-sidebar.js +++ b/extensions/amp-sidebar/0.2/test/integration/test-amp-sidebar.js @@ -16,11 +16,11 @@ import {poll} from '../../../../../testing/iframe'; -describe +describes.sandboxed .configure() .skipSafari() .skipEdge() - .run('amp-sidebar', function () { + .run('amp-sidebar', {}, function () { // Extend timeout slightly for flakes on Windows environments this.timeout(4000); const extensions = ['amp-sidebar']; diff --git a/extensions/amp-truncate-text/0.1/test/test-binary-search.js b/extensions/amp-truncate-text/0.1/test/test-binary-search.js index 7fab0b09b627..da78ceab7273 100644 --- a/extensions/amp-truncate-text/0.1/test/test-binary-search.js +++ b/extensions/amp-truncate-text/0.1/test/test-binary-search.js @@ -20,7 +20,7 @@ import { * limitations under the License. */ -describe('binarySearch', () => { +describes.sandboxed('binarySearch', {}, () => { const {NEXT, PREV} = BinarySearchPreference; const {RIGHT, LEFT} = BinarySearchStop; diff --git a/extensions/amp-viewer-integration/0.1/test/integration/test-amp-viewer-integration.js b/extensions/amp-viewer-integration/0.1/test/integration/test-amp-viewer-integration.js index 33632e7bd8d9..0062a2c781e8 100644 --- a/extensions/amp-viewer-integration/0.1/test/integration/test-amp-viewer-integration.js +++ b/extensions/amp-viewer-integration/0.1/test/integration/test-amp-viewer-integration.js @@ -234,10 +234,10 @@ describes.realWin( } ); -describe +describes.sandboxed .configure() .ifChrome() - .run('Unit Tests for messaging.js', () => { + .run('Unit Tests for messaging.js', {}, () => { describes.sandboxed('amp-viewer-integration', {}, (env) => { const viewerOrigin = 'http://localhost:9876'; const messagingToken = '32q4pAwei09W845V3j24o8OJIO3fE9l3q49p'; diff --git a/extensions/amp-viewer-integration/0.1/test/test-findtext.js b/extensions/amp-viewer-integration/0.1/test/test-findtext.js index 164daadd3dbf..abe01d66da91 100644 --- a/extensions/amp-viewer-integration/0.1/test/test-findtext.js +++ b/extensions/amp-viewer-integration/0.1/test/test-findtext.js @@ -23,7 +23,7 @@ import { textPosChar, } from '../findtext'; -describe('CircularBuffer', () => { +describes.sandboxed('CircularBuffer', {}, () => { it('add and get', () => { const buf = new CircularBuffer(5); for (let i = 0; i < 7; i++) { @@ -37,7 +37,7 @@ describe('CircularBuffer', () => { }); }); -describe('canonicalizeString', () => { +describes.sandboxed('canonicalizeString', {}, () => { it('test examples', () => { expect(canonicalizeString('a b c')).to.equal('abc'); expect(canonicalizeString('abc.d')).to.equal('abcd'); diff --git a/test/integration/test-3p-nameframe.js b/test/integration/test-3p-nameframe.js index 9c245ac48145..c17684c01790 100644 --- a/test/integration/test-3p-nameframe.js +++ b/test/integration/test-3p-nameframe.js @@ -14,7 +14,7 @@ * limitations under the License. */ -describe.skip('alt nameframe', function () { +describes.sandboxed.skip('alt nameframe', {}, function () { describes.sandboxed('alt nameframe', {}, () => { describes.realWin('nameframe', {allowExternalResources: true}, (env) => { let fixture; diff --git a/test/integration/test-amp-ad-3p.js b/test/integration/test-amp-ad-3p.js index bb34da97860b..de00383fa8f2 100644 --- a/test/integration/test-amp-ad-3p.js +++ b/test/integration/test-amp-ad-3p.js @@ -31,7 +31,7 @@ function createFixture() { ); } -describe('amp-ad 3P', () => { +describes.sandboxed('amp-ad 3P', {}, () => { let fixture; beforeEach(() => { diff --git a/test/integration/test-amp-ad-doubleclick.js b/test/integration/test-amp-ad-doubleclick.js index 131eb6990945..f6e3bcc06d62 100644 --- a/test/integration/test-amp-ad-doubleclick.js +++ b/test/integration/test-amp-ad-doubleclick.js @@ -16,10 +16,10 @@ import {createFixtureIframe, poll, pollForLayout} from '../../testing/iframe'; -describe +describes.sandboxed .configure() .enableIe() - .run('Rendering of one ad', () => { + .run('Rendering of one ad', {}, () => { let fixture; let beforeHref; diff --git a/test/integration/test-amp-analytics.js b/test/integration/test-amp-analytics.js index 6693b146b026..8e5dde6deb07 100644 --- a/test/integration/test-amp-analytics.js +++ b/test/integration/test-amp-analytics.js @@ -18,11 +18,11 @@ import {BrowserController, RequestBank} from '../../testing/test-helper'; import {parseQueryString} from '../../src/url'; // TODO(wg-analytics): These tests time out on Firefox and Safari. -describe +describes.sandboxed .configure() .skipSafari() .skipFirefox() - .run('amp-analytics', function () { + .run('amp-analytics', {}, function () { describes.integration( 'basic pageview', { diff --git a/test/integration/test-amp-bind.js b/test/integration/test-amp-bind.js index 430a991ae4c3..d6727cde6f59 100644 --- a/test/integration/test-amp-bind.js +++ b/test/integration/test-amp-bind.js @@ -20,10 +20,10 @@ const TIMEOUT = 10000; // Skip Edge, which throws "Permission denied" errors when inspecting // element properties in the testing iframe (Edge 17, Windows 10). -describe +describes.sandboxed .configure() .skipEdge() - .run('amp-bind', function () { + .run('amp-bind', {}, function () { this.timeout(TIMEOUT); // Helper that sets the poll timeout. diff --git a/test/integration/test-amp-img.js b/test/integration/test-amp-img.js index 4dc467abc3b0..ff4939b1cb66 100644 --- a/test/integration/test-amp-img.js +++ b/test/integration/test-amp-img.js @@ -22,10 +22,10 @@ import { poll, } from '../../testing/iframe.js'; -describe +describes.sandboxed .configure() .enableIe() - .run('Rendering of amp-img', () => { + .run('Rendering of amp-img', {}, () => { const timeout = window.ampTestRuntimeConfig.mochaTimeout; let fixture; @@ -105,10 +105,10 @@ describe // Move IE tests into its own `describe()` // so that we can load a different fixture. -describe +describes.sandboxed .configure() .enableIe() - .run('Rendering of amp-img', () => { + .run('Rendering of amp-img', {}, () => { let fixture; beforeEach(async () => { fixture = await createFixtureIframe('test/fixtures/images-ie.html', 500); diff --git a/test/integration/test-amp-pixel.js b/test/integration/test-amp-pixel.js index 6b481b862428..ce8058def14f 100644 --- a/test/integration/test-amp-pixel.js +++ b/test/integration/test-amp-pixel.js @@ -18,7 +18,7 @@ import {AmpPixel} from '../../builtins/amp-pixel/amp-pixel'; import {BrowserController, RequestBank} from '../../testing/test-helper'; import {createElementWithAttributes} from '../../src/dom'; -describe('amp-pixel', function () { +describes.sandboxed('amp-pixel', {}, function () { describes.integration( 'amp-pixel macro integration test', { diff --git a/test/integration/test-amp-recaptcha-input.js b/test/integration/test-amp-recaptcha-input.js index dcf3dc67d016..c8e4eea7c463 100644 --- a/test/integration/test-amp-recaptcha-input.js +++ b/test/integration/test-amp-recaptcha-input.js @@ -20,11 +20,11 @@ import {poll} from '../../testing/iframe'; // TODO(wg-components): These tests are broken on Firefox (as of v77). They // also fail on Safari. -describe +describes.sandboxed .configure() .skipFirefox() .skipSafari() - .run('amp-recaptcha-input', function () { + .run('amp-recaptcha-input', {}, function () { describes.integration( 'with form and amp-mustache', { diff --git a/test/integration/test-amp-skimlinks.js b/test/integration/test-amp-skimlinks.js index 140c94fc1b7d..cd832d5b3e11 100644 --- a/test/integration/test-amp-skimlinks.js +++ b/test/integration/test-amp-skimlinks.js @@ -42,7 +42,7 @@ function clickLinkAndNavigate_(doc, selector) { } // TODO(@slocka) Disabled due to #22154, re-enable -describe.skip('amp-skimlinks', function () { +describes.sandboxed.skip('amp-skimlinks', {}, function () { const setupBasic = { extensions: ['amp-skimlinks'], body: ` diff --git a/test/integration/test-boilerplates.js b/test/integration/test-boilerplates.js index 9c1f97d592bf..b2ea5444852e 100644 --- a/test/integration/test-boilerplates.js +++ b/test/integration/test-boilerplates.js @@ -23,7 +23,7 @@ import {isAnimationNone} from '../../testing/test-helper'; const timeout = window.ampTestRuntimeConfig.mochaTimeout; -describe('Old Opacity Boilerplate', () => { +describes.sandboxed('Old Opacity Boilerplate', {}, () => { let fixture; beforeEach(() => { return createFixtureIframe( @@ -41,7 +41,7 @@ describe('Old Opacity Boilerplate', () => { }); }); -describe('New Visibility Boilerplate', () => { +describes.sandboxed('New Visibility Boilerplate', {}, () => { let fixture; beforeEach(() => { return createFixtureIframe( diff --git a/test/integration/test-configuration.js b/test/integration/test-configuration.js index 23d8675f0afa..746f2541dd3a 100644 --- a/test/integration/test-configuration.js +++ b/test/integration/test-configuration.js @@ -17,7 +17,7 @@ import {AmpEvents} from '../../src/core/constants/amp-events'; import {createFixtureIframe} from '../../testing/iframe.js'; -describe('Configuration', function () { +describes.sandboxed('Configuration', {}, function () { let fixture; beforeEach(() => { return createFixtureIframe('test/fixtures/configuration.html', 500).then( diff --git a/test/integration/test-css.js b/test/integration/test-css.js index ca2b187b37c7..9f80e08c10ac 100644 --- a/test/integration/test-css.js +++ b/test/integration/test-css.js @@ -21,7 +21,7 @@ import { expectBodyToBecomeVisible, } from '../../testing/iframe.js'; -describe.configure().run('CSS', () => { +describes.sandboxed.configure().run('CSS', {}, () => { it('should include height of [overflow] child in size before build', async () => { const fixture = await createFixtureIframe( 'test/fixtures/overflow.html', diff --git a/test/integration/test-double-loading.js b/test/integration/test-double-loading.js index 087812e5a95a..7afd74d1b0b7 100644 --- a/test/integration/test-double-loading.js +++ b/test/integration/test-double-loading.js @@ -27,10 +27,10 @@ function checkElementUpgrade(element) { expect(element).to.not.have.class('i-amphtml-unresolved'); } -describe +describes.sandboxed .configure() .ifModuleBuild() - .run('runtime', () => { + .run('runtime', {}, () => { it('should only execute module code', async () => { const testExtension = 'amp-carousel'; const fixture = await createFixtureIframe( diff --git a/test/integration/test-extensions-loading.js b/test/integration/test-extensions-loading.js index f322b560d2b9..2462f73fa24c 100644 --- a/test/integration/test-extensions-loading.js +++ b/test/integration/test-extensions-loading.js @@ -56,56 +56,60 @@ function testLoadOrderFixture(fixtureName, testElements) { }); } -describe('test extensions loading in multiple orders', function () { - this.timeout(15000); +describes.sandboxed( + 'test extensions loading in multiple orders', + {}, + function () { + this.timeout(15000); - it('one extension, extension loads first, all scripts in header', () => { - return testLoadOrderFixture( - 'test/fixtures/script-load-extension-head-v0-head.html', - ['amp-fit-text'] - ); - }); + it('one extension, extension loads first, all scripts in header', () => { + return testLoadOrderFixture( + 'test/fixtures/script-load-extension-head-v0-head.html', + ['amp-fit-text'] + ); + }); - it('one extension, v0 loads first, all scripts in header', () => { - return testLoadOrderFixture( - 'test/fixtures/script-load-v0-head-extension-head.html', - ['amp-fit-text'] - ); - }); + it('one extension, v0 loads first, all scripts in header', () => { + return testLoadOrderFixture( + 'test/fixtures/script-load-v0-head-extension-head.html', + ['amp-fit-text'] + ); + }); - // TODO(#30528): skip this test as it doesn't make sense. The script - // tags are in the footer and our posthtml transforms break on the - // transformation of these invalid html files. - it.skip('one extension, extension loads first, all scripts in footer', () => { - return testLoadOrderFixture( - 'test/fixtures/script-load-extension-footer-v0-footer.html', - ['amp-fit-text'] - ); - }); + // TODO(#30528): skip this test as it doesn't make sense. The script + // tags are in the footer and our posthtml transforms break on the + // transformation of these invalid html files. + it.skip('one extension, extension loads first, all scripts in footer', () => { + return testLoadOrderFixture( + 'test/fixtures/script-load-extension-footer-v0-footer.html', + ['amp-fit-text'] + ); + }); - // TODO(#30528): skip this test as it doesn't make sense. The script - // tags are in the footer and our posthtml transforms break on the - // transformation of these invalid html files. - it.skip('one extension, v0 loads first, all scripts in footer', () => { - return testLoadOrderFixture( - 'test/fixtures/script-load-v0-footer-extension-footer.html', - ['amp-fit-text'] - ); - }); + // TODO(#30528): skip this test as it doesn't make sense. The script + // tags are in the footer and our posthtml transforms break on the + // transformation of these invalid html files. + it.skip('one extension, v0 loads first, all scripts in footer', () => { + return testLoadOrderFixture( + 'test/fixtures/script-load-v0-footer-extension-footer.html', + ['amp-fit-text'] + ); + }); - it('one extension, v0 in header, extension script in footer', () => { - return testLoadOrderFixture( - 'test/fixtures/script-load-v0-head-extension-footer.html', - ['amp-fit-text'] - ); - }); + it('one extension, v0 in header, extension script in footer', () => { + return testLoadOrderFixture( + 'test/fixtures/script-load-v0-head-extension-footer.html', + ['amp-fit-text'] + ); + }); - // TODO(choumx); This test times out when run with the prod AMP config. - // See #11588. - it.skip('two extensions, one of extension scripts and v0 in header', () => { - return testLoadOrderFixture('test/fixtures/script-load-extensions.html', [ - 'amp-fit-text', - 'amp-iframe', - ]); - }); -}); + // TODO(choumx); This test times out when run with the prod AMP config. + // See #11588. + it.skip('two extensions, one of extension scripts and v0 in header', () => { + return testLoadOrderFixture('test/fixtures/script-load-extensions.html', [ + 'amp-fit-text', + 'amp-iframe', + ]); + }); + } +); diff --git a/test/integration/test-released.js b/test/integration/test-released.js index edffd12e21f1..8a21167f72f1 100644 --- a/test/integration/test-released.js +++ b/test/integration/test-released.js @@ -20,11 +20,11 @@ import { pollForLayout, } from '../../testing/iframe.js'; -describe('released components: ', function () { +describes.sandboxed('released components: ', {}, function () { runTest.call(this, false); }); -describe('released components with polyfills: ', function () { +describes.sandboxed('released components with polyfills: ', {}, function () { runTest.call(this, true); }); diff --git a/test/integration/test-shadow-dom-element.js b/test/integration/test-shadow-dom-element.js index e2e24b83f0bd..2771c4e9aaa0 100644 --- a/test/integration/test-shadow-dom-element.js +++ b/test/integration/test-shadow-dom-element.js @@ -18,10 +18,10 @@ import {createFixtureIframe} from '../../testing/iframe'; import {toggleExperiment} from '../../src/experiments'; import {whenUpgradedToCustomElement} from '../../src/dom'; -describe +describes.sandboxed .configure() .enableIe() - .run('Render a shadow-dom based element', () => { + .run('Render a shadow-dom based element', {}, () => { let fixture; beforeEach(async () => { @@ -56,9 +56,9 @@ describe }); }); -describe +describes.sandboxed .configure() - .run('Render a shadow-dom based element, force polyfill', () => { + .run('Render a shadow-dom based element, force polyfill', {}, () => { let fixture; beforeEach(async () => { diff --git a/test/integration/test-video-manager.js b/test/integration/test-video-manager.js index 4331f13515ab..6e103e5f82e6 100644 --- a/test/integration/test-video-manager.js +++ b/test/integration/test-video-manager.js @@ -29,28 +29,30 @@ import {toArray} from '../../src/core/types/array'; // TODO(dvoytenko): These tests time out when run with the prod AMP config. // See #11588. -describe.configure().skip('Fake Video PlayerIntegration Tests', () => { - // We run the video player integration tests on a fake video player as part - // of functional testing. Same tests run on real video players such as - // `amp-video` and `amp-youtube` as part of integration testing. - runVideoPlayerIntegrationTests((fixture) => { - fixture.win.AMP.push({ - n: 'amp-test-fake-videoplayer', - f: function (AMP) { - AMP.registerElement( - 'amp-test-fake-videoplayer', - createFakeVideoPlayerClass(fixture.win) - ); - }, +describes.sandboxed + .configure() + .skip('Fake Video PlayerIntegration Tests', {}, () => { + // We run the video player integration tests on a fake video player as part + // of functional testing. Same tests run on real video players such as + // `amp-video` and `amp-youtube` as part of integration testing. + runVideoPlayerIntegrationTests((fixture) => { + fixture.win.AMP.push({ + n: 'amp-test-fake-videoplayer', + f: function (AMP) { + AMP.registerElement( + 'amp-test-fake-videoplayer', + createFakeVideoPlayerClass(fixture.win) + ); + }, + }); + return fixture.doc.createElement('amp-test-fake-videoplayer'); }); - return fixture.doc.createElement('amp-test-fake-videoplayer'); }); -}); -describe +describes.sandboxed .configure() .ifChrome() - .run('VideoManager', function () { + .run('VideoManager', {}, function () { describes.realWin( 'VideoManager', { @@ -281,10 +283,10 @@ describe ); }); -describe +describes.sandboxed .configure() .ifChrome() - .run('Autoplay support', () => { + .run('Autoplay support', {}, () => { let win; let video; let createElementSpy; diff --git a/test/integration/test-video-players.js b/test/integration/test-video-players.js index 7089ed5d7062..c5c1bb557ec7 100644 --- a/test/integration/test-video-players.js +++ b/test/integration/test-video-players.js @@ -29,10 +29,10 @@ import {runVideoPlayerIntegrationTests} from './test-video-players-helper'; // TODO(aghassemi,#7822): Videos may not be playable on an iOS simulator. -describe +describes.sandboxed .configure() .skipIos() - .run('amp-video', () => { + .run('amp-video', {}, () => { runVideoPlayerIntegrationTests((fixture) => { const video = fixture.doc.createElement('amp-video'); video.setAttribute('src', '/examples/av/ForBiggerJoyrides-tiny.mp4'); @@ -41,7 +41,7 @@ describe }); // TODO(alanorozco): unskip -describe.skip('amp-video-iframe', () => { +describes.sandboxed.skip('amp-video-iframe', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-video-iframe'); @@ -55,7 +55,7 @@ describe.skip('amp-video-iframe', () => { }); //TODO(aghassemi, #9379): unskip -describe.skip('amp-youtube', () => { +describes.sandboxed.skip('amp-youtube', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-youtube'); @@ -68,7 +68,7 @@ describe.skip('amp-youtube', () => { }); //TODO(aghassemi, #9379): unskip -describe.skip('amp-dailymotion', () => { +describes.sandboxed.skip('amp-dailymotion', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-dailymotion'); @@ -80,7 +80,7 @@ describe.skip('amp-dailymotion', () => { ); }); -describe.configure().skip('amp-3q-player', () => { +describes.sandboxed.configure().skip('amp-3q-player', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-3q-player'); @@ -93,7 +93,7 @@ describe.configure().skip('amp-3q-player', () => { }); //TODO(aghassemi,#8264): Unskip when integration is fixed. -describe.skip('amp-nexxtv-player', () => { +describes.sandboxed.skip('amp-nexxtv-player', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-nexxtv-player'); @@ -107,7 +107,7 @@ describe.skip('amp-nexxtv-player', () => { }); //TODO(aghassemi, #9379): unskip -describe.skip('amp-ima-video', () => { +describes.sandboxed.skip('amp-ima-video', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-ima-video'); @@ -129,7 +129,7 @@ describe.skip('amp-ima-video', () => { }); //TODO(cvializ, #14833): unskip after brid player is fixed -describe.skip('amp-brid-player', () => { +describes.sandboxed.skip('amp-brid-player', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-brid-player'); @@ -143,7 +143,7 @@ describe.skip('amp-brid-player', () => { ); }); -describe.skip('amp-brightcove', () => { +describes.sandboxed.skip('amp-brightcove', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-brightcove'); @@ -157,7 +157,7 @@ describe.skip('amp-brightcove', () => { ); }); -describe.skip('amp-delight-player', () => { +describes.sandboxed.skip('amp-delight-player', {}, () => { runVideoPlayerIntegrationTests( (fixture) => { const video = fixture.doc.createElement('amp-delight-player'); diff --git a/test/unit/3p/test-3p-messaging.js b/test/unit/3p/test-3p-messaging.js index a9b24a0334da..9f269c48a93d 100644 --- a/test/unit/3p/test-3p-messaging.js +++ b/test/unit/3p/test-3p-messaging.js @@ -19,7 +19,7 @@ import {createIframePromise} from '../../../testing/iframe'; import {listenParent} from '../../../3p/messaging'; import {postMessage} from '../../../src/iframe-helper'; -describe('3p messaging', () => { +describes.sandboxed('3p messaging', {}, () => { let testWin; let iframe; const timer = Services.timerFor(window); diff --git a/test/unit/3p/test-recaptcha.js b/test/unit/3p/test-recaptcha.js index 4e6c4dd95672..dfa3f7c5afe8 100644 --- a/test/unit/3p/test-recaptcha.js +++ b/test/unit/3p/test-recaptcha.js @@ -21,7 +21,7 @@ import { import {parseUrlDeprecated} from '../../../src/url'; import {urls} from '../../../src/config'; -describe('3p recaptcha.js', () => { +describes.sandboxed('3p recaptcha.js', {}, () => { it('should require a window.name', () => { window.name = undefined; expect(initRecaptcha).to.throw('window'); diff --git a/test/unit/ads/test-unruly.js b/test/unit/ads/test-unruly.js index ff4142b5b213..0d8b4f18f031 100644 --- a/test/unit/ads/test-unruly.js +++ b/test/unit/ads/test-unruly.js @@ -16,7 +16,7 @@ import {unruly} from '../../../ads/vendors/unruly'; -describe('unruly', () => { +describes.sandboxed('unruly', {}, () => { it('should set unruly publisher config on global', () => { const mockGlobal = {}; const mockData = { diff --git a/test/unit/test-3p-environment.js b/test/unit/test-3p-environment.js index 40eeeaed4909..6d97f518c4a6 100644 --- a/test/unit/test-3p-environment.js +++ b/test/unit/test-3p-environment.js @@ -20,7 +20,7 @@ import {createIframePromise} from '../../testing/iframe'; import {loadPromise} from '../../src/event-helper'; import {manageWin, setInViewportForTesting} from '../../3p/environment'; -describe('3p environment', () => { +describes.sandboxed('3p environment', {}, () => { let testWin; let iframeCount; const timer = Services.timerFor(window); diff --git a/test/unit/test-3p.js b/test/unit/test-3p.js index 6aeee4a9cf32..283aa898cbe2 100644 --- a/test/unit/test-3p.js +++ b/test/unit/test-3p.js @@ -23,7 +23,7 @@ import { validateSrcPrefix, } from '../../3p/3p'; -describe('3p', () => { +describes.sandboxed('3p', {}, () => { let clock; beforeEach(() => { diff --git a/test/unit/test-action.js b/test/unit/test-action.js index db547b5b648a..7192002597e4 100644 --- a/test/unit/test-action.js +++ b/test/unit/test-action.js @@ -83,7 +83,7 @@ function assertInvocation( } } -describe('ActionService parseAction', () => { +describes.sandboxed('ActionService parseAction', {}, () => { function parseMultipleActions(s) { const actionMap = parseActionMap(s); if (actionMap == null) { @@ -470,7 +470,7 @@ describe('ActionService parseAction', () => { }); }); -describe('ActionService setActions', () => { +describes.sandboxed('ActionService setActions', {}, () => { it('should set actions', () => { const action = actionService(); const element = document.createElement('div'); @@ -491,7 +491,7 @@ describe('ActionService setActions', () => { }); }); -describe('Action parseActionMap', () => { +describes.sandboxed('Action parseActionMap', {}, () => { it('should parse with a single action', () => { const m = parseActionMap('event1:action1'); expect(m['event1'][0].target).to.equal('action1'); diff --git a/test/unit/test-activity.js b/test/unit/test-activity.js index 85401300d161..1463b3ce4b2e 100644 --- a/test/unit/test-activity.js +++ b/test/unit/test-activity.js @@ -25,7 +25,7 @@ import {installViewportServiceForDoc} from '../../src/service/viewport/viewport- import {installVsyncService} from '../../src/service/vsync-impl'; import {markElementScheduledForTesting} from '../../src/service/custom-element-registry'; -describe('Activity getTotalEngagedTime', () => { +describes.sandboxed('Activity getTotalEngagedTime', {}, () => { let clock; let fakeDoc; let fakeWin; @@ -259,7 +259,7 @@ describe('Activity getTotalEngagedTime', () => { ); }); -describe('Activity getIncrementalEngagedTime', () => { +describes.sandboxed('Activity getIncrementalEngagedTime', {}, () => { let clock; let fakeDoc; let fakeWin; diff --git a/test/unit/test-ad-helper.js b/test/unit/test-ad-helper.js index e1ab266313a7..341c45685bfb 100644 --- a/test/unit/test-ad-helper.js +++ b/test/unit/test-ad-helper.js @@ -18,7 +18,7 @@ import {computedStyle} from '../../src/style'; import {createIframePromise} from '../../testing/iframe'; import {getAdContainer, isAdPositionAllowed} from '../../src/ad-helper'; -describe('ad-helper', () => { +describes.sandboxed('ad-helper', {}, () => { describe('isAdPositionAllowed function', () => { it('should allow position fixed element that is allowlisted', () => { return createIframePromise().then((iframe) => { diff --git a/test/unit/test-ads-config.js b/test/unit/test-ads-config.js index fd7c293749ee..00f645b87c15 100644 --- a/test/unit/test-ads-config.js +++ b/test/unit/test-ads-config.js @@ -17,7 +17,7 @@ import {adConfig} from '../../ads/_config'; import {hasOwn} from '../../src/core/types/object'; -describe('test-ads-config', () => { +describes.sandboxed('test-ads-config', {}, () => { it('should have all ad networks configured', () => { window.ampTestRuntimeConfig.adTypes.forEach((adType) => { expect(adConfig, `Missing config for [${adType}]`).to.contain.key(adType); diff --git a/test/unit/test-alp-handler.js b/test/unit/test-alp-handler.js index 1575d70732c8..84dfe98b1f61 100644 --- a/test/unit/test-alp-handler.js +++ b/test/unit/test-alp-handler.js @@ -17,7 +17,7 @@ import {handleClick, warmupDynamic, warmupStatic} from '../../ads/alp/handler'; import {parseUrlDeprecated} from '../../src/url'; -describe('alp-handler', () => { +describes.sandboxed('alp-handler', {}, () => { let event; let anchor; let open; diff --git a/test/unit/test-amp-context.js b/test/unit/test-amp-context.js index 9c66836ad8b5..69bfe6d55397 100644 --- a/test/unit/test-amp-context.js +++ b/test/unit/test-amp-context.js @@ -19,7 +19,7 @@ import {Platform} from '../../src/service/platform-impl'; const NOOP = () => {}; -describe('3p ampcontext.js', () => { +describes.sandboxed('3p ampcontext.js', {}, () => { let windowPostMessageSpy; let windowMessageHandler; let win; diff --git a/test/unit/test-amp-inabox.js b/test/unit/test-amp-inabox.js index 44d08f522f1d..2e300a4a9c18 100644 --- a/test/unit/test-amp-inabox.js +++ b/test/unit/test-amp-inabox.js @@ -20,7 +20,7 @@ import {installAmpdocServices} from '../../src/service/core-services'; import {installAmpdocServicesForInabox} from '../../src/inabox/inabox-services'; import {removeItem} from '../../src/core/types/array'; -describe('amp-inabox', () => { +describes.sandboxed('amp-inabox', {}, () => { describes.realWin('installAmpdocServicesForInabox', {amp: false}, (env) => { it('should install same services for inabox', () => { let installedServices = []; diff --git a/test/unit/test-animation.js b/test/unit/test-animation.js index 56ea7326bd13..9bcb34c6a5bb 100644 --- a/test/unit/test-animation.js +++ b/test/unit/test-animation.js @@ -16,7 +16,7 @@ import {Animation} from '../../src/animation'; -describe('Animation', () => { +describes.sandboxed('Animation', {}, () => { let vsync; let vsyncTasks; let anim; diff --git a/test/unit/test-batched-json.js b/test/unit/test-batched-json.js index 509c869a8b3f..e3bc70e35900 100644 --- a/test/unit/test-batched-json.js +++ b/test/unit/test-batched-json.js @@ -18,7 +18,7 @@ import {Services} from '../../src/services'; import {UrlReplacementPolicy, batchFetchJsonFor} from '../../src/batched-json'; import {user} from '../../src/log'; -describe('batchFetchJsonFor', () => { +describes.sandboxed('batchFetchJsonFor', {}, () => { // Fakes. const ampdoc = {win: null}; // Service fakes. diff --git a/test/unit/test-callout-vendors.js b/test/unit/test-callout-vendors.js index 4ab64df17ba5..5a877d963e51 100644 --- a/test/unit/test-callout-vendors.js +++ b/test/unit/test-callout-vendors.js @@ -19,7 +19,7 @@ import {isSecureUrlDeprecated} from '../../src/url'; // The keys of RTC_VENDORS are not allowed to have any capital letters. // This test acts as a presubmit to enforce that. -describe('RTC_VENDORS', () => { +describes.sandboxed('RTC_VENDORS', {}, () => { it('should have all lowercase keys', () => Object.keys(RTC_VENDORS).forEach((key) => expect(key).to.equal(key.toLowerCase()) diff --git a/test/unit/test-chunk.js b/test/unit/test-chunk.js index cc3385a38208..4b574d3a8523 100644 --- a/test/unit/test-chunk.js +++ b/test/unit/test-chunk.js @@ -24,7 +24,7 @@ import { } from '../../src/chunk'; import {installDocService} from '../../src/service/ampdoc-impl'; -describe('chunk2', () => { +describes.sandboxed('chunk2', {}, () => { beforeEach(() => { activateChunkingForTesting(); }); @@ -360,7 +360,7 @@ describe('chunk2', () => { ); }); -describe('long tasks', () => { +describes.sandboxed('long tasks', {}, () => { describes.fakeWin( 'long chunk tasks force a macro task between work', { @@ -482,7 +482,7 @@ describe('long tasks', () => { ); }); -describe('isInputPending usage', () => { +describes.sandboxed('isInputPending usage', {}, () => { describes.fakeWin( 'pending input breaks microtask loop to subsequent macrotask', { @@ -589,7 +589,7 @@ describe('isInputPending usage', () => { ); }); -describe('onIdle', () => { +describes.sandboxed('onIdle', {}, () => { let win; let calls; let callbackCalled; diff --git a/test/unit/test-cid.js b/test/unit/test-cid.js index 68786f77ab9b..cbf9ae5e7c16 100644 --- a/test/unit/test-cid.js +++ b/test/unit/test-cid.js @@ -803,7 +803,7 @@ describes.sandboxed('cid', {}, (env) => { } }); -describe('getProxySourceOrigin', () => { +describes.sandboxed('getProxySourceOrigin', {}, () => { it('should fail on non-proxy origin', () => { allowConsoleError(() => { expect(() => { diff --git a/test/unit/test-curve.js b/test/unit/test-curve.js index 0fe09799732d..1c7f36c7d5ae 100644 --- a/test/unit/test-curve.js +++ b/test/unit/test-curve.js @@ -16,7 +16,7 @@ import {Curves, bezierCurve, getCurve} from '../../src/curve'; -describe('Curve', () => { +describes.sandboxed('Curve', {}, () => { it('bezierCurve', () => { let curve = bezierCurve(0.75, 0, 0.75, 0.9); expect(curve(0.2)).to.be.closeTo(0.024374631, 1e-6); diff --git a/test/unit/test-describes.js b/test/unit/test-describes.js index d784c3cc831e..344db0629374 100644 --- a/test/unit/test-describes.js +++ b/test/unit/test-describes.js @@ -15,7 +15,7 @@ */ // Test `fetch-mock` integration in describes. -describe('fetch-mock', () => { +describes.sandboxed('fetch-mock', {}, () => { /** @param {!Object} env */ function runTests(env) { it('should mock fetches', () => { diff --git a/test/unit/test-document-info.js b/test/unit/test-document-info.js index a0bffc556a4e..1584e13947e8 100644 --- a/test/unit/test-document-info.js +++ b/test/unit/test-document-info.js @@ -21,10 +21,10 @@ import {createIframePromise} from '../../testing/iframe'; import {installDocService} from '../../src/service/ampdoc-impl'; import {installDocumentInfoServiceForDoc} from '../../src/service/document-info-impl'; -describe +describes.sandboxed .configure() .skipFirefox() - .run('document-info', () => { + .run('document-info', {}, () => { beforeEach(() => { window.sandbox.stub(CID, 'getRandomString64').returns('abcdef'); }); diff --git a/test/unit/test-document-ready.js b/test/unit/test-document-ready.js index 8212e620f468..4963e139f9db 100644 --- a/test/unit/test-document-ready.js +++ b/test/unit/test-document-ready.js @@ -22,7 +22,7 @@ import { whenDocumentReady, } from '../../src/document-ready'; -describe('documentReady', () => { +describes.sandboxed('documentReady', {}, () => { let testDoc; let eventListeners; const timer = Services.timerFor(window); diff --git a/test/unit/test-event-helper.js b/test/unit/test-event-helper.js index 1a16bbc1c540..92769843938e 100644 --- a/test/unit/test-event-helper.js +++ b/test/unit/test-event-helper.js @@ -31,7 +31,7 @@ import { supportsPassiveEventListener, } from '../../src/event-helper-listen'; -describe('EventHelper', () => { +describes.sandboxed('EventHelper', {}, () => { function getEvent(name, target) { const event = document.createEvent('Event'); event.initEvent(name, true, true); diff --git a/test/unit/test-experiments.js b/test/unit/test-experiments.js index e45eb0d3e9f8..d37aabd43361 100644 --- a/test/unit/test-experiments.js +++ b/test/unit/test-experiments.js @@ -38,7 +38,7 @@ function fakeLocalStorage(initial = {}) { }; } -describe('experimentToggles', () => { +describes.sandboxed('experimentToggles', {}, () => { it('should return experiment status map', () => { const win = { localStorage: fakeLocalStorage({ @@ -106,7 +106,7 @@ describe('experimentToggles', () => { }); }); -describe('isExperimentOn', () => { +describes.sandboxed('isExperimentOn', {}, () => { let win; beforeEach(() => { @@ -212,7 +212,7 @@ describe('isExperimentOn', () => { }); }); -describe('toggleExperiment', () => { +describes.sandboxed('toggleExperiment', {}, () => { let clock; beforeEach(() => { @@ -531,7 +531,7 @@ describes.fakeWin('url override', {}, (env) => { }); }); -describe('isCanary', () => { +describes.sandboxed('isCanary', {}, () => { it('should return value based on binary version', () => { const win = { AMP_CONFIG: { @@ -544,7 +544,7 @@ describe('isCanary', () => { }); }); -describe('getBinaryType', () => { +describes.sandboxed('getBinaryType', {}, () => { it('should return correct type', () => { const win = { AMP_CONFIG: { @@ -566,7 +566,7 @@ describe('getBinaryType', () => { }); }); -describe('experiment branch tests', () => { +describes.sandboxed('experiment branch tests', {}, () => { describe('#randomlySelectUnsetExperiments', () => { let accurateRandomStub; let cachedAccuratePrng; diff --git a/test/unit/test-exponential-backoff.js b/test/unit/test-exponential-backoff.js index fa9537269e7e..bfa655476644 100644 --- a/test/unit/test-exponential-backoff.js +++ b/test/unit/test-exponential-backoff.js @@ -19,7 +19,7 @@ import { exponentialBackoffClock, } from '../../src/exponential-backoff'; -describe('exponentialBackoff', () => { +describes.sandboxed('exponentialBackoff', {}, () => { let clock; beforeEach(() => { diff --git a/test/unit/test-finite-state-machine.js b/test/unit/test-finite-state-machine.js index 4869671f31b8..d2543d22857b 100644 --- a/test/unit/test-finite-state-machine.js +++ b/test/unit/test-finite-state-machine.js @@ -16,7 +16,7 @@ import {FiniteStateMachine} from '../../src/finite-state-machine'; -describe('Finite State Machine', () => { +describes.sandboxed('Finite State Machine', {}, () => { describe('simple machines', () => { let fsm; let spy; diff --git a/test/unit/test-focus-history.js b/test/unit/test-focus-history.js index 056426c19122..d17b25c7fffd 100644 --- a/test/unit/test-focus-history.js +++ b/test/unit/test-focus-history.js @@ -17,7 +17,7 @@ import {FocusHistory} from '../../src/focus-history'; import {installTimerService} from '../../src/service/timer-impl'; -describe('FocusHistory', () => { +describes.sandboxed('FocusHistory', {}, () => { let clock; let testDoc; let eventListeners; diff --git a/test/unit/test-gesture-recognizers.js b/test/unit/test-gesture-recognizers.js index 778c9eacdbeb..768718c2cc38 100644 --- a/test/unit/test-gesture-recognizers.js +++ b/test/unit/test-gesture-recognizers.js @@ -23,7 +23,7 @@ import { } from '../../src/gesture-recognizers'; import {Gestures} from '../../src/gesture'; -describe('TapRecognizer', () => { +describes.sandboxed('TapRecognizer', {}, () => { let element; let recognizer; let gestures; @@ -118,7 +118,7 @@ describe('TapRecognizer', () => { }); }); -describe('DoubletapRecognizer', () => { +describes.sandboxed('DoubletapRecognizer', {}, () => { let element; let recognizer; let gestures; @@ -224,7 +224,7 @@ describe('DoubletapRecognizer', () => { }); }); -describe('SwipeXYRecognizer', () => { +describes.sandboxed('SwipeXYRecognizer', {}, () => { let element; let clock; let recognizer; @@ -483,7 +483,7 @@ describe('SwipeXYRecognizer', () => { }); }); -describe('TapzoomRecognizer', () => { +describes.sandboxed('TapzoomRecognizer', {}, () => { let element; let clock; let recognizer; @@ -697,7 +697,7 @@ describe('TapzoomRecognizer', () => { }); }); -describe('PinchRecognizer', () => { +describes.sandboxed('PinchRecognizer', {}, () => { let element; let clock; let recognizer; diff --git a/test/unit/test-gesture.js b/test/unit/test-gesture.js index 6036952853a9..428b84df7c02 100644 --- a/test/unit/test-gesture.js +++ b/test/unit/test-gesture.js @@ -16,7 +16,7 @@ import {GestureRecognizer, Gestures} from '../../src/gesture'; -describe('Gestures', () => { +describes.sandboxed('Gestures', {}, () => { class TestRecognizer extends GestureRecognizer { constructor(manager) { super('test', manager); diff --git a/test/unit/test-get-html.js b/test/unit/test-get-html.js index 9a27afc4092a..8525a387c9d7 100644 --- a/test/unit/test-get-html.js +++ b/test/unit/test-get-html.js @@ -28,7 +28,7 @@ const template = `
import {getHtml} from '../../src/get-html'; -describe('getHtml', () => { +describes.sandboxed('getHtml', {}, () => { let element; beforeEach(() => { diff --git a/test/unit/test-ie-media-bug.js b/test/unit/test-ie-media-bug.js index f89eb5c39bb1..bba1f4bfbfe8 100644 --- a/test/unit/test-ie-media-bug.js +++ b/test/unit/test-ie-media-bug.js @@ -17,7 +17,7 @@ import {dev} from '../../src/log'; import {ieMediaCheckAndFix} from '../../src/service/ie-media-bug'; -describe('ie-media-bug', () => { +describes.sandboxed('ie-media-bug', {}, () => { let clock; let windowApi, windowMock; let platform; diff --git a/test/unit/test-iframe-helper.js b/test/unit/test-iframe-helper.js index 85ed19fc73a8..1ad939cb8419 100644 --- a/test/unit/test-iframe-helper.js +++ b/test/unit/test-iframe-helper.js @@ -17,10 +17,10 @@ import * as IframeHelper from '../../src/iframe-helper'; import {createIframePromise} from '../../testing/iframe'; import {generateSentinel} from '../../src/3p-frame'; -describe +describes.sandboxed .configure() .skipFirefox() - .run('iframe-helper', function () { + .run('iframe-helper', {}, function () { const iframeSrc = 'http://iframe.localhost:' + location.port + diff --git a/test/unit/test-iframe-stub.js b/test/unit/test-iframe-stub.js index 2d02e6ab25cf..6bf11f889648 100644 --- a/test/unit/test-iframe-stub.js +++ b/test/unit/test-iframe-stub.js @@ -19,10 +19,10 @@ import { expectPostMessage, } from '../../testing/iframe'; -describe +describes.sandboxed .configure() .skipFirefox() - .run('test-iframe-createIframeWithMessageStub', () => { + .run('test-iframe-createIframeWithMessageStub', {}, () => { const data1 = { foo: 'bar', test: true, diff --git a/test/unit/test-input.js b/test/unit/test-input.js index cbfb73791480..7e1bcaa1b73d 100644 --- a/test/unit/test-input.js +++ b/test/unit/test-input.js @@ -18,7 +18,7 @@ import {Input} from '../../src/input'; import {installTimerService} from '../../src/service/timer-impl.js'; import {stubService} from '../../testing/test-helper'; -describe('Input', () => { +describes.sandboxed('Input', {}, () => { let clock; let input; let eventListeners; diff --git a/test/unit/test-integration.js b/test/unit/test-integration.js index 1389cb171db9..1de39ab91fb5 100644 --- a/test/unit/test-integration.js +++ b/test/unit/test-integration.js @@ -27,7 +27,7 @@ import { } from '../../3p/integration-lib'; import {getRegistrations, register} from '../../3p/3p'; -describe('3p integration.js', () => { +describes.sandboxed('3p integration.js', {}, () => { const registrations = getRegistrations(); afterEach(() => { delete registrations.testAction; diff --git a/test/unit/test-intersection-observer-polyfill.js b/test/unit/test-intersection-observer-polyfill.js index d29bb30c6e79..46b63d91df30 100644 --- a/test/unit/test-intersection-observer-polyfill.js +++ b/test/unit/test-intersection-observer-polyfill.js @@ -167,7 +167,7 @@ describes.sandboxed('getIntersectionChangeEntry', {}, (env) => { }); }); -describe('intersectionRatio', () => { +describes.sandboxed('intersectionRatio', {}, () => { let smallRectMock; let largeRectMock; beforeEach(() => { diff --git a/test/unit/test-json.js b/test/unit/test-json.js index 3745674fe74e..7058d2c00ebb 100644 --- a/test/unit/test-json.js +++ b/test/unit/test-json.js @@ -22,7 +22,7 @@ import { tryParseJson, } from '../../src/json'; -describe('json', () => { +describes.sandboxed('json', {}, () => { describe('getValueForExpr', () => { it('should return self for "."', () => { const obj = {str: 'A', num: 1, bool: true, val: null}; diff --git a/test/unit/test-layout-rect.js b/test/unit/test-layout-rect.js index 0b6f63a15477..e583edcd3978 100644 --- a/test/unit/test-layout-rect.js +++ b/test/unit/test-layout-rect.js @@ -16,7 +16,7 @@ import * as lr from '../../src/layout-rect'; -describe('LayoutRect', () => { +describes.sandboxed('LayoutRect', {}, () => { it('layoutRectLtwh', () => { const rect = lr.layoutRectLtwh(1, 2, 3, 4); expect(rect.left).to.equal(1); @@ -119,7 +119,7 @@ describe('LayoutRect', () => { }); }); -describe('cloneLayoutMarginsChangeDef', () => { +describes.sandboxed('cloneLayoutMarginsChangeDef', {}, () => { it('should clone margins change correctly into new object', () => { const marginsChange = { top: 1, @@ -135,7 +135,7 @@ describe('cloneLayoutMarginsChangeDef', () => { }); }); -describe('layoutRectSizeEquals', () => { +describes.sandboxed('layoutRectSizeEquals', {}, () => { it('should detect changes', () => { const from = lr.layoutRectLtwh(10, 20, 1, 1); const to = lr.layoutRectLtwh(10, 20, 40, 50); @@ -149,7 +149,7 @@ describe('layoutRectSizeEquals', () => { }); }); -describe('areMarginsChanged', () => { +describes.sandboxed('areMarginsChanged', {}, () => { it('should find margins are not changed when values the same', () => { const margins = { top: 1, diff --git a/test/unit/test-layout.js b/test/unit/test-layout.js index 115b5d8e23dd..12bfd48b2726 100644 --- a/test/unit/test-layout.js +++ b/test/unit/test-layout.js @@ -28,7 +28,7 @@ import { } from '../../src/layout'; import {isExperimentOn, toggleExperiment} from '../../src/experiments'; -describe('Layout', () => { +describes.sandboxed('Layout', {}, () => { let div; let aspectRatioEnabled; diff --git a/test/unit/test-log.js b/test/unit/test-log.js index ceeebb66bb5e..9996f06e3b14 100644 --- a/test/unit/test-log.js +++ b/test/unit/test-log.js @@ -27,7 +27,7 @@ import { userAssert, } from '../../src/log'; -describe('Logging', () => { +describes.sandboxed('Logging', {}, () => { const RETURNS_FINE = () => LogLevel.FINE; const RETURNS_INFO = () => LogLevel.INFO; const RETURNS_WARN = () => LogLevel.WARN; diff --git a/test/unit/test-mode.js b/test/unit/test-mode.js index 6c4dfb89e2fa..eb02439afc96 100644 --- a/test/unit/test-mode.js +++ b/test/unit/test-mode.js @@ -21,7 +21,7 @@ import { } from '../../src/mode'; import {parseUrlDeprecated} from '../../src/url'; -describe('getMode', () => { +describes.sandboxed('getMode', {}, () => { function getWin(url) { const win = { location: parseUrlDeprecated(url), @@ -52,7 +52,7 @@ describe('getMode', () => { }); }); -describe('getRtvVersion', () => { +describes.sandboxed('getRtvVersion', {}, () => { afterEach(() => { resetRtvVersionForTesting(); }); diff --git a/test/unit/test-motion.js b/test/unit/test-motion.js index 41aca7923483..79716accca1d 100644 --- a/test/unit/test-motion.js +++ b/test/unit/test-motion.js @@ -16,7 +16,7 @@ import {calcVelocity, continueMotion} from '../../src/motion'; -describe('Motion calcVelocity', () => { +describes.sandboxed('Motion calcVelocity', {}, () => { it('should dampen velocity when prevVelocity is 0', () => { expect(calcVelocity(200, 10, 0)).to.be.closeTo(15.999, 1e-3); }); @@ -50,7 +50,7 @@ describe('Motion calcVelocity', () => { }); }); -describe('Motion continueMotion', () => { +describes.sandboxed('Motion continueMotion', {}, () => { let clock; let vsync; let vsyncTasks; diff --git a/test/unit/test-mustache.js b/test/unit/test-mustache.js index b0040b9d6354..1ca44128a332 100644 --- a/test/unit/test-mustache.js +++ b/test/unit/test-mustache.js @@ -16,7 +16,7 @@ import mustache from '../../third_party/mustache/mustache'; -describe('Mustache', () => { +describes.sandboxed('Mustache', {}, () => { let savedSanitizer; beforeEach(() => { diff --git a/test/unit/test-pass.js b/test/unit/test-pass.js index 97f57b4adaee..3ffb712b7118 100644 --- a/test/unit/test-pass.js +++ b/test/unit/test-pass.js @@ -17,7 +17,7 @@ import {Pass} from '../../src/pass'; import {Services} from '../../src/services'; -describe('Pass', () => { +describes.sandboxed('Pass', {}, () => { let pass; let timerMock; let handlerCalled; diff --git a/test/unit/test-platform.js b/test/unit/test-platform.js index 33dd6e8a67f3..1227b98672c9 100644 --- a/test/unit/test-platform.js +++ b/test/unit/test-platform.js @@ -16,7 +16,7 @@ import {Platform} from '../../src/service/platform-impl'; -describe('Platform', () => { +describes.sandboxed('Platform', {}, () => { let isIos; let isAndroid; let isChrome; diff --git a/test/unit/test-pull-to-refresh.js b/test/unit/test-pull-to-refresh.js index 5174a9649282..0ebc65c06654 100644 --- a/test/unit/test-pull-to-refresh.js +++ b/test/unit/test-pull-to-refresh.js @@ -16,7 +16,7 @@ import {PullToRefreshBlocker} from '../../src/pull-to-refresh'; -describe('PullToRefreshBlocker', () => { +describes.sandboxed('PullToRefreshBlocker', {}, () => { let eventListeners; let viewportMock; let blocker; diff --git a/test/unit/test-purifier.js b/test/unit/test-purifier.js index bbefe36ab1fb..565c345ecf21 100644 --- a/test/unit/test-purifier.js +++ b/test/unit/test-purifier.js @@ -17,10 +17,10 @@ import * as urlRewrite from '../../src/url-rewrite'; import {Purifier} from '../../src/purifier/purifier'; -describe +describes.sandboxed .configure() .skipFirefox() - .run('DOMPurify-based', () => { + .run('DOMPurify-based', {}, () => { let purify; let purifyTripleMustache; let rewriteAttributeValueSpy; @@ -766,10 +766,10 @@ describe }); }); -describe +describes.sandboxed .configure() .skipFirefox() - .run('DOMPurify-based, custom html', () => { + .run('DOMPurify-based, custom html', {}, () => { let html; let purify; @@ -868,7 +868,7 @@ describe }); }); -describe('validateAttributeChange', () => { +describes.sandboxed('validateAttributeChange', {}, () => { let purifier; let vac; @@ -933,7 +933,7 @@ describe('validateAttributeChange', () => { }); }); -describe('getAllowedTags', () => { +describes.sandboxed('getAllowedTags', {}, () => { let allowedTags; beforeEach(() => { diff --git a/test/unit/test-render-delaying-services.js b/test/unit/test-render-delaying-services.js index c26779da5c4c..b1cf39540bfc 100644 --- a/test/unit/test-render-delaying-services.js +++ b/test/unit/test-render-delaying-services.js @@ -23,7 +23,7 @@ import { } from '../../src/render-delaying-services'; import {macroTask} from '../../testing/yield'; -describe('waitForServices', () => { +describes.sandboxed('waitForServices', {}, () => { let win; let clock; let dynamicCssResolve; diff --git a/test/unit/test-resource.js b/test/unit/test-resource.js index 178a0b2812e1..de82dd5f9d54 100644 --- a/test/unit/test-resource.js +++ b/test/unit/test-resource.js @@ -981,7 +981,7 @@ describes.realWin('Resource', {amp: true}, (env) => { }); }); -describe('Resource idleRenderOutsideViewport', () => { +describes.sandboxed('Resource idleRenderOutsideViewport', {}, () => { let element; let resources; let resource; diff --git a/test/unit/test-sanitizer.js b/test/unit/test-sanitizer.js index 09aab69d9924..03ec8cd0ee6a 100644 --- a/test/unit/test-sanitizer.js +++ b/test/unit/test-sanitizer.js @@ -19,7 +19,7 @@ import {sanitizeHtml, sanitizeTagsForTripleMustache} from '../../src/sanitizer'; let sanitize; let html; -describe('Caja-based', () => { +describes.sandboxed('Caja-based', {}, () => { beforeEach(() => { html = document.createElement('html'); const documentEl = {documentElement: html}; diff --git a/test/unit/test-service.js b/test/unit/test-service.js index b1db32f8316c..b9fcc7fdd2f6 100644 --- a/test/unit/test-service.js +++ b/test/unit/test-service.js @@ -39,7 +39,7 @@ import { } from '../../src/service'; import {loadPromise} from '../../src/event-helper'; -describe('service', () => { +describes.sandboxed('service', {}, () => { describe('disposable interface', () => { let disposable; let nonDisposable; diff --git a/test/unit/test-srcset.js b/test/unit/test-srcset.js index 322cb664b50e..151a6f7f01f1 100644 --- a/test/unit/test-srcset.js +++ b/test/unit/test-srcset.js @@ -21,7 +21,7 @@ import { srcsetFromSrc, } from '../../src/srcset'; -describe('Srcset', () => { +describes.sandboxed('Srcset', {}, () => { describe('parseSrcset', () => { function test(s, expected) { const res = parseSrcset(s); diff --git a/test/unit/test-static-template.js b/test/unit/test-static-template.js index b52f05aebd01..f88ccd60e46e 100644 --- a/test/unit/test-static-template.js +++ b/test/unit/test-static-template.js @@ -16,7 +16,7 @@ import {htmlFor, htmlRefs} from '../../src/static-template'; -describe('Static Template', () => { +describes.sandboxed('Static Template', {}, () => { describe('html', () => { it('generates static html tree', () => { const div = htmlFor(document)`

`; diff --git a/test/unit/test-style-installer.js b/test/unit/test-style-installer.js index efca284d29b1..7ed0632db00e 100644 --- a/test/unit/test-style-installer.js +++ b/test/unit/test-style-installer.js @@ -25,7 +25,7 @@ import {installPlatformService} from '../../src/service/platform-impl'; import {isAnimationNone} from '../../testing/test-helper'; import {setShadowDomSupportedVersionForTesting} from '../../src/web-components'; -describe('Styles', () => { +describes.sandboxed('Styles', {}, () => { describes.realWin('makeBodyVisible', {amp: true}, (env) => { let win, doc, ampdoc; let resources; diff --git a/test/unit/test-style.js b/test/unit/test-style.js index 010c23fe5bf3..eb09d94fb961 100644 --- a/test/unit/test-style.js +++ b/test/unit/test-style.js @@ -16,7 +16,7 @@ import * as st from '../../src/style'; -describe('Style', () => { +describes.sandboxed('Style', {}, () => { it('toggle', () => { const element = document.createElement('div'); diff --git a/test/unit/test-task-queue.js b/test/unit/test-task-queue.js index 9bce175dab71..b0f117f4769b 100644 --- a/test/unit/test-task-queue.js +++ b/test/unit/test-task-queue.js @@ -16,7 +16,7 @@ import {TaskQueue} from '../../src/service/task-queue'; -describe('TaskQueue', () => { +describes.sandboxed('TaskQueue', {}, () => { let clock; let queue; diff --git a/test/unit/test-transition.js b/test/unit/test-transition.js index d2fd08ea370c..ecccc544afa7 100644 --- a/test/unit/test-transition.js +++ b/test/unit/test-transition.js @@ -16,7 +16,7 @@ import * as tr from '../../src/transition'; -describe('Transition', () => { +describes.sandboxed('Transition', {}, () => { it('all', () => { const func1 = window.sandbox.spy(); const func2 = window.sandbox.spy(); diff --git a/test/unit/test-types.js b/test/unit/test-types.js index fdedfbde9277..751b7124d4b4 100644 --- a/test/unit/test-types.js +++ b/test/unit/test-types.js @@ -16,7 +16,7 @@ import * as types from '../../src/types'; -describe('Types', () => { +describes.sandboxed('Types', {}, () => { describe('isFiniteNumber', () => { it('should yield false for non-numbers', () => { expect(types.isFiniteNumber(null)).to.be.false; diff --git a/test/unit/test-url-rewrite.js b/test/unit/test-url-rewrite.js index 3bd1d2d994a0..90d911aae35c 100644 --- a/test/unit/test-url-rewrite.js +++ b/test/unit/test-url-rewrite.js @@ -19,7 +19,7 @@ import { rewriteAttributesForElement, } from '../../src/url-rewrite'; -describe('resolveUrlAttr', () => { +describes.sandboxed('resolveUrlAttr', {}, () => { it('should throw if __amp_source_origin is set', () => { allowConsoleError(() => { expect(() => @@ -147,7 +147,7 @@ describe('resolveUrlAttr', () => { }); }); -describe('rewriteAttributesForElement', () => { +describes.sandboxed('rewriteAttributesForElement', {}, () => { let location = 'https://pub.com/'; it('should not modify `target` on publisher origin', () => { const element = document.createElement('a'); diff --git a/test/unit/test-url.js b/test/unit/test-url.js index 4862094cc3e3..09a39f5e2f99 100644 --- a/test/unit/test-url.js +++ b/test/unit/test-url.js @@ -42,7 +42,7 @@ import { serializeQueryString, } from '../../src/url'; -describe('getWinOrigin', () => { +describes.sandboxed('getWinOrigin', {}, () => { it('should return origin if available', () => { expect( getWinOrigin({ @@ -98,7 +98,7 @@ describe('getWinOrigin', () => { }); }); -describe('parseUrlDeprecated', () => { +describes.sandboxed('parseUrlDeprecated', {}, () => { const currentPort = location.port; function compareParse(url, result) { @@ -259,7 +259,7 @@ describe('parseUrlDeprecated', () => { }); }); -describe('parseQueryString', () => { +describes.sandboxed('parseQueryString', {}, () => { it('should return empty params when query string is empty or null', () => { expect(parseQueryString(null)).to.deep.equal({}); expect(parseQueryString('')).to.deep.equal({}); @@ -311,7 +311,7 @@ describe('parseQueryString', () => { }); }); -describe('serializeQueryString', () => { +describes.sandboxed('serializeQueryString', {}, () => { it('should return empty string for empty params', () => { expect(serializeQueryString({})).to.equal(''); expect( @@ -340,7 +340,7 @@ describe('serializeQueryString', () => { }); }); -describe('assertHttpsUrl/isSecureUrl', () => { +describes.sandboxed('assertHttpsUrl/isSecureUrl', {}, () => { const referenceElement = document.createElement('div'); it('should NOT allow null or undefined, but allow empty string', () => { allowConsoleError(() => { @@ -392,7 +392,7 @@ describe('assertHttpsUrl/isSecureUrl', () => { }); }); -describe('assertAbsoluteHttpOrHttpsUrl', () => { +describes.sandboxed('assertAbsoluteHttpOrHttpsUrl', {}, () => { it('should allow http', () => { expect(assertAbsoluteHttpOrHttpsUrl('http://twitter.com/')).to.equal( 'http://twitter.com/' @@ -434,7 +434,7 @@ describe('assertAbsoluteHttpOrHttpsUrl', () => { }); }); -describe('removeFragment', () => { +describes.sandboxed('removeFragment', {}, () => { it('should remove fragment', () => { expect(removeFragment('https://twitter.com/path#abc')).to.equal( 'https://twitter.com/path' @@ -452,7 +452,7 @@ describe('removeFragment', () => { }); }); -describe('removeSearch', () => { +describes.sandboxed('removeSearch', {}, () => { it('should remove search', () => { expect(removeSearch('https://twitter.com/path?abc')).to.equal( 'https://twitter.com/path' @@ -503,7 +503,7 @@ describe('removeSearch', () => { }); }); -describe('addParamToUrl', () => { +describes.sandboxed('addParamToUrl', {}, () => { let url; beforeEach(() => { @@ -568,7 +568,7 @@ describe('addParamToUrl', () => { }); }); -describe('addParamsToUrl', () => { +describes.sandboxed('addParamsToUrl', {}, () => { let url; const params = { hello: 'world', @@ -607,7 +607,7 @@ describe('addParamsToUrl', () => { }); }); -describe('addMissingParamsToUrl', () => { +describes.sandboxed('addMissingParamsToUrl', {}, () => { let url; const params = { hello: 'world', @@ -626,7 +626,7 @@ describe('addMissingParamsToUrl', () => { }); }); -describe('isProxyOrigin', () => { +describes.sandboxed('isProxyOrigin', {}, () => { function testProxyOrigin(href, bool) { it( 'should return that ' + @@ -677,7 +677,7 @@ describe('isProxyOrigin', () => { ); }); -describe('isLocalhostOrigin', () => { +describes.sandboxed('isLocalhostOrigin', {}, () => { function testLocalhostOrigin(href, bool) { it( 'should return that ' + @@ -698,7 +698,7 @@ describe('isLocalhostOrigin', () => { testLocalhostOrigin('http://www.example.com/foo.html', false); }); -describe('isProtocolValid', () => { +describes.sandboxed('isProtocolValid', {}, () => { function testProtocolValid(href, bool) { it.configure() .skipFirefox() @@ -728,7 +728,7 @@ describe('isProtocolValid', () => { testProtocolValid('vbscript:foo', false); }); -describe('getSourceOrigin/Url', () => { +describes.sandboxed('getSourceOrigin/Url', {}, () => { function testOrigin(href, sourceHref) { it('should return the source origin/url from ' + href, () => { expect(getSourceUrl(href)).to.equal(sourceHref); @@ -888,7 +888,7 @@ describe('getSourceOrigin/Url', () => { }); }); -describe('resolveRelativeUrl', () => { +describes.sandboxed('resolveRelativeUrl', {}, () => { function testRelUrl(href, baseHref, resolvedHref) { it.configure() .skipFirefox() @@ -982,7 +982,7 @@ describe('resolveRelativeUrl', () => { ); }); -describe('getCorsUrl', () => { +describes.sandboxed('getCorsUrl', {}, () => { it('should error if __amp_source_origin is set', () => { allowConsoleError(() => { expect(() => @@ -1002,7 +1002,7 @@ describe('getCorsUrl', () => { }); }); -describe('removeAmpJsParamsFromUrl', () => { +describes.sandboxed('removeAmpJsParamsFromUrl', {}, () => { it('should handle unaffected URLs', () => { expect(removeAmpJsParamsFromUrl('http://example.com')).to.equal( 'http://example.com/' @@ -1056,7 +1056,7 @@ describe('removeAmpJsParamsFromUrl', () => { }); }); -describe('removeParamsFromSearch', () => { +describes.sandboxed('removeParamsFromSearch', {}, () => { it('should remove the leading ? or &', () => { expect(removeParamsFromSearch('?a=1&', 'a')).to.equal(''); }); @@ -1072,7 +1072,7 @@ describe('removeParamsFromSearch', () => { }); }); -describe('getProxyServingType', () => { +describes.sandboxed('getProxyServingType', {}, () => { it('should ignore non-proxy origins', () => { expect(getProxyServingType('http://www.example.com')).to.be.null; expect(getProxyServingType('http://cdn.ampproject.org/c/o.com/foo/')).to.be diff --git a/test/unit/test-viewport.js b/test/unit/test-viewport.js index 211dfbbc0089..bfa955247e0c 100644 --- a/test/unit/test-viewport.js +++ b/test/unit/test-viewport.js @@ -1257,7 +1257,7 @@ describes.fakeWin('Viewport', {}, (env) => { }); }); -describe('Viewport META', () => { +describes.sandboxed('Viewport META', {}, () => { describe('parseViewportMeta', () => { it('should accept null or empty strings', () => { expect(parseViewportMeta(null)).to.be.empty; @@ -1558,7 +1558,7 @@ describe('Viewport META', () => { }); }); -describe('createViewport', () => { +describes.sandboxed('createViewport', {}, () => { describes.fakeWin( 'in Android', { diff --git a/test/unit/test-web-components.js b/test/unit/test-web-components.js index 6c24268c4ee5..6d369e41f00d 100644 --- a/test/unit/test-web-components.js +++ b/test/unit/test-web-components.js @@ -21,7 +21,7 @@ import { setShadowDomSupportedVersionForTesting, } from '../../src/web-components'; -describe('web components', () => { +describes.sandboxed('web components', {}, () => { beforeEach(() => { setShadowDomSupportedVersionForTesting(undefined); }); diff --git a/test/unit/test-xhr.js b/test/unit/test-xhr.js index 9da811ff2a35..b20fcf4c2b6e 100644 --- a/test/unit/test-xhr.js +++ b/test/unit/test-xhr.js @@ -26,10 +26,10 @@ import {utf8FromArrayBuffer} from '../../extensions/amp-a4a/0.1/amp-a4a'; import {xhrServiceForTesting} from '../../src/service/xhr-impl'; // TODO(jridgewell, #11827): Make this test work on Safari. -describe +describes.sandboxed .configure() .skipSafari() - .run('XHR', function () { + .run('XHR', {}, function () { let ampdocServiceForStub; let ampdoc; let ampdocViewerStub; diff --git a/test/unit/utils/test-base64.js b/test/unit/utils/test-base64.js index a2f87b393467..9367e1798b5b 100644 --- a/test/unit/utils/test-base64.js +++ b/test/unit/utils/test-base64.js @@ -25,10 +25,10 @@ import { import {stringToBytes, utf8Decode, utf8Encode} from '../../../src/utils/bytes'; // TODO(amphtml, #25621): Cannot find atob / btoa on Safari. -describe +describes.sandboxed .configure() .skipSafari() - .run('base64', () => { + .run('base64', {}, () => { describe('base64 <> utf-8 encode/decode', () => { const testCases = [ 'SimplyFoo', diff --git a/test/unit/utils/test-bytes.js b/test/unit/utils/test-bytes.js index 82fe40e55713..a66207a4c1fa 100644 --- a/test/unit/utils/test-bytes.js +++ b/test/unit/utils/test-bytes.js @@ -23,7 +23,7 @@ import { utf8Encode, } from '../../../src/utils/bytes'; -describe('stringToBytes', function () { +describes.sandboxed('stringToBytes', {}, function () { let fakeWin; beforeEach(() => { @@ -81,7 +81,7 @@ describe('stringToBytes', function () { ); }); -describe('utf8', function () { +describes.sandboxed('utf8', {}, function () { // Examples here courtesy of StackOverflow: // http://stackoverflow.com/questions/478201/how-to-test-an-application-for // -correct-encoding-e-g-utf-8 @@ -379,7 +379,7 @@ describe('utf8', function () { }); }); -describe('bytesToUInt32', function () { +describes.sandboxed('bytesToUInt32', {}, function () { it('should convert Uint8Arrays into unsigned 32-bit integers', () => { expect(bytesToUInt32(new Uint8Array([0xff, 0xff, 0xff, 0xff]))).to.equal( 0xffffffff diff --git a/test/unit/web-worker/test-amp-worker.js b/test/unit/web-worker/test-amp-worker.js index efdd3e0a986d..b2a71b36588b 100644 --- a/test/unit/web-worker/test-amp-worker.js +++ b/test/unit/web-worker/test-amp-worker.js @@ -23,7 +23,7 @@ import {dev} from '../../../src/log'; import {getMode} from '../../../src/mode'; import {installXhrService} from '../../../src/service/xhr-impl'; -describe('invokeWebWorker', () => { +describes.sandboxed('invokeWebWorker', {}, () => { let fakeWin; let ampWorker; From 2f43dd65d075df98b305ee936cfdf11e158ab549 Mon Sep 17 00:00:00 2001 From: Raghu Simha Date: Tue, 11 May 2021 00:18:41 -0400 Subject: [PATCH 2/3] Use `env.sandbox` instead of the global `window.sandbox` --- .../test-line-delimited-response-handler.js | 6 +- ads/google/a4a/test/test-utils.js | 38 ++-- .../amp-a4a/0.1/test/test-a4a-integration.js | 16 +- extensions/amp-a4a/0.1/test/test-refresh.js | 8 +- .../0.1/test/test-amp-login-done-dialog.js | 16 +- extensions/amp-access/0.1/test/test-jwt.js | 8 +- .../0.1/test/filters/test-click-delay.js | 10 +- .../test-amp-ad-network-doubleclick-impl.js | 2 +- ...est-amp-ad-network-valueimpression-impl.js | 2 +- .../test-amp-ad-xorigin-iframe-handler.js | 28 +-- extensions/amp-ad/0.1/test/test-amp-ad.js | 2 +- ...st-legacy-ad-intersection-observer-host.js | 16 +- .../0.1/test/test-iframe-transport-client.js | 18 +- .../0.1/test/test-linker-reader.js | 8 +- .../amp-analytics/0.1/test/test-linker.js | 10 +- .../amp-analytics/0.1/test/test-variables.js | 4 +- .../amp-analytics/0.1/test/test-vendors.js | 6 +- .../0.1/test/integration/test-bind-impl.js | 6 +- .../amp-bind/0.1/test/test-bind-evaluator.js | 4 +- .../amp-consent/0.1/test/test-amp-consent.js | 14 +- .../0.1/test/test-consent-policy-manager.js | 4 +- .../0.1/test/test-linker-reader.js | 8 +- .../amp-consent/0.1/test/test-linker.js | 10 +- .../0.1/test/test-tcf-api-command-manager.js | 6 +- .../0.1/test/test-amp-gwd-animation.js | 8 +- .../amp-iframe/0.1/test/test-amp-iframe.js | 2 +- .../test/test-amp-install-serviceworker.js | 6 +- .../amp-live-list/0.1/test/test-poller.js | 12 +- .../0.1/test/unit/test-amp-script.js | 10 +- .../amp-sidebar/0.1/test/test-toolbar.js | 4 +- .../0.1/test/test-amp-skimlinks.js | 4 +- .../0.1/test/test-story-ad-page.js | 18 +- .../amp-story/1.0/test/test-amp-story.js | 10 +- .../0.1/test/test-viewer-platform.js | 2 +- .../integration/test-messaging-handshake.js | 4 +- test/integration/test-actions.js | 4 +- test/integration/test-video-manager.js | 12 +- test/integration/test-video-players-helper.js | 5 +- test/integration/test-video-players.js | 31 ++- test/unit/ads/test-ssp.js | 4 +- .../data-structures/test-priority-queue.js | 4 +- test/unit/core/test-error.js | 4 +- test/unit/core/types/test-function.js | 10 +- test/unit/test-3p.js | 4 +- test/unit/test-activity.js | 29 ++- test/unit/test-alp-handler.js | 22 +- test/unit/test-amp-context.js | 22 +- test/unit/test-animation.js | 4 +- test/unit/test-batched-json.js | 16 +- test/unit/test-chunk.js | 4 +- test/unit/test-document-info.js | 6 +- test/unit/test-document-ready.js | 28 +-- test/unit/test-error-reporting.js | 20 +- test/unit/test-event-helper.js | 12 +- test/unit/test-experiments.js | 188 +++++++++--------- test/unit/test-exponential-backoff.js | 6 +- test/unit/test-finite-state-machine.js | 6 +- test/unit/test-fixed-layer.js | 22 +- test/unit/test-focus-history.js | 4 +- test/unit/test-gesture-recognizers.js | 62 +++--- test/unit/test-gesture.js | 70 +++---- test/unit/test-ie-media-bug.js | 18 +- test/unit/test-iframe-helper.js | 4 +- test/unit/test-input.js | 4 +- test/unit/test-log.js | 8 +- test/unit/test-motion.js | 4 +- test/unit/test-notification-ui-manager.js | 12 +- test/unit/test-pass.js | 20 +- test/unit/test-platform.js | 4 +- test/unit/test-pull-to-refresh.js | 10 +- test/unit/test-purifier.js | 4 +- test/unit/test-render-delaying-services.js | 20 +- test/unit/test-resource.js | 9 +- test/unit/test-service.js | 20 +- test/unit/test-shadow-embed.js | 4 +- test/unit/test-style.js | 4 +- test/unit/test-task-queue.js | 4 +- test/unit/test-transition.js | 6 +- test/unit/test-viewport.js | 6 +- test/unit/test-xhr-document-fetcher.js | 2 +- test/unit/test-xhr.js | 51 +++-- test/unit/web-worker/test-amp-worker.js | 16 +- 82 files changed, 580 insertions(+), 579 deletions(-) diff --git a/ads/google/a4a/test/test-line-delimited-response-handler.js b/ads/google/a4a/test/test-line-delimited-response-handler.js index 93e9a030788e..6758989a6686 100644 --- a/ads/google/a4a/test/test-line-delimited-response-handler.js +++ b/ads/google/a4a/test/test-line-delimited-response-handler.js @@ -19,7 +19,7 @@ import { metaJsonCreativeGrouper, } from '../line-delimited-response-handler'; -describes.sandboxed('#line-delimited-response-handler', {}, () => { +describes.sandboxed('#line-delimited-response-handler', {}, (env) => { let chunkHandlerStub; let slotData; let win; @@ -92,7 +92,7 @@ describes.sandboxed('#line-delimited-response-handler', {}, () => { } beforeEach(() => { - chunkHandlerStub = window.sandbox.stub(); + chunkHandlerStub = env.sandbox.stub(); }); describe('stream not supported', () => { @@ -154,7 +154,7 @@ describes.sandboxed('#line-delimited-response-handler', {}, () => { } beforeEach(() => { - readStub = window.sandbox.stub(); + readStub = env.sandbox.stub(); response = { text: () => Promise.resolve(), body: { diff --git a/ads/google/a4a/test/test-utils.js b/ads/google/a4a/test/test-utils.js index 3f7d1f2c7187..1048ab4de584 100644 --- a/ads/google/a4a/test/test-utils.js +++ b/ads/google/a4a/test/test-utils.js @@ -90,7 +90,7 @@ function noopMethods( sandbox.stub(impl.element, 'offsetHeight').value(pageLayoutBox.height); } -describes.sandboxed('Google A4A utils', {}, () => { +describes.sandboxed('Google A4A utils', {}, (env) => { //TODO: Add tests for other utils functions. describe('#additionalDimensions', () => { @@ -249,7 +249,7 @@ describes.sandboxed('Google A4A utils', {}, () => { }); it('should add the correct CSI signals', () => { - window.sandbox + env.sandbox .stub(Services, 'documentInfoForDoc') .returns({pageViewId: 777}); const mockElement = { @@ -388,7 +388,7 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); return fixture.addElement(elem).then(() => googleAdUrl(impl, '', 0, [], []).then((url1) => { expect(url1).to.match(/ady=11/); @@ -409,7 +409,7 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); const getRect = () => { return {'width': 100, 'height': 200}; }; @@ -418,7 +418,7 @@ describes.sandboxed('Google A4A utils', {}, () => { }; const getScrollLeft = () => 12.1; const getScrollTop = () => 34.2; - const viewportStub = window.sandbox.stub(Services, 'viewportForDoc'); + const viewportStub = env.sandbox.stub(Services, 'viewportForDoc'); viewportStub.returns({getRect, getSize, getScrollTop, getScrollLeft}); return googleAdUrl(impl, '', 0, {}, []).then((url1) => { expect(url1).to.match(/scr_x=12&scr_y=34/); @@ -441,7 +441,7 @@ describes.sandboxed('Google A4A utils', {}, () => { [AMP_EXPERIMENT_ATTRIBUTE]: '111,222', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); return fixture.addElement(elem).then(() => { return googleAdUrl(impl, '', 0, {}, ['789', '098']).then((url1) => { expect(url1).to.match(/eid=123%2C456%2C789%2C098/); @@ -462,7 +462,7 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); impl.win.AMP_CONFIG = {type: 'production'}; impl.win.location.hash = 'foo,deid=123456,654321,bar'; return fixture.addElement(elem).then(() => { @@ -484,7 +484,7 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); impl.win.gaGlobal = {cid: 'foo', hid: 'bar'}; return fixture.addElement(elem).then(() => { return googleAdUrl(impl, '', 0, [], []).then((url) => { @@ -506,8 +506,8 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); - const createElementStub = window.sandbox.stub( + noopMethods(impl, fixture.ampdoc, env.sandbox); + const createElementStub = env.sandbox.stub( impl.win.document, 'createElement' ); @@ -535,8 +535,8 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); - const createElementStub = window.sandbox.stub( + noopMethods(impl, fixture.ampdoc, env.sandbox); + const createElementStub = env.sandbox.stub( impl.win.document, 'createElement' ); @@ -562,9 +562,9 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); impl.win.SVGElement = undefined; - const createElementStub = window.sandbox.stub( + const createElementStub = env.sandbox.stub( impl.win.document, 'createElement' ); @@ -592,11 +592,11 @@ describes.sandboxed('Google A4A utils', {}, () => { 'height': '50', }); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); - window.sandbox + noopMethods(impl, fixture.ampdoc, env.sandbox); + env.sandbox .stub(Services.viewerForDoc(impl.getAmpDoc()), 'getReferrerUrl') .returns(new Promise(() => {})); - const createElementStub = window.sandbox.stub( + const createElementStub = env.sandbox.stub( impl.win.document, 'createElement' ); @@ -621,7 +621,7 @@ describes.sandboxed('Google A4A utils', {}, () => { doc.win = fixture.win; const elem = createElementWithAttributes(doc, 'amp-a4a', {}); const impl = new MockA4AImpl(elem); - noopMethods(impl, fixture.ampdoc, window.sandbox); + noopMethods(impl, fixture.ampdoc, env.sandbox); return fixture.addElement(elem).then(() => { return googleAdUrl(impl, '', Date.now(), [], []).then((url) => { expect(url).to.match(/[&?]bdt=[1-9][0-9]*[&$]/); @@ -989,7 +989,7 @@ describes.sandboxed('Google A4A utils', {}, () => { }); it('should include viewer lastVisibleTime', () => { - window.sandbox.stub(ampdoc, 'getLastVisibleTime').returns(300); + env.sandbox.stub(ampdoc, 'getLastVisibleTime').returns(300); const vars = getCsiAmpAnalyticsVariables('trigger', a4a, null); expect(vars['viewerLastVisibleTime']).to.be.a('number'); diff --git a/extensions/amp-a4a/0.1/test/test-a4a-integration.js b/extensions/amp-a4a/0.1/test/test-a4a-integration.js index 12ecca17adcd..19f4c9b94fa3 100644 --- a/extensions/amp-a4a/0.1/test/test-a4a-integration.js +++ b/extensions/amp-a4a/0.1/test/test-a4a-integration.js @@ -78,7 +78,7 @@ function expectRenderedInXDomainIframe(element, src) { expect(child, 'iframe child').to.be.visible; } -describes.sandboxed('integration test: a4a', {}, () => { +describes.sandboxed('integration test: a4a', {}, (env) => { let fixture; let fetchMock; let adResponse; @@ -151,7 +151,7 @@ describes.sandboxed('integration test: a4a', {}, () => { // TODO(tdrl) Currently layoutCallback rejects, even though something *is* // rendered. This should be fixed in a refactor, and we should change this // .catch to a .then. - const forceCollapseStub = window.sandbox.spy( + const forceCollapseStub = env.sandbox.spy( MockA4AImpl.prototype, 'forceCollapse' ); @@ -169,7 +169,7 @@ describes.sandboxed('integration test: a4a', {}, () => { it('should collapse slot when creative response has code 204', async () => { adResponse.status = 204; adResponse.body = null; - const forceCollapseStub = window.sandbox.spy( + const forceCollapseStub = env.sandbox.spy( MockA4AImpl.prototype, 'forceCollapse' ); @@ -179,7 +179,7 @@ describes.sandboxed('integration test: a4a', {}, () => { it('should collapse slot when creative response.arrayBuffer() is empty', async () => { adResponse.body = ''; - const forceCollapseStub = window.sandbox.spy( + const forceCollapseStub = env.sandbox.spy( MockA4AImpl.prototype, 'forceCollapse' ); @@ -191,7 +191,7 @@ describes.sandboxed('integration test: a4a', {}, () => { await fixture.addElement(a4aElement); await expectRenderedInFriendlyIframe(a4aElement, 'Hello, world.'); const a4a = new MockA4AImpl(a4aElement); - const initiateAdRequestMock = window.sandbox + const initiateAdRequestMock = env.sandbox .stub(MockA4AImpl.prototype, 'initiateAdRequest') .callsFake(() => { a4a.adPromise_ = Promise.resolve(); @@ -199,16 +199,16 @@ describes.sandboxed('integration test: a4a', {}, () => { // up any unrelated asserts. a4a.isRefreshing = false; }); - const tearDownSlotMock = window.sandbox.stub( + const tearDownSlotMock = env.sandbox.stub( MockA4AImpl.prototype, 'tearDownSlot' ); tearDownSlotMock.returns(undefined); - const destroyFrameSpy = window.sandbox.spy( + const destroyFrameSpy = env.sandbox.spy( MockA4AImpl.prototype, 'destroyFrame' ); - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); await a4a.refresh(callback); expect(initiateAdRequestMock).to.be.called; expect(tearDownSlotMock).to.be.called; diff --git a/extensions/amp-a4a/0.1/test/test-refresh.js b/extensions/amp-a4a/0.1/test/test-refresh.js index 969fa53d57fb..56c3dd424030 100644 --- a/extensions/amp-a4a/0.1/test/test-refresh.js +++ b/extensions/amp-a4a/0.1/test/test-refresh.js @@ -23,7 +23,7 @@ import { } from '../refresh-manager'; import {Services} from '../../../../src/services'; -describes.sandboxed('refresh', {}, () => { +describes.sandboxed('refresh', {}, (env) => { let mockA4a; const config = { visiblePercentageMin: 50, @@ -36,7 +36,7 @@ describes.sandboxed('refresh', {}, () => { div.setAttribute('style', 'width:1px; height:1px;'); div.setAttribute('type', 'doubleclick'); div.setAttribute(DATA_ATTR_NAME, '35'); - window.sandbox.replaceGetter(div, 'isConnected', () => true); + env.sandbox.replaceGetter(div, 'isConnected', () => true); div.getAmpDoc = () => { return { getMetaByName: (name) => { @@ -107,7 +107,7 @@ describes.sandboxed('refresh', {}, () => { }); it('should call convertConfiguration_ and set proper units', () => { - const getConfigurationSpy = window.sandbox.spy( + const getConfigurationSpy = env.sandbox.spy( RefreshManager.prototype, 'convertAndSanitizeConfiguration_' ); @@ -171,7 +171,7 @@ describes.sandboxed('refresh', {}, () => { it('should execute the refresh event correctly', () => { // Attach element to DOM, as is necessary for request ampdoc. window.document.body.appendChild(mockA4a.element); - const refreshSpy = window.sandbox.spy(mockA4a, 'refresh'); + const refreshSpy = env.sandbox.spy(mockA4a, 'refresh'); // Ensure initial call to initiateRefreshCycle doesn't trigger refresh, as // this can have flaky results. diff --git a/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js b/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js index cf21ebe702f9..b7ba02fc6d6d 100644 --- a/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js +++ b/extensions/amp-access/0.1/test/test-amp-login-done-dialog.js @@ -16,7 +16,7 @@ import {LoginDoneDialog, buildLangSelector} from '../amp-login-done-dialog'; -describes.sandboxed('LoginDoneDialog', {}, () => { +describes.sandboxed('LoginDoneDialog', {}, (env) => { let clock; let windowApi; let dialog; @@ -25,19 +25,19 @@ describes.sandboxed('LoginDoneDialog', {}, () => { let closeButton; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); messageListener = undefined; closeButton = {}; windowApi = { - close: window.sandbox.spy(), + close: env.sandbox.spy(), navigator: { language: 'fr-FR', }, location: { hash: '#result1', search: '', - replace: window.sandbox.spy(), + replace: env.sandbox.spy(), }, addEventListener: (type, callback) => { if (type == 'message') { @@ -73,7 +73,7 @@ describes.sandboxed('LoginDoneDialog', {}, () => { }, }, }; - openerMock = window.sandbox.mock(windowApi.opener); + openerMock = env.sandbox.mock(windowApi.opener); dialog = new LoginDoneDialog(windowApi); }); @@ -160,7 +160,7 @@ describes.sandboxed('LoginDoneDialog', {}, () => { openerMock .expects('postMessage') .withExactArgs( - window.sandbox.match((arg) => { + env.sandbox.match((arg) => { return ( arg.sentinel == 'amp' && arg.type == 'result' && @@ -310,7 +310,7 @@ describes.sandboxed('LoginDoneDialog', {}, () => { openerMock .expects('postMessage') .withExactArgs( - window.sandbox.match((arg) => { + env.sandbox.match((arg) => { return ( arg.sentinel == 'amp' && arg.type == 'result' && @@ -359,7 +359,7 @@ describes.sandboxed('LoginDoneDialog', {}, () => { }); it('should revert to error mode if window is not closed', () => { - dialog.postbackError_ = window.sandbox.spy(); + dialog.postbackError_ = env.sandbox.spy(); dialog.postbackSuccess_(); expect(windowApi.close).to.be.calledOnce; expect(dialog.postbackError_).to.have.not.been.called; diff --git a/extensions/amp-access/0.1/test/test-jwt.js b/extensions/amp-access/0.1/test/test-jwt.js index 790434ec0da3..655f8c212221 100644 --- a/extensions/amp-access/0.1/test/test-jwt.js +++ b/extensions/amp-access/0.1/test/test-jwt.js @@ -16,7 +16,7 @@ import {JwtHelper, pemToBytes} from '../jwt'; -describes.sandboxed('JwtHelper', {}, () => { +describes.sandboxed('JwtHelper', {}, (env) => { // Generated from https://jwt.io/#debugger // Name deliberately changed from "John Doe" to "John ௵Z加䅌ਇ☎Èʘغޝ" to test // correct unicode handling on our part. @@ -171,7 +171,7 @@ describes.sandboxed('JwtHelper', {}, () => { importKey: () => {}, verify: () => {}, }; - subtleMock = window.sandbox.mock(subtle); + subtleMock = env.sandbox.mock(subtle); windowApi = { crypto: {subtle}, @@ -237,8 +237,8 @@ describes.sandboxed('JwtHelper', {}, () => { .withExactArgs( {name: 'RSASSA-PKCS1-v1_5'}, key, - /* sig */ window.sandbox.match(() => true), - /* verifiable */ window.sandbox.match(() => true) + /* sig */ env.sandbox.match(() => true), + /* verifiable */ env.sandbox.match(() => true) ) .returns(Promise.resolve(true)) .once(); diff --git a/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js b/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js index 285af715f397..eb14572ffd5c 100644 --- a/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js +++ b/extensions/amp-ad-exit/0.1/test/filters/test-click-delay.js @@ -17,7 +17,7 @@ import {ClickDelayFilter} from '../../filters/click-delay'; import {FilterType} from '../../filters/filter'; -describes.sandboxed('click-delay', {}, () => { +describes.sandboxed('click-delay', {}, (env) => { const DEFAULT_CONFIG = { type: FilterType.CLICK_DELAY, delay: 123, @@ -26,7 +26,7 @@ describes.sandboxed('click-delay', {}, () => { it('should use performance timing', () => { const win = {performance: {timing: {'navigationStart': 456}}}; - window.sandbox.stub(Date, 'now').returns(123); + env.sandbox.stub(Date, 'now').returns(123); expect( new ClickDelayFilter('foo', DEFAULT_CONFIG, win).intervalStart ).to.equal(456); @@ -57,7 +57,7 @@ describes.sandboxed('click-delay', {}, () => { ).to.throw(win.err) ); } else { - window.sandbox.stub(Date, 'now').returns(123); + env.sandbox.stub(Date, 'now').returns(123); expect( new ClickDelayFilter('foo', test.config, test.win).intervalStart ).to.equal(123); @@ -72,7 +72,7 @@ describes.sandboxed('click-delay', {}, () => { const filter = new ClickDelayFilter('foo', DEFAULT_CONFIG, { performance: {timing: {navigationStart: 1}}, }); - const nowStub = window.sandbox.stub(Date, 'now'); + const nowStub = env.sandbox.stub(Date, 'now'); nowStub.onFirstCall().returns(1001); expect(filter.filter()).to.be.true; }); @@ -81,7 +81,7 @@ describes.sandboxed('click-delay', {}, () => { const filter = new ClickDelayFilter('foo', DEFAULT_CONFIG, { performance: {timing: {navigationStart: 1}}, }); - const nowStub = window.sandbox.stub(Date, 'now'); + const nowStub = env.sandbox.stub(Date, 'now'); nowStub.onFirstCall().returns(1); nowStub.onSecondCall().returns(125); expect(filter.filter()).to.be.false; diff --git a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js index 7f9d72fc0926..14ccb849f495 100644 --- a/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js +++ b/extensions/amp-ad-network-doubleclick-impl/0.1/test/test-amp-ad-network-doubleclick-impl.js @@ -632,7 +632,7 @@ describes.realWin('amp-ad-network-doubleclick-impl', realWinConfig, (env) => { doc.body.appendChild(element); impl = new AmpAdNetworkDoubleclickImpl(element); // Temporary fix for local test failure. - window.sandbox + env.sandbox .stub(impl, 'getIntersectionElementLayoutBox') .callsFake(() => { return { diff --git a/extensions/amp-ad-network-valueimpression-impl/0.1/test/test-amp-ad-network-valueimpression-impl.js b/extensions/amp-ad-network-valueimpression-impl/0.1/test/test-amp-ad-network-valueimpression-impl.js index d6dffbc79205..259d374b9fdb 100644 --- a/extensions/amp-ad-network-valueimpression-impl/0.1/test/test-amp-ad-network-valueimpression-impl.js +++ b/extensions/amp-ad-network-valueimpression-impl/0.1/test/test-amp-ad-network-valueimpression-impl.js @@ -126,7 +126,7 @@ describes.realWin( element.setAttribute('rtc-config', JSON.stringify(rtcConfig)); doc.body.appendChild(element); impl = new AmpAdNetworkValueimpressionImpl(element); - window.sandbox + env.sandbox .stub(impl, 'getIntersectionElementLayoutBox') .callsFake(() => { return { diff --git a/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js b/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js index c107acc56755..a9e8180a1890 100644 --- a/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js +++ b/extensions/amp-ad/0.1/test/test-amp-ad-xorigin-iframe-handler.js @@ -26,7 +26,7 @@ import { import {layoutRectLtwh} from '../../../../src/layout-rect'; import {toggleExperiment} from '../../../../src/experiments'; -describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { +describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, (env) => { let ampdoc; let adImpl; let signals; @@ -47,7 +47,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }; signals = new Signals(); adElement.signals = () => signals; - renderStartedSpy = window.sandbox.spy(); + renderStartedSpy = env.sandbox.spy(); adElement.renderStarted = () => { renderStartedSpy(); signals.signal('render-start'); @@ -61,7 +61,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }; document.body.appendChild(adElement); adImpl.uiHandler = new AmpAdUIHandler(adImpl); - adImpl.uiHandler.onResizeSuccess = window.sandbox.spy(); + adImpl.uiHandler.onResizeSuccess = env.sandbox.spy(); iframeHandler = new AmpAdXOriginIframeHandler(adImpl); testIndex++; @@ -82,14 +82,14 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { beforeEach(() => { adImpl.config = {renderStartImplemented: true}; - window.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { + env.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { return Promise.resolve({ success: true, newWidth: 114, newHeight: 217, }); }); - noContentSpy = window.sandbox./*OK*/ spy( + noContentSpy = env.sandbox./*OK*/ spy( iframeHandler, 'freeXOriginIframe' ); @@ -204,7 +204,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { sentinel: 'amp3ptest' + testIndex, type: 'bootstrap-loaded', }).then(() => { - const clock = window.sandbox.useFakeTimers(); + const clock = env.sandbox.useFakeTimers(); clock.tick(0); const timeoutPromise = Services.timerFor(window).timeoutPromise( 2000, @@ -236,7 +236,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { it('should be able to use user-error API', () => { const err = new Error(); err.message = 'error test'; - const userErrorReportSpy = window.sandbox.stub( + const userErrorReportSpy = env.sandbox.stub( iframeHandler, 'userErrorForAnalytics_' ); @@ -269,7 +269,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { ); it('should trigger visibility on timeout', () => { - const clock = window.sandbox.useFakeTimers(); + const clock = env.sandbox.useFakeTimers(); iframe.name = 'test_master'; initPromise = iframeHandler.init(iframe); return new Promise((resolve) => { @@ -301,7 +301,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }); it('should be able to use embed-state API', () => { - window.sandbox./*OK*/ stub(ampdoc, 'isVisible').returns(true); + env.sandbox./*OK*/ stub(ampdoc, 'isVisible').returns(true); iframe.postMessageToParent({ type: 'send-embed-state', sentinel: 'amp3ptest' + testIndex, @@ -317,7 +317,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }); it('should be able to use embed-size API, change size deny', () => { - window.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { + env.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { return Promise.resolve({ success: false, newWidth: 114, @@ -343,7 +343,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }); it('should be able to use embed-size API, change size succeed', () => { - window.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { + env.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { return Promise.resolve({ success: true, newWidth: 114, @@ -370,7 +370,7 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { }); it('should be able to use embed-size API to resize height only', () => { - window.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { + env.sandbox.stub(adImpl.uiHandler, 'updateSize').callsFake(() => { return Promise.resolve({ success: true, newWidth: undefined, @@ -402,12 +402,12 @@ describes.sandboxed('amp-ad-xorigin-iframe-handler', {}, () => { iframe.setAttribute('data-amp-3p-sentinel', 'amp3ptest' + testIndex); iframe.name = 'test_nomaster'; iframeHandler.init(iframe); - window.sandbox + env.sandbox ./*OK*/ stub(iframeHandler.viewport_, 'getClientRectAsync') .callsFake(() => { return Promise.resolve(layoutRectLtwh(1, 1, 1, 1)); }); - window.sandbox + env.sandbox ./*OK*/ stub(iframeHandler.viewport_, 'getRect') .callsFake(() => { return layoutRectLtwh(1, 1, 1, 1); diff --git a/extensions/amp-ad/0.1/test/test-amp-ad.js b/extensions/amp-ad/0.1/test/test-amp-ad.js index 9cf4c5d01cf7..386822821389 100644 --- a/extensions/amp-ad/0.1/test/test-amp-ad.js +++ b/extensions/amp-ad/0.1/test/test-amp-ad.js @@ -63,7 +63,7 @@ describes.realWin('Ad loader', {amp: true}, (env) => { beforeEach(() => { const getUserNotificationStub = stubService( - window.sandbox, + env.sandbox, win, 'userNotificationManager', 'get' diff --git a/extensions/amp-ad/0.1/test/test-legacy-ad-intersection-observer-host.js b/extensions/amp-ad/0.1/test/test-legacy-ad-intersection-observer-host.js index 431fd7f4e1c0..511e571f49e7 100644 --- a/extensions/amp-ad/0.1/test/test-legacy-ad-intersection-observer-host.js +++ b/extensions/amp-ad/0.1/test/test-legacy-ad-intersection-observer-host.js @@ -21,7 +21,7 @@ import {deserializeMessage} from '../../../../src/3p-frame-messaging'; import {getIntersectionChangeEntry} from '../../../../src/utils/intersection-observer-3p-host'; import {layoutRectLtwh} from '../../../../src/layout-rect'; -describes.sandboxed('IntersectionObserverHostForAd', {}, () => { +describes.sandboxed('IntersectionObserverHostForAd', {}, (env) => { const ElementClass = createAmpElementForTesting(window, BaseElement); customElements.define('amp-int', ElementClass); @@ -54,9 +54,9 @@ describes.sandboxed('IntersectionObserverHostForAd', {}, () => { } beforeEach(() => { - clock = window.sandbox.useFakeTimers(); - onScrollSpy = window.sandbox.spy(); - onChangeSpy = window.sandbox.spy(); + clock = env.sandbox.useFakeTimers(); + onScrollSpy = env.sandbox.spy(); + onChangeSpy = env.sandbox.spy(); testIframe = getIframe(iframeSrc); element = new ElementClass(); element.win = window; @@ -86,7 +86,7 @@ describes.sandboxed('IntersectionObserverHostForAd', {}, () => { fireObserved = true; }, unobserve: () => (fireObserved = false), - disconnect: window.sandbox.spy(), + disconnect: env.sandbox.spy(), }; return host.fireInOb_; }; @@ -104,7 +104,7 @@ describes.sandboxed('IntersectionObserverHostForAd', {}, () => { testIframe ); insert(testIframe); - const postMessageSpy = window.sandbox /*OK*/ + const postMessageSpy = env.sandbox /*OK*/ .spy(testIframe.contentWindow, 'postMessage'); ioInstance.fire(); clock.tick(0); @@ -188,7 +188,7 @@ describes.sandboxed('IntersectionObserverHostForAd', {}, () => { }); it('should init listeners when element is in viewport', () => { - const sendElementIntersectionSpy = window.sandbox.spy( + const sendElementIntersectionSpy = env.sandbox.spy( LegacyAdIntersectionObserverHost.prototype, 'sendElementIntersection_' ); @@ -206,7 +206,7 @@ describes.sandboxed('IntersectionObserverHostForAd', {}, () => { }); it('should unlisten listeners when element is out of viewport', () => { - const sendElementIntersectionSpy = window.sandbox.spy( + const sendElementIntersectionSpy = env.sandbox.spy( LegacyAdIntersectionObserverHost.prototype, 'sendElementIntersection_' ); diff --git a/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js b/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js index adba2ab1168c..1c115cb28d04 100644 --- a/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js +++ b/extensions/amp-analytics/0.1/test/test-iframe-transport-client.js @@ -28,7 +28,7 @@ function createUniqueId() { return String(++nextId); } -describes.sandboxed('iframe-transport-client', {}, () => { +describes.sandboxed('iframe-transport-client', {}, (env) => { let iframeTransportClient; let sentinel; @@ -123,7 +123,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { }); it('calls onNewContextInstance', () => { - const onNewContextInstanceSpy = window.sandbox.spy(); + const onNewContextInstanceSpy = env.sandbox.spy(); window.onNewContextInstance = (ctx) => onNewContextInstanceSpy(ctx); const ctx = new IframeTransportContext( window, @@ -137,7 +137,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { }); it('Sets listener and baseMessage properly', () => { - const onNewContextInstanceSpy = window.sandbox.spy(); + const onNewContextInstanceSpy = env.sandbox.spy(); window.onNewContextInstance = (ctx) => onNewContextInstanceSpy(ctx); const ctx = new IframeTransportContext( window, @@ -149,8 +149,8 @@ describes.sandboxed('iframe-transport-client', {}, () => { expect(ctx.baseMessage_).to.not.be.null; expect(ctx.baseMessage_.creativeId).to.equal('my_creative'); expect(ctx.baseMessage_.vendor).to.equal('my_vendor'); - const listener1 = window.sandbox.spy(); - const listener2 = window.sandbox.spy(); + const listener1 = env.sandbox.spy(); + const listener2 = env.sandbox.spy(); ctx.onAnalyticsEvent(listener1); expect(ctx.listener_).to.equal(listener1); ctx.onAnalyticsEvent(listener2); @@ -159,7 +159,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { }); it('dispatches event', () => { - const onNewContextInstanceSpy = window.sandbox.spy(); + const onNewContextInstanceSpy = env.sandbox.spy(); window.onNewContextInstance = (ctx) => onNewContextInstanceSpy(ctx); const ctx = new IframeTransportContext( window, @@ -167,7 +167,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { 'my_creative', 'my_vendor' ); - const listener = window.sandbox.spy(); + const listener = env.sandbox.spy(); ctx.onAnalyticsEvent(listener); const event = 'Something important happened'; ctx.dispatch(event); @@ -177,7 +177,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { }); it('sends response', () => { - const onNewContextInstanceSpy = window.sandbox.spy(); + const onNewContextInstanceSpy = env.sandbox.spy(); window.onNewContextInstance = (ctx) => onNewContextInstanceSpy(ctx); // This const exists solely to avoid triggering a false positive on the // presubmit rule that says you can't call stub() on a cross-domain iframe. @@ -189,7 +189,7 @@ describes.sandboxed('iframe-transport-client', {}, () => { 'my_vendor' ); const response = {foo: 'bar', answer: '42'}; - window.sandbox.stub(imc, 'sendMessage').callsFake((type, opt_payload) => { + env.sandbox.stub(imc, 'sendMessage').callsFake((type, opt_payload) => { expect(type).to.equal(MessageType.IFRAME_TRANSPORT_RESPONSE); expect(opt_payload).to.not.be.null; expect(opt_payload.creativeId).to.equal('my_creative'); diff --git a/extensions/amp-analytics/0.1/test/test-linker-reader.js b/extensions/amp-analytics/0.1/test/test-linker-reader.js index 00d0c9d74187..22b517e811f8 100644 --- a/extensions/amp-analytics/0.1/test/test-linker-reader.js +++ b/extensions/amp-analytics/0.1/test/test-linker-reader.js @@ -20,16 +20,16 @@ import { } from '../linker-reader'; import {mockWindowInterface} from '../../../../testing/test-helper'; -describes.sandboxed('LinkerReader', {}, () => { +describes.sandboxed('LinkerReader', {}, (env) => { let linkerReader; let mockWin; beforeEach(() => { // Can not import from test-linker.js because all test in test-liner.js // will be run with the test-linker-reader if we do so. - window.sandbox.useFakeTimers(1533329483292); - window.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); - mockWin = mockWindowInterface(window.sandbox); + env.sandbox.useFakeTimers(1533329483292); + env.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); + mockWin = mockWindowInterface(env.sandbox); mockWin.getUserAgent.returns( 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 ' + diff --git a/extensions/amp-analytics/0.1/test/test-linker.js b/extensions/amp-analytics/0.1/test/test-linker.js index 474edb4c9275..ed78000233ef 100644 --- a/extensions/amp-analytics/0.1/test/test-linker.js +++ b/extensions/amp-analytics/0.1/test/test-linker.js @@ -245,13 +245,13 @@ const createLinkerTests = [ }, ]; -describes.sandboxed('Linker', {}, () => { +describes.sandboxed('Linker', {}, (env) => { let mockWin; beforeEach(() => { // Linker uses a timestamp value to generate checksum. - window.sandbox.useFakeTimers(BASE_TIME); - window.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); - mockWin = mockWindowInterface(window.sandbox); + env.sandbox.useFakeTimers(BASE_TIME); + env.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); + mockWin = mockWindowInterface(env.sandbox); mockWin.getUserAgent.returns( 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 ' + @@ -278,7 +278,7 @@ describes.sandboxed('Linker', {}, () => { expectAsyncConsoleError(TAG + ' ' + test.errorMsg); } if (test.currentTime) { - window.sandbox.useFakeTimers(test.currentTime); + env.sandbox.useFakeTimers(test.currentTime); } expect(parseLinker(test.value)).to.deep.equal(test.output); }); diff --git a/extensions/amp-analytics/0.1/test/test-variables.js b/extensions/amp-analytics/0.1/test/test-variables.js index a6e4a12e7dd1..8bc7ae82a2cc 100644 --- a/extensions/amp-analytics/0.1/test/test-variables.js +++ b/extensions/amp-analytics/0.1/test/test-variables.js @@ -479,7 +479,7 @@ describes.fakeWin('amp-analytics.VariableService', {amp: true}, (env) => { }); it('replaces CONSENT_METADATA', () => { - window.sandbox.stub(Services, 'consentPolicyServiceForDocOrNull').returns( + env.sandbox.stub(Services, 'consentPolicyServiceForDocOrNull').returns( Promise.resolve({ getConsentMetadataInfo: () => { return Promise.resolve({ @@ -498,7 +498,7 @@ describes.fakeWin('amp-analytics.VariableService', {amp: true}, (env) => { }); it('replaces CONSENT_STRING', () => { - window.sandbox.stub(Services, 'consentPolicyServiceForDocOrNull').returns( + env.sandbox.stub(Services, 'consentPolicyServiceForDocOrNull').returns( Promise.resolve({ getConsentStringInfo: () => { return Promise.resolve('userConsentString'); diff --git a/extensions/amp-analytics/0.1/test/test-vendors.js b/extensions/amp-analytics/0.1/test/test-vendors.js index dd0d7e3dd2b8..054d6398b616 100644 --- a/extensions/amp-analytics/0.1/test/test-vendors.js +++ b/extensions/amp-analytics/0.1/test/test-vendors.js @@ -84,7 +84,7 @@ describes.realWin( const urlReplacements = Services.urlReplacementsForDoc( doc.documentElement ); - window.sandbox + env.sandbox .stub(urlReplacements.getVariableSource(), 'get') .callsFake(function (name) { expect(this.replacements_).to.have.property(name); @@ -93,7 +93,7 @@ describes.realWin( }; }); - window.sandbox + env.sandbox .stub(ExpansionOptions.prototype, 'getVar') .callsFake(function (name) { let val = this.vars[name]; @@ -112,7 +112,7 @@ describes.realWin( // Have to get service after analytics element is created const variableService = variableServiceForDoc(doc); - window.sandbox + env.sandbox .stub(variableService, 'getMacros') .callsFake(function () { // Add all the macros in amp-analytics diff --git a/extensions/amp-bind/0.1/test/integration/test-bind-impl.js b/extensions/amp-bind/0.1/test/integration/test-bind-impl.js index 2993a027ee5b..9cafea9417aa 100644 --- a/extensions/amp-bind/0.1/test/integration/test-bind-impl.js +++ b/extensions/amp-bind/0.1/test/integration/test-bind-impl.js @@ -212,8 +212,8 @@ const FORM_VALUE_CHANGE_EVENT_ARGUMENTS = { type: AmpEvents.FORM_VALUE_CHANGE, bubbles: true, }; -const chromed = describe.configure().ifChrome(); -chromed.run('Bind', function () { +const chromed = describes.sandboxed.configure().ifChrome(); +chromed.run('Bind', {}, function () { describes.repeated( 'Walker', { @@ -1037,7 +1037,7 @@ chromed.run('Bind', function () { describe('with trusted viewer', () => { beforeEach(() => { - window.sandbox + env.sandbox .stub(viewer, 'isTrustedViewer') .returns(Promise.resolve(true)); }); diff --git a/extensions/amp-bind/0.1/test/test-bind-evaluator.js b/extensions/amp-bind/0.1/test/test-bind-evaluator.js index 3371ccc6793e..d94156b1cfb3 100644 --- a/extensions/amp-bind/0.1/test/test-bind-evaluator.js +++ b/extensions/amp-bind/0.1/test/test-bind-evaluator.js @@ -17,7 +17,7 @@ import {BindEvaluator} from '../bind-evaluator'; import {BindExpression} from '../bind-expression'; -describes.sandboxed('BindEvaluator', {}, () => { +describes.sandboxed('BindEvaluator', {}, (env) => { let evaluator; beforeEach(() => { @@ -91,7 +91,7 @@ describes.sandboxed('BindEvaluator', {}, () => { expressionString: '1+1', }, ]); - const stub = window.sandbox.stub(BindExpression.prototype, 'evaluate'); + const stub = env.sandbox.stub(BindExpression.prototype, 'evaluate'); stub.returns('stubbed'); evaluator.evaluateBindings({}); expect(stub.calledOnce).to.be.true; diff --git a/extensions/amp-consent/0.1/test/test-amp-consent.js b/extensions/amp-consent/0.1/test/test-amp-consent.js index c40188a276cb..b592eae440ab 100644 --- a/extensions/amp-consent/0.1/test/test-amp-consent.js +++ b/extensions/amp-consent/0.1/test/test-amp-consent.js @@ -769,7 +769,7 @@ describes.realWin( 'checkConsentHref': 'https://server-test-7/', }; ampConsent = getAmpConsent(doc, inlineConfig); - const validationSpy = window.sandbox.spy( + const validationSpy = env.sandbox.spy( ampConsent, 'validatePurposeConsents_' ); @@ -1167,7 +1167,7 @@ describes.realWin( doc.body.appendChild(consentElement); ampConsent = new AmpConsent(consentElement); actionSpy = env.sandbox.stub(ampConsent, 'handleAction_'); - window.sandbox.stub(ampConsent, 'isReadyToHandleAction_').returns(true); + env.sandbox.stub(ampConsent, 'isReadyToHandleAction_').returns(true); ampConsent.enableInteractions_(); ampIframe = document.createElement('amp-iframe'); iframe = doc.createElement('iframe'); @@ -1209,7 +1209,7 @@ describes.realWin( beforeEach(async () => { ampConsent.buildCallback(); await macroTask(); - managerSpy = window.sandbox.spy( + managerSpy = env.sandbox.spy( ampConsent.consentStateManager_, 'updateConsentInstancePurposes' ); @@ -1632,10 +1632,10 @@ describes.realWin( doc.body.appendChild(consentElement); ampConsent = new AmpConsent(consentElement); await ampConsent.buildCallback(); - window.sandbox + env.sandbox .stub(ampConsent.consentStateManager_, 'getConsentInstanceInfo') .returns(Promise.resolve({})); - const spy = window.sandbox.spy( + const spy = env.sandbox.spy( ampConsent, 'checkGranularConsentRequired_' ); @@ -1708,7 +1708,7 @@ describes.realWin( it('purposeConsentDefault handles empty and null purposeConsentRequired', async () => { const mockInvocation = {args: {purposeConsentDefault: true}}; ampConsent.purposeConsentRequired_ = Promise.resolve(); - window.sandbox.stub(ampConsent, 'hide_').callsFake(() => {}); + env.sandbox.stub(ampConsent, 'hide_').callsFake(() => {}); await ampConsent.buildCallback(); await macroTask(); updateConsentInstancePurposeSpy = env.sandbox.spy( @@ -1746,7 +1746,7 @@ describes.realWin( it('handles setPurpose with no args', async () => { const mockInvocation = {args: null}; - const devSpy = window.sandbox.spy(dev(), 'error'); + const devSpy = env.sandbox.spy(dev(), 'error'); await ampConsent.buildCallback(); await macroTask(); updateConsentInstancePurposeSpy = env.sandbox.spy( diff --git a/extensions/amp-consent/0.1/test/test-consent-policy-manager.js b/extensions/amp-consent/0.1/test/test-consent-policy-manager.js index 04af94054b2b..74262408c931 100644 --- a/extensions/amp-consent/0.1/test/test-consent-policy-manager.js +++ b/extensions/amp-consent/0.1/test/test-consent-policy-manager.js @@ -437,7 +437,7 @@ describes.realWin( }); it('will fire only fire for a valid change', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); manager.setOnPolicyChange(spy); expect(manager.tcfConsentChangeHandler_).to.not.be.null; @@ -454,7 +454,7 @@ describes.realWin( }); it('will fire on multiple changes', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); manager.setOnPolicyChange(spy); expect(manager.tcfConsentChangeHandler_).to.not.be.null; diff --git a/extensions/amp-consent/0.1/test/test-linker-reader.js b/extensions/amp-consent/0.1/test/test-linker-reader.js index 0bac61de9eb1..9f2dfbb5eb32 100644 --- a/extensions/amp-consent/0.1/test/test-linker-reader.js +++ b/extensions/amp-consent/0.1/test/test-linker-reader.js @@ -17,15 +17,15 @@ import {ConsentLinkerReader} from '../linker-reader'; import {mockWindowInterface} from '../../../../testing/test-helper'; -describes.realWin('LinkerReader', {amp: true}, () => { +describes.realWin('LinkerReader', {amp: true}, (env) => { let linkerReader; let mockWin; let url; beforeEach(() => { - window.sandbox.useFakeTimers(1533329483292); - window.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); - mockWin = mockWindowInterface(window.sandbox); + env.sandbox.useFakeTimers(1533329483292); + env.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); + mockWin = mockWindowInterface(env.sandbox); mockWin.getUserAgent.returns( 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 ' + diff --git a/extensions/amp-consent/0.1/test/test-linker.js b/extensions/amp-consent/0.1/test/test-linker.js index 90792c3f736b..700b78784a6b 100644 --- a/extensions/amp-consent/0.1/test/test-linker.js +++ b/extensions/amp-consent/0.1/test/test-linker.js @@ -245,13 +245,13 @@ const createLinkerTests = [ }, ]; -describes.sandboxed('Linker', {}, () => { +describes.sandboxed('Linker', {}, (env) => { let mockWin; beforeEach(() => { // Linker uses a timestamp value to generate checksum. - window.sandbox.useFakeTimers(BASE_TIME); - window.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); - mockWin = mockWindowInterface(window.sandbox); + env.sandbox.useFakeTimers(BASE_TIME); + env.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns(420); + mockWin = mockWindowInterface(env.sandbox); mockWin.getUserAgent.returns( 'Mozilla/5.0 (X11; Linux x86_64) ' + 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 ' + @@ -278,7 +278,7 @@ describes.sandboxed('Linker', {}, () => { expectAsyncConsoleError(TAG + ' ' + test.errorMsg); } if (test.currentTime) { - window.sandbox.useFakeTimers(test.currentTime); + env.sandbox.useFakeTimers(test.currentTime); } expect(parseLinker(test.value)).to.deep.equal(test.output); }); diff --git a/extensions/amp-consent/0.1/test/test-tcf-api-command-manager.js b/extensions/amp-consent/0.1/test/test-tcf-api-command-manager.js index 03843779c7b1..082a2a9773c2 100644 --- a/extensions/amp-consent/0.1/test/test-tcf-api-command-manager.js +++ b/extensions/amp-consent/0.1/test/test-tcf-api-command-manager.js @@ -40,8 +40,8 @@ describes.realWin( let callId; beforeEach(() => { - mockWin = mockWindowInterface(window.sandbox); - mockWin.postMessage = window.sandbox.spy(); + mockWin = mockWindowInterface(env.sandbox); + mockWin.postMessage = env.sandbox.spy(); mockMetadata = {}; mockSharedData = {}; mockTcString = ''; @@ -55,7 +55,7 @@ describes.realWin( getMergedSharedData: (opt_policy) => { return Promise.resolve(mockSharedData); }, - setOnPolicyChange: window.sandbox.spy(), + setOnPolicyChange: env.sandbox.spy(), }; }); diff --git a/extensions/amp-gwd-animation/0.1/test/test-amp-gwd-animation.js b/extensions/amp-gwd-animation/0.1/test/test-amp-gwd-animation.js index 5f51ff817858..d2dc63274174 100644 --- a/extensions/amp-gwd-animation/0.1/test/test-amp-gwd-animation.js +++ b/extensions/amp-gwd-animation/0.1/test/test-amp-gwd-animation.js @@ -27,7 +27,7 @@ import {Services} from '../../../../src/services'; import {createCustomEvent} from '../../../../src/event-helper'; import {getServiceForDocOrNull} from '../../../../src/service'; -describes.sandboxed('AMP GWD Animation', {}, () => { +describes.sandboxed('AMP GWD Animation', {}, (env) => { /** * Creates a test amp-gwd-animation element in the given document. * @param {!Document} root @@ -503,9 +503,9 @@ describes.sandboxed('AMP GWD Animation', {}, () => { let actionService; beforeEach(() => { - actionService = {setActions: window.sandbox.stub()}; + actionService = {setActions: env.sandbox.stub()}; element = document.createElement('div'); - window.sandbox + env.sandbox .stub(Services, 'actionServiceForDoc') .withArgs(element) .returns(actionService); @@ -541,7 +541,7 @@ describes.sandboxed('AMP GWD Animation', {}, () => { const target = document.createElement('div'); target.setAttribute('on', 'event2:node2.hide'); // FIE should have its own ActionService. - const fieActionService = {setActions: window.sandbox.stub()}; + const fieActionService = {setActions: env.sandbox.stub()}; Services.actionServiceForDoc.withArgs(target).returns(fieActionService); // Provide `target` as the service context to simulate FIE case. addAction(target, target, 'event1', 'node1.foo()'); diff --git a/extensions/amp-iframe/0.1/test/test-amp-iframe.js b/extensions/amp-iframe/0.1/test/test-amp-iframe.js index e8a51be50727..f559bad00faa 100644 --- a/extensions/amp-iframe/0.1/test/test-amp-iframe.js +++ b/extensions/amp-iframe/0.1/test/test-amp-iframe.js @@ -764,7 +764,7 @@ describes.realWin( }); it('should listen for embed-ready event', function* () { - const activateIframeSpy_ = window.sandbox./*OK*/ spy( + const activateIframeSpy_ = env.sandbox./*OK*/ spy( AmpIframe.prototype, 'activateIframe_' ); diff --git a/extensions/amp-install-serviceworker/0.1/test/test-amp-install-serviceworker.js b/extensions/amp-install-serviceworker/0.1/test/test-amp-install-serviceworker.js index ae8428385c37..a9bf6e8166df 100644 --- a/extensions/amp-install-serviceworker/0.1/test/test-amp-install-serviceworker.js +++ b/extensions/amp-install-serviceworker/0.1/test/test-amp-install-serviceworker.js @@ -519,7 +519,7 @@ describes.fakeWin( describe('install conditions', () => { beforeEach(() => { - window.sandbox.stub(implementation, 'preloadShell_'); + env.sandbox.stub(implementation, 'preloadShell_'); }); it('should install rewriter', () => { @@ -610,7 +610,7 @@ describes.fakeWin( let preloadStub; beforeEach(() => { - mutateElementStub = window.sandbox + mutateElementStub = env.sandbox .stub(implementation, 'mutateElement') .callsFake((callback) => callback()); preloadStub = env.sandbox.stub(implementation, 'preloadShell_'); @@ -683,7 +683,7 @@ describes.fakeWin( let origHref; beforeEach(() => { - window.sandbox.stub(implementation, 'preloadShell_'); + env.sandbox.stub(implementation, 'preloadShell_'); implementation.maybeInstallUrlRewrite_(); rewriter = implementation.urlRewriter_; anchor = win.document.createElement('a'); diff --git a/extensions/amp-live-list/0.1/test/test-poller.js b/extensions/amp-live-list/0.1/test/test-poller.js index f75a39796a0e..fa02149aa307 100644 --- a/extensions/amp-live-list/0.1/test/test-poller.js +++ b/extensions/amp-live-list/0.1/test/test-poller.js @@ -17,19 +17,19 @@ import {Poller} from '../poller'; import {Services} from '../../../../src/services'; -describes.sandboxed('Poller', {}, () => { +describes.sandboxed('Poller', {}, (env) => { let clock; let poller; let workStub; const timer = Services.timerFor(window); beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); const obj = { work() {}, }; - workStub = window.sandbox.stub(obj, 'work'); - window.sandbox.stub(Math, 'random').callsFake(() => 1); + workStub = env.sandbox.stub(obj, 'work'); + env.sandbox.stub(Math, 'random').callsFake(() => 1); const wait = 5000; poller = new Poller(window, wait, workStub); }); @@ -243,13 +243,13 @@ describes.sandboxed('Poller', {}, () => { }); it('should clear timeout ids if stopped', () => { - const delaySpy = window.sandbox.spy(timer, 'delay'); + const delaySpy = env.sandbox.spy(timer, 'delay'); const retriableErr = new Error('HTTP Error'); retriableErr.retriable = true; workStub.onCall(0).returns(Promise.reject(retriableErr)); workStub.onCall(1).returns(Promise.reject(retriableErr)); workStub.returns(Promise.resolve()); - const clearSpy = window.sandbox.spy(timer, 'cancel'); + const clearSpy = env.sandbox.spy(timer, 'cancel'); expect(poller.lastTimeoutId_).to.be.null; diff --git a/extensions/amp-script/0.1/test/unit/test-amp-script.js b/extensions/amp-script/0.1/test/unit/test-amp-script.js index 95629e9d45d7..ea82c301f360 100644 --- a/extensions/amp-script/0.1/test/unit/test-amp-script.js +++ b/extensions/amp-script/0.1/test/unit/test-amp-script.js @@ -339,7 +339,7 @@ describes.repeated( } ); -describes.sandboxed('SanitizerImpl', {}, () => { +describes.sandboxed('SanitizerImpl', {}, (env) => { let el; let win; let s; @@ -543,11 +543,11 @@ describes.sandboxed('SanitizerImpl', {}, () => { beforeEach(() => { bind = { - getStateValue: window.sandbox.stub(), - setState: window.sandbox.stub(), - constrain: window.sandbox.stub(), + getStateValue: env.sandbox.stub(), + setState: env.sandbox.stub(), + constrain: env.sandbox.stub(), }; - window.sandbox.stub(Services, 'bindForDocOrNull').resolves(bind); + env.sandbox.stub(Services, 'bindForDocOrNull').resolves(bind); }); it('AMP.setState(json), without user interaction', async () => { diff --git a/extensions/amp-sidebar/0.1/test/test-toolbar.js b/extensions/amp-sidebar/0.1/test/test-toolbar.js index 342fbf64047a..86c6d7ae9e87 100644 --- a/extensions/amp-sidebar/0.1/test/test-toolbar.js +++ b/extensions/amp-sidebar/0.1/test/test-toolbar.js @@ -23,7 +23,7 @@ import {toArray} from '../../../../src/core/types/array'; adopt(window); -describes.sandboxed('amp-sidebar - toolbar', {}, () => { +describes.sandboxed('amp-sidebar - toolbar', {}, (env) => { let timer; function getToolbars(options) { @@ -43,7 +43,7 @@ describes.sandboxed('amp-sidebar - toolbar', {}, () => { }, }; - window.sandbox.stub(timer, 'delay').callsFake(function (callback) { + env.sandbox.stub(timer, 'delay').callsFake(function (callback) { callback(); }); diff --git a/extensions/amp-skimlinks/0.1/test/test-amp-skimlinks.js b/extensions/amp-skimlinks/0.1/test/test-amp-skimlinks.js index a624588b5650..e50648511953 100644 --- a/extensions/amp-skimlinks/0.1/test/test-amp-skimlinks.js +++ b/extensions/amp-skimlinks/0.1/test/test-amp-skimlinks.js @@ -309,7 +309,7 @@ describes.fakeWin( it('Should wait until visible to send the impression tracking', () => { const isVisibleDefer = new Deferred(); - window.sandbox + env.sandbox .stub(ampdoc, 'whenFirstVisible') .returns(isVisibleDefer.promise); @@ -369,7 +369,7 @@ describes.fakeWin( it('Should wait until visible to send the impression tracking', () => { const isVisibleDefer = new Deferred(); - window.sandbox + env.sandbox .stub(ampdoc, 'whenFirstVisible') .returns(isVisibleDefer.promise); diff --git a/extensions/amp-story-auto-ads/0.1/test/test-story-ad-page.js b/extensions/amp-story-auto-ads/0.1/test/test-story-ad-page.js index 75f78bdad364..15bb1dee0c03 100644 --- a/extensions/amp-story-auto-ads/0.1/test/test-story-ad-page.js +++ b/extensions/amp-story-auto-ads/0.1/test/test-story-ad-page.js @@ -132,7 +132,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { describe('#hasTimedOut', () => { it('should timeout after > 10 seconds', () => { - const clock = window.sandbox.useFakeTimers(1555555555555); + const clock = env.sandbox.useFakeTimers(1555555555555); storyAdPage.build(); expect(storyAdPage.hasTimedOut()).to.be.false; clock.tick(10009); // 10 second timeout. @@ -164,7 +164,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { describe('#registerLoadCallback', () => { it('registers given functions and executes when loaded', async () => { - const someFunc = window.sandbox.spy(); + const someFunc = env.sandbox.spy(); const pageElement = storyAdPage.build(); // Stub delegateVideoAutoplay. pageElement.getImpl = () => Promise.resolve(pageImplMock); @@ -403,7 +403,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { 'https://googleads.g.doubleclick.net/pagead/images/mtad/ad_choices_blue.png' ); - const openWindowDialogStub = window.sandbox.stub(dom, 'openWindowDialog'); + const openWindowDialogStub = env.sandbox.stub(dom, 'openWindowDialog'); attribution.click(); expect(openWindowDialogStub).to.be.calledOnce; expect(openWindowDialogStub).to.be.calledWithExactly( @@ -487,8 +487,8 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { beforeEach(() => { const storyAnalytics = new StoryAdAnalytics(env.ampdoc); - fireEventStub = window.sandbox.stub(storyAnalytics, 'fireEvent'); - window.sandbox + fireEventStub = env.sandbox.stub(storyAnalytics, 'fireEvent'); + env.sandbox .stub(service, 'getServicePromiseForDoc') .resolves(storyAnalytics); storyAdPage = new StoryAdPage( @@ -507,7 +507,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { pageElement, 1, // adIndex 'story-ad-request', - {requestTime: window.sandbox.match.number} + {requestTime: env.sandbox.match.number} ); }); @@ -524,7 +524,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { pageElement, 1, // adIndex 'story-ad-load', - {loadTime: window.sandbox.match.number} + {loadTime: env.sandbox.match.number} ); }); @@ -544,7 +544,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { pageElement, 1, // adIndex 'story-ad-swipe', - {swipeTime: window.sandbox.match.number} + {swipeTime: env.sandbox.match.number} ); }); @@ -572,7 +572,7 @@ describes.realWin('story-ad-page', {amp: true}, (env) => { pageElement, 1, // adIndex 'story-ad-click', - {clickTime: window.sandbox.match.number} + {clickTime: env.sandbox.match.number} ); }); }); diff --git a/extensions/amp-story/1.0/test/test-amp-story.js b/extensions/amp-story/1.0/test/test-amp-story.js index 5c1b1f1e96ac..a5c3b501264e 100644 --- a/extensions/amp-story/1.0/test/test-amp-story.js +++ b/extensions/amp-story/1.0/test/test-amp-story.js @@ -718,7 +718,7 @@ describes.realWin( await createStoryWithPages(2, ['cover', 'page-1']); await story.layoutCallback(); - const setStateStub = window.sandbox.stub(story.activePage_, 'setState'); + const setStateStub = env.sandbox.stub(story.activePage_, 'setState'); story.getAmpDoc().overrideVisibilityState(VisibilityState.INACTIVE); expect(setStateStub.getCall(1)).to.have.been.calledWithExactly( PageState.NOT_ACTIVE @@ -737,7 +737,7 @@ describes.realWin( await createStoryWithPages(2, ['cover', 'page-1']); await story.layoutCallback(); - const setStateStub = window.sandbox.stub(story.activePage_, 'setState'); + const setStateStub = env.sandbox.stub(story.activePage_, 'setState'); story.getAmpDoc().overrideVisibilityState(VisibilityState.HIDDEN); expect(setStateStub).to.have.been.calledOnceWithExactly( PageState.PAUSED @@ -756,7 +756,7 @@ describes.realWin( await createStoryWithPages(2, ['cover', 'page-1']); await story.layoutCallback(); - const setStateStub = window.sandbox.stub(story.activePage_, 'setState'); + const setStateStub = env.sandbox.stub(story.activePage_, 'setState'); story.getAmpDoc().overrideVisibilityState(VisibilityState.PAUSED); expect(setStateStub).to.have.been.calledOnceWithExactly( PageState.PAUSED @@ -776,7 +776,7 @@ describes.realWin( await createStoryWithPages(2, ['cover', 'page-1']); await story.layoutCallback(); - const setStateStub = window.sandbox.stub(story.activePage_, 'setState'); + const setStateStub = env.sandbox.stub(story.activePage_, 'setState'); story.getAmpDoc().overrideVisibilityState(VisibilityState.PAUSED); story.getAmpDoc().overrideVisibilityState(VisibilityState.ACTIVE); expect(setStateStub.getCall(1)).to.have.been.calledWithExactly( @@ -788,7 +788,7 @@ describes.realWin( await createStoryWithPages(2, ['cover', 'page-1']); await story.layoutCallback(); - const setStateStub = window.sandbox.stub(story.activePage_, 'setState'); + const setStateStub = env.sandbox.stub(story.activePage_, 'setState'); story.getAmpDoc().overrideVisibilityState(VisibilityState.PAUSED); story.getAmpDoc().overrideVisibilityState(VisibilityState.INACTIVE); story.getAmpDoc().overrideVisibilityState(VisibilityState.ACTIVE); diff --git a/extensions/amp-subscriptions/0.1/test/test-viewer-platform.js b/extensions/amp-subscriptions/0.1/test/test-viewer-platform.js index 7d768c8f7675..566e984ee018 100644 --- a/extensions/amp-subscriptions/0.1/test/test-viewer-platform.js +++ b/extensions/amp-subscriptions/0.1/test/test-viewer-platform.js @@ -68,7 +68,7 @@ describes.fakeWin('ViewerSubscriptionPlatform', {amp: true}, (env) => { beforeEach(() => { ampdoc = env.ampdoc; win = env.win; - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); serviceAdapter = new ServiceAdapter(null); const analytics = new SubscriptionAnalytics(ampdoc.getRootNode()); env.sandbox.stub(serviceAdapter, 'getAnalytics').callsFake(() => analytics); diff --git a/extensions/amp-viewer-integration/0.1/test/integration/test-messaging-handshake.js b/extensions/amp-viewer-integration/0.1/test/integration/test-messaging-handshake.js index 83822fe997e2..40e7b24d0df4 100644 --- a/extensions/amp-viewer-integration/0.1/test/integration/test-messaging-handshake.js +++ b/extensions/amp-viewer-integration/0.1/test/integration/test-messaging-handshake.js @@ -17,7 +17,7 @@ import {Messaging} from '../../messaging/messaging'; import {getWinOrigin, serializeQueryString} from '../../../../../src/url'; -describes.sandboxed('AmpViewerMessagingIntegration', {}, () => { +describes.sandboxed('AmpViewerMessagingIntegration', {}, (env) => { const ampDocSrc = '/test/fixtures/served/ampdoc-with-messaging.html'; describe @@ -123,7 +123,7 @@ describes.sandboxed('AmpViewerMessagingIntegration', {}, () => { iframeOrigin, 'bar' ).then((messaging) => { - const handlerStub = window.sandbox.stub(); + const handlerStub = env.sandbox.stub(); messaging.setDefaultHandler(handlerStub); expect(handlerStub).to.not.have.been.called; }); diff --git a/test/integration/test-actions.js b/test/integration/test-actions.js index a5971017a97c..f4e89b706871 100644 --- a/test/integration/test-actions.js +++ b/test/integration/test-actions.js @@ -82,7 +82,7 @@ describes.integration( // This is brittle but I don't know how else to stub // window navigation. const navigationService = win.__AMP_SERVICES.navigation.obj; - const navigateTo = window.sandbox.stub( + const navigateTo = env.sandbox.stub( navigationService, 'navigateTo' ); @@ -95,7 +95,7 @@ describes.integration( }); it('AMP.print()', async () => { - const print = window.sandbox.stub(win, 'print'); + const print = env.sandbox.stub(win, 'print'); doc.getElementById('printBtn').click(); await poll('print() called once', () => print.calledOnce); diff --git a/test/integration/test-video-manager.js b/test/integration/test-video-manager.js index 6e103e5f82e6..97ef03c07ea9 100644 --- a/test/integration/test-video-manager.js +++ b/test/integration/test-video-manager.js @@ -31,11 +31,11 @@ import {toArray} from '../../src/core/types/array'; // See #11588. describes.sandboxed .configure() - .skip('Fake Video PlayerIntegration Tests', {}, () => { + .skip('Fake Video PlayerIntegration Tests', {}, (env) => { // We run the video player integration tests on a fake video player as part // of functional testing. Same tests run on real video players such as // `amp-video` and `amp-youtube` as part of integration testing. - runVideoPlayerIntegrationTests((fixture) => { + runVideoPlayerIntegrationTests(env, (fixture) => { fixture.win.AMP.push({ n: 'amp-test-fake-videoplayer', f: function (AMP) { @@ -286,7 +286,7 @@ describes.sandboxed describes.sandboxed .configure() .ifChrome() - .run('Autoplay support', {}, () => { + .run('Autoplay support', {}, (env) => { let win; let video; let createElementSpy; @@ -318,9 +318,9 @@ describes.sandboxed win = {document: doc}; - createElementSpy = window.sandbox.spy(doc, 'createElement'); - setAttributeSpy = window.sandbox.spy(video, 'setAttribute'); - playStub = window.sandbox.stub(video, 'play'); + createElementSpy = env.sandbox.spy(doc, 'createElement'); + setAttributeSpy = env.sandbox.spy(video, 'setAttribute'); + playStub = env.sandbox.stub(video, 'play'); resetIsAutoplaySupported(win); }); diff --git a/test/integration/test-video-players-helper.js b/test/integration/test-video-players-helper.js index 1b6d5ba6cc59..1bcd43bec506 100644 --- a/test/integration/test-video-players-helper.js +++ b/test/integration/test-video-players-helper.js @@ -39,6 +39,7 @@ function skipIfAutoplayUnsupported(win) { } export function runVideoPlayerIntegrationTests( + env, createVideoElementFunc, opt_experiment, timeout = 2000 @@ -500,7 +501,7 @@ export function runVideoPlayerIntegrationTests( autoFullscreen = manager.getAutoFullscreenManagerForTesting_(); } if (!isInLandscapeStub) { - isInLandscapeStub = window.sandbox.stub( + isInLandscapeStub = env.sandbox.stub( autoFullscreen, 'isInLandscape' ); @@ -530,7 +531,7 @@ export function runVideoPlayerIntegrationTests( }) .then(async () => { const impl = await video.getImpl(false); - const enter = window.sandbox.stub(impl, 'fullscreenEnter'); + const enter = env.sandbox.stub(impl, 'fullscreenEnter'); mockLandscape(true); autoFullscreen.onRotation_(); return poll('fullscreen enter', () => enter.called); diff --git a/test/integration/test-video-players.js b/test/integration/test-video-players.js index c5c1bb557ec7..10ac6e13c228 100644 --- a/test/integration/test-video-players.js +++ b/test/integration/test-video-players.js @@ -32,8 +32,8 @@ import {runVideoPlayerIntegrationTests} from './test-video-players-helper'; describes.sandboxed .configure() .skipIos() - .run('amp-video', {}, () => { - runVideoPlayerIntegrationTests((fixture) => { + .run('amp-video', {}, (env) => { + runVideoPlayerIntegrationTests(env, (fixture) => { const video = fixture.doc.createElement('amp-video'); video.setAttribute('src', '/examples/av/ForBiggerJoyrides-tiny.mp4'); return video; @@ -41,8 +41,9 @@ describes.sandboxed }); // TODO(alanorozco): unskip -describes.sandboxed.skip('amp-video-iframe', {}, () => { +describes.sandboxed.skip('amp-video-iframe', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-video-iframe'); video.setAttribute('src', '/examples/amp-video-iframe/frame.html'); @@ -55,8 +56,9 @@ describes.sandboxed.skip('amp-video-iframe', {}, () => { }); //TODO(aghassemi, #9379): unskip -describes.sandboxed.skip('amp-youtube', {}, () => { +describes.sandboxed.skip('amp-youtube', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-youtube'); video.setAttribute('data-videoid', 'O0QDEXZhow4'); @@ -68,8 +70,9 @@ describes.sandboxed.skip('amp-youtube', {}, () => { }); //TODO(aghassemi, #9379): unskip -describes.sandboxed.skip('amp-dailymotion', {}, () => { +describes.sandboxed.skip('amp-dailymotion', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-dailymotion'); video.setAttribute('data-videoid', 'x3rdtfy'); @@ -80,8 +83,9 @@ describes.sandboxed.skip('amp-dailymotion', {}, () => { ); }); -describes.sandboxed.configure().skip('amp-3q-player', {}, () => { +describes.sandboxed.configure().skip('amp-3q-player', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-3q-player'); video.setAttribute('data-id', 'c8dbe7f4-7f7f-11e6-a407-0cc47a188158'); @@ -93,8 +97,9 @@ describes.sandboxed.configure().skip('amp-3q-player', {}, () => { }); //TODO(aghassemi,#8264): Unskip when integration is fixed. -describes.sandboxed.skip('amp-nexxtv-player', {}, () => { +describes.sandboxed.skip('amp-nexxtv-player', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-nexxtv-player'); video.setAttribute('data-mediaid', 'PTPFEC4U184674'); @@ -107,8 +112,9 @@ describes.sandboxed.skip('amp-nexxtv-player', {}, () => { }); //TODO(aghassemi, #9379): unskip -describes.sandboxed.skip('amp-ima-video', {}, () => { +describes.sandboxed.skip('amp-ima-video', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-ima-video'); video.setAttribute('width', 640); @@ -129,8 +135,9 @@ describes.sandboxed.skip('amp-ima-video', {}, () => { }); //TODO(cvializ, #14833): unskip after brid player is fixed -describes.sandboxed.skip('amp-brid-player', {}, () => { +describes.sandboxed.skip('amp-brid-player', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-brid-player'); video.setAttribute('data-partner', '264'); @@ -143,8 +150,9 @@ describes.sandboxed.skip('amp-brid-player', {}, () => { ); }); -describes.sandboxed.skip('amp-brightcove', {}, () => { +describes.sandboxed.skip('amp-brightcove', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-brightcove'); video.setAttribute('data-account-id', '1290862519001'); @@ -157,8 +165,9 @@ describes.sandboxed.skip('amp-brightcove', {}, () => { ); }); -describes.sandboxed.skip('amp-delight-player', {}, () => { +describes.sandboxed.skip('amp-delight-player', {}, (env) => { runVideoPlayerIntegrationTests( + env, (fixture) => { const video = fixture.doc.createElement('amp-delight-player'); video.setAttribute('data-content-id', '-LLoCCZqWi18O73b6M0w'); diff --git a/test/unit/ads/test-ssp.js b/test/unit/ads/test-ssp.js index afe93ae16f8d..2ed132359313 100644 --- a/test/unit/ads/test-ssp.js +++ b/test/unit/ads/test-ssp.js @@ -25,7 +25,7 @@ import { ssp, } from '../../../ads/vendors/ssp'; -describes.fakeWin('amp-ad-ssp', {}, () => { +describes.fakeWin('amp-ad-ssp', {}, (env) => { let sandbox; let win; let commonData; @@ -35,7 +35,7 @@ describes.fakeWin('amp-ad-ssp', {}, () => { * Set up our test environment. */ beforeEach(() => { - sandbox = window.sandbox; + sandbox = env.sandbox; commonData = { width: '200', diff --git a/test/unit/core/data-structures/test-priority-queue.js b/test/unit/core/data-structures/test-priority-queue.js index cb030bfa7494..b38186d207df 100644 --- a/test/unit/core/data-structures/test-priority-queue.js +++ b/test/unit/core/data-structures/test-priority-queue.js @@ -16,7 +16,7 @@ import PriorityQueue from '../../../../src/core/data-structures/priority-queue'; -describes.sandboxed('PriorityQueue', {}, () => { +describes.sandboxed('PriorityQueue', {}, (env) => { let pq; beforeEach(() => { @@ -91,7 +91,7 @@ describes.sandboxed('PriorityQueue', {}, () => { }); it('should iterate through queue', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); pq.enqueue('p', 1); pq.enqueue('m', 2); pq.enqueue('a', 3); diff --git a/test/unit/core/test-error.js b/test/unit/core/test-error.js index 150e6f8540f7..1ba9da313879 100644 --- a/test/unit/core/test-error.js +++ b/test/unit/core/test-error.js @@ -17,12 +17,12 @@ import {duplicateErrorIfNecessary, rethrowAsync} from '../../../src/core/error'; import {isUserErrorMessage, user} from '../../../src/log'; -describes.sandboxed('errors', {}, () => { +describes.sandboxed('errors', {}, (env) => { describe('rethrowAsync', () => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); restoreAsyncErrorThrows(); }); diff --git a/test/unit/core/types/test-function.js b/test/unit/core/types/test-function.js index db47e4f38cf0..ccefb6e728d5 100644 --- a/test/unit/core/types/test-function.js +++ b/test/unit/core/types/test-function.js @@ -16,16 +16,16 @@ import {debounce, throttle} from '../../../../src/core/types/function'; -describes.sandboxed('type helpers - functions', {}, () => { +describes.sandboxed('type helpers - functions', {}, (env) => { describe('throttle', () => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); }); it('should work', () => { - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); const throttledCallback = throttle(window, callback, 100); throttledCallback(1); @@ -86,11 +86,11 @@ describes.sandboxed('type helpers - functions', {}, () => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); }); it('should wait before calling', () => { - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); const debounced = debounce(window, callback, 100); debounced(1); diff --git a/test/unit/test-3p.js b/test/unit/test-3p.js index 283aa898cbe2..45c7f33b73c4 100644 --- a/test/unit/test-3p.js +++ b/test/unit/test-3p.js @@ -23,11 +23,11 @@ import { validateSrcPrefix, } from '../../3p/3p'; -describes.sandboxed('3p', {}, () => { +describes.sandboxed('3p', {}, (env) => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); }); afterEach(() => { diff --git a/test/unit/test-activity.js b/test/unit/test-activity.js index 1463b3ce4b2e..0f4a4123385a 100644 --- a/test/unit/test-activity.js +++ b/test/unit/test-activity.js @@ -25,7 +25,7 @@ import {installViewportServiceForDoc} from '../../src/service/viewport/viewport- import {installVsyncService} from '../../src/service/vsync-impl'; import {markElementScheduledForTesting} from '../../src/service/custom-element-registry'; -describes.sandboxed('Activity getTotalEngagedTime', {}, () => { +describes.sandboxed('Activity getTotalEngagedTime', {}, (env) => { let clock; let fakeDoc; let fakeWin; @@ -39,7 +39,7 @@ describes.sandboxed('Activity getTotalEngagedTime', {}, () => { let scrollObservable; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); // start at something other than 0 clock.tick(123456); @@ -112,17 +112,17 @@ describes.sandboxed('Activity getTotalEngagedTime', {}, () => { const whenFirstVisiblePromise = new Promise((resolve) => { whenFirstVisibleResolve = resolve; }); - window.sandbox + env.sandbox .stub(ampdoc, 'whenFirstVisible') .returns(whenFirstVisiblePromise); - window.sandbox.stub(ampdoc, 'onVisibilityChanged').callsFake((handler) => { + env.sandbox.stub(ampdoc, 'onVisibilityChanged').callsFake((handler) => { return visibilityObservable.add(handler); }); installViewportServiceForDoc(ampdoc); viewport = Services.viewportForDoc(ampdoc); - window.sandbox.stub(viewport, 'onScroll').callsFake((handler) => { + env.sandbox.stub(viewport, 'onScroll').callsFake((handler) => { scrollObservable.add(handler); }); @@ -177,9 +177,7 @@ describes.sandboxed('Activity getTotalEngagedTime', {}, () => { }); it('should not accumulate engaged time after inactivity', () => { - const isVisibleStub = window.sandbox - .stub(ampdoc, 'isVisible') - .returns(true); + const isVisibleStub = env.sandbox.stub(ampdoc, 'isVisible').returns(true); whenFirstVisibleResolve(); return ampdoc .whenFirstVisible() @@ -218,10 +216,7 @@ describes.sandboxed('Activity getTotalEngagedTime', {}, () => { 'should set event listeners on the document for' + ' "mousedown", "mouseup", "mousemove", "keyup", "keydown", "mouseleave"', () => { - const addEventListenerSpy = window.sandbox.spy( - fakeDoc, - 'addEventListener' - ); + const addEventListenerSpy = env.sandbox.spy(fakeDoc, 'addEventListener'); expect(addEventListenerSpy).to.not.have.been.calledWith( 'mousedown', activity.boundHandleActivity_ @@ -259,7 +254,7 @@ describes.sandboxed('Activity getTotalEngagedTime', {}, () => { ); }); -describes.sandboxed('Activity getIncrementalEngagedTime', {}, () => { +describes.sandboxed('Activity getIncrementalEngagedTime', {}, (env) => { let clock; let fakeDoc; let fakeWin; @@ -272,7 +267,7 @@ describes.sandboxed('Activity getIncrementalEngagedTime', {}, () => { let scrollObservable; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); // start at something other than 0 clock.tick(123456); @@ -342,17 +337,17 @@ describes.sandboxed('Activity getIncrementalEngagedTime', {}, () => { const whenFirstVisiblePromise = new Promise((resolve) => { whenFirstVisibleResolve = resolve; }); - window.sandbox + env.sandbox .stub(ampdoc, 'whenFirstVisible') .returns(whenFirstVisiblePromise); - window.sandbox.stub(ampdoc, 'onVisibilityChanged').callsFake((handler) => { + env.sandbox.stub(ampdoc, 'onVisibilityChanged').callsFake((handler) => { return visibilityObservable.add(handler); }); installViewportServiceForDoc(ampdoc); viewport = Services.viewportForDoc(ampdoc); - window.sandbox.stub(viewport, 'onScroll').callsFake((handler) => { + env.sandbox.stub(viewport, 'onScroll').callsFake((handler) => { scrollObservable.add(handler); }); diff --git a/test/unit/test-alp-handler.js b/test/unit/test-alp-handler.js index 84dfe98b1f61..d8ed0f74aa40 100644 --- a/test/unit/test-alp-handler.js +++ b/test/unit/test-alp-handler.js @@ -17,7 +17,7 @@ import {handleClick, warmupDynamic, warmupStatic} from '../../ads/alp/handler'; import {parseUrlDeprecated} from '../../src/url'; -describes.sandboxed('alp-handler', {}, () => { +describes.sandboxed('alp-handler', {}, (env) => { let event; let anchor; let open; @@ -32,32 +32,32 @@ describes.sandboxed('alp-handler', {}, () => { Image() { image = this; }, - postMessage: window.sandbox.stub(), + postMessage: env.sandbox.stub(), _id: 'base-win', }; win.parent = { - postMessage: window.sandbox.stub(), + postMessage: env.sandbox.stub(), _id: 'p0', }; win.parent.parent = { - postMessage: window.sandbox.stub(), + postMessage: env.sandbox.stub(), _id: 'p1', }; win.parent.parent.parent = { - postMessage: window.sandbox.stub(), + postMessage: env.sandbox.stub(), _id: 'p2', }; win.parent.parent.parent.parent = { - postMessage: window.sandbox.stub(), + postMessage: env.sandbox.stub(), _id: 'p3', }; - open = window.sandbox.stub(win, 'open').callsFake(() => { + open = env.sandbox.stub(win, 'open').callsFake(() => { return {}; }); const doc = { defaultView: win, head: { - appendChild: window.sandbox.spy(), + appendChild: env.sandbox.spy(), }, }; win.document = doc; @@ -70,7 +70,7 @@ describes.sandboxed('alp-handler', {}, () => { 'https://cdn.ampproject.org/c/www.example.com/amp.html' ), ownerDocument: doc, - getAttribute: window.sandbox.stub(), + getAttribute: env.sandbox.stub(), get search() { return parseUrlDeprecated(this.href).search; }, @@ -79,7 +79,7 @@ describes.sandboxed('alp-handler', {}, () => { trusted: true, buttons: 0, target: anchor, - preventDefault: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), defaultPrevented: false, }; }); @@ -190,7 +190,7 @@ describes.sandboxed('alp-handler', {}, () => { }); it('should perform special navigation if specially asked for', () => { - const navigateSpy = window.sandbox.spy(); + const navigateSpy = env.sandbox.spy(); const opt_navigate = (val) => { navigateSpy(); expect(val).to.equal( diff --git a/test/unit/test-amp-context.js b/test/unit/test-amp-context.js index 69bfe6d55397..c4834d2d8d26 100644 --- a/test/unit/test-amp-context.js +++ b/test/unit/test-amp-context.js @@ -19,13 +19,13 @@ import {Platform} from '../../src/service/platform-impl'; const NOOP = () => {}; -describes.sandboxed('3p ampcontext.js', {}, () => { +describes.sandboxed('3p ampcontext.js', {}, (env) => { let windowPostMessageSpy; let windowMessageHandler; let win; beforeEach(() => { - windowPostMessageSpy = window.sandbox.spy(); + windowPostMessageSpy = env.sandbox.spy(); win = { addEventListener: (eventType, handlerFn) => { expect(eventType).to.equal('message'); @@ -166,7 +166,7 @@ describes.sandboxed('3p ampcontext.js', {}, () => { it('should be able to send an intersection observer request', () => { win.name = generateSerializedAttributes(); const context = new AmpContext(win); - const callbackSpy = window.sandbox.spy(); + const callbackSpy = env.sandbox.spy(); // Resetting since a message is sent on construction. windowPostMessageSpy.resetHistory(); @@ -211,7 +211,7 @@ describes.sandboxed('3p ampcontext.js', {}, () => { it('should send a pM and set callback when onPageVisibilityChange()', () => { win.name = generateSerializedAttributes(); const context = new AmpContext(win); - const callbackSpy = window.sandbox.spy(); + const callbackSpy = env.sandbox.spy(); const stopObserving = context.onPageVisibilityChange(callbackSpy); // window.context should have sent postMessage asking for visibility @@ -258,8 +258,8 @@ describes.sandboxed('3p ampcontext.js', {}, () => { // Resetting since a message is sent on construction. windowPostMessageSpy.resetHistory(); - const successCallbackSpy = window.sandbox.spy(); - const failureCallbackSpy = window.sandbox.spy(); + const successCallbackSpy = env.sandbox.spy(); + const failureCallbackSpy = env.sandbox.spy(); const initialId = context.nextResizeRequestId_; const height = 100; @@ -315,10 +315,10 @@ describes.sandboxed('3p ampcontext.js', {}, () => { // Resetting since a message is sent on construction. windowPostMessageSpy.resetHistory(); - context.sendDeprecationNotice_ = window.sandbox.spy(); + context.sendDeprecationNotice_ = env.sandbox.spy(); - const successCallbackSpy = window.sandbox.spy(); - const deniedCallbackSpy = window.sandbox.spy(); + const successCallbackSpy = env.sandbox.spy(); + const deniedCallbackSpy = env.sandbox.spy(); context.onResizeSuccess(successCallbackSpy); context.onResizeDenied(deniedCallbackSpy); @@ -365,8 +365,8 @@ describes.sandboxed('3p ampcontext.js', {}, () => { // Resetting since a message is sent on construction. windowPostMessageSpy.resetHistory(); - const successCallbackSpy = window.sandbox.spy(); - const deniedCallbackSpy = window.sandbox.spy(); + const successCallbackSpy = env.sandbox.spy(); + const deniedCallbackSpy = env.sandbox.spy(); context.onResizeSuccess(successCallbackSpy); context.onResizeDenied(deniedCallbackSpy); diff --git a/test/unit/test-animation.js b/test/unit/test-animation.js index 9bcb34c6a5bb..b8daecf77467 100644 --- a/test/unit/test-animation.js +++ b/test/unit/test-animation.js @@ -16,7 +16,7 @@ import {Animation} from '../../src/animation'; -describes.sandboxed('Animation', {}, () => { +describes.sandboxed('Animation', {}, (env) => { let vsync; let vsyncTasks; let anim; @@ -24,7 +24,7 @@ describes.sandboxed('Animation', {}, () => { let contextNode; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); vsyncTasks = []; vsync = { canAnimate: () => true, diff --git a/test/unit/test-batched-json.js b/test/unit/test-batched-json.js index e3bc70e35900..8b844e554705 100644 --- a/test/unit/test-batched-json.js +++ b/test/unit/test-batched-json.js @@ -18,7 +18,7 @@ import {Services} from '../../src/services'; import {UrlReplacementPolicy, batchFetchJsonFor} from '../../src/batched-json'; import {user} from '../../src/log'; -describes.sandboxed('batchFetchJsonFor', {}, () => { +describes.sandboxed('batchFetchJsonFor', {}, (env) => { // Fakes. const ampdoc = {win: null}; // Service fakes. @@ -43,24 +43,24 @@ describes.sandboxed('batchFetchJsonFor', {}, () => { beforeEach(() => { urlReplacements = { - expandUrlAsync: window.sandbox.stub(), - collectDisallowedVarsSync: window.sandbox.stub(), + expandUrlAsync: env.sandbox.stub(), + collectDisallowedVarsSync: env.sandbox.stub(), }; - window.sandbox + env.sandbox .stub(Services, 'urlReplacementsForDoc') .returns(urlReplacements); - fetchJson = window.sandbox.stub().returns( + fetchJson = env.sandbox.stub().returns( Promise.resolve({ json: () => Promise.resolve(data), }) ); xhr = {xssiJson: () => Promise.resolve(data)}; - window.sandbox.stub(Services, 'xhrFor').returns(xhr); + env.sandbox.stub(Services, 'xhrFor').returns(xhr); batchedXhr = {fetchJson}; - window.sandbox.stub(Services, 'batchedXhrFor').returns(batchedXhr); + env.sandbox.stub(Services, 'batchedXhrFor').returns(batchedXhr); }); describe('URL replacement', () => { @@ -100,7 +100,7 @@ describes.sandboxed('batchFetchJsonFor', {}, () => { .withArgs('https://data.com?x=FOO&y=BAR') .returns(Promise.resolve('https://data.com?x=abc&y=BAR')); - const userError = window.sandbox.stub(user(), 'error'); + const userError = env.sandbox.stub(user(), 'error'); const all = UrlReplacementPolicy.ALL; return batchFetchJsonFor(ampdoc, el, {urlReplacement: all}).then(() => { expect(fetchJson).to.be.calledWith('https://data.com?x=abc&y=BAR'); diff --git a/test/unit/test-chunk.js b/test/unit/test-chunk.js index 4b574d3a8523..a999956a063d 100644 --- a/test/unit/test-chunk.js +++ b/test/unit/test-chunk.js @@ -589,14 +589,14 @@ describes.sandboxed('isInputPending usage', {}, () => { ); }); -describes.sandboxed('onIdle', {}, () => { +describes.sandboxed('onIdle', {}, (env) => { let win; let calls; let callbackCalled; let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); calls = []; callbackCalled = false; win = { diff --git a/test/unit/test-document-info.js b/test/unit/test-document-info.js index 1584e13947e8..9e184e726ef0 100644 --- a/test/unit/test-document-info.js +++ b/test/unit/test-document-info.js @@ -24,9 +24,9 @@ import {installDocumentInfoServiceForDoc} from '../../src/service/document-info- describes.sandboxed .configure() .skipFirefox() - .run('document-info', {}, () => { + .run('document-info', {}, (env) => { beforeEach(() => { - window.sandbox.stub(CID, 'getRandomString64').returns('abcdef'); + env.sandbox.stub(CID, 'getRandomString64').returns('abcdef'); }); function getWin(links, metas) { @@ -55,7 +55,7 @@ describes.sandboxed } const {win} = iframe; installDocService(win, /* isSingleDoc */ true); - window.sandbox.stub(win.Math, 'random').callsFake(() => 0.123456789); + env.sandbox.stub(win.Math, 'random').callsFake(() => 0.123456789); win.__AMP_SERVICES.documentInfo = null; installDocumentInfoServiceForDoc(win.document); return iframe.win; diff --git a/test/unit/test-document-ready.js b/test/unit/test-document-ready.js index 4963e139f9db..301e6dd0b039 100644 --- a/test/unit/test-document-ready.js +++ b/test/unit/test-document-ready.js @@ -22,7 +22,7 @@ import { whenDocumentReady, } from '../../src/document-ready'; -describes.sandboxed('documentReady', {}, () => { +describes.sandboxed('documentReady', {}, (env) => { let testDoc; let eventListeners; const timer = Services.timerFor(window); @@ -57,7 +57,7 @@ describes.sandboxed('documentReady', {}, () => { it('should call callback immediately when ready', () => { testDoc.readyState = 'complete'; - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); onDocumentReady(testDoc, callback); expect(callback).to.be.calledOnce; expect(callback.getCall(0).args).to.deep.equal([testDoc]); @@ -65,7 +65,7 @@ describes.sandboxed('documentReady', {}, () => { it('should wait to call callback until ready', () => { testDoc.readyState = 'loading'; - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); onDocumentReady(testDoc, callback); expect(callback).to.have.not.been.called; expect(eventListeners['readystatechange']).to.not.equal(undefined); @@ -80,7 +80,7 @@ describes.sandboxed('documentReady', {}, () => { it('should wait to call callback for several loading events', () => { testDoc.readyState = 'loading'; - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); onDocumentReady(testDoc, callback); expect(callback).to.have.not.been.called; expect(eventListeners['readystatechange']).to.not.equal(undefined); @@ -101,9 +101,9 @@ describes.sandboxed('documentReady', {}, () => { describe('whenDocumentReady', () => { it('should call callback immediately when ready', () => { testDoc.readyState = 'complete'; - const spy = window.sandbox.spy(); - const spy2 = window.sandbox.spy(); - const spy3 = window.sandbox.spy(); + const spy = env.sandbox.spy(); + const spy2 = env.sandbox.spy(); + const spy3 = env.sandbox.spy(); whenDocumentReady(testDoc).then(spy).then(spy2); @@ -122,7 +122,7 @@ describes.sandboxed('documentReady', {}, () => { }); it('should not call callback', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); whenDocumentReady(testDoc).then(spy); expect(spy).to.have.not.been.called; return timer.promise().then(() => { @@ -132,7 +132,7 @@ describes.sandboxed('documentReady', {}, () => { it('should wait to call callback until ready', () => { testDoc.readyState = 'loading'; - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); whenDocumentReady(testDoc).then(callback); return timer.promise().then(() => { @@ -155,9 +155,9 @@ describes.sandboxed('documentReady', {}, () => { describe('whenDocumentComplete', () => { it('should call callback immediately when complete', () => { testDoc.readyState = 'complete'; - const spy = window.sandbox.spy(); - const spy2 = window.sandbox.spy(); - const spy3 = window.sandbox.spy(); + const spy = env.sandbox.spy(); + const spy2 = env.sandbox.spy(); + const spy3 = env.sandbox.spy(); whenDocumentComplete(testDoc).then(spy).then(spy2); @@ -176,7 +176,7 @@ describes.sandboxed('documentReady', {}, () => { }); it('should not call callback', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); whenDocumentComplete(testDoc).then(spy); expect(spy).to.have.not.been.called; return timer.promise().then(() => { @@ -186,7 +186,7 @@ describes.sandboxed('documentReady', {}, () => { it('should wait to call callback until ready', () => { testDoc.readyState = 'loading'; - const callback = window.sandbox.spy(); + const callback = env.sandbox.spy(); whenDocumentComplete(testDoc).then(callback); return timer.promise().then(() => { diff --git a/test/unit/test-error-reporting.js b/test/unit/test-error-reporting.js index d0f1d1108854..62ba1e512251 100644 --- a/test/unit/test-error-reporting.js +++ b/test/unit/test-error-reporting.js @@ -97,7 +97,7 @@ describes.fakeWin('installErrorReporting', {}, (env) => { }); }); -describes.sandboxed('reportErrorToServerOrViewer', {}, () => { +describes.sandboxed('reportErrorToServerOrViewer', {}, (env) => { let win; let viewer; let ampdocServiceForStub; @@ -116,7 +116,7 @@ describes.sandboxed('reportErrorToServerOrViewer', {}, () => { const optedInDoc = window.document.implementation.createHTMLDocument(''); optedInDoc.documentElement.setAttribute('report-errors-to-viewer', ''); - ampdocServiceForStub = window.sandbox.stub(Services, 'ampdocServiceFor'); + ampdocServiceForStub = env.sandbox.stub(Services, 'ampdocServiceFor'); const ampdoc = {getRootNode: () => optedInDoc}; ampdocServiceForStub.returns({ isSingleDoc: () => true, @@ -129,11 +129,11 @@ describes.sandboxed('reportErrorToServerOrViewer', {}, () => { isTrustedViewer: () => Promise.resolve(true), sendMessage: () => true, }; - sendMessageStub = window.sandbox.stub(viewer, 'sendMessage'); + sendMessageStub = env.sandbox.stub(viewer, 'sendMessage'); - window.sandbox.stub(Services, 'viewerForDoc').returns(viewer); + env.sandbox.stub(Services, 'viewerForDoc').returns(viewer); - createXhr = window.sandbox.spy(XMLHttpRequest.prototype, 'open'); + createXhr = env.sandbox.spy(XMLHttpRequest.prototype, 'open'); }); it('should report to server if AMP doc is not single', () => { @@ -159,7 +159,7 @@ describes.sandboxed('reportErrorToServerOrViewer', {}, () => { }); it('should report to server if viewer is not capable', () => { - window.sandbox + env.sandbox .stub(viewer, 'hasCapability') .withArgs('errorReporting') .returns(false); @@ -170,9 +170,7 @@ describes.sandboxed('reportErrorToServerOrViewer', {}, () => { }); it('should report to server if viewer is not trusted', () => { - window.sandbox - .stub(viewer, 'isTrustedViewer') - .returns(Promise.resolve(false)); + env.sandbox.stub(viewer, 'isTrustedViewer').returns(Promise.resolve(false)); return reportErrorToServerOrViewer(win, data).then(() => { expect(createXhr).to.be.calledOnce; expect(sendMessageStub).to.not.have.been.called; @@ -200,14 +198,14 @@ describes.sandboxed('reportErrorToServerOrViewer', {}, () => { ); }); -describes.sandboxed('getErrorReportData', {}, () => { +describes.sandboxed('getErrorReportData', {}, (env) => { let onError; let nextRandomNumber; beforeEach(() => { onError = window.onerror; nextRandomNumber = 0; - window.sandbox.stub(Math, 'random').callsFake(() => nextRandomNumber); + env.sandbox.stub(Math, 'random').callsFake(() => nextRandomNumber); self.__AMP_MODE = undefined; }); diff --git a/test/unit/test-event-helper.js b/test/unit/test-event-helper.js index 92769843938e..d0d318abd222 100644 --- a/test/unit/test-event-helper.js +++ b/test/unit/test-event-helper.js @@ -31,7 +31,7 @@ import { supportsPassiveEventListener, } from '../../src/event-helper-listen'; -describes.sandboxed('EventHelper', {}, () => { +describes.sandboxed('EventHelper', {}, (env) => { function getEvent(name, target) { const event = document.createEvent('Event'); event.initEvent(name, true, true); @@ -295,7 +295,7 @@ describes.sandboxed('EventHelper', {}, () => { expect(native.type).to.equal('foo'); expect(native.detail).to.deep.equal({bar: 123}); - const initCustomEventSpy = window.sandbox.spy(); + const initCustomEventSpy = env.sandbox.spy(); const win = {}; win.CustomEvent = {}; win.document = {}; @@ -318,11 +318,11 @@ describes.sandboxed('EventHelper', {}, () => { } }; // Simulate an addEventListener that accepts options - addEventListenerStub = window.sandbox + addEventListenerStub = env.sandbox .stub(self, 'addEventListener') .callsFake(eventListenerStubAcceptOpts); // Simulate a removeEventListener that accepts options - removeEventListenerStub = window.sandbox + removeEventListenerStub = env.sandbox .stub(self, 'removeEventListener') .callsFake(eventListenerStubAcceptOpts); resetEvtListenerOptsSupportForTesting(); @@ -350,11 +350,11 @@ describes.sandboxed('EventHelper', {}, () => { } }; // Simulate an addEventListener that does not accept options - addEventListenerStub = window.sandbox + addEventListenerStub = env.sandbox .stub(self, 'addEventListener') .callsFake(eventListenerStubRejectOpts); // Simulate a removeEventListener that does not accept options - removeEventListenerStub = window.sandbox + removeEventListenerStub = env.sandbox .stub(self, 'removeEventListener') .callsFake(eventListenerStubRejectOpts); resetEvtListenerOptsSupportForTesting(); diff --git a/test/unit/test-experiments.js b/test/unit/test-experiments.js index d37aabd43361..19ed4393f6ef 100644 --- a/test/unit/test-experiments.js +++ b/test/unit/test-experiments.js @@ -106,7 +106,7 @@ describes.sandboxed('experimentToggles', {}, () => { }); }); -describes.sandboxed('isExperimentOn', {}, () => { +describes.sandboxed('isExperimentOn', {}, (env) => { let win; beforeEach(() => { @@ -187,7 +187,7 @@ describes.sandboxed('isExperimentOn', {}, () => { win.AMP_CONFIG['e2'] = 0; expectExperiment('', 'e2').to.be.false; - window.sandbox.stub(Math, 'random').returns(0.5); + env.sandbox.stub(Math, 'random').returns(0.5); win.AMP_CONFIG['e3'] = 0.3; expectExperiment('', 'e3').to.be.false; @@ -202,7 +202,7 @@ describes.sandboxed('isExperimentOn', {}, () => { }); it('should cache calc value', () => { - window.sandbox.stub(Math, 'random').returns(0.4); + env.sandbox.stub(Math, 'random').returns(0.4); win.AMP_CONFIG['e1'] = 0.5; win.AMP_CONFIG['e2'] = 0.1; @@ -212,11 +212,11 @@ describes.sandboxed('isExperimentOn', {}, () => { }); }); -describes.sandboxed('toggleExperiment', {}, () => { +describes.sandboxed('toggleExperiment', {}, (env) => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); clock.tick(1); }); @@ -566,7 +566,7 @@ describes.sandboxed('getBinaryType', {}, () => { }); }); -describes.sandboxed('experiment branch tests', {}, () => { +describes.sandboxed('experiment branch tests', {}, (env) => { describe('#randomlySelectUnsetExperiments', () => { let accurateRandomStub; let cachedAccuratePrng; @@ -581,7 +581,7 @@ describes.sandboxed('experiment branch tests', {}, () => { branches: ['branch1_id', 'branch2_id'], }, ]; - window.sandbox.win = { + env.sandbox.win = { location: { hostname: 'test.server.name.com', }, @@ -593,7 +593,7 @@ describes.sandboxed('experiment branch tests', {}, () => { querySelector: () => {}, }, }; - accurateRandomStub = window.sandbox.stub().returns(-1); + accurateRandomStub = env.sandbox.stub().returns(-1); cachedAccuratePrng = RANDOM_NUMBER_GENERATORS.accuratePrng; RANDOM_NUMBER_GENERATORS.accuratePrng = accurateRandomStub; }); @@ -604,62 +604,62 @@ describes.sandboxed('experiment branch tests', {}, () => { it('handles empty experiments list', () => { // Opt out of experiment. - toggleExperiment(window.sandbox.win, 'testExperimentId', false, true); - randomlySelectUnsetExperiments(window.sandbox.win, {}); + toggleExperiment(env.sandbox.win, 'testExperimentId', false, true); + randomlySelectUnsetExperiments(env.sandbox.win, {}); expect( - isExperimentOn(window.sandbox.win, 'testExperimentId'), + isExperimentOn(env.sandbox.win, 'testExperimentId'), 'experiment is on' ).to.be.false; - expect(window.sandbox.win.__AMP_EXPERIMENT_BRANCHES).to.be.empty; + expect(env.sandbox.win.__AMP_EXPERIMENT_BRANCHES).to.be.empty; }); it('handles experiment not diverted path', () => { // Opt out of experiment. - toggleExperiment(window.sandbox.win, 'testExperimentId', false, true); - randomlySelectUnsetExperiments(window.sandbox.win, testExperimentList); + toggleExperiment(env.sandbox.win, 'testExperimentId', false, true); + randomlySelectUnsetExperiments(env.sandbox.win, testExperimentList); expect( - isExperimentOn(window.sandbox.win, 'testExperimentId'), + isExperimentOn(env.sandbox.win, 'testExperimentId'), 'experiment is on' ).to.be.false; - expect(getExperimentBranch(window.sandbox.win, 'testExperimentId')).to.not - .be.ok; + expect(getExperimentBranch(env.sandbox.win, 'testExperimentId')).to.not.be + .ok; }); it('handles experiment diverted path 1', () => { // Force experiment on. - toggleExperiment(window.sandbox.win, 'testExperimentId', true, true); + toggleExperiment(env.sandbox.win, 'testExperimentId', true, true); // force the control branch to be chosen by making the accurate PRNG // return a value < 0.5. RANDOM_NUMBER_GENERATORS.accuratePrng.onFirstCall().returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, testExperimentList); + randomlySelectUnsetExperiments(env.sandbox.win, testExperimentList); expect( - isExperimentOn(window.sandbox.win, 'testExperimentId'), + isExperimentOn(env.sandbox.win, 'testExperimentId'), 'experiment is on' ).to.be.true; - expect( - getExperimentBranch(window.sandbox.win, 'testExperimentId') - ).to.equal('branch1_id'); + expect(getExperimentBranch(env.sandbox.win, 'testExperimentId')).to.equal( + 'branch1_id' + ); }); it('handles experiment diverted path 2', () => { // Force experiment on. - toggleExperiment(window.sandbox.win, 'testExperimentId', true, true); + toggleExperiment(env.sandbox.win, 'testExperimentId', true, true); // Force the experiment branch to be chosen by making the accurate PRNG // return a value > 0.5. RANDOM_NUMBER_GENERATORS.accuratePrng.onFirstCall().returns(0.6); - randomlySelectUnsetExperiments(window.sandbox.win, testExperimentList); + randomlySelectUnsetExperiments(env.sandbox.win, testExperimentList); expect( - isExperimentOn(window.sandbox.win, 'testExperimentId'), + isExperimentOn(env.sandbox.win, 'testExperimentId'), 'experiment is on' ).to.be.true; - expect( - getExperimentBranch(window.sandbox.win, 'testExperimentId') - ).to.equal('branch2_id'); + expect(getExperimentBranch(env.sandbox.win, 'testExperimentId')).to.equal( + 'branch2_id' + ); }); it('picks a branch if traffic eligible', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - window.sandbox.win.trafficEligible = true; + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + env.sandbox.win.trafficEligible = true; const experimentInfo = [ { experimentId: 'expt_0', @@ -670,14 +670,14 @@ describes.sandboxed('experiment branch tests', {}, () => { }, ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0')).to.be.true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.equal('0_0'); + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0')).to.be.true; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.equal('0_0'); }); it("doesn't pick a branch if traffic ineligible", () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - window.sandbox.win.trafficEligible = false; + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + env.sandbox.win.trafficEligible = false; const experimentInfo = [ { experimentId: 'expt_0', @@ -688,13 +688,13 @@ describes.sandboxed('experiment branch tests', {}, () => { }, ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0')).to.be.true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.be.null; + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0')).to.be.true; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.be.null; }); it("doesn't pick a branch if no traffic eligibility function", () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); + toggleExperiment(env.sandbox.win, 'expt_0', true, true); const experimentInfo = [ { experimentId: 'expt_0', @@ -703,17 +703,17 @@ describes.sandboxed('experiment branch tests', {}, () => { }, ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0')).to.be.true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.be.null; + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0')).to.be.true; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.be.null; }); it( "doesn't pick a branch if traffic becomes eligible after first " + 'diversion', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - window.sandbox.win.trafficEligible = false; + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + env.sandbox.win.trafficEligible = false; const experimentInfo = [ { experimentId: 'expt_0', @@ -725,23 +725,23 @@ describes.sandboxed('experiment branch tests', {}, () => { ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0')).to.be.true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.be.null; + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0')).to.be.true; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.be.null; - window.sandbox.win.trafficEligible = true; + env.sandbox.win.trafficEligible = true; - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0')).to.be.true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.be.null; + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0')).to.be.true; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.be.null; } ); it('handles multiple experiments', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - toggleExperiment(window.sandbox.win, 'expt_1', false, true); - toggleExperiment(window.sandbox.win, 'expt_2', true, true); - toggleExperiment(window.sandbox.win, 'expt_3', true, true); + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + toggleExperiment(env.sandbox.win, 'expt_1', false, true); + toggleExperiment(env.sandbox.win, 'expt_2', true, true); + toggleExperiment(env.sandbox.win, 'expt_3', true, true); const experimentInfo = [ { @@ -762,24 +762,24 @@ describes.sandboxed('experiment branch tests', {}, () => { // expt_3 omitted. ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.6); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0'), 'expt_0 is on').to.be + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0'), 'expt_0 is on').to.be .true; - expect(isExperimentOn(window.sandbox.win, 'expt_1'), 'expt_1 is on').to.be + expect(isExperimentOn(env.sandbox.win, 'expt_1'), 'expt_1 is on').to.be .false; - expect(isExperimentOn(window.sandbox.win, 'expt_2'), 'expt_2 is on').to.be + expect(isExperimentOn(env.sandbox.win, 'expt_2'), 'expt_2 is on').to.be .true; // Note: calling isExperimentOn('expt_3') would actually evaluate the // frequency for expt_3, possibly enabling it. Since we wanted it to be // omitted altogether, we'll evaluate it only via its branch. - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.equal('0_e'); - expect(getExperimentBranch(window.sandbox.win, 'expt_1')).to.not.be.ok; - expect(getExperimentBranch(window.sandbox.win, 'expt_2')).to.equal('2_e'); - expect(getExperimentBranch(window.sandbox.win, 'expt_3')).to.not.be.ok; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.equal('0_e'); + expect(getExperimentBranch(env.sandbox.win, 'expt_1')).to.not.be.ok; + expect(getExperimentBranch(env.sandbox.win, 'expt_2')).to.equal('2_e'); + expect(getExperimentBranch(env.sandbox.win, 'expt_3')).to.not.be.ok; }); it('handles multi-way branches', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); + toggleExperiment(env.sandbox.win, 'expt_0', true, true); const experimentInfo = [ { experimentId: 'expt_0', @@ -788,17 +788,17 @@ describes.sandboxed('experiment branch tests', {}, () => { }, ]; RANDOM_NUMBER_GENERATORS.accuratePrng.returns(0.7); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0'), 'expt_0 is on').to.be + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0'), 'expt_0 is on').to.be .true; - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.equal('0_3'); + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.equal('0_3'); }); it('handles multiple experiments with multi-way branches', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - toggleExperiment(window.sandbox.win, 'expt_1', false, true); - toggleExperiment(window.sandbox.win, 'expt_2', true, true); - toggleExperiment(window.sandbox.win, 'expt_3', true, true); + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + toggleExperiment(env.sandbox.win, 'expt_1', false, true); + toggleExperiment(env.sandbox.win, 'expt_2', true, true); + toggleExperiment(env.sandbox.win, 'expt_3', true, true); const experimentInfo = [ { @@ -819,20 +819,20 @@ describes.sandboxed('experiment branch tests', {}, () => { ]; RANDOM_NUMBER_GENERATORS.accuratePrng.onFirstCall().returns(0.7); RANDOM_NUMBER_GENERATORS.accuratePrng.onSecondCall().returns(0.3); - randomlySelectUnsetExperiments(window.sandbox.win, experimentInfo); - expect(isExperimentOn(window.sandbox.win, 'expt_0'), 'expt_0 is on').to.be + randomlySelectUnsetExperiments(env.sandbox.win, experimentInfo); + expect(isExperimentOn(env.sandbox.win, 'expt_0'), 'expt_0 is on').to.be .true; - expect(isExperimentOn(window.sandbox.win, 'expt_1'), 'expt_1 is on').to.be + expect(isExperimentOn(env.sandbox.win, 'expt_1'), 'expt_1 is on').to.be .false; - expect(isExperimentOn(window.sandbox.win, 'expt_2'), 'expt_2 is on').to.be + expect(isExperimentOn(env.sandbox.win, 'expt_2'), 'expt_2 is on').to.be .true; // Note: calling isExperimentOn('expt_3') would actually evaluate the // frequency for expt_3, possibly enabling it. Since we wanted it to be // omitted altogether, we'll evaluate it only via its branch. - expect(getExperimentBranch(window.sandbox.win, 'expt_0')).to.equal('0_3'); - expect(getExperimentBranch(window.sandbox.win, 'expt_1')).to.not.be.ok; - expect(getExperimentBranch(window.sandbox.win, 'expt_2')).to.equal('2_1'); - expect(getExperimentBranch(window.sandbox.win, 'expt_3')).to.not.be.ok; + expect(getExperimentBranch(env.sandbox.win, 'expt_0')).to.equal('0_3'); + expect(getExperimentBranch(env.sandbox.win, 'expt_1')).to.not.be.ok; + expect(getExperimentBranch(env.sandbox.win, 'expt_2')).to.equal('2_1'); + expect(getExperimentBranch(env.sandbox.win, 'expt_3')).to.not.be.ok; }); it('should not process the same experiment twice', () => { @@ -850,42 +850,42 @@ describes.sandboxed('experiment branch tests', {}, () => { branches: ['246810', '108642'], }, ]; - toggleExperiment(window.sandbox.win, 'fooExpt', false, true); - randomlySelectUnsetExperiments(window.sandbox.win, exptAInfo); - randomlySelectUnsetExperiments(window.sandbox.win, exptBInfo); + toggleExperiment(env.sandbox.win, 'fooExpt', false, true); + randomlySelectUnsetExperiments(env.sandbox.win, exptAInfo); + randomlySelectUnsetExperiments(env.sandbox.win, exptBInfo); // Even though we tried to set up a second time, using a config // parameter that should ensure that the experiment was activated, the // experiment framework should evaluate each experiment only once per // page and should not enable it. - expect(isExperimentOn(window.sandbox.win, 'fooExpt')).to.be.false; - expect(getExperimentBranch(window.sandbox.win, 'fooExpt')).to.not.be.ok; + expect(isExperimentOn(env.sandbox.win, 'fooExpt')).to.be.false; + expect(getExperimentBranch(env.sandbox.win, 'fooExpt')).to.not.be.ok; }); it('returns empty experiments map', () => { // Opt out of experiment. - toggleExperiment(window.sandbox.win, 'testExperimentId', false, true); - const exps = randomlySelectUnsetExperiments(window.sandbox.win, {}); + toggleExperiment(env.sandbox.win, 'testExperimentId', false, true); + const exps = randomlySelectUnsetExperiments(env.sandbox.win, {}); expect(exps).to.be.empty; }); it('returns map with experiment diverted path 1', () => { // Force experiment on. - toggleExperiment(window.sandbox.win, 'testExperimentId', true, true); + toggleExperiment(env.sandbox.win, 'testExperimentId', true, true); // force the control branch to be chosen by making the accurate PRNG // return a value < 0.5. RANDOM_NUMBER_GENERATORS.accuratePrng.onFirstCall().returns(0.3); const exps = randomlySelectUnsetExperiments( - window.sandbox.win, + env.sandbox.win, testExperimentList ); expect(exps).to.deep.equal({'testExperimentId': 'branch1_id'}); }); it('returns map with multiple experiments with multi-way branches', () => { - toggleExperiment(window.sandbox.win, 'expt_0', true, true); - toggleExperiment(window.sandbox.win, 'expt_1', false, true); - toggleExperiment(window.sandbox.win, 'expt_2', true, true); - toggleExperiment(window.sandbox.win, 'expt_3', true, true); + toggleExperiment(env.sandbox.win, 'expt_0', true, true); + toggleExperiment(env.sandbox.win, 'expt_1', false, true); + toggleExperiment(env.sandbox.win, 'expt_2', true, true); + toggleExperiment(env.sandbox.win, 'expt_3', true, true); const experimentInfo = [ { @@ -907,7 +907,7 @@ describes.sandboxed('experiment branch tests', {}, () => { RANDOM_NUMBER_GENERATORS.accuratePrng.onFirstCall().returns(0.7); RANDOM_NUMBER_GENERATORS.accuratePrng.onSecondCall().returns(0.3); const exps = randomlySelectUnsetExperiments( - window.sandbox.win, + env.sandbox.win, experimentInfo ); diff --git a/test/unit/test-exponential-backoff.js b/test/unit/test-exponential-backoff.js index bfa655476644..2824850cdc0b 100644 --- a/test/unit/test-exponential-backoff.js +++ b/test/unit/test-exponential-backoff.js @@ -19,12 +19,12 @@ import { exponentialBackoffClock, } from '../../src/exponential-backoff'; -describes.sandboxed('exponentialBackoff', {}, () => { +describes.sandboxed('exponentialBackoff', {}, (env) => { let clock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); - window.sandbox.stub(Math, 'random').callsFake(() => 1); + clock = env.sandbox.useFakeTimers(); + env.sandbox.stub(Math, 'random').callsFake(() => 1); }); it('should backoff exponentially', () => { diff --git a/test/unit/test-finite-state-machine.js b/test/unit/test-finite-state-machine.js index d2543d22857b..5b640292e1d1 100644 --- a/test/unit/test-finite-state-machine.js +++ b/test/unit/test-finite-state-machine.js @@ -16,7 +16,7 @@ import {FiniteStateMachine} from '../../src/finite-state-machine'; -describes.sandboxed('Finite State Machine', {}, () => { +describes.sandboxed('Finite State Machine', {}, (env) => { describe('simple machines', () => { let fsm; let spy; @@ -24,8 +24,8 @@ describes.sandboxed('Finite State Machine', {}, () => { beforeEach(() => { fsm = new FiniteStateMachine('init'); - spy = window.sandbox.spy(); - other = window.sandbox.spy(); + spy = env.sandbox.spy(); + other = env.sandbox.spy(); fsm.addTransition('init', 'start', spy); fsm.addTransition('init', 'other', other); diff --git a/test/unit/test-fixed-layer.js b/test/unit/test-fixed-layer.js index 043868f46823..44579ec96571 100644 --- a/test/unit/test-fixed-layer.js +++ b/test/unit/test-fixed-layer.js @@ -27,7 +27,7 @@ import {installViewerServiceForDoc} from '../../src/service/viewer-impl'; import {toggle} from '../../src/style'; import {user} from '../../src/log'; -describes.sandboxed('FixedLayer', {}, () => { +describes.sandboxed('FixedLayer', {}, (env) => { let parentApi; let documentApi; let ampdoc; @@ -552,7 +552,7 @@ describes.sandboxed('FixedLayer', {}, () => { }); it('should add and remove element directly', () => { - const updateStub = window.sandbox.stub(fixedLayer, 'update'); + const updateStub = env.sandbox.stub(fixedLayer, 'update'); expect(fixedLayer.elements_).to.have.length(5); // Add. @@ -898,7 +898,7 @@ describes.sandboxed('FixedLayer', {}, () => { expect(state['F0'].top).to.equal('0px'); // Update to transient padding. - window.sandbox.stub(fixedLayer, 'update').callsFake(() => {}); + env.sandbox.stub(fixedLayer, 'update').callsFake(() => {}); fixedLayer.updatePaddingTop(22, /* transient */ true); vsyncTasks[0].measure(state); expect(state['F0'].fixed).to.be.true; @@ -1168,7 +1168,7 @@ describes.sandboxed('FixedLayer', {}, () => { element1.setAttribute('style', 'bottom: 10px'); element1.style.bottom = '10px'; - const userError = window.sandbox.stub(user(), 'error'); + const userError = env.sandbox.stub(user(), 'error'); fixedLayer.setup(); // Expect error regarding inline styles. expect(userError).calledWithMatch( @@ -1200,7 +1200,7 @@ describes.sandboxed('FixedLayer', {}, () => { element1.computedStyle['display'] = ''; - window.sandbox.stub(timer, 'delay').callsFake((callback) => { + env.sandbox.stub(timer, 'delay').callsFake((callback) => { callback(); }); return mutationObserver @@ -1220,7 +1220,7 @@ describes.sandboxed('FixedLayer', {}, () => { }); it('should ignore descendants of already-tracked elements', () => { - const updateStub = window.sandbox.stub(fixedLayer, 'update'); + const updateStub = env.sandbox.stub(fixedLayer, 'update'); expect(fixedLayer.elements_).to.have.length(5); element1.appendChild(element6); @@ -1232,7 +1232,7 @@ describes.sandboxed('FixedLayer', {}, () => { }); it('should replace descendants of tracked elements', () => { - const updateStub = window.sandbox.stub(fixedLayer, 'update'); + const updateStub = env.sandbox.stub(fixedLayer, 'update'); expect(fixedLayer.elements_).to.have.length(5); element6.appendChild(element1); @@ -1574,7 +1574,7 @@ describes.sandboxed('FixedLayer', {}, () => { element1.setAttribute('style', 'bottom: 10px'); element1.style.bottom = '10px'; - const userError = window.sandbox.stub(user(), 'error'); + const userError = env.sandbox.stub(user(), 'error'); fixedLayer.setup(); // Expect error regarding inline styles. expect(userError).calledWithMatch( @@ -1606,7 +1606,7 @@ describes.sandboxed('FixedLayer', {}, () => { element1.computedStyle['display'] = ''; - window.sandbox.stub(timer, 'delay').callsFake((callback) => { + env.sandbox.stub(timer, 'delay').callsFake((callback) => { callback(); }); return mutationObserver @@ -1837,7 +1837,7 @@ describes.sandboxed( describes.sandboxed( 'FixedLayer bug due to calling browser native instead of AMP implementation', {}, - () => { + (env) => { let win; let ampdoc; let viewer; @@ -1865,7 +1865,7 @@ describes.sandboxed( }); it('should call Animation.animate in animateFixedElements', () => { - const animateSpy = window.sandbox.spy(Animation, 'animate'); + const animateSpy = env.sandbox.spy(Animation, 'animate'); ampdoc = new AmpDocSingle(win); installPlatformService(win); diff --git a/test/unit/test-focus-history.js b/test/unit/test-focus-history.js index d17b25c7fffd..b16c9cc7c52e 100644 --- a/test/unit/test-focus-history.js +++ b/test/unit/test-focus-history.js @@ -17,7 +17,7 @@ import {FocusHistory} from '../../src/focus-history'; import {installTimerService} from '../../src/service/timer-impl'; -describes.sandboxed('FocusHistory', {}, () => { +describes.sandboxed('FocusHistory', {}, (env) => { let clock; let testDoc; let eventListeners; @@ -26,7 +26,7 @@ describes.sandboxed('FocusHistory', {}, () => { let focusHistory; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); eventListeners = {}; testDoc = { diff --git a/test/unit/test-gesture-recognizers.js b/test/unit/test-gesture-recognizers.js index 768718c2cc38..3f6c5ac0b014 100644 --- a/test/unit/test-gesture-recognizers.js +++ b/test/unit/test-gesture-recognizers.js @@ -23,7 +23,7 @@ import { } from '../../src/gesture-recognizers'; import {Gestures} from '../../src/gesture'; -describes.sandboxed('TapRecognizer', {}, () => { +describes.sandboxed('TapRecognizer', {}, (env) => { let element; let recognizer; let gestures; @@ -38,7 +38,7 @@ describes.sandboxed('TapRecognizer', {}, () => { }; gestures = new Gestures(element); - gesturesMock = window.sandbox.mock(gestures); + gesturesMock = env.sandbox.mock(gestures); recognizer = new TapRecognizer(gestures); }); @@ -105,7 +105,7 @@ describes.sandboxed('TapRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.clientX == 101 && data.clientY == 201 && data.target === target ); @@ -118,7 +118,7 @@ describes.sandboxed('TapRecognizer', {}, () => { }); }); -describes.sandboxed('DoubletapRecognizer', {}, () => { +describes.sandboxed('DoubletapRecognizer', {}, (env) => { let element; let recognizer; let gestures; @@ -133,7 +133,7 @@ describes.sandboxed('DoubletapRecognizer', {}, () => { }; gestures = new Gestures(element); - gesturesMock = window.sandbox.mock(gestures); + gesturesMock = env.sandbox.mock(gestures); recognizer = new DoubletapRecognizer(gestures); }); @@ -212,7 +212,7 @@ describes.sandboxed('DoubletapRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return data.clientX == 101 && data.clientY == 201; }), null @@ -224,7 +224,7 @@ describes.sandboxed('DoubletapRecognizer', {}, () => { }); }); -describes.sandboxed('SwipeXYRecognizer', {}, () => { +describes.sandboxed('SwipeXYRecognizer', {}, (env) => { let element; let clock; let recognizer; @@ -232,7 +232,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { let gesturesMock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); element = { addEventListener: (unusedEventType, unusedHandler) => {}, @@ -242,7 +242,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { }; gestures = new Gestures(element); - gesturesMock = window.sandbox.mock(gestures); + gesturesMock = env.sandbox.mock(gestures); recognizer = new SwipeXYRecognizer(gestures); }); @@ -312,7 +312,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === true && data.last === false && @@ -350,7 +350,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === false && @@ -386,7 +386,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === true && @@ -420,7 +420,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === true && @@ -483,7 +483,7 @@ describes.sandboxed('SwipeXYRecognizer', {}, () => { }); }); -describes.sandboxed('TapzoomRecognizer', {}, () => { +describes.sandboxed('TapzoomRecognizer', {}, (env) => { let element; let clock; let recognizer; @@ -491,7 +491,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { let gesturesMock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); element = { addEventListener: (unusedEventType, unusedHandler) => {}, @@ -501,7 +501,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { }; gestures = new Gestures(element); - gesturesMock = window.sandbox.mock(gestures); + gesturesMock = env.sandbox.mock(gestures); recognizer = new TapzoomRecognizer(gestures); }); @@ -604,7 +604,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === true && data.last === false && @@ -637,7 +637,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === false && @@ -673,7 +673,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === true && @@ -697,7 +697,7 @@ describes.sandboxed('TapzoomRecognizer', {}, () => { }); }); -describes.sandboxed('PinchRecognizer', {}, () => { +describes.sandboxed('PinchRecognizer', {}, (env) => { let element; let clock; let recognizer; @@ -705,7 +705,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { let gesturesMock; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); element = { addEventListener: (unusedEventType, unusedHandler) => {}, @@ -715,7 +715,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { }; gestures = new Gestures(element); - gesturesMock = window.sandbox.mock(gestures); + gesturesMock = env.sandbox.mock(gestures); recognizer = new PinchRecognizer(gestures); }); @@ -848,7 +848,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === true && data.last === false && @@ -903,7 +903,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((unusedData) => true), + env.sandbox.match((unusedData) => true), null ) .once(); @@ -920,7 +920,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === false && @@ -961,7 +961,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((unusedData) => true), + env.sandbox.match((unusedData) => true), null ) .once(); @@ -973,7 +973,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === true && @@ -1012,7 +1012,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((unusedData) => true), + env.sandbox.match((unusedData) => true), null ) .once(); @@ -1024,7 +1024,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.first === false && data.last === true && @@ -1068,7 +1068,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.centerClientX == 100 && data.centerClientY == 100 && @@ -1089,7 +1089,7 @@ describes.sandboxed('PinchRecognizer', {}, () => { .expects('signalEmit_') .withExactArgs( recognizer, - window.sandbox.match((data) => { + env.sandbox.match((data) => { return ( data.centerClientX == 100 && data.centerClientY == 100 && diff --git a/test/unit/test-gesture.js b/test/unit/test-gesture.js index 428b84df7c02..f3bfd86c33a3 100644 --- a/test/unit/test-gesture.js +++ b/test/unit/test-gesture.js @@ -16,7 +16,7 @@ import {GestureRecognizer, Gestures} from '../../src/gesture'; -describes.sandboxed('Gestures', {}, () => { +describes.sandboxed('Gestures', {}, (env) => { class TestRecognizer extends GestureRecognizer { constructor(manager) { super('test', manager); @@ -38,7 +38,7 @@ describes.sandboxed('Gestures', {}, () => { let onGesture; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); eventListeners = {}; element = { @@ -53,13 +53,13 @@ describes.sandboxed('Gestures', {}, () => { }, }; - onGesture = window.sandbox.spy(); + onGesture = env.sandbox.spy(); gestures = Gestures.get(element); gestures.onGesture(TestRecognizer, onGesture); expect(gestures.recognizers_.length).to.equal(1); recognizer = gestures.recognizers_[0]; - recognizerMock = window.sandbox.mock(recognizer); + recognizerMock = env.sandbox.mock(recognizer); }); afterEach(() => { @@ -73,7 +73,7 @@ describes.sandboxed('Gestures', {}, () => { } it('onPointerDown should be called', () => { - const handler = window.sandbox.spy(); + const handler = env.sandbox.spy(); gestures.onPointerDown(handler); sendEvent({type: 'touchstart'}); expect(handler).to.be.calledOnce; @@ -257,7 +257,7 @@ describes.sandboxed('Gestures', {}, () => { it('should allow youngest to start', () => { gestures.onGesture(Test2Recognizer, () => {}); - const recognizer2Mock = window.sandbox.mock(gestures.recognizers_[1]); + const recognizer2Mock = env.sandbox.mock(gestures.recognizers_[1]); gestures.ready_[0] = 10; gestures.ready_[1] = 9; @@ -272,8 +272,8 @@ describes.sandboxed('Gestures', {}, () => { it('should allow event to propagate when nothing happening', () => { const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -284,8 +284,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.eventing_ = recognizer; const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.be.calledOnce; @@ -300,8 +300,8 @@ describes.sandboxed('Gestures', {}, () => { const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.be.calledOnce; @@ -313,8 +313,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.ready_[0] = 1; const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.be.calledOnce; @@ -325,8 +325,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.pending_[0] = 1; let event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.be.calledOnce; @@ -335,8 +335,8 @@ describes.sandboxed('Gestures', {}, () => { clock.tick(10); event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -356,7 +356,7 @@ describes.sandboxed('Gestures', {}, () => { it('should remove listeners and shared cache instance on cleanup', () => { const eventNames = ['touchstart', 'touchend', 'touchmove', 'touchcancel']; const prop = '__AMP_Gestures'; - const removeSpy = window.sandbox.spy(element, 'removeEventListener'); + const removeSpy = env.sandbox.spy(element, 'removeEventListener'); expect(element[prop]).to.exist; @@ -378,7 +378,7 @@ describes.sandboxed('Gestures', {}, () => { let onGesture; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); eventListeners = {}; element = { @@ -390,13 +390,13 @@ describes.sandboxed('Gestures', {}, () => { }, }; - onGesture = window.sandbox.spy(); + onGesture = env.sandbox.spy(); gestures = Gestures.get(element, /* shouldNotPreventDefault */ true); gestures.onGesture(TestRecognizer, onGesture); expect(gestures.recognizers_.length).to.equal(1); recognizer = gestures.recognizers_[0]; - recognizerMock = window.sandbox.mock(recognizer); + recognizerMock = env.sandbox.mock(recognizer); }); afterEach(() => { @@ -407,8 +407,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.eventing_ = recognizer; const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -423,8 +423,8 @@ describes.sandboxed('Gestures', {}, () => { const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -436,8 +436,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.ready_[0] = 1; const event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -448,8 +448,8 @@ describes.sandboxed('Gestures', {}, () => { gestures.pending_[0] = 1; let event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -458,8 +458,8 @@ describes.sandboxed('Gestures', {}, () => { clock.tick(10); event = { type: 'touchend', - preventDefault: window.sandbox.spy(), - stopPropagation: window.sandbox.spy(), + preventDefault: env.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.preventDefault).to.have.not.been.called; @@ -486,7 +486,7 @@ describes.sandboxed('Gestures', {}, () => { }, }; - onGesture = window.sandbox.spy(); + onGesture = env.sandbox.spy(); gestures = Gestures.get( element, @@ -496,7 +496,7 @@ describes.sandboxed('Gestures', {}, () => { gestures.onGesture(TestRecognizer, onGesture); expect(gestures.recognizers_.length).to.equal(1); recognizer = gestures.recognizers_[0]; - recognizerMock = window.sandbox.mock(recognizer); + recognizerMock = env.sandbox.mock(recognizer); }); afterEach(() => { @@ -506,7 +506,7 @@ describes.sandboxed('Gestures', {}, () => { it('should stop event from propagating', () => { const event = { type: 'touchend', - stopPropagation: window.sandbox.spy(), + stopPropagation: env.sandbox.spy(), }; eventListeners[event.type](event); expect(event.stopPropagation).to.have.be.calledOnce; diff --git a/test/unit/test-ie-media-bug.js b/test/unit/test-ie-media-bug.js index bba1f4bfbfe8..71ef6290f2f6 100644 --- a/test/unit/test-ie-media-bug.js +++ b/test/unit/test-ie-media-bug.js @@ -17,7 +17,7 @@ import {dev} from '../../src/log'; import {ieMediaCheckAndFix} from '../../src/service/ie-media-bug'; -describes.sandboxed('ie-media-bug', {}, () => { +describes.sandboxed('ie-media-bug', {}, (env) => { let clock; let windowApi, windowMock; let platform; @@ -25,12 +25,12 @@ describes.sandboxed('ie-media-bug', {}, () => { let devErrorStub; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); platform = { isIe: () => false, }; - platformMock = window.sandbox.mock(platform); - devErrorStub = window.sandbox.stub(dev(), 'error'); + platformMock = env.sandbox.mock(platform); + devErrorStub = env.sandbox.stub(dev(), 'error'); windowApi = { innerWidth: 320, @@ -38,7 +38,7 @@ describes.sandboxed('ie-media-bug', {}, () => { clearInterval: () => {}, matchMedia: () => {}, }; - windowMock = window.sandbox.mock(windowApi); + windowMock = env.sandbox.mock(windowApi); }); afterEach(() => { @@ -82,7 +82,7 @@ describes.sandboxed('ie-media-bug', {}, () => { windowMock .expects('setInterval') .withExactArgs( - window.sandbox.match((arg) => { + env.sandbox.match((arg) => { intervalCallback = arg; return true; }), @@ -100,7 +100,7 @@ describes.sandboxed('ie-media-bug', {}, () => { // Second pass. clock.tick(10); - windowMock = window.sandbox.mock(windowApi); + windowMock = env.sandbox.mock(windowApi); windowMock .expects('matchMedia') .withExactArgs('(min-width: 319px) AND (max-width: 321px)') @@ -114,7 +114,7 @@ describes.sandboxed('ie-media-bug', {}, () => { // Third pass - succeed. clock.tick(10); - windowMock = window.sandbox.mock(windowApi); + windowMock = env.sandbox.mock(windowApi); windowMock .expects('matchMedia') .withExactArgs('(min-width: 319px) AND (max-width: 321px)') @@ -144,7 +144,7 @@ describes.sandboxed('ie-media-bug', {}, () => { windowMock .expects('setInterval') .withExactArgs( - window.sandbox.match((arg) => { + env.sandbox.match((arg) => { intervalCallback = arg; return true; }), diff --git a/test/unit/test-iframe-helper.js b/test/unit/test-iframe-helper.js index 1ad939cb8419..ccb5016de43a 100644 --- a/test/unit/test-iframe-helper.js +++ b/test/unit/test-iframe-helper.js @@ -20,7 +20,7 @@ import {generateSentinel} from '../../src/3p-frame'; describes.sandboxed .configure() .skipFirefox() - .run('iframe-helper', {}, function () { + .run('iframe-helper', {}, function (env) { const iframeSrc = 'http://iframe.localhost:' + location.port + @@ -209,7 +209,7 @@ describes.sandboxed // TODO(wg-components, #32103): This fails regularly during CI it.skip('should set sentinel on postMessage data', () => { insert(testIframe); - const postMessageSpy = window.sandbox /*OK*/ + const postMessageSpy = env.sandbox /*OK*/ .spy(testIframe.contentWindow, 'postMessage'); IframeHelper.postMessage( testIframe, diff --git a/test/unit/test-input.js b/test/unit/test-input.js index 7e1bcaa1b73d..3e2187a83a65 100644 --- a/test/unit/test-input.js +++ b/test/unit/test-input.js @@ -18,7 +18,7 @@ import {Input} from '../../src/input'; import {installTimerService} from '../../src/service/timer-impl.js'; import {stubService} from '../../testing/test-helper'; -describes.sandboxed('Input', {}, () => { +describes.sandboxed('Input', {}, (env) => { let clock; let input; let eventListeners; @@ -26,7 +26,7 @@ describes.sandboxed('Input', {}, () => { let documentApi; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); eventListeners = {}; diff --git a/test/unit/test-log.js b/test/unit/test-log.js index 9996f06e3b14..5b4942bd4d6e 100644 --- a/test/unit/test-log.js +++ b/test/unit/test-log.js @@ -27,7 +27,7 @@ import { userAssert, } from '../../src/log'; -describes.sandboxed('Logging', {}, () => { +describes.sandboxed('Logging', {}, (env) => { const RETURNS_FINE = () => LogLevel.FINE; const RETURNS_INFO = () => LogLevel.INFO; const RETURNS_WARN = () => LogLevel.WARN; @@ -43,8 +43,8 @@ describes.sandboxed('Logging', {}, () => { mode = {}; window.__AMP_MODE = mode; - logSpy = window.sandbox.spy(); - timeoutSpy = window.sandbox.spy(); + logSpy = env.sandbox.spy(); + timeoutSpy = env.sandbox.spy(); win = { console: { log: logSpy, @@ -53,7 +53,7 @@ describes.sandboxed('Logging', {}, () => { setTimeout: timeoutSpy, __AMP_REPORT_ERROR: (error) => error, }; - window.sandbox.stub(self, '__AMP_REPORT_ERROR').callsFake((error) => error); + env.sandbox.stub(self, '__AMP_REPORT_ERROR').callsFake((error) => error); }); afterEach(() => { diff --git a/test/unit/test-motion.js b/test/unit/test-motion.js index 79716accca1d..ae8ed295f6a3 100644 --- a/test/unit/test-motion.js +++ b/test/unit/test-motion.js @@ -50,14 +50,14 @@ describes.sandboxed('Motion calcVelocity', {}, () => { }); }); -describes.sandboxed('Motion continueMotion', {}, () => { +describes.sandboxed('Motion continueMotion', {}, (env) => { let clock; let vsync; let vsyncTasks; let contextNode; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); vsyncTasks = []; vsync = { runAnimMutateSeries: (unusedContextNode, mutator) => { diff --git a/test/unit/test-notification-ui-manager.js b/test/unit/test-notification-ui-manager.js index f7e32759e154..5126373dba64 100644 --- a/test/unit/test-notification-ui-manager.js +++ b/test/unit/test-notification-ui-manager.js @@ -16,7 +16,7 @@ import {NotificationUiManager} from '../../src/service/notification-ui-manager'; import {macroTask} from '../../testing/yield'; -describes.realWin('NotificationUiManager', {amp: 1}, () => { +describes.realWin('NotificationUiManager', {amp: 1}, (env) => { describe('Notification UI Manager', () => { let manager; let show1, show2, show3; @@ -25,9 +25,9 @@ describes.realWin('NotificationUiManager', {amp: 1}, () => { let p1, p2, p3; beforeEach(() => { manager = new NotificationUiManager(); - showSpy1 = window.sandbox.spy(); - showSpy2 = window.sandbox.spy(); - showSpy3 = window.sandbox.spy(); + showSpy1 = env.sandbox.spy(); + showSpy2 = env.sandbox.spy(); + showSpy3 = env.sandbox.spy(); p1 = new Promise((resolve) => { resolve1 = resolve; @@ -81,7 +81,7 @@ describes.realWin('NotificationUiManager', {amp: 1}, () => { }); it('queue empty handler', function* () { - const handler = window.sandbox.spy(); + const handler = env.sandbox.spy(); manager.registerUI(show1); manager.registerUI(show2); manager.onQueueEmpty(handler); @@ -93,7 +93,7 @@ describes.realWin('NotificationUiManager', {amp: 1}, () => { }); it('queue not empty handler', function* () { - const handler = window.sandbox.spy(); + const handler = env.sandbox.spy(); manager.onQueueNotEmpty(handler); manager.registerUI(show1); manager.registerUI(show2); diff --git a/test/unit/test-pass.js b/test/unit/test-pass.js index 3ffb712b7118..9a2e4b94634d 100644 --- a/test/unit/test-pass.js +++ b/test/unit/test-pass.js @@ -17,13 +17,13 @@ import {Pass} from '../../src/pass'; import {Services} from '../../src/services'; -describes.sandboxed('Pass', {}, () => { +describes.sandboxed('Pass', {}, (env) => { let pass; let timerMock; let handlerCalled; beforeEach(() => { - timerMock = window.sandbox.mock(Services.timerFor(window)); + timerMock = env.sandbox.mock(Services.timerFor(window)); handlerCalled = 0; pass = new Pass(window, () => { handlerCalled++; @@ -40,7 +40,7 @@ describes.sandboxed('Pass', {}, () => { timerMock .expects('delay') .withExactArgs( - window.sandbox.match((value) => { + env.sandbox.match((value) => { delayedFunc = value; return true; }), @@ -62,7 +62,7 @@ describes.sandboxed('Pass', {}, () => { it('schedule no delay', () => { timerMock .expects('delay') - .withExactArgs(window.sandbox.match.func, 0) + .withExactArgs(env.sandbox.match.func, 0) .returns(1) .once(); timerMock.expects('cancel').never(); @@ -72,7 +72,7 @@ describes.sandboxed('Pass', {}, () => { it('schedule with delay', () => { timerMock .expects('delay') - .withExactArgs(window.sandbox.match.func, 111) + .withExactArgs(env.sandbox.match.func, 111) .returns(1) .once(); timerMock.expects('cancel').never(); @@ -82,7 +82,7 @@ describes.sandboxed('Pass', {}, () => { it('schedule later', () => { timerMock .expects('delay') - .withExactArgs(window.sandbox.match.func, 111) + .withExactArgs(env.sandbox.match.func, 111) .returns(1) .once(); timerMock.expects('cancel').never(); @@ -95,12 +95,12 @@ describes.sandboxed('Pass', {}, () => { it('schedule earlier', () => { timerMock .expects('delay') - .withExactArgs(window.sandbox.match.func, 222) + .withExactArgs(env.sandbox.match.func, 222) .returns(1) .once(); timerMock .expects('delay') - .withExactArgs(window.sandbox.match.func, 111) + .withExactArgs(env.sandbox.match.func, 111) .returns(2) .once(); timerMock.expects('cancel').withExactArgs(1).once(); @@ -122,7 +122,7 @@ describes.sandboxed('Pass', {}, () => { timerMock .expects('delay') .withExactArgs( - window.sandbox.match((value) => { + env.sandbox.match((value) => { delayedFunc0 = value; return true; }), @@ -133,7 +133,7 @@ describes.sandboxed('Pass', {}, () => { timerMock .expects('delay') .withExactArgs( - window.sandbox.match((value) => { + env.sandbox.match((value) => { delayedFunc1 = value; return true; }), diff --git a/test/unit/test-platform.js b/test/unit/test-platform.js index 1227b98672c9..eb7b7fe2ef8a 100644 --- a/test/unit/test-platform.js +++ b/test/unit/test-platform.js @@ -16,7 +16,7 @@ import {Platform} from '../../src/service/platform-impl'; -describes.sandboxed('Platform', {}, () => { +describes.sandboxed('Platform', {}, (env) => { let isIos; let isAndroid; let isChrome; @@ -71,7 +71,7 @@ describes.sandboxed('Platform', {}, () => { standalone: standAloneBoolean, userAgent: userAgentString, }, - matchMedia: window.sandbox.stub().returns({matches: true}), + matchMedia: env.sandbox.stub().returns({matches: true}), }); expect(platform.isStandalone()).to.equal(isStandalone); } diff --git a/test/unit/test-pull-to-refresh.js b/test/unit/test-pull-to-refresh.js index 0ebc65c06654..e8a8da88e54f 100644 --- a/test/unit/test-pull-to-refresh.js +++ b/test/unit/test-pull-to-refresh.js @@ -16,7 +16,7 @@ import {PullToRefreshBlocker} from '../../src/pull-to-refresh'; -describes.sandboxed('PullToRefreshBlocker', {}, () => { +describes.sandboxed('PullToRefreshBlocker', {}, (env) => { let eventListeners; let viewportMock; let blocker; @@ -37,7 +37,7 @@ describes.sandboxed('PullToRefreshBlocker', {}, () => { const viewportApi = { getScrollTop: () => 0, }; - viewportMock = window.sandbox.mock(viewportApi); + viewportMock = env.sandbox.mock(viewportApi); blocker = new PullToRefreshBlocker(documentApi, viewportApi); }); @@ -120,7 +120,7 @@ describes.sandboxed('PullToRefreshBlocker', {}, () => { sendEvent({type: 'touchstart', touches: [{clientY: 111}]}); expect(blocker.tracking_).to.equal(true); - const preventDefault = window.sandbox.spy(); + const preventDefault = env.sandbox.spy(); sendEvent({type: 'touchmove', touches: [{clientY: 112}]}, preventDefault); expect(blocker.tracking_).to.equal(false); expect(preventDefault).to.be.calledOnce; @@ -135,7 +135,7 @@ describes.sandboxed('PullToRefreshBlocker', {}, () => { sendEvent({type: 'touchstart', touches: [{clientY: 111}]}); expect(blocker.tracking_).to.equal(true); - const preventDefault = window.sandbox.spy(); + const preventDefault = env.sandbox.spy(); sendEvent({type: 'touchmove', touches: [{clientY: 100}]}, preventDefault); expect(blocker.tracking_).to.equal(false); expect(preventDefault).to.have.not.been.called; @@ -150,7 +150,7 @@ describes.sandboxed('PullToRefreshBlocker', {}, () => { sendEvent({type: 'touchstart', touches: [{clientY: 111}]}); expect(blocker.tracking_).to.equal(true); - const preventDefault = window.sandbox.spy(); + const preventDefault = env.sandbox.spy(); sendEvent({type: 'touchmove', touches: [{clientY: 111}]}, preventDefault); expect(blocker.tracking_).to.equal(true); expect(preventDefault).to.have.not.been.called; diff --git a/test/unit/test-purifier.js b/test/unit/test-purifier.js index 565c345ecf21..81d546c56283 100644 --- a/test/unit/test-purifier.js +++ b/test/unit/test-purifier.js @@ -20,13 +20,13 @@ import {Purifier} from '../../src/purifier/purifier'; describes.sandboxed .configure() .skipFirefox() - .run('DOMPurify-based', {}, () => { + .run('DOMPurify-based', {}, (env) => { let purify; let purifyTripleMustache; let rewriteAttributeValueSpy; beforeEach(() => { - rewriteAttributeValueSpy = window.sandbox.spy( + rewriteAttributeValueSpy = env.sandbox.spy( urlRewrite, 'rewriteAttributeValue' ); diff --git a/test/unit/test-render-delaying-services.js b/test/unit/test-render-delaying-services.js index b1cf39540bfc..7660cc8dce49 100644 --- a/test/unit/test-render-delaying-services.js +++ b/test/unit/test-render-delaying-services.js @@ -23,7 +23,7 @@ import { } from '../../src/render-delaying-services'; import {macroTask} from '../../testing/yield'; -describes.sandboxed('waitForServices', {}, () => { +describes.sandboxed('waitForServices', {}, (env) => { let win; let clock; let dynamicCssResolve; @@ -33,17 +33,21 @@ describes.sandboxed('waitForServices', {}, () => { let variantStub; beforeEach(() => { - const getService = window.sandbox.stub(service, 'getServicePromise'); - dynamicCssResolve = waitForService(getService, 'amp-dynamic-css-classes'); - experimentResolve = waitForService(getService, 'amp-experiment'); + const getService = env.sandbox.stub(service, 'getServicePromise'); + dynamicCssResolve = waitForService( + env, + getService, + 'amp-dynamic-css-classes' + ); + experimentResolve = waitForService(env, getService, 'amp-experiment'); variantService = { whenReady: () => { throw new Error('whenReady should be stubbed'); }, }; - variantResolve = waitForService(getService, 'variant', variantService); - variantStub = window.sandbox + variantResolve = waitForService(env, getService, 'variant', variantService); + variantStub = env.sandbox .stub(variantService, 'whenReady') .returns(Promise.resolve()); @@ -123,9 +127,9 @@ describes.sandboxed('waitForServices', {}, () => { }); }); -function waitForService(getService, serviceId, service) { +function waitForService(env, getService, serviceId, service) { let resolve = null; - getService.withArgs(window.sandbox.match.any, serviceId).returns( + getService.withArgs(env.sandbox.match.any, serviceId).returns( new Promise((r) => { resolve = r.bind(this, service); }) diff --git a/test/unit/test-resource.js b/test/unit/test-resource.js index de82dd5f9d54..73114137dccf 100644 --- a/test/unit/test-resource.js +++ b/test/unit/test-resource.js @@ -981,7 +981,7 @@ describes.realWin('Resource', {amp: true}, (env) => { }); }); -describes.sandboxed('Resource idleRenderOutsideViewport', {}, () => { +describes.sandboxed('Resource idleRenderOutsideViewport', {}, (env) => { let element; let resources; let resource; @@ -989,7 +989,7 @@ describes.sandboxed('Resource idleRenderOutsideViewport', {}, () => { let isWithinViewportRatio; beforeEach(() => { - idleRenderOutsideViewport = window.sandbox.stub(); + idleRenderOutsideViewport = env.sandbox.stub(); element = { idleRenderOutsideViewport, ownerDocument: {defaultView: window}, @@ -1014,10 +1014,7 @@ describes.sandboxed('Resource idleRenderOutsideViewport', {}, () => { }; resources = new ResourcesImpl(new AmpDocSingle(window)); resource = new Resource(1, element, resources); - isWithinViewportRatio = window.sandbox.stub( - resource, - 'isWithinViewportRatio' - ); + isWithinViewportRatio = env.sandbox.stub(resource, 'isWithinViewportRatio'); }); it('should return true if isWithinViewportRatio', () => { diff --git a/test/unit/test-service.js b/test/unit/test-service.js index b9fcc7fdd2f6..395a7e79b9fe 100644 --- a/test/unit/test-service.js +++ b/test/unit/test-service.js @@ -39,14 +39,14 @@ import { } from '../../src/service'; import {loadPromise} from '../../src/event-helper'; -describes.sandboxed('service', {}, () => { +describes.sandboxed('service', {}, (env) => { describe('disposable interface', () => { let disposable; let nonDisposable; beforeEach(() => { nonDisposable = {}; - disposable = {dispose: window.sandbox.spy()}; + disposable = {dispose: env.sandbox.spy()}; }); it('should test disposable interface', () => { @@ -76,7 +76,7 @@ describes.sandboxed('service', {}, () => { this.count = ++count; } }; - factory = window.sandbox.spy(() => { + factory = env.sandbox.spy(() => { return new Class(); }); resetServiceForTesting(window, 'a'); @@ -234,7 +234,7 @@ describes.sandboxed('service', {}, () => { this.count = ++count; } }; - factory = window.sandbox.spy(function () { + factory = env.sandbox.spy(function () { return new Class(); }); windowApi = { @@ -246,7 +246,7 @@ describes.sandboxed('service', {}, () => { isSingleDoc: () => false, win: windowApi, }; - ampdocMock = window.sandbox.mock(ampdoc); + ampdocMock = env.sandbox.mock(ampdoc); ampdocServiceApi = {getAmpDoc: () => ampdoc}; registerServiceBuilder(windowApi, 'ampdoc', function () { return ampdocServiceApi; @@ -431,7 +431,7 @@ describes.sandboxed('service', {}, () => { expectAsyncConsoleError(/intentional/); const disposableFactory = function () { return { - dispose: window.sandbox.spy(), + dispose: env.sandbox.spy(), }; }; registerServiceBuilderForDoc(node, 'a', disposableFactory); @@ -439,7 +439,7 @@ describes.sandboxed('service', {}, () => { registerServiceBuilderForDoc(node, 'b', function () { return { - dispose: window.sandbox.stub().throws('intentional'), + dispose: env.sandbox.stub().throws('intentional'), }; }); const disposableWithError = getServiceForDoc(node, 'b'); @@ -537,7 +537,7 @@ describes.sandboxed('service', {}, () => { isSingleDoc: () => false, win: windowApi, }; - window.sandbox.stub(ampdocServiceApi, 'getAmpDoc').callsFake((node) => { + env.sandbox.stub(ampdocServiceApi, 'getAmpDoc').callsFake((node) => { if (node == childWinNode || node == grandChildWinNode) { return childAmpdoc; } @@ -559,7 +559,7 @@ describes.sandboxed('service', {}, () => { win: windowApi, }; registerServiceBuilderForDoc(childAmpdoc, 'c', factory); - window.sandbox.stub(ampdocServiceApi, 'getAmpDoc').callsFake((node) => { + env.sandbox.stub(ampdocServiceApi, 'getAmpDoc').callsFake((node) => { if (node == childWinNode || node == grandChildWinNode) { return childAmpdoc; } @@ -601,7 +601,7 @@ describes.sandboxed('service', {}, () => { it('should dispose disposable services', () => { const disposableFactory = function () { return { - dispose: window.sandbox.spy(), + dispose: env.sandbox.spy(), }; }; diff --git a/test/unit/test-shadow-embed.js b/test/unit/test-shadow-embed.js index 0369bf88aa7b..391ada7dfb69 100644 --- a/test/unit/test-shadow-embed.js +++ b/test/unit/test-shadow-embed.js @@ -33,7 +33,7 @@ import { import {installStylesForDoc} from '../../src/style-installer'; import {toArray} from '../../src/core/types/array'; -describes.sandboxed('shadow-embed', {}, () => { +describes.sandboxed('shadow-embed', {}, (env) => { afterEach(() => { setShadowDomSupportedVersionForTesting(undefined); }); @@ -354,7 +354,7 @@ describes.sandboxed('shadow-embed', {}, () => { let isFirefox; beforeEach(() => { - createHTMLDocumentSpy = window.sandbox.spy(); + createHTMLDocumentSpy = env.sandbox.spy(); isFirefox = false; const platform = { isFirefox: () => isFirefox, diff --git a/test/unit/test-style.js b/test/unit/test-style.js index eb09d94fb961..7f7b5c3ab758 100644 --- a/test/unit/test-style.js +++ b/test/unit/test-style.js @@ -16,7 +16,7 @@ import * as st from '../../src/style'; -describes.sandboxed('Style', {}, () => { +describes.sandboxed('Style', {}, (env) => { it('toggle', () => { const element = document.createElement('div'); @@ -72,7 +72,7 @@ describes.sandboxed('Style', {}, () => { }); it('setImportantStyles with vendor prefix', () => { - const spy = window.sandbox.spy(); + const spy = env.sandbox.spy(); const element = { style: { WebkitTransitionDurationImportant: '', diff --git a/test/unit/test-task-queue.js b/test/unit/test-task-queue.js index b0f117f4769b..8435077cb29d 100644 --- a/test/unit/test-task-queue.js +++ b/test/unit/test-task-queue.js @@ -16,12 +16,12 @@ import {TaskQueue} from '../../src/service/task-queue'; -describes.sandboxed('TaskQueue', {}, () => { +describes.sandboxed('TaskQueue', {}, (env) => { let clock; let queue; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); queue = new TaskQueue(); }); diff --git a/test/unit/test-transition.js b/test/unit/test-transition.js index ecccc544afa7..2ef14dc1bef1 100644 --- a/test/unit/test-transition.js +++ b/test/unit/test-transition.js @@ -16,10 +16,10 @@ import * as tr from '../../src/transition'; -describes.sandboxed('Transition', {}, () => { +describes.sandboxed('Transition', {}, (env) => { it('all', () => { - const func1 = window.sandbox.spy(); - const func2 = window.sandbox.spy(); + const func1 = env.sandbox.spy(); + const func2 = env.sandbox.spy(); const all = tr.all([func1, func2]); expect(func1).to.have.not.been.called; diff --git a/test/unit/test-viewport.js b/test/unit/test-viewport.js index bfa955247e0c..23de12935b9e 100644 --- a/test/unit/test-viewport.js +++ b/test/unit/test-viewport.js @@ -1257,7 +1257,7 @@ describes.fakeWin('Viewport', {}, (env) => { }); }); -describes.sandboxed('Viewport META', {}, () => { +describes.sandboxed('Viewport META', {}, (env) => { describe('parseViewportMeta', () => { it('should accept null or empty strings', () => { expect(parseViewportMeta(null)).to.be.empty; @@ -1431,7 +1431,7 @@ describes.sandboxed('Viewport META', {}, () => { let viewportMetaSetter; beforeEach(() => { - clock = window.sandbox.useFakeTimers(); + clock = env.sandbox.useFakeTimers(); viewer = { isEmbedded: () => false, getParam: (param) => { @@ -1448,7 +1448,7 @@ describes.sandboxed('Viewport META', {}, () => { originalViewportMetaString = 'width=device-width,minimum-scale=1'; viewportMetaString = originalViewportMetaString; viewportMeta = Object.create(null); - viewportMetaSetter = window.sandbox.spy(); + viewportMetaSetter = env.sandbox.spy(); Object.defineProperty(viewportMeta, 'content', { get: () => viewportMetaString, set: (value) => { diff --git a/test/unit/test-xhr-document-fetcher.js b/test/unit/test-xhr-document-fetcher.js index 1d71e7752061..f585460bdc2a 100644 --- a/test/unit/test-xhr-document-fetcher.js +++ b/test/unit/test-xhr-document-fetcher.js @@ -150,7 +150,7 @@ describes.realWin('DocumentFetcher', {amp: true}, function (env) { sendMessageAwaitResponse: getDefaultResponsePromise, whenFirstVisible: () => Promise.resolve(), }; - sendMessageStub = window.sandbox.stub(viewer, 'sendMessageAwaitResponse'); + sendMessageStub = env.sandbox.stub(viewer, 'sendMessageAwaitResponse'); sendMessageStub.returns(getDefaultResponsePromise()); ampdocViewerStub.returns(viewer); interceptionEnabledWin = { diff --git a/test/unit/test-xhr.js b/test/unit/test-xhr.js index b20fcf4c2b6e..02f6d183f579 100644 --- a/test/unit/test-xhr.js +++ b/test/unit/test-xhr.js @@ -29,7 +29,7 @@ import {xhrServiceForTesting} from '../../src/service/xhr-impl'; describes.sandboxed .configure() .skipSafari() - .run('XHR', {}, function () { + .run('XHR', {}, function (env) { let ampdocServiceForStub; let ampdoc; let ampdocViewerStub; @@ -62,7 +62,7 @@ describes.sandboxed ]; function setupMockXhr() { - const mockXhr = window.sandbox.useFakeXMLHttpRequest(); + const mockXhr = env.sandbox.useFakeXMLHttpRequest(); xhrCreated = new Promise((resolve) => (mockXhr.onCreate = resolve)); } @@ -76,7 +76,7 @@ describes.sandboxed } beforeEach(() => { - ampdocServiceForStub = window.sandbox.stub(Services, 'ampdocServiceFor'); + ampdocServiceForStub = env.sandbox.stub(Services, 'ampdocServiceFor'); ampdoc = { getRootNode: () => null, whenFirstVisible: () => Promise.resolve(), @@ -86,7 +86,7 @@ describes.sandboxed getAmpDoc: () => ampdoc, getSingleDoc: () => ampdoc, }); - ampdocViewerStub = window.sandbox.stub(Services, 'viewerForDoc'); + ampdocViewerStub = env.sandbox.stub(Services, 'viewerForDoc'); ampdocViewerStub.returns({}); location.href = 'https://acme.com/path'; @@ -147,14 +147,14 @@ describes.sandboxed it('should allow FormData as body', () => { const fakeWin = null; - window.sandbox.stub(Services, 'platformFor').returns({ + env.sandbox.stub(Services, 'platformFor').returns({ isIos() { return false; }, }); const formData = createFormDataWrapper(fakeWin); - window.sandbox.stub(JSON, 'stringify'); + env.sandbox.stub(JSON, 'stringify'); formData.append('name', 'John Miller'); formData.append('age', 56); const post = xhr.fetchJson.bind(xhr, '/post', { @@ -259,13 +259,13 @@ describes.sandboxed test.win.fetch.restore(); }); it('should not call fetch if view is not visible ', () => { - const fetchCall = window.sandbox.spy(test.win, 'fetch'); + const fetchCall = env.sandbox.spy(test.win, 'fetch'); ampdoc.whenFirstVisible = () => Promise.reject(); xhr.fetchJson('/get', {ampCors: false}); expect(fetchCall.notCalled).to.be.true; }); it('should call fetch if view is visible ', () => { - const fetchCall = window.sandbox.spy(test.win, 'fetch'); + const fetchCall = env.sandbox.spy(test.win, 'fetch'); ampdoc.whenFirstVisible = () => Promise.resolve(); const fetch = xhr.fetchJson('/get', {ampCors: false}); fetch.then(() => { @@ -371,7 +371,7 @@ describes.sandboxed }); it('should do simple JSON fetch', () => { - window.sandbox.stub(user(), 'assert'); + env.sandbox.stub(user(), 'assert'); return xhr .fetchJson(`${baseUrl}/get?k=v1`) .then((res) => res.json()) @@ -484,7 +484,7 @@ describes.sandboxed beforeEach(() => { xhr = xhrServiceForTesting(test.win); - fetchStub = window.sandbox + fetchStub = env.sandbox .stub(xhr, 'fetchAmpCors_') .callsFake(() => Promise.resolve(new Response(TEST_TEXT))); }); @@ -675,10 +675,7 @@ describes.sandboxed sendMessageAwaitResponse: getDefaultResponsePromise, whenFirstVisible: () => Promise.resolve(), }; - sendMessageStub = window.sandbox.stub( - viewer, - 'sendMessageAwaitResponse' - ); + sendMessageStub = env.sandbox.stub(viewer, 'sendMessageAwaitResponse'); sendMessageStub.returns(getDefaultResponsePromise()); ampdocViewerStub.returns(viewer); interceptionEnabledWin = { @@ -737,7 +734,7 @@ describes.sandboxed }); it('should not intercept if viewer is not capable', () => { - window.sandbox + env.sandbox .stub(viewer, 'hasCapability') .withArgs('xhrInterceptor') .returns(false); @@ -749,7 +746,7 @@ describes.sandboxed }); it('should not intercept if viewer untrusted and non-dev mode', () => { - window.sandbox + env.sandbox .stub(viewer, 'isTrustedViewer') .returns(Promise.resolve(false)); interceptionEnabledWin.AMP_DEV_MODE = false; @@ -778,10 +775,10 @@ describes.sandboxed }); it('should intercept if viewer untrusted but in local dev mode', () => { - window.sandbox + env.sandbox .stub(viewer, 'isTrustedViewer') .returns(Promise.resolve(false)); - window.sandbox.stub(mode, 'getMode').returns({localDev: true}); + env.sandbox.stub(mode, 'getMode').returns({localDev: true}); const xhr = xhrServiceForTesting(interceptionEnabledWin); @@ -791,11 +788,11 @@ describes.sandboxed }); it('should intercept if untrusted-xhr-interception experiment enabled', () => { - window.sandbox + env.sandbox .stub(viewer, 'isTrustedViewer') .returns(Promise.resolve(false)); - window.sandbox.stub(mode, 'getMode').returns({localDev: false}); - window.sandbox + env.sandbox.stub(mode, 'getMode').returns({localDev: false}); + env.sandbox .stub(viewer, 'hasCapability') .withArgs('xhrInterceptor') .returns(true); @@ -813,7 +810,7 @@ describes.sandboxed }); it('should intercept if non-dev mode but viewer trusted', () => { - window.sandbox + env.sandbox .stub(viewer, 'isTrustedViewer') .returns(Promise.resolve(true)); interceptionEnabledWin.AMP_DEV_MODE = false; @@ -833,7 +830,7 @@ describes.sandboxed .then(() => expect(sendMessageStub).to.have.been.calledWithMatch( 'xhr', - window.sandbox.match.any + env.sandbox.match.any ) ); }); @@ -843,7 +840,7 @@ describes.sandboxed return xhr.fetch('https://www.some-url.org/some-resource/').then(() => expect(sendMessageStub).to.have.been.calledWithMatch( - window.sandbox.match.any, + env.sandbox.match.any, { originalRequest: { input: @@ -870,7 +867,7 @@ describes.sandboxed }) .then(() => expect(sendMessageStub).to.have.been.calledWithMatch( - window.sandbox.match.any, + env.sandbox.match.any, { originalRequest: { input: @@ -893,7 +890,7 @@ describes.sandboxed const xhr = xhrServiceForTesting(interceptionEnabledWin); const fakeWin = null; - window.sandbox.stub(Services, 'platformFor').returns({ + env.sandbox.stub(Services, 'platformFor').returns({ isIos() { return false; }, @@ -911,7 +908,7 @@ describes.sandboxed }) .then(() => expect(sendMessageStub).to.have.been.calledWithMatch( - window.sandbox.match.any, + env.sandbox.match.any, { originalRequest: { input: diff --git a/test/unit/web-worker/test-amp-worker.js b/test/unit/web-worker/test-amp-worker.js index b2a71b36588b..bc7e5a6138de 100644 --- a/test/unit/web-worker/test-amp-worker.js +++ b/test/unit/web-worker/test-amp-worker.js @@ -23,7 +23,7 @@ import {dev} from '../../../src/log'; import {getMode} from '../../../src/mode'; import {installXhrService} from '../../../src/service/xhr-impl'; -describes.sandboxed('invokeWebWorker', {}, () => { +describes.sandboxed('invokeWebWorker', {}, (env) => { let fakeWin; let ampWorker; @@ -34,12 +34,12 @@ describes.sandboxed('invokeWebWorker', {}, () => { let workerReadyPromise; beforeEach(() => { - window.sandbox.stub(Services, 'ampdocServiceFor').returns({ + env.sandbox.stub(Services, 'ampdocServiceFor').returns({ isSingleDoc: () => false, }); - postMessageStub = window.sandbox.stub(); - blobStub = window.sandbox.stub(); + postMessageStub = env.sandbox.stub(); + blobStub = env.sandbox.stub(); fakeWorker = {}; fakeWorker.postMessage = postMessageStub; @@ -48,13 +48,13 @@ describes.sandboxed('invokeWebWorker', {}, () => { fakeWin = { Worker: () => fakeWorker, Blob: blobStub, - URL: {createObjectURL: window.sandbox.stub()}, + URL: {createObjectURL: env.sandbox.stub()}, location: window.location, }; // Stub xhr.fetchText() to return a resolved promise. installXhrService(fakeWin); - fetchTextCallStub = window.sandbox + fetchTextCallStub = env.sandbox .stub(Services.xhrFor(fakeWin), 'fetchText') .callsFake(() => Promise.resolve({ @@ -83,7 +83,7 @@ describes.sandboxed('invokeWebWorker', {}, () => { return workerReadyPromise.then(() => { expect(postMessageStub).to.have.been.calledWithMatch({ method: 'foo', - args: window.sandbox.match(['bar', 123]), + args: env.sandbox.match(['bar', 123]), id: 0, }); @@ -195,7 +195,7 @@ describes.sandboxed('invokeWebWorker', {}, () => { }); it('should log error when unexpected message is received', () => { - const errorStub = window.sandbox.stub(dev(), 'error'); + const errorStub = env.sandbox.stub(dev(), 'error'); invokeWebWorker(fakeWin, 'foo'); From 149653a62b0c21aecfe7b1aec1644fe0b799c858 Mon Sep 17 00:00:00 2001 From: Raghu Simha Date: Tue, 11 May 2021 13:13:41 -0400 Subject: [PATCH 3/3] Update configured top-level `describe` blocks --- .../test-integration-amp-date-picker-actions.js | 4 ++-- .../integration/test-integration-amp-date-picker-init.js | 4 ++-- .../test/integration/test-integration-dates-attributes.js | 4 ++-- .../test/integration/test-integration-maximum-nights.js | 4 ++-- .../test/integration/test-integration-form-verifiers.js | 4 ++-- .../0.1/test/integration/test-amp-fx-fade-in-scroll.js | 4 ++-- .../0.1/test/integration/test-amp-fx-fade-in.js | 4 ++-- .../0.1/test/integration/test-amp-fx-parallax.js | 4 ++-- .../0.1/test/integration/test-amp-image-slider.js | 4 ++-- .../integration/test-integration-amp-inputmask-date.js | 4 ++-- .../0.1/test/integration/test-integration-amp-inputmask.js | 4 ++-- .../1.0/test/integration/test-amp-story-affiliate-link.js | 4 ++-- test/integration/test-amp-carousel.js | 4 ++-- test/integration/test-amp-story-analytics.js | 4 ++-- test/integration/test-amphtml-ads.js | 6 +++--- test/integration/test-position-observer.js | 4 ++-- test/integration/test-user-error-reporting.js | 4 ++-- test/integration/test-visibility-states.js | 7 +++++-- 18 files changed, 40 insertions(+), 37 deletions(-) diff --git a/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-actions.js b/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-actions.js index b25125997042..21b587831367 100644 --- a/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-actions.js +++ b/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-actions.js @@ -17,8 +17,8 @@ import * as fakeTimers from '@sinonjs/fake-timers'; import {poll} from '../../../../../testing/iframe'; -const config = describe.configure().ifChrome(); -config.skip('amp-date-picker', function () { +const config = describes.sandboxed.configure().ifChrome(); +config.skip('amp-date-picker', {}, function () { this.timeout(10000); const extensions = ['amp-date-picker']; diff --git a/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-init.js b/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-init.js index 33384efb1330..06fc9fccc66e 100644 --- a/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-init.js +++ b/extensions/amp-date-picker/0.1/test/integration/test-integration-amp-date-picker-init.js @@ -27,9 +27,9 @@ function checkElementUpgrade(element) { } // NOTE: this only executes on module build tests -const config = describe.configure().ifModuleBuild(); +const config = describes.sandboxed.configure().ifModuleBuild(); -config.run('amp-date-picker', async () => { +config.run('amp-date-picker', {}, async () => { it('initializes the date picker', async () => { const testExtension = 'amp-date-picker'; const fixture = await createFixtureIframe( diff --git a/extensions/amp-date-picker/0.1/test/integration/test-integration-dates-attributes.js b/extensions/amp-date-picker/0.1/test/integration/test-integration-dates-attributes.js index 13e2bbf7517e..41a98116b816 100644 --- a/extensions/amp-date-picker/0.1/test/integration/test-integration-dates-attributes.js +++ b/extensions/amp-date-picker/0.1/test/integration/test-integration-dates-attributes.js @@ -18,9 +18,9 @@ import * as fakeTimers from '@sinonjs/fake-timers'; import {htmlFor} from '../../../../../src/static-template'; import {poll} from '../../../../../testing/iframe'; -const config = describe.configure().ifChrome(); +const config = describes.sandboxed.configure().ifChrome(); -config.run('amp-date-picker', function () { +config.run('amp-date-picker', {}, function () { this.timeout(10000); const extensions = ['amp-date-picker']; diff --git a/extensions/amp-date-picker/0.1/test/integration/test-integration-maximum-nights.js b/extensions/amp-date-picker/0.1/test/integration/test-integration-maximum-nights.js index 51cc53ec1c35..8d03f62b3b34 100644 --- a/extensions/amp-date-picker/0.1/test/integration/test-integration-maximum-nights.js +++ b/extensions/amp-date-picker/0.1/test/integration/test-integration-maximum-nights.js @@ -18,9 +18,9 @@ import * as fakeTimers from '@sinonjs/fake-timers'; import {htmlFor} from '../../../../../src/static-template'; import {poll} from '../../../../../testing/iframe'; -const config = describe.configure().ifChrome(); +const config = describes.sandboxed.configure().ifChrome(); -config.run('amp-date-picker', function () { +config.run('amp-date-picker', {}, function () { this.timeout(10000); const extensions = ['amp-date-picker']; diff --git a/extensions/amp-form/0.1/test/integration/test-integration-form-verifiers.js b/extensions/amp-form/0.1/test/integration/test-integration-form-verifiers.js index d14aba9bf65c..bc2bfdcdcdf5 100644 --- a/extensions/amp-form/0.1/test/integration/test-integration-form-verifiers.js +++ b/extensions/amp-form/0.1/test/integration/test-integration-form-verifiers.js @@ -17,10 +17,10 @@ import {poll} from '../../../../../testing/iframe'; const RENDER_TIMEOUT = 15000; -const describeChrome = describe.configure().ifChrome(); +const describeChrome = describes.sandboxed.configure().ifChrome(); // TODO(cvializ, #19647): Broken on SL Chrome 71. -describeChrome.skip('amp-form verifiers', function () { +describeChrome.skip('amp-form verifiers', {}, function () { const {testServerPort} = window.ampTestRuntimeConfig; const baseUrl = `http://localhost:${testServerPort}`; diff --git a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in-scroll.js b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in-scroll.js index 01f478e2ca50..b3fb80e683cb 100644 --- a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in-scroll.js +++ b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in-scroll.js @@ -14,8 +14,8 @@ * limitations under the License. */ -const config = describe.configure().ifChrome(); -config.run('amp-fx-collection', function () { +const config = describes.sandboxed.configure().ifChrome(); +config.run('amp-fx-collection', {}, function () { const css = ` .spacer { height: 100vh; diff --git a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in.js b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in.js index d80a661aaeef..eba40533e240 100644 --- a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in.js +++ b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-fade-in.js @@ -14,8 +14,8 @@ * limitations under the License. */ -const config = describe.configure().ifChrome(); -config.run('amp-fx-collection', function () { +const config = describes.sandboxed.configure().ifChrome(); +config.run('amp-fx-collection', {}, function () { const css = ` .spacer { height: 100vh; diff --git a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-parallax.js b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-parallax.js index 2730f7f1fa34..fce9444ae736 100644 --- a/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-parallax.js +++ b/extensions/amp-fx-collection/0.1/test/integration/test-amp-fx-parallax.js @@ -14,8 +14,8 @@ * limitations under the License. */ -const config = describe.configure().ifChrome(); -config.run('amp-fx-collection', function () { +const config = describes.sandboxed.configure().ifChrome(); +config.run('amp-fx-collection', {}, function () { const css = ` .spacer { height: 100vh; diff --git a/extensions/amp-image-slider/0.1/test/integration/test-amp-image-slider.js b/extensions/amp-image-slider/0.1/test/integration/test-amp-image-slider.js index ae0fda881a55..7afec4dc61bd 100644 --- a/extensions/amp-image-slider/0.1/test/integration/test-amp-image-slider.js +++ b/extensions/amp-image-slider/0.1/test/integration/test-amp-image-slider.js @@ -16,9 +16,9 @@ import {createPointerEvent} from '../../../../../testing/test-helper'; -const t = describe.configure().ifChrome(); +const t = describes.sandboxed.configure().ifChrome(); -t.run('amp-image-slider', function () { +t.run('amp-image-slider', {}, function () { this.timeout(20000); const DEFAULT_TIMEOUT = 1600; diff --git a/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask-date.js b/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask-date.js index 91084b4b8e70..591f1fecccae 100644 --- a/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask-date.js +++ b/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask-date.js @@ -16,8 +16,8 @@ import {simulateKeyboardInteraction} from './utils'; -const config = describe.configure().ifChrome(); -config.skip('amp-inputmask', () => { +const config = describes.sandboxed.configure().ifChrome(); +config.skip('amp-inputmask', {}, () => { const {testServerPort} = window.ampTestRuntimeConfig; describes.integration( diff --git a/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask.js b/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask.js index 603a379283dc..c0ece94295a4 100644 --- a/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask.js +++ b/extensions/amp-inputmask/0.1/test/integration/test-integration-amp-inputmask.js @@ -17,8 +17,8 @@ import {poll} from '../../../../../testing/iframe'; import {simulateKeyboardInteraction} from './utils'; -const config = describe.configure().ifChrome(); -config.skip('amp-inputmask', () => { +const config = describes.sandboxed.configure().ifChrome(); +config.skip('amp-inputmask', {}, () => { const {testServerPort} = window.ampTestRuntimeConfig; describes.integration( diff --git a/extensions/amp-story/1.0/test/integration/test-amp-story-affiliate-link.js b/extensions/amp-story/1.0/test/integration/test-amp-story-affiliate-link.js index d8537f62dfcc..8378f89d412a 100644 --- a/extensions/amp-story/1.0/test/integration/test-amp-story-affiliate-link.js +++ b/extensions/amp-story/1.0/test/integration/test-amp-story-affiliate-link.js @@ -19,9 +19,9 @@ import { RequestBank, } from '../../../../../testing/test-helper'; -const t = describe.configure().skipSafari().skipEdge(); +const t = describes.sandboxed.configure().skipSafari().skipEdge(); -t.run('amp-story-affiliate link', () => { +t.run('amp-story-affiliate link', {}, () => { describes.integration( 'analytics on click', { diff --git a/test/integration/test-amp-carousel.js b/test/integration/test-amp-carousel.js index 6f55c0688c2b..f19b87fa9c6d 100644 --- a/test/integration/test-amp-carousel.js +++ b/test/integration/test-amp-carousel.js @@ -17,9 +17,9 @@ import {CommonSignals} from '../../src/core/constants/common-signals'; import {whenUpgradedToCustomElement} from '../../src/dom'; -const t = describe.configure().ifChrome(); +const t = describes.sandboxed.configure().ifChrome(); -t.run('amp-carousel', function () { +t.run('amp-carousel', {}, function () { this.timeout(10000); let document; diff --git a/test/integration/test-amp-story-analytics.js b/test/integration/test-amp-story-analytics.js index d8ec942583c4..6c997a3011a3 100644 --- a/test/integration/test-amp-story-analytics.js +++ b/test/integration/test-amp-story-analytics.js @@ -17,9 +17,9 @@ import {BrowserController, RequestBank} from '../../testing/test-helper'; import {parseQueryString} from '../../src/url'; -const config = describe.configure().skipEdge().skipSafari(); +const config = describes.sandboxed.configure().skipEdge().skipSafari(); -config.run('amp-story analytics', () => { +config.run('amp-story analytics', {}, () => { const extensions = ['amp-story:1.0', 'amp-analytics', 'amp-social-share']; describes.integration( 'amp-story analytics', diff --git a/test/integration/test-amphtml-ads.js b/test/integration/test-amphtml-ads.js index 719c3105d8be..dec1d1ebe0de 100644 --- a/test/integration/test-amphtml-ads.js +++ b/test/integration/test-amphtml-ads.js @@ -20,9 +20,9 @@ import {parseQueryString} from '../../src/url'; import {xhrServiceForTesting} from '../../src/service/xhr-impl'; // TODO(wg-monetization, #29112): Unskip on Safari. -const t = describe.configure().skipSafari(); +const t = describes.sandboxed.configure().skipSafari(); -t.run('AMPHTML ad on AMP Page', () => { +t.run('AMPHTML ad on AMP Page', {}, () => { describes.integration( 'ATF', { @@ -85,7 +85,7 @@ t.run('AMPHTML ad on AMP Page', () => { ); }); -t.run('AMPHTML ad on non-AMP page (inabox)', () => { +t.run('AMPHTML ad on non-AMP page (inabox)', {}, () => { describes.integration( 'ATF', { diff --git a/test/integration/test-position-observer.js b/test/integration/test-position-observer.js index b51726a92274..d1aece798f5a 100644 --- a/test/integration/test-position-observer.js +++ b/test/integration/test-position-observer.js @@ -18,8 +18,8 @@ import {poll} from '../../testing/iframe'; //TODO(aghassemi,#10878): Run in all platforms. //TODO(aghasemi, #10877): in-a-box, FIE integration tests. -const config = describe.configure().ifChrome(); -config.run('amp-position-observer', function () { +const config = describes.sandboxed.configure().ifChrome(); +config.run('amp-position-observer', {}, function () { this.timeout(100000); const css = ` diff --git a/test/integration/test-user-error-reporting.js b/test/integration/test-user-error-reporting.js index 9aae42d430db..37a349289836 100644 --- a/test/integration/test-user-error-reporting.js +++ b/test/integration/test-user-error-reporting.js @@ -17,9 +17,9 @@ import {BrowserController, RequestBank} from '../../testing/test-helper'; // TODO(zhouyx, #11459): Unskip the test on Safari and Firefox. -const t = describe.configure().skipSafari().skipFirefox().skipEdge(); +const t = describes.sandboxed.configure().skipSafari().skipFirefox().skipEdge(); -t.run('user-error', function () { +t.run('user-error', {}, function () { describes.integration( 'user-error integration test', { diff --git a/test/integration/test-visibility-states.js b/test/integration/test-visibility-states.js index db7dbb46cac4..0dd5bb564716 100644 --- a/test/integration/test-visibility-states.js +++ b/test/integration/test-visibility-states.js @@ -20,9 +20,12 @@ import {createCustomEvent} from '../../src/event-helper'; import {getVendorJsPropertyName} from '../../src/style'; import {whenUpgradedToCustomElement} from '../../src/dom'; -const t = describe.configure().skipIfPropertiesObfuscated().ifChrome(); +const t = describes.sandboxed + .configure() + .skipIfPropertiesObfuscated() + .ifChrome(); -t.run('Viewer Visibility State', () => { +t.run('Viewer Visibility State', {}, () => { function noop() {} describes.integration(