Skip to content

Commit

Permalink
Harden some tests; fix a typo.
Browse files Browse the repository at this point in the history
Convert some of the throttle tests to use sinon timers for more reliable
testing.

Fix some tutorial tests since Chrome 64 changed srcdoc in iframe usage.

Harden the test to check if a video is ready to play.
  • Loading branch information
manthey committed Feb 9, 2018
1 parent d1a5813 commit 9d19874
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/gl/polygonFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var gl_polygonFeature = function (arg) {
});
}

// tranform to map gcs
// transform to map gcs
geometry.vertices = transform.transformCoordinates(
target_gcs,
map_gcs,
Expand Down
32 changes: 32 additions & 0 deletions tests/cases/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ var Helper = function () {
describe('geo.util.debounce', function () {
'use strict';

var clock;
beforeEach(function () {
clock = sinon.useFakeTimers();
});
afterEach(function () {
clock.restore();
});

it('at_begin=false, accumulator=undefined', function (done) {
var helper = new Helper();
var wrapped = geo.util.debounce(100, helper.delay);
Expand Down Expand Up @@ -90,6 +98,12 @@ describe('geo.util.debounce', function () {
helper.expect('accum');
done();
}, 600);
clock.tick(1); // 1
clock.tick(4); // 5
clock.tick(10); // 15
clock.tick(185); // 200
clock.tick(50); // 250
clock.tick(350); // 600
});

it('at_begin=false, accumulator=defined', function (done) {
Expand Down Expand Up @@ -133,6 +147,12 @@ describe('geo.util.debounce', function () {
helper.expect('accum', args);
done();
}, 600);
clock.tick(1); // 1
clock.tick(4); // 5
clock.tick(10); // 15
clock.tick(185); // 200
clock.tick(50); // 250
clock.tick(350); // 600
});

it('at_begin=true, accumulator=undefined', function (done) {
Expand Down Expand Up @@ -176,6 +196,12 @@ describe('geo.util.debounce', function () {
helper.expect('accum');
done();
}, 600);
clock.tick(1); // 1
clock.tick(4); // 5
clock.tick(10); // 15
clock.tick(185); // 200
clock.tick(50); // 250
clock.tick(350); // 600
});

it('at_begin=true, accumulator=defined', function (done) {
Expand Down Expand Up @@ -219,6 +245,12 @@ describe('geo.util.debounce', function () {
helper.expect('accum', args);
done();
}, 600);
clock.tick(1); // 1
clock.tick(4); // 5
clock.tick(10); // 15
clock.tick(185); // 200
clock.tick(50); // 250
clock.tick(350); // 600
});
});

Expand Down
8 changes: 6 additions & 2 deletions tests/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ describe('tutorials', function () {
describe('Test ' + tutorialName, function () {
/* Load the tutorial in the test iframe */
beforeEach(function (done) {
$('#map').one('load', done);
sinon.stub(console, 'warn', function () {});
$('#map').one('load', function () { window.setTimeout(done, 1); });
$('#map').attr('src', '/tutorials/' + tutorialName + '/index.html');
});
afterEach(function () {
console.warn.restore();
});
it('Run tutorial tests', function (done) {
var base$, tests;

Expand Down Expand Up @@ -53,7 +57,7 @@ describe('tutorials', function () {
deferreds.push(defer);
var idle = targetWindow.eval(idleFunc);
if (!tut$.isFunction(idle)) {
idle = idle.done;
idle = idle.then || idle.done;
}
idle(function () {
defer.resolve();
Expand Down
22 changes: 17 additions & 5 deletions tutorials/common/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function run_block(selector, notLast, debounce, forceRun) {
* process.
*/
function process_block(selector) {
processBlockInfo.lastelem = null;
var elem = $(selector).closest('.codeblock'),
target = elem.attr('target'),
targetelem = $('#' + target),
Expand Down Expand Up @@ -134,11 +135,10 @@ function process_block(selector) {
js +
'\ngeo.util.restoreVGLRenderer();\n';
}
/* If we are in a test environment, redirect the console to the parent
* window to make debugging easier. */
/* If we are in a test environment, redirect the tutorial's console to the
* test's parent window to make debugging easier. */
if (window.parent && window.parent !== window) {
js = 'window.console = window.parent.parent.console;\n' +
'window.parent.console = window.parent.parent.console;\n' +
'console.log("Testing " + window.parent.document.title);\n' +
js;
}
Expand All @@ -153,6 +153,7 @@ function process_block(selector) {
* Although (a) is the most compatible, it doesn't allow access to local
* urls from within the iframe. (c) solves this, but requires extra work
* for browsers that don't support srcdoc. */
processBlockInfo.lastsrc = html;
targetelem.attr('srcdoc', html);
if (!processBlockInfo.srcdocSupport) {
jsurl = 'javascript: window.frameElement.getAttribute("srcdoc");';
Expand All @@ -161,7 +162,6 @@ function process_block(selector) {
}
targetelem.attr('src', jsurl);
}
processBlockInfo.lastsrc = html;
/* Expose the frame's global variables in the 'tutorial' variable. If
* there are multiple tutorials (multiple iframes), then this is the last
* one executed. All of them will be accessible in the 'tutorials'
Expand All @@ -186,7 +186,7 @@ function process_block_debounce(selector, debounce) {
processBlockInfo.timer = null;
}
if (!selector.is(processBlockInfo.lastelem) || !debounce) {
if (processBlockInfo.lastelem) {
if (processBlockInfo.lastelem && !selector.is(processBlockInfo.lastelem)) {
process_block(processBlockInfo.lastelem);
}
processBlockInfo.lastelem = selector;
Expand Down Expand Up @@ -296,6 +296,11 @@ function start_keeper(alwaysKeep) {
* parameter is not specified.
*/
function start_tutorial(useCodeMirror, alwaysKeep) {
/* If we are in a test environment, redirect the test's console to the parent
* window to make debugging easier. */
if (window.parent && window.parent !== window) {
window.console = window.parent.console;
}
/* clean up whitespace and store a default value for each code block */
$('.codeblock').each(function () {
var elem = $('textarea', this),
Expand Down Expand Up @@ -327,6 +332,13 @@ function start_tutorial(useCodeMirror, alwaysKeep) {
}
/* Check if iframe srcdoc support is present */
processBlockInfo.srcdocSupport = !!('srcdoc' in document.createElement('iframe'));
/* Chrome 64 introduced a change which removes some srcdoc support, so
* mark it as unavailable in Chrome. It would be nicer to not have user
* agent testings, but doing this generically causes problems in Firefox
* headless tests. */
if (/Chrome\//.test(navigator.userAgent)) {
processBlockInfo.srcdocSupport = false;
}
start_keeper(alwaysKeep);
run_tutorial();
}
Expand Down
8 changes: 6 additions & 2 deletions tutorials/video_transport/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,13 @@ block mainTutorial
'map.layers()[0].features()[0] instanceof geo.quadFeature'
], [
'waitForLoadAndMap = function (done) {\n' +
' $(video).on("loadeddata", function () {\n' +
' if (video.HAVE_CURRENT_DATA !== undefined && video.readyState >= video.HAVE_CURRENT_DATA) {\n' +
' map.onIdle(done);\n' +
' });\n' +
' } else {\n' +
' $(video).on("loadeddata", function () {\n' +
' map.onIdle(done);\n' +
' });\n' +
' }\n' +
'}'
])

Expand Down

0 comments on commit 9d19874

Please sign in to comment.