Harden some tests; fix a typo.
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.
MODIFY
src/gl/polygonFeature.js
src/gl/polygonFeature.js
@@ -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,

MODIFY
tests/cases/throttle.js
tests/cases/throttle.js
@@ -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);
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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
});
});

MODIFY
tests/tutorials.js
tests/tutorials.js
@@ -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;
@@ -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();

MODIFY
tutorials/common/tutorials.js
tutorials/common/tutorials.js
@@ -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),
@@ -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;
}
@@ -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");';
@@ -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'
@@ -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;
@@ -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),
@@ -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();
}

MODIFY
tutorials/video_transport/index.pug
tutorials/video_transport/index.pug
@@ -110,9 +110,13 @@ block mainTutorial
'map.layers()[0].features()[0] instanceof geo.quadFeature'
], [
'waitForLoadAndMap = function (done) {\n' +
+ ' if (video.HAVE_CURRENT_DATA !== undefined && video.readyState >= video.HAVE_CURRENT_DATA) {\n' +
+ ' map.onIdle(done);\n' +
+ ' } else {\n' +
' $(video).on("loadeddata", function () {\n' +
' map.onIdle(done);\n' +
' });\n' +
+ ' }\n' +
'}'
])

Harden some tests; fix a typo.

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.