From 4b3dd8b2e6aa89d3f4b88be309a2dcd937e0cf6f Mon Sep 17 00:00:00 2001 From: William Chou Date: Mon, 23 Jan 2017 14:57:56 -0500 Subject: [PATCH] Add amp-bind experiment (#7157) * add amp-bind experiment * add experiment check to amp-state * fix unit test --- extensions/amp-bind/0.1/amp-state.js | 4 ++++ extensions/amp-bind/0.1/bind-impl.js | 2 +- extensions/amp-bind/0.1/test/test-bind-impl.js | 12 ++++++------ tools/experiments/experiments.js | 7 +++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/extensions/amp-bind/0.1/amp-state.js b/extensions/amp-bind/0.1/amp-state.js index 3ba75c4e87f7..129dc4580551 100644 --- a/extensions/amp-bind/0.1/amp-state.js +++ b/extensions/amp-bind/0.1/amp-state.js @@ -15,6 +15,7 @@ */ import {bindForDoc} from '../../../src/bind'; +import {isExperimentOn} from '../../../src/experiments'; import {isJsonScriptTag} from '../../../src/dom'; import {toggle} from '../../../src/style'; import {tryParseJson} from '../../../src/json'; @@ -47,6 +48,9 @@ export class AmpState extends AMP.BaseElement { /** @override */ buildCallback() { + user().assert(isExperimentOn(this.win, 'amp-bind'), + `Experiment "amp-bind" is disabled.`); + const TAG = this.getName_(); toggle(this.element, false); diff --git a/extensions/amp-bind/0.1/bind-impl.js b/extensions/amp-bind/0.1/bind-impl.js index 43a24c5123a1..9438a5d6d3fc 100644 --- a/extensions/amp-bind/0.1/bind-impl.js +++ b/extensions/amp-bind/0.1/bind-impl.js @@ -23,7 +23,7 @@ import {isExperimentOn} from '../../../src/experiments'; import {isFiniteNumber} from '../../../src/types'; import {resourcesForDoc} from '../../../src/resources'; -const TAG = 'AMP-BIND'; +const TAG = 'amp-bind'; /** * Regular expression that identifies AMP CSS classes. diff --git a/extensions/amp-bind/0.1/test/test-bind-impl.js b/extensions/amp-bind/0.1/test/test-bind-impl.js index ea164509bc65..32dae93bbe97 100644 --- a/extensions/amp-bind/0.1/test/test-bind-impl.js +++ b/extensions/amp-bind/0.1/test/test-bind-impl.js @@ -32,7 +32,7 @@ describes.realWin('amp-bind', { let canBindStub; beforeEach(() => { - toggleExperiment(env.win, 'AMP-BIND', true); + toggleExperiment(env.win, 'amp-bind', true); // Stub validator methods to return true for ease of testing. canBindStub = env.sandbox.stub( @@ -44,7 +44,7 @@ describes.realWin('amp-bind', { }); afterEach(() => { - toggleExperiment(env.win, 'AMP-BIND', false); + toggleExperiment(env.win, 'amp-bind', false); }); /** @@ -105,10 +105,10 @@ describes.realWin('amp-bind', { } it('should throw error if experiment is not enabled', () => { - toggleExperiment(env.win, 'AMP-BIND', false); + toggleExperiment(env.win, 'amp-bind', false); expect(() => { new Bind(env.ampdoc); - }).to.throw('Experiment "AMP-BIND" is disabled.'); + }).to.throw('Experiment "amp-bind" is disabled.'); }); it('should scan for bindings when ampdoc is ready', () => { @@ -131,7 +131,7 @@ describes.realWin('amp-bind', { env.sandbox.stub(window, 'AMP_MODE', {development: true}); // Only the initial value for [a] binding does not match. createElementWithBinding('[a]="a" [b]="b" b="b"'); - const errorStub = env.sandbox.stub(user(), 'error').withArgs('AMP-BIND'); + const errorStub = env.sandbox.stub(user(), 'error').withArgs('amp-bind'); return onBindReady(() => { expect(errorStub.callCount).to.equal(1); }); @@ -141,7 +141,7 @@ describes.realWin('amp-bind', { env.sandbox.stub(window, 'AMP_MODE', {development: true}); // Only the initial value for [c] binding does not match. createElementWithBinding(`a [a]="true" [b]="false" c="false" [c]="false"`); - const errorStub = env.sandbox.stub(user(), 'error').withArgs('AMP-BIND'); + const errorStub = env.sandbox.stub(user(), 'error').withArgs('amp-bind'); return onBindReady(() => { expect(errorStub.callCount).to.equal(1); }); diff --git a/tools/experiments/experiments.js b/tools/experiments/experiments.js index db1a06494211..a022666d25c3 100644 --- a/tools/experiments/experiments.js +++ b/tools/experiments/experiments.js @@ -242,6 +242,13 @@ const EXPERIMENTS = [ name: 'Format to apply filters to analytics variables', cleanupIssue: 'https://github.com/ampproject/amphtml/issues/2198', }, + { + id: 'amp-bind', + name: 'AMP extension for dynamic content', + cleanupIssue: 'https://github.com/ampproject/amphtml/issues/7156', + spec: 'https://github.com/ampproject/amphtml/blob/master/extensions/' + + 'amp-bind/amp-bind.md', + }, ]; if (getMode().localDev) {