Skip to content

Commit

Permalink
Merge branch 'master' into 20377/wait-for-head
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher De Leon committed Feb 4, 2019
2 parents cb20687 + 4242638 commit fbc5b72
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 43 deletions.
5 changes: 2 additions & 3 deletions extensions/amp-skimlinks/0.1/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

export const AMP_SKIMLINKS_VERSION = '1.0.2';
export const AMP_SKIMLINKS_VERSION = '1.0.3';
export const XCUST_ATTRIBUTE_NAME = 'data-skimlinks-custom-tracking-id';
export const AFFILIATION_API = 'https://go.skimresources.com';
export const WAYPOINT_BASE_URL = 'https://go.skimresources.com';
export const PLATFORM_NAME = 'amp@' + AMP_SKIMLINKS_VERSION;
export const SKIMLINKS_REWRITER_ID = 'amp-skimlinks';

Expand All @@ -33,7 +33,6 @@ export const DEFAULT_CONFIG = {
pageTrackingUrl: PAGE_IMPRESSION_TRACKING_URL,
linksTrackingUrl: LINKS_IMPRESSIONS_TRACKING_URL,
nonAffiliateTrackingUrl: NA_CLICK_TRACKING_URL,
waypointUrl: AFFILIATION_API,
beaconUrl: DOMAIN_RESOLVER_API_URL,
};

Expand Down
24 changes: 22 additions & 2 deletions extensions/amp-skimlinks/0.1/skim-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
DEFAULT_CONFIG,
GLOBAL_DOMAIN_BLACKLIST,
OPTIONS_ERRORS,
WAYPOINT_BASE_URL,
} from './constants';

/**
Expand All @@ -46,6 +47,7 @@ export function getAmpSkimlinksOptions(element, docInfo) {
tracking: getTrackingStatus_(element),
customTrackingId: getCustomTrackingId_(element),
linkSelector: getLinkSelector_(element),
waypointBaseUrl: getWaypointBaseUrl(element),
config: getConfig_(element),
};
}
Expand Down Expand Up @@ -147,6 +149,26 @@ function getInternalDomains_(docInfo) {
return internalDomains;
}

/**
* Use CNAME domain defined in "custom-redirect-domain" option if specified
* or "https://go.skimresources.com" by default.
* @param {!Element} element
* @return {string}
*/
function getWaypointBaseUrl(element) {
let customSubDomain = element.getAttribute('custom-redirect-domain');
if (customSubDomain) {
// Remove potential HTTP protocol and potential trailing slash.
customSubDomain = customSubDomain.replace(/^\/\/|^https?:\/\/|\/$/g, '');

// Use http since publisher CNAME to go.redirectingat.com does not support
// https.
return `http://${customSubDomain}`;
}

return WAYPOINT_BASE_URL;
}

/**
* @param {!Element} element
* @return {!Object}
Expand All @@ -166,8 +188,6 @@ function getConfig_(element) {
DEFAULT_CONFIG.linksTrackingUrl,
nonAffiliateTrackingUrl: customConfigJson['nonAffiliateTrackingUrl'] ||
DEFAULT_CONFIG.nonAffiliateTrackingUrl,
waypointUrl: customConfigJson['waypointUrl'] ||
DEFAULT_CONFIG.waypointUrl,
beaconUrl: customConfigJson['beaconUrl'] ||
DEFAULT_CONFIG.beaconUrl,
};
Expand Down
8 changes: 8 additions & 0 deletions extensions/amp-skimlinks/0.1/test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {DEFAULT_CONFIG, WAYPOINT_BASE_URL} from '../constants';

export const pubcode = 'pubXcode';

export const DEFAULT_SKIM_OPTIONS = {
pubcode,
tracking: true,
waypointBaseUrl: WAYPOINT_BASE_URL,
config: DEFAULT_CONFIG,
};
11 changes: 3 additions & 8 deletions extensions/amp-skimlinks/0.1/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

import {AmpSkimlinks} from '../amp-skimlinks';
import {CustomEventReporterBuilder} from '../../../../src/extension-analytics';
import {DEFAULT_CONFIG} from '../constants';
import {DEFAULT_SKIM_OPTIONS} from './constants';
import {Services} from '../../../../src/services';
import {Tracking} from '../tracking';
import {pubcode} from './constants';

const helpersFactory = env => {
const {win} = env;
Expand Down Expand Up @@ -58,12 +57,8 @@ const helpersFactory = env => {
},

createTrackingWithStubAnalytics(skimOptions) {
skimOptions = Object.assign(
{
tracking: true,
pubcode,
config: DEFAULT_CONFIG,
},
skimOptions = Object.assign({},
DEFAULT_SKIM_OPTIONS,
skimOptions
);
this.stubCustomEventReporterBuilder();
Expand Down
33 changes: 17 additions & 16 deletions extensions/amp-skimlinks/0.1/test/test-affiliate-link-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
AffiliateLinkResolver,
} from '../affiliate-link-resolver';
import {DEFAULT_CONFIG} from '../constants';
import {DEFAULT_SKIM_OPTIONS, pubcode} from './constants';
import {Services} from '../../../../src/services';
import {Waypoint} from '../waypoint';
import {pubcode} from './constants';
import helpersFactory from './helpers';

const DOMAIN_RESOLVER_API_URL = DEFAULT_CONFIG.beaconUrl;
Expand All @@ -48,12 +48,9 @@ describes.fakeWin(

beforeEach(() => {
trackingService = helpers.createTrackingWithStubAnalytics();
const skimOptions = {
config: {waypointUrl: 'https://go.skimresources.com/'},
};
waypoint = new Waypoint(
env.ampdoc,
skimOptions,
DEFAULT_SKIM_OPTIONS,
trackingService,
'referrer'
);
Expand Down Expand Up @@ -209,11 +206,11 @@ describes.fakeWin(
describe('Does correct request to domain resolver API', () => {
beforeEach(() => {
mock = env.sandbox.mock(xhr);
const skimOptions = {
pubcode,
config: {beaconUrl: DOMAIN_RESOLVER_API_URL},
};
resolver = new AffiliateLinkResolver(xhr, skimOptions, waypoint);
resolver = new AffiliateLinkResolver(
xhr,
DEFAULT_SKIM_OPTIONS,
waypoint
);
});

afterEach(() => {
Expand Down Expand Up @@ -287,10 +284,11 @@ describes.fakeWin(
const stubXhr = helpers.createStubXhr({
'merchant_domains': ['merchant1.com', 'merchant2.com'],
});
const skimOptions = {
excludedDomains: ['excluded-merchant.com'],
config: {beaconUrl: DOMAIN_RESOLVER_API_URL},
};
const skimOptions = Object.assign({},
DEFAULT_SKIM_OPTIONS,
{excludedDomains: ['excluded-merchant.com']}
);

resolver = new AffiliateLinkResolver(
stubXhr,
skimOptions,
Expand Down Expand Up @@ -424,8 +422,11 @@ describes.fakeWin(
});

describe('getAnchorDomain_', () => {
const skimOptions = {config: {beaconUrl: DOMAIN_RESOLVER_API_URL}};
const resolver = new AffiliateLinkResolver({}, skimOptions, waypoint);
const resolver = new AffiliateLinkResolver(
{},
DEFAULT_SKIM_OPTIONS,
waypoint
);

it('Removes http protocol', () => {
const anchor = helpers.createAnchor('http://test.com');
Expand Down
50 changes: 49 additions & 1 deletion extensions/amp-skimlinks/0.1/test/test-skim-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {WAYPOINT_BASE_URL} from '../constants';
import {getAmpSkimlinksOptions} from '../skim-options';
import helpersFactory from './helpers';

Expand Down Expand Up @@ -74,7 +75,6 @@ describes.fakeWin(
.members(['go.redirectingat.com', 'go.skimresources.com']);
});


it('Should not overwrite internal & global blacklist when using option',
() => {
const element = helpers.createAmpSkimlinksElement({
Expand All @@ -90,5 +90,53 @@ describes.fakeWin(
}
);
});

describe('custom-redirect-domain', () => {
const cname = 'go.publisher.com';

it('Should return normal waypoint base url if not defined', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
});
const options = getAmpSkimlinksOptions(element, docInfo);
expect(options.waypointBaseUrl).to.equal(WAYPOINT_BASE_URL);
});

it('Should overwrite waypoint base url if defined', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
'custom-redirect-domain': cname,
});
const options = getAmpSkimlinksOptions(element, docInfo);
expect(options.waypointBaseUrl).to.equal(`http://${cname}`);
});

it('Should accept redirect domain containing the protocol', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
'custom-redirect-domain': `http://${cname}`,
});
const options = getAmpSkimlinksOptions(element, docInfo);
expect(options.waypointBaseUrl).to.equal(`http://${cname}`);
});

it('Should force custom redirect base url to use http', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
'custom-redirect-domain': `https://${cname}`,
});
const options = getAmpSkimlinksOptions(element, docInfo);
expect(options.waypointBaseUrl).to.equal(`http://${cname}`);
});

it('Should remove trailing slash', () => {
const element = helpers.createAmpSkimlinksElement({
'publisher-code': '123X123',
'custom-redirect-domain': `https://${cname}/`,
});
const options = getAmpSkimlinksOptions(element, docInfo);
expect(options.waypointBaseUrl).to.equal(`http://${cname}`);
});
});
}
);
7 changes: 2 additions & 5 deletions extensions/amp-skimlinks/0.1/test/test-waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import {DEFAULT_SKIM_OPTIONS, pubcode} from './constants';
import {Waypoint} from '../waypoint';
import {XCUST_ATTRIBUTE_NAME} from '../constants';
import {parseQueryString, parseUrlDeprecated} from '../../../../src/url';
import {pubcode} from './constants';
import helpersFactory from './helpers';

describes.fakeWin(
Expand Down Expand Up @@ -60,12 +60,9 @@ describes.fakeWin(
canonicalUrl: 'canonical_url',
});
env.sandbox.stub(Date.prototype, 'getTimezoneOffset').returns('-120');
const skimOptions = {
config: {waypointUrl: 'https://go.skimresources.com/'},
};
waypoint = new Waypoint(
env.ampdoc,
skimOptions,
DEFAULT_SKIM_OPTIONS,
trackingService,
'referrer_url'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-->
<!--
Test Description:
Valid amp-test tag
Valid amp-skimlinks tag
-->
<!doctype html>
<html >
Expand All @@ -27,10 +27,11 @@
<body>
<amp-skimlinks
layout="nodisplay"
publisher-code="68019X1584676"
publisher-code="123X123"
excluded-domains="samsung.com asos.com"
link-selector="article:not(.no-skimlinks) a"
custom-tracking-id="phones"
custom-redirect-domain="go.publisher.com"
></amp-skimlinks>
</body>
</html>
5 changes: 3 additions & 2 deletions extensions/amp-skimlinks/0.1/test/validator-amp-skimlinks.out
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PASS
| -->
| <!--
| Test Description:
| Valid amp-test tag
| Valid amp-skimlinks tag
| -->
| <!doctype html>
| <html ⚡>
Expand All @@ -28,10 +28,11 @@ PASS
| <body>
| <amp-skimlinks
| layout="nodisplay"
| publisher-code="68019X1584676"
| publisher-code="123X123"
| excluded-domains="samsung.com asos.com"
| link-selector="article:not(.no-skimlinks) a"
| custom-tracking-id="phones"
| custom-redirect-domain="go.publisher.com"
| ></amp-skimlinks>
| </body>
| </html>
33 changes: 33 additions & 0 deletions extensions/amp-skimlinks/0.1/test/validator-minimal-options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
Copyright 2019 The AMP HTML Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the license.
-->
<!--
Test Description:
Valid amp-skimlinks tag with minimal options
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async custom-element='amp-skimlinks' src='https://cdn.ampproject.org/v0/amp-skimlinks-0.1.js'></script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<amp-skimlinks
layout="nodisplay"
publisher-code="123X123"
></amp-skimlinks>
</body>
</html>
34 changes: 34 additions & 0 deletions extensions/amp-skimlinks/0.1/test/validator-minimal-options.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
PASS
| <!--
| Copyright 2019 The AMP HTML Authors. All Rights Reserved.
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
| http://www.apache.org/licenses/LICENSE-2.0
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS-IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the license.
| -->
| <!--
| Test Description:
| Valid amp-skimlinks tag with minimal options
| -->
| <!doctype html>
| <html ⚡>
| <head>
| <meta charset="utf-8">
| <link rel="canonical" href="./regular-html-version.html">
| <meta name="viewport" content="width=device-width,minimum-scale=1">
| <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
| <script async custom-element='amp-skimlinks' src='https://cdn.ampproject.org/v0/amp-skimlinks-0.1.js'></script>
| <script async src="https://cdn.ampproject.org/v0.js"></script>
| </head>
| <body>
| <amp-skimlinks
| layout="nodisplay"
| publisher-code="123X123"
| ></amp-skimlinks>
| </body>
| </html>

0 comments on commit fbc5b72

Please sign in to comment.