Added some nice testing

This commit is contained in:
Caleb James DeLisle
2017-12-15 16:09:30 +01:00
parent bb548b3428
commit 6a2d79249d
5 changed files with 70 additions and 25 deletions

View File

@@ -290,6 +290,12 @@ define([
if (newPad && !AppConfig.displayCreationScreen) {
common.openTemplatePicker();
}
if (Test.testing) {
cpNfInner.chainpad.onSettle(function () {
Test.passed();
});
}
};
var onConnectionChange = function (info) {
stateChange(info.state ? STATE.INITIALIZING : STATE.DISCONNECTED);
@@ -385,10 +391,7 @@ define([
}).nThen(function (waitFor) {
common.getSframeChannel().onReady(waitFor());
}).nThen(function (waitFor) {
if (common.getMetadataMgr().getPrivateData().isTesting) {
Test.registerInner(common.getSframeChannel());
}
Test.registerInner(common.getSframeChannel());
if (!AppConfig.displayCreationScreen) { return; }
if (common.getMetadataMgr().getPrivateData().isNewFile) {
common.getPadCreationScreen(waitFor());

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,10 @@
define([], function () {
var out = function () { };
if (window.__CRYPTPAD_TEST_OBJ_) { return window.__CRYPTPAD_TEST_OBJ_; }
var out = window.__CRYPTPAD_TEST_OBJ__ = function (f) { if (out.testing) { f(); } };
out.passed = out.failed = out;
if (window.location.hash.indexOf("test=auto") > -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 +54,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',
@@ -71,13 +73,13 @@ define([], function () {
out.registerInner = function (sframeChan) {
sframeChan.whenReg('EV_TESTDATA', function () {
cpt.data.forEach(function (x) { sframeChan.fire('EV_TESTDATA', x); });
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.fire('EV_TESTDATA', elem);
sframeChan.event('EV_TESTDATA', elem);
}
},
getData: function () {
@@ -89,10 +91,9 @@ define([], function () {
out.registerOuter = function (sframeChan) {
sframeChan.on('EV_TESTDATA', function (data) { cpt.data.push(data); });
};
} else if (window.location.hash.indexOf("test=manual") > -1) {
out = function (f) { f(); };
out.testing = true;
};
var enableManual = function () {
out.testing = 'manual';
out.passed = function () {
window.alert("Test passed");
};
@@ -101,10 +102,27 @@ define([], function () {
};
out.registerInner = function () { };
out.registerOuter = function () { };
} else {
out.testing = false;
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;
});