Skip to content

Commit

Permalink
Merge tag '1455773092418' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinmombay committed Feb 18, 2016
2 parents 4727058 + 80c66ec commit a2688b6
Show file tree
Hide file tree
Showing 58 changed files with 1,114 additions and 556 deletions.
1 change: 1 addition & 0 deletions build-system/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ module.exports = {
'!validator/node_modules/**/*.*',
'!build-system/tasks/presubmit-checks.js',
'!build/polyfills.js',
'!build/polyfills/*.js',
'!gulpfile.js',
'!third_party/**/*.*',
],
Expand Down
55 changes: 55 additions & 0 deletions build-system/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

readonly MERGE_FOLDER="${HOME}/.amp-release/amphtml"

rm -rvf "$MERGE_FOLDER"

mkdir -p "$MERGE_FOLDER"

git clone https://github.com/ampproject/amphtml.git "$MERGE_FOLDER"

cd "$MERGE_FOLDER"
echo "===================="
echo "in folder $(pwd)"
echo "===================="

git checkout canary

git merge master

echo "done with merging master into canary"
echo "===================="

git checkout release

readonly last_release_tag=$(git describe --abbrev=0 --first-parent --tags canary)

echo "trying to merging ${last_release_tag} into release"

git merge "$last_release_tag"

echo "done with merging ${last_release_tag} into canary"
echo "===================="

git checkout master

echo "
====================
Please manually push the branches if merges were successful.
If canary was not ahead of release, you might not need to push release
and merge would have exited with \"Already-up-to-date.\"
cd ${MERGE_FOLDER}
https push (needs auth login entry):
git push https://github.com/ampproject/amphtml.git canary
git push https://github.com/ampproject/amphtml.git release
ssh push:
git push git@github.com:ampproject/amphtml.git canary
git push git@github.com:ampproject/amphtml.git release
single line ssh push (if both branches can be pushed):
cd ${MERGE_FOLDER} && git push git@github.com:ampproject/amphtml.git canary && git push git@github.com:ampproject/amphtml.git release
"
33 changes: 24 additions & 9 deletions build-system/tasks/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var rename = require('gulp-rename');
var replace = require('gulp-replace');
var internalRuntimeVersion = require('../internal-version').VERSION;
var internalRuntimeToken = require('../internal-version').TOKEN;
var rimraf = require('rimraf');

var isProdBuild = !!argv.type;
var queue = [];
Expand Down Expand Up @@ -69,14 +70,12 @@ function compile(entryModuleFilename, outputDir,
entryModuleFilename.replace(/\//g, '_').replace(/^\./, '');
console./*OK*/log('Starting closure compiler for ', entryModuleFilename);
fs.mkdirsSync('build/cc');
rimraf.sync('build/fake-module');
fs.mkdirsSync('build/fake-module/third_party/babel');
fs.mkdirsSync('build/fake-module/src');
fs.writeFileSync(
'build/fake-module/third_party/babel/custom-babel-helpers.js',
'// Not needed in closure compiler\n');
fs.writeFileSync(
'build/fake-module/src/polyfills.js',
'// Not needed in closure compiler\n');
fs.mkdirsSync('build/fake-module/src/polyfills/');
var unneededFiles = [
'build/fake-module/third_party/babel/custom-babel-helpers.js',
];
var wrapper = windowConfig.getTemplate() +
'(function(){var process={env:{NODE_ENV:"production"}};' +
'%output%})();';
Expand Down Expand Up @@ -106,6 +105,7 @@ function compile(entryModuleFilename, outputDir,
'build/**/*.js',
'!build/cc/**',
'!build/polyfills.js',
'!build/polyfills/**/*.js',
'src/**/*.js',
'!third_party/babel/custom-babel-helpers.js',
// Exclude since it's not part of the runtime/extension binaries.
Expand All @@ -114,6 +114,7 @@ function compile(entryModuleFilename, outputDir,
'third_party/caja/html-sanitizer.js',
'third_party/closure-library/sha384-generated.js',
'third_party/mustache/**/*.js',
'node_modules/promise-pjs/promise.js',
'node_modules/document-register-element/build/' +
'document-register-element.max.js',
'node_modules/core-js/modules/**.js',
Expand All @@ -128,10 +129,24 @@ function compile(entryModuleFilename, outputDir,
// once. Since all files automatically wait for the main binary to load
// this works fine.
if (options.includePolyfills) {
srcs.push('!build/fake-module/src/polyfills.js');
srcs.push(
'!build/fake-module/src/polyfills.js',
'!build/fake-module/src/polyfills/**/*.js'
);
} else {
srcs.push('!src/polyfills.js');
srcs.push(
'!src/polyfills.js',
'!src/polyfills/**/*.js'
);
unneededFiles.push(
'build/fake-module/src/polyfills.js',
'build/fake-module/src/polyfills/promise.js',
'build/fake-module/src/polyfills/math-sign.js'
);
}
unneededFiles.forEach(function(fake) {
fs.writeFileSync(fake, '// Not needed in closure compiler\n');
});
/*eslint "google-camelcase/google-camelcase": 0*/
return gulp.src(srcs)
.pipe(closureCompiler({
Expand Down
2 changes: 0 additions & 2 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ var forbiddenTerms = {
'Array\\.of': es6polyfill,
// These currently depend on core-js/modules/web.dom.iterable which
// we don't want. That decision could be reconsidered.
'Promise\\.all': es6polyfill,
'Promise\\.race': es6polyfill,
'\\.startsWith': {
message: es6polyfill,
whitelist: [
Expand Down
2 changes: 1 addition & 1 deletion builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export function installAd(win) {
}
return cidForOrNull(this.getWin()).then(cidService => {
if (!cidService) {
return Promise.resolve();
return;
}
let consent = Promise.resolve();
const consentId = this.element.getAttribute(
Expand Down
5 changes: 2 additions & 3 deletions examples/analytics-notification.amp.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
background: #46b6ac;
}

amp-user-notification button {
amp-user-notification .btn {
border: none;
border-radius: 2px;

Expand Down Expand Up @@ -69,8 +69,7 @@
data-show-if-href="http://localhost:8000/api/show?timestamp=TIMESTAMP"
data-dismiss-href="http://localhost:8000/api/echo/post">
This site uses cookies to personalize content.
<a href="#learn-more">Learn more.</a>
<button on="tap:amp-user-notification1.dismiss">I accept</button>
<a class="btn" on="tap:amp-user-notification1.dismiss">I accept</a>
</amp-user-notification>

<amp-analytics data-consent-notification-id="amp-user-notification1">
Expand Down
24 changes: 18 additions & 6 deletions extensions/amp-access/0.1/amp-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import {all} from '../../../src/promise';
import {actionServiceFor} from '../../../src/action';
import {analyticsFor} from '../../../src/analytics';
import {assert, assertEnumValue} from '../../../src/asserts';
Expand Down Expand Up @@ -168,6 +167,9 @@ export class AccessService {
/** @private {?Promise} */
this.loginPromise_ = null;

/** @private {time} */
this.loginStartTime_ = 0;

/** @private {!Promise<!InstrumentationService>} */
this.analyticsPromise_ = analyticsFor(this.win);

Expand Down Expand Up @@ -438,7 +440,7 @@ export class AccessService {
for (let i = 0; i < elements.length; i++) {
promises.push(this.applyAuthorizationToElement_(elements[i], response));
}
return all(promises);
return Promise.all(promises);
}

/**
Expand Down Expand Up @@ -502,7 +504,7 @@ export class AccessService {
promises.push(p);
}
}
return promises.length > 0 ? all(promises) : null;
return promises.length > 0 ? Promise.all(promises) : null;
}

/**
Expand Down Expand Up @@ -675,7 +677,13 @@ export class AccessService {
* @return {!Promise}
*/
login() {
if (this.loginPromise_) {
const now = this.timer_.now();

// If login is pending, block a new one from starting for 1 second. After
// 1 second, however, the new login request will be allowed to proceed,
// given that we cannot always determine fully if the previous attempt is
// "stuck".
if (this.loginPromise_ && (now - this.loginStartTime_ < 1000)) {
return this.loginPromise_;
}

Expand All @@ -684,7 +692,7 @@ export class AccessService {
// Login URL should always be available at this time.
const loginUrl = assert(this.loginUrl_, 'Login URL is not ready');
this.analyticsEvent_('access-login-started');
this.loginPromise_ = this.openLoginDialog_(loginUrl).then(result => {
const loginPromise = this.openLoginDialog_(loginUrl).then(result => {
log.fine(TAG, 'Login dialog completed: ', result);
this.loginPromise_ = null;
const query = parseQueryString(result);
Expand All @@ -701,9 +709,13 @@ export class AccessService {
}).catch(reason => {
log.fine(TAG, 'Login dialog failed: ', reason);
this.analyticsEvent_('access-login-failed');
this.loginPromise_ = null;
if (this.loginPromise_ == loginPromise) {
this.loginPromise_ = null;
}
throw reason;
});
this.loginPromise_ = loginPromise;
this.loginStartTime_ = now;
return this.loginPromise_;
}

Expand Down
33 changes: 27 additions & 6 deletions extensions/amp-access/0.1/test/test-amp-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,13 +958,15 @@ describe('AccessService pingback', () => {
describe('AccessService login', () => {

let sandbox;
let clock;
let configElement;
let cidMock;
let analyticsMock;
let serviceMock;

beforeEach(() => {
sandbox = sinon.sandbox.create();
clock = sandbox.useFakeTimers();

markElementScheduledForTesting(window, 'amp-analytics');
installCidService(window);
Expand Down Expand Up @@ -1126,16 +1128,35 @@ describe('AccessService login', () => {
});
});

it('should run login only once at a time', () => {
it('should block login for 1 second', () => {
let p1Reject;
const p1Promise = new Promise((unusedResolve, reject) => {
p1Reject = reject;
});
service.runAuthorization_ = sandbox.spy();
serviceMock.expects('openLoginDialog_')
.withExactArgs('https://acme.com/l?rid=R')
.returns(new Promise(() => {}))
.once();
const openLoginDialogStub = sandbox.stub(service, 'openLoginDialog_');
openLoginDialogStub.onCall(0).returns(p1Promise);
openLoginDialogStub.onCall(1).returns(new Promise(() => {}));
openLoginDialogStub.onCall(2).throws();
const p1 = service.login();

// The immediate second attempt is blocked.
const p2 = service.login();
expect(p1).to.equal(service.loginPromise_);
expect(service.loginPromise_).to.equal(p1);
expect(p2).to.equal(p1);

// The delayed third attempt succeeds after 1 second.
clock.tick(1001);
const p3 = service.login();
expect(service.loginPromise_).to.equal(p3);
expect(p3).to.not.equal(p1);

// Rejecting the first login attempt does not reject the current promise.
p1Reject();
return p1Promise.then(() => 'SUCCESS', () => 'ERROR').then(res => {
expect(res).to.equal('ERROR');
expect(service.loginPromise_).to.equal(p3);
});
});
});

Expand Down
10 changes: 7 additions & 3 deletions extensions/amp-analytics/0.1/amp-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class AmpAnalytics extends AMP.BaseElement {
* @return {!Promise<>}
*/
fetchRemoteConfig_() {
const remoteConfigUrl = this.element.getAttribute('config');
let remoteConfigUrl = this.element.getAttribute('config');
if (!remoteConfigUrl) {
return Promise.resolve();
}
Expand All @@ -188,13 +188,17 @@ export class AmpAnalytics extends AMP.BaseElement {
if (this.element.hasAttribute('data-credentials')) {
fetchConfig.credentials = this.element.getAttribute('data-credentials');
}
return xhrFor(this.getWin()).fetchJson(remoteConfigUrl, fetchConfig)
return urlReplacementsFor(this.getWin()).expand(remoteConfigUrl)
.then(expandedUrl => {
remoteConfigUrl = expandedUrl;
return xhrFor(this.getWin()).fetchJson(remoteConfigUrl, fetchConfig);
})
.then(jsonValue => {
this.remoteConfig_ = jsonValue;
log.fine(this.getName_(), 'Remote config loaded', remoteConfigUrl);
}, err => {
console./*OK*/error(this.getName_(), 'Error loading remote config: ',
remoteConfigUrl, err);
remoteConfigUrl, err);
});
}

Expand Down
15 changes: 14 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 @@ -38,7 +38,8 @@ describe('amp-analytics', function() {
let uidService;

const jsonMockResponses = {
'config1': '{"vars": {"title": "remote"}}'
'config1': '{"vars": {"title": "remote"}}',
'https://foo/Test%20Title': '{"vars": {"title": "magic"}}'
};

beforeEach(() => {
Expand Down Expand Up @@ -588,6 +589,18 @@ describe('amp-analytics', function() {
});
});

it('expands urls in config request', () => {
const analytics = getAnalyticsTag({
'requests': {'foo': 'https://example.com/${title}'},
'triggers': [{'on': 'visible', 'request': 'foo'}]
}, {
'config': 'https://foo/TITLE'
});
return waitForSendRequest(analytics).then(() => {
expect(sendRequestSpy.args[0][0]).to.equal('https://example.com/magic');
});
});

it('updates requestCount on each request', () => {
const analytics = getAnalyticsTag({
'host': 'example.com',
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/0.1/vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const ANALYTICS_CONFIG = {
'atinternet': {
'transport': {'beacon': false, 'xhrpost': false, 'image': true},
'requests': {
'base': 'https://${log}${domain}/?s=${site}&ts=${timestamp}&r=${screenWidth}x${screenHeight}x${screenColorDepth}&re=${availableScreenWidth}x${availableScreenHeight}',
'base': 'https://${log}${domain}/hit.xiti?s=${site}&ts=${timestamp}&r=${screenWidth}x${screenHeight}x${screenColorDepth}&re=${availableScreenWidth}x${availableScreenHeight}',
'suffix': '&ref=${documentReferrer}',
'pageview': '${base}&' +
'p=${title}&' +
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-analytics/amp-analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Adds support for Quantcast Measurement. More details for adding Quantcast Measur
#### <a name="attributes"></a>Attributes

- `type` See [Analytics vendors](#analytics-vendors)
- `config` Optional attribute. This attribute can be used to load a configuration from a specified remote URL. The URL specified here should use https scheme. See also `data-include-credentials` attribute below.
- `config` Optional attribute. This attribute can be used to load a configuration from a specified remote URL. The URL specified here should use https scheme. See also `data-include-credentials` attribute below. The URL may include [AMP URL vars](../../spec/amp-var-substitutions.md).

```
<amp-analytics config="https://example.com/analytics.config.json"></amp-analytics>
Expand Down
1 change: 0 additions & 1 deletion extensions/amp-carousel/0.1/base-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export class BaseCarousel extends AMP.BaseElement {
*/
go(dir, animate) {
this.goCallback(dir, animate);
this.setControlsState();
}

/**
Expand Down
1 change: 1 addition & 0 deletions extensions/amp-carousel/0.1/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class AmpCarousel extends BaseCarousel {
this.doLayout_(newPos);
this.preloadNext_(newPos, Math.sign(newPos - oldPos));
this.updateInViewport_(newPos, oldPos);
this.setControlsState();
}

/**
Expand Down
Loading

0 comments on commit a2688b6

Please sign in to comment.