Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change error integration test to use fragment based dev-mode inference #1388

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ function getMode_() {
// occur during local dev.
!!document.querySelector('script[src*="/dist/"],script[src*="/base/"]');

const overrideDevelopment = parseQueryString(location.hash)['development'];
const overrideDevelopment = parseQueryString(
// location.originalHash is set by the viewer when it removes the fragment
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, Viewer also remembers all original args in hash and can return them via getParam(name). You can always use this if convenient/possible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want mode.js depend on viewer.

// from the URL.
location.originalHash || location.hash)['development'];
const development = overrideDevelopment != undefined
? overrideDevelopment == '1'
: !!document.querySelector('script[development]');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer used. Let's remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CL is a step towards that.


return {
localDev: isLocalDev,
// Triggers validation
Expand Down
3 changes: 3 additions & 0 deletions src/service/viewer-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ export class Viewer {
if (this.isEmbedded_) {
const newUrl = removeFragment(this.win.location.href);
if (newUrl != this.win.location.href && this.win.history.replaceState) {
// Persist the hash that we removed has location.originalHash.
// This is currently used my mode.js to infer development mode.
this.win.location.originalHash = this.win.location.hash;
this.win.history.replaceState({}, '', newUrl);
log.fine(TAG_, 'replace url:' + this.win.location.href);
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/errors.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script async custom-element="amp-iframe" src="/base/dist/v0/amp-iframe-0.1.max.js"></script>
<script async custom-element="amp-youtube" src="/base/dist/v0/amp-youtube-0.1.max.js"></script>
<style>body {opacity: 0}</style><noscript><style>body {opacity: 1}</style></noscript>
<script async src="/base/dist/amp.js" development></script>
<script async src="/base/dist/amp.js"></script>
</head>
<body>

Expand Down
6 changes: 5 additions & 1 deletion test/integration/test-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {createFixtureIframe, poll, expectBodyToBecomeVisible} from
describe('error page', () => {
let fixture;
beforeEach(() => {
return createFixtureIframe('test/fixtures/errors.html', 500).then(f => {
return createFixtureIframe('test/fixtures/errors.html', 500, win => {
// Trigger dev mode.
win.history.pushState({}, '', 'test2.html#development=1');
console.error('updated', win.location.hash);
}).then(f => {
fixture = f;
return poll('errors to happen', () => {
return fixture.doc.querySelectorAll('[error-message]').length >= 2;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test-example-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {loadPromise} from '../../src/event-helper';
if (!window.validatorLoad) {
window.validatorLoad = (function() {
const s = document.createElement('script');
s.src = 'https://www.gstatic.com/amphtml/v0/validator.js';
s.src = 'https://cdn.ampproject.org/v0/validator.js';
document.body.appendChild(s);
return loadPromise(s);
})();
Expand Down
8 changes: 7 additions & 1 deletion testing/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ let iframeCount = 0;
*
* @param {string} fixture The name of the fixture file.
* @param {number} initialIframeHeight in px.
* @param {function(!Window)} opt_beforeLoad Called just before any other JS
* executes in the window.
* @return {!Promise<{
* win: !Window,
* doc: !Document,
* iframe: !Element,
* awaitEvent: function(string, number):!Promise
* }>}
*/
export function createFixtureIframe(fixture, initialIframeHeight, done) {
export function createFixtureIframe(fixture, initialIframeHeight, opt_beforeLoad) {
return new Promise((resolve, reject) => {
// Counts the supported custom events.
const events = {
Expand All @@ -68,6 +70,9 @@ export function createFixtureIframe(fixture, initialIframeHeight, done) {
window.beforeLoad = function(win) {
// Flag as being a test window.
win.AMP_TEST = true;
if (opt_beforeLoad) {
opt_beforeLoad(win);
}
// Function that returns a promise for when the given event fired at
// least count times.
let awaitEvent = (eventName, count) => {
Expand Down Expand Up @@ -100,6 +105,7 @@ export function createFixtureIframe(fixture, initialIframeHeight, done) {
let errors = [];
win.console.error = function() {
errors.push('Error: ' + [].slice.call(arguments).join(' '));
console.error.apply(console, arguments);
};
// Make time go 10x as fast
win.setTimeout = function(fn, ms) {
Expand Down