Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

This commit is contained in:
ansuz
2017-12-21 15:53:16 +01:00
13 changed files with 264 additions and 23 deletions

View File

@@ -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 = {};
/*
@@ -459,6 +461,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

View File

@@ -12,6 +12,7 @@ define([
'/common/common-feedback.js',
'/customize/application_config.js',
'/bower_components/chainpad/chainpad.dist.js',
'/common/test.js',
'/bower_components/file-saver/FileSaver.min.js',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
@@ -30,7 +31,8 @@ define([
Thumb,
Feedback,
AppConfig,
ChainPad)
ChainPad,
Test)
{
var SaveAs = window.saveAs;
@@ -72,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; };
@@ -257,7 +268,11 @@ define([
// We're getting 'new pad' but there is an existing file
// We don't know exactly why this can happen but under no circumstances
// should we overwrite the content, so lets just try again.
common.gotoURL();
console.log("userDoc is '' but this is not a new pad.");
console.log("Either this is an empty document which has not been touched");
console.log("Or else something is terribly wrong, reloading.");
Feedback.send("NON_EMPTY_NEWDOC");
setTimeout(function () { common.gotoURL(); }, 1000);
return;
}
console.log('updating title');
@@ -385,6 +400,7 @@ define([
}).nThen(function (waitFor) {
common.getSframeChannel().onReady(waitFor());
}).nThen(function (waitFor) {
Test.registerInner(common.getSframeChannel());
if (!AppConfig.displayCreationScreen) { return; }
if (common.getMetadataMgr().getPrivateData().isNewFile) {
common.getPadCreationScreen(waitFor());

View File

@@ -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')]);
});

View File

@@ -24,6 +24,7 @@ define([
var Notifier;
var Utils = {};
var AppConfig;
var Test;
nThen(function (waitFor) {
// Load #2, the loading screen is up so grab whatever you need...
@@ -45,9 +46,10 @@ define([
'/customize/application_config.js',
'/common/outer/network-config.js',
'/bower_components/netflux-websocket/netflux-client.js',
'/common/test.js',
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
_FilePicker, _Messaging, _Notifier, _Hash, _Util, _Realtime,
_Constants, _Feedback, _LocalStore, _AppConfig, NetConfig, Netflux) {
_Constants, _Feedback, _LocalStore, _AppConfig, NetConfig, Netflux, _Test) {
CpNfOuter = _CpNfOuter;
Cryptpad = _Cryptpad;
Crypto = _Crypto;
@@ -63,6 +65,7 @@ define([
Utils.Feedback = _Feedback;
Utils.LocalStore = _LocalStore;
AppConfig = _AppConfig;
Test = _Test;
if (localStorage.CRYPTPAD_URLARGS !== ApiConfig.requireConf.urlArgs) {
console.log("New version, flushing cache");
@@ -208,6 +211,8 @@ define([
sframeChan.event('EV_LOGOUT');
});
Test.registerOuter(sframeChan);
// Put in the following function the RPC queries that should also work in filepicker
var addCommonRpc = function (sframeChan) {
sframeChan.on('Q_ANON_RPC_MESSAGE', function (data, cb) {

View File

@@ -213,4 +213,8 @@ define({
// Pad creation screen: create a pad with the selected attributes (owned, expire)
'Q_CREATE_PAD': true,
// This is for sending data out of the iframe when we are in testing mode
// The exact protocol is defined in common/test.js
'EV_TESTDATA': true,
});

View File

@@ -1,7 +1,47 @@
define([], function () {
var out = function () { };
if (window.__CRYPTPAD_TEST_OBJ_) { return window.__CRYPTPAD_TEST_OBJ_; }
var locks = [];
var tests = [];
var failed = false;
var totalTests = 0;
var out = window.__CRYPTPAD_TEST_OBJ__ = function (f) {
if (!out.testing) { return; }
tests.push(f);
totalTests++;
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) {
console.log("Completed " + totalTests + " successfully");
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;
if (window.location.hash.indexOf("?test=test") > -1) {
var enableAuto = function () {
console.log("Enable auto testing 1 " + window.origin);
if (window.__CRYPTPAD_TEST__) { return; }
var cpt = window.__CRYPTPAD_TEST__ = {
data: [],
getData: function () {
@@ -51,8 +91,7 @@ define([], function () {
error: { message: e.message, stack: e.stack }
});
};
out = function (f) { f(); };
out.testing = true;
out.testing = 'auto';
out.passed = function () {
cpt.data.push({
type: 'report',
@@ -68,8 +107,59 @@ define([], function () {
error: { message: e.message, stack: e.stack }
});
};
} else {
out.testing = false;
out.registerInner = function (sframeChan) {
sframeChan.whenReg('EV_TESTDATA', function () {
cpt.data.forEach(function (x) { sframeChan.event('EV_TESTDATA', x); });
// override cpt.data.push() with a function which will send the content to the
// outside where it will go on the outer window cpt.data array.
cpt = window.__CRYPTPAD_TEST__ = {
data: {
push: function (elem) {
sframeChan.event('EV_TESTDATA', elem);
}
},
getData: function () {
throw new Error('getData should never be called from the inside');
}
};
});
};
out.registerOuter = function (sframeChan) {
sframeChan.on('EV_TESTDATA', function (data) { cpt.data.push(data); });
};
};
var enableManual = function () {
out.testing = 'manual';
out.passed = function () {
window.alert("Test passed");
};
out.failed = function (reason) {
window.alert("Test failed [" + reason + "]");
};
out.registerInner = function () { };
out.registerOuter = function () { };
};
out.options = {};
out.testing = false;
out.registerInner = function () { };
out.registerOuter = function () { };
if (window.location.hash.indexOf("test=auto") > -1) {
enableAuto();
} else if (window.location.hash.indexOf("test=manual") > -1) {
enableManual();
} else if (document.cookie.indexOf('test=') === 0) {
try {
var x = JSON.parse(decodeURIComponent(document.cookie.replace('test=', '')));
if (x.test === 'auto') {
out.options = x.opts;
enableAuto('auto');
}
console.log("Enable auto testing " + window.origin);
} catch (e) { }
}
return out;
});