diff --git a/www/common/common-interface.js b/www/common/common-interface.js index cb3e5b16a..08e735615 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -9,10 +9,12 @@ define([ '/common/tippy.min.js', '/customize/pages.js', '/common/hyperscript.js', + '/common/test.js', + '/bower_components/bootstrap-tokenfield/dist/bootstrap-tokenfield.js', 'css!/common/tippy.css', ], function ($, Messages, Util, Hash, Notifier, AppConfig, - Alertify, Tippy, Pages, h) { + Alertify, Tippy, Pages, h, Test) { var UI = {}; /* @@ -449,6 +451,10 @@ define([ } }; UI.removeLoadingScreen = function (cb) { + // Release the test blocker, hopefully every test has been registered. + // This test is created in sframe-boot2.js + if (Test.__ASYNC_BLOCKER__) { Test.__ASYNC_BLOCKER__.pass(); } + $('#' + LOADING).fadeOut(750, cb); var $tip = $('#cp-loading-tip').css('top', '') // loading.less sets transition-delay: $wait-time diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 4722b1974..e5ce318b7 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -74,6 +74,15 @@ define([ var contentContainer = options.contentContainer || (function () { throw new Error("contentContainer must be specified"); }()); + Test(function (t) { + console.log("Here is the test"); + evOnReady.reg(function () { + cpNfInner.chainpad.onSettle(function () { + console.log("The test has passed") + t.pass(); + }); + }); + }); var titleRecommender = function () { return false; }; var contentGetter = function () { return UNINITIALIZED; }; @@ -294,12 +303,6 @@ define([ if (newPad && !AppConfig.displayCreationScreen) { common.openTemplatePicker(); } - - Test(function () { - cpNfInner.chainpad.onSettle(function () { - Test.passed(); - }); - }); }; var onConnectionChange = function (info) { stateChange(info.state ? STATE.INITIALIZING : STATE.DISCONNECTED); diff --git a/www/common/sframe-boot2.js b/www/common/sframe-boot2.js index 9b0f055b3..818e3b0a0 100644 --- a/www/common/sframe-boot2.js +++ b/www/common/sframe-boot2.js @@ -1,6 +1,9 @@ // This is stage 1, it can be changed but you must bump the version of the project. // Note: This must only be loaded from inside of a sandbox-iframe. -define(['/common/requireconfig.js'], function (RequireConfig) { +define([ + '/common/requireconfig.js', + '/common/test.js' +], function (RequireConfig, Test) { require.config(RequireConfig()); // most of CryptPad breaks if you don't support isArray @@ -23,5 +26,10 @@ define(['/common/requireconfig.js'], function (RequireConfig) { window.CRYPTPAD_INSIDE = true; + // This test is for keeping the testing infrastructure operating + // until all tests have been registered. + // This test is completed in common-interface.js + Test(function (t) { Test.__ASYNC_BLOCKER__ = t; }); + require([document.querySelector('script[data-bootload]').getAttribute('data-bootload')]); }); diff --git a/www/common/test.js b/www/common/test.js index e2824b8c0..fb6bf6034 100644 --- a/www/common/test.js +++ b/www/common/test.js @@ -1,6 +1,38 @@ define([], function () { if (window.__CRYPTPAD_TEST_OBJ_) { return window.__CRYPTPAD_TEST_OBJ_; } - var out = window.__CRYPTPAD_TEST_OBJ__ = function (f) { if (out.testing) { f(); } }; + + var locks = []; + var tests = []; + var failed = false; + var out = window.__CRYPTPAD_TEST_OBJ__ = function (f) { + if (!out.testing) { return; } + tests.push(f); + var runLock = function (lock) { + lock(function () { setTimeout(function () { runLock(locks.shift()); }); }); + }; + f({ + pass: function () { + if (failed) { return; } + var i = tests.indexOf(f); + if (i === -1) { + throw new Error("Pass called on an unknown test (called multiple times?)"); + } + tests.splice(i, 1); + if (!tests.length) { out.passed(); } + }, + fail: function (reason) { + failed = true; + out.failed(reason); + }, + lock: function (f) { + locks.push(f); + if (locks.length === 1) { + runLock(locks.shift()); + } + } + }); + }; + out.passed = out.failed = out; var enableAuto = function () { console.log("Enable auto testing 1 " + window.origin);