Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
William Chou committed Jul 14, 2017
1 parent 4fc7be9 commit 8201942
Show file tree
Hide file tree
Showing 34 changed files with 187 additions and 134 deletions.
3 changes: 2 additions & 1 deletion ads/google/a4a/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ function elapsedTimeWithCeiling(time, start) {
export function getCorrelator(win, opt_cid, opt_nodeOrDoc) {
if (!win.ampAdPageCorrelator) {
win.ampAdPageCorrelator = makeCorrelator(
opt_cid, Services.documentInfoForDoc(opt_nodeOrDoc || win.document).pageViewId);
opt_cid,
Services.documentInfoForDoc(opt_nodeOrDoc || win.document).pageViewId);
}
return win.ampAdPageCorrelator;
}
Expand Down
11 changes: 6 additions & 5 deletions extensions/amp-ad/0.1/amp-ad-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export class AmpAdCustom extends AMP.BaseElement {
// If this promise has no URL yet, create one for it.
if (!(fullUrl in ampCustomadXhrPromises)) {
// Here is a promise that will return the data for this URL
ampCustomadXhrPromises[fullUrl] = Services.xhrFor(this.win).fetchJson(fullUrl)
.then(res => res.json());
ampCustomadXhrPromises[fullUrl] =
Services.xhrFor(this.win).fetchJson(fullUrl).then(res => res.json());
}
return ampCustomadXhrPromises[fullUrl].then(data => {
const element = this.element;
Expand All @@ -98,10 +98,11 @@ export class AmpAdCustom extends AMP.BaseElement {
// Set UI state
if (templateData !== null && typeof templateData == 'object') {
this.renderStarted();
Services.templatesFor(this.win).findAndRenderTemplate(element, templateData)
Services.templatesFor(this.win)
.findAndRenderTemplate(element, templateData)
.then(renderedElement => {
// Get here when the template has been rendered
// Clear out the template and replace it by the rendered version
// Get here when the template has been rendered
// Clear out the template and replace it by the rendered version
removeChildren(element);
element.appendChild(renderedElement);
});
Expand Down
9 changes: 6 additions & 3 deletions extensions/amp-analytics/0.1/amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,12 @@ export class AmpAnalytics extends AMP.BaseElement {
fetchConfig.credentials = this.element.getAttribute('data-credentials');
}
const ampdoc = this.getAmpDoc();
return Services.urlReplacementsForDoc(this.element).expandAsync(remoteConfigUrl)
return Services.urlReplacementsForDoc(this.element)
.expandAsync(remoteConfigUrl)
.then(expandedUrl => {
remoteConfigUrl = expandedUrl;
return Services.xhrFor(ampdoc.win).fetchJson(remoteConfigUrl, fetchConfig);
return Services.xhrFor(ampdoc.win).fetchJson(
remoteConfigUrl, fetchConfig);
})
.then(res => res.json())
.then(jsonValue => {
Expand Down Expand Up @@ -682,7 +684,8 @@ export class AmpAnalytics extends AMP.BaseElement {
*/
expandTemplateWithUrlParams_(spec, expansionOptions) {
return this.variableService_.expandTemplate(spec, expansionOptions)
.then(key => Services.urlReplacementsForDoc(this.element).expandUrlAsync(key));
.then(key => Services.urlReplacementsForDoc(
this.element).expandUrlAsync(key));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-analytics/0.1/test/test-amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ describe('amp-analytics', function() {
const analytics = getAnalyticsTag(clearVendorOnlyConfig(config));
analytics.createdCallback();
analytics.buildCallback();
const urlReplacements = Services.urlReplacementsForDoc(analytics.element);
const urlReplacements =
Services.urlReplacementsForDoc(analytics.element);
sandbox.stub(urlReplacements.getVariableSource(), 'get',
function(name) {
expect(this.replacements_).to.have.property(name);
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-auto-ads/0.1/anchor-ad-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export class AnchorAdStrategy {
}

placeStickyAd_() {
const viewportWidth = Services.viewportForDoc(this.win_.document).getWidth();
const viewportWidth =
Services.viewportForDoc(this.win_.document).getWidth();
const attributes = /** @type {!JsonObject} */ (
Object.assign(dict(), this.baseAttributes_, dict({
'width': String(viewportWidth),
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-auto-ads/0.1/test/test-ad-network-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ describes.realWin('ad-network-config', {
});

it('should get the ad constraints', () => {
const viewportMock = sandbox.mock(Services.viewportForDoc(env.win.document));
const viewportMock =
sandbox.mock(Services.viewportForDoc(env.win.document));
viewportMock.expects('getSize').returns(
{width: 320, height: 500}).atLeast(1);

Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-auto-ads/0.1/test/test-amp-auto-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ describes.realWin('amp-auto-ads', {
toggleExperiment(env.win, 'amp-auto-ads', true);
sandbox = env.sandbox;

const viewportMock = sandbox.mock(Services.viewportForDoc(env.win.document));
const viewportMock =
sandbox.mock(Services.viewportForDoc(env.win.document));
viewportMock.expects('getSize').returns(
{width: 320, height: 500}).atLeast(1);

Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-auto-ads/0.1/test/test-anchor-ad-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describes.realWin('anchor-ad-strategy', {

beforeEach(() => {
sandbox = env.sandbox;
const viewportMock = sandbox.mock(Services.viewportForDoc(env.win.document));
const viewportMock =
sandbox.mock(Services.viewportForDoc(env.win.document));
viewportMock.expects('getWidth').returns(360).atLeast(1);

configObj = {
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-carousel/0.1/slidescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export class AmpSlideScroll extends BaseSlides {
/** @private {boolean} */
this.shouldDisableCssSnap_ = isExperimentOn(this.win,
'slidescroll-disable-css-snap') &&
startsWith(Services.platformFor(this.win).getIosVersionString(), '10.3');
startsWith(
Services.platformFor(this.win).getIosVersionString(), '10.3');
}

/** @override */
Expand Down
9 changes: 5 additions & 4 deletions extensions/amp-experiment/0.1/variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ function getBucketTicket(ampdoc, group, opt_cidScope) {
return Promise.resolve(ampdoc.win.Math.random() * 100);
}

const cidPromise = Services.cidForDoc(ampdoc).then(cidService => cidService.get({
scope: dev().assertString(opt_cidScope),
createCookieIfNotPresent: true,
}, Promise.resolve()));
const cidPromise = Services.cidForDoc(ampdoc).then(cidService =>
cidService.get({
scope: dev().assertString(opt_cidScope),
createCookieIfNotPresent: true,
}, Promise.resolve()));

return Promise.all([cidPromise, Services.cryptoFor(ampdoc.win)])
.then(results => results[1].uniform(group + ':' + results[0]))
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-image-lightbox/0.1/amp-image-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ class AmpImageLightbox extends AMP.BaseElement {
// element size depends on window size directly and the measurement
// happens in window.resize event. Adding a timeout for correct
// measurement. See https://github.com/ampproject/amphtml/issues/8479
if (startsWith(Services.platformFor(this.win).getIosVersionString(), '10.3')) {
if (startsWith(
Services.platformFor(this.win).getIosVersionString(), '10.3')) {
Services.timerFor(this.win).delay(() => {
this.imageViewer_.measure();
}, 500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ describe('amp-image-lightbox image viewer', () => {
lightboxMock = sandbox.mock(lightbox);
loadPromiseStub = sandbox.stub().returns(Promise.resolve());

sandbox.stub(Services.timerFor(window), 'promise').returns(Promise.resolve());
sandbox.stub(Services.timerFor(window), 'promise')
.returns(Promise.resolve());
imageViewer = new ImageViewer(lightbox, window, loadPromiseStub);
document.body.appendChild(imageViewer.getElement());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export class AmpInstallServiceWorker extends AMP.BaseElement {
waitToPreloadShell_(shellUrl) {
// Ensure that document is loaded and visible first.
const whenReady = this.loadPromise(this.win);
const whenVisible = Services.viewerForDoc(this.getAmpDoc()).whenFirstVisible();
const whenVisible =
Services.viewerForDoc(this.getAmpDoc()).whenFirstVisible();
return Promise.all([whenReady, whenVisible]).then(() => {
this.deferMutate(() => this.preloadShell_(shellUrl));
});
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-live-list/0.1/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export class Poller {
if (opt_immediate) {
work();
} else {
this.lastTimeoutId_ = Services.timerFor(this.win).delay(work, this.getTimeout_());
this.lastTimeoutId_ =
Services.timerFor(this.win).delay(work, this.getTimeout_());
}
}
}
138 changes: 75 additions & 63 deletions extensions/amp-share-tracking/0.1/test/test-amp-share-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,39 +63,43 @@ describes.fakeWin('amp-share-tracking', {
it('should get incoming fragment starting with dot', () => {
historyGetFragmentStub.onFirstCall().returns(Promise.resolve('.12345'));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('12345');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('12345');
});
});

it('should get incoming fragment starting with dot and ignore ' +
'other parameters', () => {
historyGetFragmentStub.onFirstCall()
.returns(Promise.resolve('.12345&key=value'));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('12345');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('12345');
});
});

it('should ignore incoming fragment if it is empty', () => {
historyGetFragmentStub.onFirstCall().returns(Promise.resolve(''));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('');
});
});

it('should ignore incoming fragment if it does not start with dot', () => {
historyGetFragmentStub.onFirstCall().returns(Promise.resolve('12345'));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.incomingFragment).to.equal('');
});
});

it('should get outgoing fragment randomly if no vendor url is provided ' +
Expand All @@ -104,13 +108,14 @@ describes.fakeWin('amp-share-tracking', {
historyGetFragmentStub.onFirstCall().returns(Promise.resolve(''));
randomBytesStub.onFirstCall().returns(new Uint8Array([1, 2, 3, 4, 5, 6]));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG')).to.be
.calledOnce;
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG')).to.be
.calledOnce;
});
});

it('should get outgoing fragment randomly if no vendor url is provided ' +
Expand All @@ -119,13 +124,14 @@ describes.fakeWin('amp-share-tracking', {
historyGetFragmentStub.onFirstCall().returns(Promise.resolve('.12345'));
randomBytesStub.onFirstCall().returns(new Uint8Array([1, 2, 3, 4, 5, 6]));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG')).to.be
.calledOnce;
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG')).to.be
.calledOnce;
});
});

it('should get outgoing fragment randomly if no vendor url is provided ' +
Expand All @@ -136,13 +142,14 @@ describes.fakeWin('amp-share-tracking', {
'.12345&key=value'));
randomBytesStub.onFirstCall().returns(new Uint8Array([1, 2, 3, 4, 5, 6]));
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG&key=value'))
.to.be.calledOnce;
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
// the base64url of byte array [1, 2, 3, 4, 5, 6]
expect(fragments.outgoingFragment).to.equal('AQIDBAUG');
expect(historyUpdateFragmentStub.withArgs('.AQIDBAUG&key=value'))
.to.be.calledOnce;
});
});

it('should get outgoing fragment randomly if no vendor url ' +
Expand All @@ -151,12 +158,13 @@ describes.fakeWin('amp-share-tracking', {
sandbox.stub(Math, 'random').returns(0.123456789123456789);
randomBytesStub.onFirstCall().returns(null);
const ampShareTracking = getAmpShareTracking();
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('H5rdN8Eh');
expect(historyUpdateFragmentStub.withArgs('.H5rdN8Eh')).to.be
.calledOnce;
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('H5rdN8Eh');
expect(historyUpdateFragmentStub.withArgs('.H5rdN8Eh')).to.be
.calledOnce;
});
});

it('should get outgoing fragment from vendor if vendor url is provided ' +
Expand All @@ -169,11 +177,12 @@ describes.fakeWin('amp-share-tracking', {
},
}));
const ampShareTracking = getAmpShareTracking('http://foo.bar');
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('54321');
expect(historyUpdateFragmentStub.withArgs('.54321')).to.be.calledOnce;
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('54321');
expect(historyUpdateFragmentStub.withArgs('.54321')).to.be.calledOnce;
});
});

it('should get empty outgoing fragment if vendor url is provided ' +
Expand All @@ -185,11 +194,12 @@ describes.fakeWin('amp-share-tracking', {
},
}));
const ampShareTracking = getAmpShareTracking('http://foo.bar');
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub).to.not.be.called;
expect(fragments.outgoingFragment).to.equal('');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub).to.not.be.called;
expect(fragments.outgoingFragment).to.equal('');
});
});

it('should call fetchJson with correct request when getting outgoing' +
Expand All @@ -208,11 +218,12 @@ describes.fakeWin('amp-share-tracking', {
credentials: 'include',
body: {},
});
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub.withArgs('.54321')).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('54321');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub.withArgs('.54321')).to.be.calledOnce;
expect(fragments.outgoingFragment).to.equal('54321');
});
});

it('should get empty outgoing fragment if vendor url is provided ' +
Expand All @@ -225,10 +236,11 @@ describes.fakeWin('amp-share-tracking', {
},
}));
const ampShareTracking = getAmpShareTracking('http://foo.bar');
return Services.shareTrackingForOrNull(ampShareTracking.win).then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub).to.not.be.called;
expect(fragments.outgoingFragment).to.equal('');
});
return Services.shareTrackingForOrNull(ampShareTracking.win)
.then(fragments => {
expect(historyGetFragmentStub).to.be.calledOnce;
expect(historyUpdateFragmentStub).to.not.be.called;
expect(fragments.outgoingFragment).to.equal('');
});
});
});
Loading

0 comments on commit 8201942

Please sign in to comment.