Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Dec 9, 2016
1 parent b565814 commit bfc33f9
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 98 deletions.
6 changes: 2 additions & 4 deletions src/service/extension-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ export function calculateExtensionScriptUrl(location, extensionId, isLocalDev,
export function calculateEntryPointScriptUrl(location, entryPoint, isLocalDev,
isTest) {
const base = calculateScriptBaseUrl(location, isLocalDev, isTest);
if (isLocalDev) {
return `${base}/${entryPoint}${isMax(location) ? '.max' : ''}.js`;
}
return `${base}/rtv/${getMode().rtvVersion}/${entryPoint}.js`;
const serveMax = isLocalDev && isMax(location);
return `${base}/${entryPoint}${serveMax ? '.max' : ''}.js`;
}

/**
Expand Down
186 changes: 186 additions & 0 deletions test/functional/test-extension-location.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* Copyright 2016 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.
*/

import {
calculateExtensionScriptUrl,
} from '../../src/service/extension-location';
import {
initLogConstructor,
resetLogConstructorForTesting,
} from '../../src/log';

describes.sandboxed('Extension Location', {}, () => {
describe('get correct script source', () => {
beforeEach(() => {
// These functions must not rely on log for cases in SW.
resetLogConstructorForTesting();
});

afterEach(() => {
initLogConstructor();
});

it('with local mode for testing with compiled js', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true, true, true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.js');
});

it('with local mode for testing without compiled js', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:80',
protocol: 'https:',
}, 'amp-ad', true, true, false);
expect(script).to.equal('https://localhost:80/dist/v0/amp-ad-0.1.max.js');
});

it('with local mode normal pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'https:',
}, 'amp-ad', true);
expect(script).to.equal('https://cdn.ampproject.org/v0/amp-ad-0.1.js');
});

it('with local mode min pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.js');
});

it('with local mode max pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.max.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.max.js');
});

it('with remote mode', () => {
window.AMP_MODE = {rtvVersion: '123'};
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', false);
expect(script).to.equal(
'https://cdn.ampproject.org/rtv/123/v0/amp-ad-0.1.js');
});

it('with document proxy mode: max', () => {
const script = calculateExtensionScriptUrl({
pathname: '/max/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:80/dist/v0/amp-ad-0.1.max.js');
});

it('with document proxy mode: min', () => {
const script = calculateExtensionScriptUrl({
pathname: '/min/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:80/dist/v0/amp-ad-0.1.js');
});
});

describe('get correct entry point source', () => {
beforeEach(() => {
// These functions must not rely on log for cases in SW.
resetLogConstructorForTesting();
});

afterEach(() => {
initLogConstructor();
});

it('with local mode for testing', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'sw.js', true, true);
expect(script).to.equal('http://localhost:8000/dist/sw.js');
});

it('with local mode normal pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'https:',
}, 'sw.js', true);
expect(script).to.equal('https://cdn.ampproject.org/sw.js');
});

it('with local mode min pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'sw.js', true);
expect(script).to.equal('http://localhost:8000/dist/sw.js');
});

it('with local mode max pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.max.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'sw.js', true);
expect(script).to.equal('http://localhost:8000/dist/sw.max.js');
});

it('with remote mode', () => {
window.AMP_MODE = {rtvVersion: '123'};
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'sw.js', false);
expect(script).to.equal(
'https://cdn.ampproject.org/sw.js');
});

it('with document proxy mode: max', () => {
const script = calculateExtensionScriptUrl({
pathname: '/max/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'sw.js', true);
expect(script).to.equal('http://localhost:80/dist/sw.js');
});

it('with document proxy mode: min', () => {
const script = calculateExtensionScriptUrl({
pathname: '/min/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'sw.js', true);
expect(script).to.equal('http://localhost:80/dist/sw.js');
});
});
});
91 changes: 0 additions & 91 deletions test/functional/test-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ import {
addDocFactoryToExtension,
addElementToExtension,
addShadowRootFactoryToExtension,
calculateExtensionScriptUrl,
installExtensionsInShadowDoc,
installExtensionsService,
registerExtension,
} from '../../src/service/extensions-impl';
import {
initLogConstructor,
resetLogConstructorForTesting,
} from '../../src/log';
import {resetScheduledElementForTesting} from '../../src/custom-element';
import {loadPromise} from '../../src/event-helper';

Expand Down Expand Up @@ -537,90 +532,4 @@ describes.sandboxed('Extensions', {}, () => {
});
});
});

describe('get correct script source', () => {

beforeEach(() => {
// These functions must not rely on log for cases in SW.
resetLogConstructorForTesting();
});

afterEach(() => {
initLogConstructor();
});

it('with local mode for testing with compiled js', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true, true, true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.js');
});

it('with local mode for testing without compiled js', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:80',
protocol: 'https:',
}, 'amp-ad', true, true, false);
expect(script).to.equal('https://localhost:80/dist/v0/amp-ad-0.1.max.js');
});

it('with local mode normal pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.html',
host: 'localhost:8000',
protocol: 'https:',
}, 'amp-ad', true);
expect(script).to.equal('https://cdn.ampproject.org/v0/amp-ad-0.1.js');
});

it('with local mode min pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.js');
});

it('with local mode max pathname', () => {
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.max.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:8000/dist/v0/amp-ad-0.1.max.js');
});

it('with remote mode', () => {
window.AMP_MODE = {rtvVersion: '123'};
const script = calculateExtensionScriptUrl({
pathname: 'examples/ads.amp.min.html',
host: 'localhost:8000',
protocol: 'http:',
}, 'amp-ad', false);
expect(script).to.equal(
'https://cdn.ampproject.org/rtv/123/v0/amp-ad-0.1.js');
});

it('with document proxy mode: max', () => {
const script = calculateExtensionScriptUrl({
pathname: '/max/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:80/dist/v0/amp-ad-0.1.max.js');
});

it('with document proxy mode: min', () => {
const script = calculateExtensionScriptUrl({
pathname: '/min/output.jsbin.com/pegizoq/quiet',
host: 'localhost:80',
protocol: 'http:',
}, 'amp-ad', true);
expect(script).to.equal('http://localhost:80/dist/v0/amp-ad-0.1.js');
});
});
});
4 changes: 1 addition & 3 deletions test/manual/cache-sw.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
<html >
<head>
<meta charset="utf-8">
<title>Ad examples</title>
<title>Cache SW Manual Testing</title>
<link rel="canonical" href="http://nonblocking.io/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script>
window.AMP_CONFIG = {
'cache-service-worker': 1
};
</script>
<!-- temporary, until new changes make it into production -->
<!-- <script async src="https://cdn.ampproject.org/v0.js"></script> -->
<script async src="../../dist/v0.js"></script>
<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 src="../../dist/v0/amp-accordion-0.1.js"></script>
Expand Down

0 comments on commit bfc33f9

Please sign in to comment.