Skip to content

Commit

Permalink
Rename AMP_MODE to __AMP_MODE. (#24052)
Browse files Browse the repository at this point in the history
  • Loading branch information
William Chou authored Aug 20, 2019
1 parent 1aa3fef commit 2cf7ec2
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion 3p/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ function init(win) {
const config = getAmpConfig();

// Overriding to short-circuit src/mode#getMode()
win.AMP_MODE = config.mode;
win.__AMP_MODE = config.mode;

setReportError(console.error.bind(console));

Expand Down
14 changes: 7 additions & 7 deletions extensions/amp-a4a/0.1/test/test-amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -2579,7 +2579,7 @@ describe('amp-a4a', () => {
});

it('should create an error if needed', () => {
window.AMP_MODE = {development: true};
window.__AMP_MODE = {development: true};
a4a.promiseErrorHandler_('intentional');
expect(userErrorStub).to.be.calledOnce;
expect(userErrorStub.args[0][1]).to.be.instanceOf(Error);
Expand All @@ -2588,7 +2588,7 @@ describe('amp-a4a', () => {
});

it('should configure ignoreStack when specified', () => {
window.AMP_MODE = {development: true};
window.__AMP_MODE = {development: true};
a4a.promiseErrorHandler_('intentional', /* ignoreStack */ true);
expect(userErrorStub).to.be.calledOnce;
expect(userErrorStub.args[0][1]).to.be.instanceOf(Error);
Expand All @@ -2598,7 +2598,7 @@ describe('amp-a4a', () => {

it('should route error to user.error in dev mode', () => {
const error = new Error('intentional');
window.AMP_MODE = {development: true};
window.__AMP_MODE = {development: true};
a4a.promiseErrorHandler_(error);
expect(userErrorStub).to.be.calledOnce;
expect(userErrorStub.args[0][1]).to.be.equal(error);
Expand All @@ -2609,7 +2609,7 @@ describe('amp-a4a', () => {

it('should route error to user.warn in prod mode', () => {
const error = new Error('intentional');
window.AMP_MODE = {development: false};
window.__AMP_MODE = {development: false};
a4a.promiseErrorHandler_(error);
expect(userWarnStub).to.be.calledOnce;
expect(userWarnStub.args[0][1]).to.be.equal(error);
Expand All @@ -2620,7 +2620,7 @@ describe('amp-a4a', () => {
it('should send an expected error in prod mode with sampling', () => {
const error = new Error('intentional');
sandbox.stub(Math, 'random').callsFake(() => 0.005);
window.AMP_MODE = {development: false};
window.__AMP_MODE = {development: false};
a4a.promiseErrorHandler_(error);
expect(devExpectedErrorStub).to.be.calledOnce;
expect(devExpectedErrorStub.args[0][1]).to.be.equal(error);
Expand All @@ -2631,7 +2631,7 @@ describe('amp-a4a', () => {
it('should NOT send an expected error in prod mode with sampling', () => {
const error = new Error('intentional');
sandbox.stub(Math, 'random').callsFake(() => 0.011);
window.AMP_MODE = {development: false};
window.__AMP_MODE = {development: false};
a4a.promiseErrorHandler_(error);
expect(devExpectedErrorStub).to.not.be.called;
});
Expand Down Expand Up @@ -2932,7 +2932,7 @@ describes.realWin('AmpA4a-RTC', {amp: true}, env => {
beforeEach(() => {
sandbox = env.sandbox;
// ensures window location == AMP cache passes
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;
const doc = env.win.document;
element = createElementWithAttributes(env.win.document, 'amp-ad', {
'width': '200',
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/test/test-amp-ad-template-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describes.fakeWin('AmpAdTemplateHelper', {amp: true}, env => {

beforeEach(() => {
win = env.win;
win.AMP_MODE = {localDev: false};
win.__AMP_MODE = {localDev: false};
doc = win.document;
fetchTextMock = sandbox.stub(Xhr.prototype, 'fetchText');
ampAdTemplateHelper = new AmpAdTemplateHelper(win);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describes.realWin('real-time-config-manager', {amp: true}, env => {
sandbox = env.sandbox;

// Ensures window location == AMP cache passes.
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;

const doc = env.win.document;
element = createElementWithAttributes(env.win.document, 'amp-ad', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describes.fakeWin('amp-ad-network-adzerk-impl', {amp: true}, env => {

beforeEach(() => {
win = env.win;
win.AMP_MODE = {localDev: false};
win.__AMP_MODE = {localDev: false};
win.AMP.registerTemplate('amp-mustache', AmpMustache);
doc = win.document;
fetchTextMock = sandbox.stub(Xhr.prototype, 'fetchText');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describes.realWin('DoubleClick Fast Fetch Fluid', realWinConfig, env => {

beforeEach(() => {
sandbox = env.sandbox;
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;
const doc = env.win.document;
// TODO(a4a-cam@): This is necessary in the short term, until A4A is
// smarter about host document styling. The issue is that it needs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describes.realWin('DoubleClick Fast Fetch RTC', {amp: true}, env => {

beforeEach(() => {
sandbox = env.sandbox;
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;
const doc = env.win.document;
// TODO(a4a-cam@): This is necessary in the short term, until A4A is
// smarter about host document styling. The issue is that it needs to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describes.realWin('DoubleClick Fast Fetch - Safeframe', realWinConfig, env => {

beforeEach(() => {
sandbox = env.sandbox;
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;
doc = env.win.document;
setup(ampAdHeight, ampAdWidth, ampAdHeight, ampAdWidth);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describes.realWin('Doubleclick SRA', config, env => {
doc = env.win.document;
sandbox = env.sandbox;
// ensures window location == AMP cache passes
env.win.AMP_MODE.test = true;
env.win.__AMP_MODE.test = true;
});

function createAndAppendAdElement(opt_attributes, opt_type, opt_domElement) {
Expand Down
8 changes: 4 additions & 4 deletions extensions/amp-analytics/0.1/test/test-amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ describes.realWin(
}

it('does send a hit when parentPostMessage is provided inabox', function() {
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
const analytics = getAnalyticsTag({
'requests': {'foo': 'https://example.com/bar'},
'triggers': [{'on': 'visible', 'parentPostMessage': 'foo'}],
Expand Down Expand Up @@ -1813,7 +1813,7 @@ describes.realWin(
});

it('not send when request and parentPostMessage are not provided', function() {
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
expectAsyncConsoleError(onAndRequestAttributesInaboxError);
const analytics = getAnalyticsTag({
'requests': {'foo': 'https://example.com/bar'},
Expand All @@ -1826,7 +1826,7 @@ describes.realWin(
});

it('send when request and parentPostMessage are provided', function() {
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
const analytics = getAnalyticsTag({
'requests': {'foo': 'https://example.com/bar'},
'triggers': [
Expand Down Expand Up @@ -1868,7 +1868,7 @@ describes.realWin(
});

it('is 0 for inabox', () => {
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
expect(getAnalyticsTag(getConfig()).getLayoutPriority()).to.equal(
LayoutPriority.CONTENT
);
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/test/test-analytics-root.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describes.realWin('AmpdocAnalyticsRoot', {amp: 1}, env => {
});

it('should provide the correct rect for ini-load for inabox', () => {
win.AMP_MODE = {runtime: 'inabox'};
win.__AMP_MODE = {runtime: 'inabox'};
sandbox.stub(viewport, 'getLayoutRect').callsFake(element => {
if (element == win.document.documentElement) {
return {left: 10, top: 11, width: 100, height: 200};
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/test/test-cookie-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describes.realWin(
});

it('Resolve when in inabox ad', () => {
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
const config = dict({
'cookies': {
'testId': {
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/test/test-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ describes.realWin(
});

it('initialize iframe transport when used with inabox', () => {
win.AMP_MODE = win.AMP_MODE || {};
win.AMP_MODE.runtime = 'inabox';
win.__AMP_MODE = win.__AMP_MODE || {};
win.__AMP_MODE.runtime = 'inabox';
expect(getMode(win).runtime).to.equal('inabox');

const transport = new Transport(win, {
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/test/test-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describes.fakeWin('amp-analytics.VariableService', {amp: true}, env => {

it('COOKIE resolves to empty string when inabox', async () => {
doc.cookie = 'test=123';
env.win.AMP_MODE.runtime = 'inabox';
env.win.__AMP_MODE.runtime = 'inabox';
await check('COOKIE(test)', '');
doc.cookie = '';
});
Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-analytics/0.1/test/test-visibility-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describes.fakeWin('VisibilityManagerForDoc', {amp: true}, env => {
});

it('should resolve root layout box for in-a-box', () => {
win.AMP_MODE = {runtime: 'inabox'};
win.__AMP_MODE = {runtime: 'inabox'};
root = new VisibilityManagerForDoc(ampdoc);
const rootElement = win.document.documentElement;
sandbox.stub(viewport, 'getLayoutRect').callsFake(element => {
Expand Down Expand Up @@ -186,7 +186,7 @@ describes.fakeWin('VisibilityManagerForDoc', {amp: true}, env => {
});

it('should switch visibility for in-a-box', () => {
win.AMP_MODE = {runtime: 'inabox'};
win.__AMP_MODE = {runtime: 'inabox'};
root = new VisibilityManagerForDoc(ampdoc);

// Check observer is correctly set.
Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-bind/0.1/test/integration/test-bind-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ describe
});

it('should verify class bindings in dev mode', () => {
window.AMP_MODE = {development: true, test: true};
window.__AMP_MODE = {development: true, test: true};
createElement(env, container, '[class]="\'foo\'" class="foo"');
createElement(env, container, '[class]="\'foo\'" class=" foo "');
createElement(env, container, '[class]="\'\'"');
Expand All @@ -523,7 +523,7 @@ describe
});

it('should verify string attribute bindings in dev mode', () => {
window.AMP_MODE = {development: true, test: true};
window.__AMP_MODE = {development: true, test: true};
// Only the initial value for [a] binding does not match.
createElement(
env,
Expand All @@ -538,7 +538,7 @@ describe
});

it('should verify boolean attribute bindings in dev mode', () => {
window.AMP_MODE = {development: true, test: true};
window.__AMP_MODE = {development: true, test: true};
createElement(env, container, '[disabled]="true" disabled', 'button');
createElement(env, container, '[disabled]="false"', 'button');
createElement(env, container, '[disabled]="true"', 'button'); // Mismatch.
Expand Down
22 changes: 11 additions & 11 deletions extensions/amp-geo/0.1/test/test-amp-geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describes.realWin(
});

afterEach(() => {
delete win.AMP_MODE.geoOverride;
delete win.__AMP_MODE.geoOverride;
});

function addConfigElement(opt_elementName, opt_type, opt_textContent) {
Expand Down Expand Up @@ -171,7 +171,7 @@ describes.realWin(
});

it('should allow hash to override geo in test', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -192,7 +192,7 @@ describes.realWin(
});

it('should allow preset country groups', () => {
win.AMP_MODE.geoOverride = 'fr';
win.__AMP_MODE.geoOverride = 'fr';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -207,7 +207,7 @@ describes.realWin(
});

it('should set amp-geo-no-group if no group matches', () => {
win.AMP_MODE.geoOverride = 'za';
win.__AMP_MODE.geoOverride = 'za';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -226,7 +226,7 @@ describes.realWin(
});

it('should return configured and matched groups in `geo` service', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -240,7 +240,7 @@ describes.realWin(
});

it('isInCountryGroup works with multiple group targets', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -259,7 +259,7 @@ describes.realWin(
});

it('isInCountryGroup works with single group targets', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -276,7 +276,7 @@ describes.realWin(
});

it('should allow uppercase hash to override geo in test', () => {
win.AMP_MODE.geoOverride = 'NZ';
win.__AMP_MODE.geoOverride = 'NZ';
addConfigElement('script');
geo.buildCallback();

Expand All @@ -291,7 +291,7 @@ describes.realWin(
});

it('should accept uppercase country codes in config', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
addConfigElement(
'script',
'application/json',
Expand Down Expand Up @@ -329,7 +329,7 @@ describes.realWin(
});

it('should allow hash to override pre-rendered geo in test', () => {
win.AMP_MODE.geoOverride = 'nz';
win.__AMP_MODE.geoOverride = 'nz';
doc.body.classList.add('amp-iso-country-mx', 'amp-geo-group-nafta');
addConfigElement('script');
geo.buildCallback();
Expand Down Expand Up @@ -376,7 +376,7 @@ describes.realWin(

it('geo should log an error if unpatched in production. ', () => {
expectAsyncConsoleError(/GEONOTPATCHED/);
sandbox.stub(win.AMP_MODE, 'localDev').value(false);
sandbox.stub(win.__AMP_MODE, 'localDev').value(false);
addConfigElement('script');

geo.buildCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe.configure().skip('amp-lightbox-gallery', function() {

beforeEach(() => {
win = env.win;
win.AMP_MODE.localDev = true;
win.__AMP_MODE.localDev = true;
triggerAnalyticsEventSpy = env.sandbox.spy(
analytics,
'triggerAnalyticsEvent'
Expand Down Expand Up @@ -210,7 +210,7 @@ describe.configure().skip('amp-lightbox-gallery', function() {

beforeEach(() => {
win = env.win;
win.AMP_MODE.localDev = true;
win.__AMP_MODE.localDev = true;
triggerAnalyticsEventSpy = env.sandbox.spy(
analytics,
'triggerAnalyticsEvent'
Expand Down
6 changes: 3 additions & 3 deletions src/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ let rtvVersion = '';
*/
export function getMode(opt_win) {
const win = opt_win || self;
if (win.AMP_MODE) {
return win.AMP_MODE;
if (win.__AMP_MODE) {
return win.__AMP_MODE;
}
return (win.AMP_MODE = getMode_(win));
return (win.__AMP_MODE = getMode_(win));
}

/**
Expand Down
Loading

0 comments on commit 2cf7ec2

Please sign in to comment.