From 6ac4fa4689461b852491839d1d373afdb2781f22 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Thu, 14 Dec 2017 11:34:44 +0100 Subject: [PATCH] wip --- TestSelenium.js | 6 ++--- www/common/sframe-app-framework.js | 8 ++++++- www/common/sframe-common-outer.js | 7 +++++- www/common/test.js | 37 +++++++++++++++++++++++++++++- www/register/main.js | 1 - 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/TestSelenium.js b/TestSelenium.js index fccd4e067..16b20f71c 100644 --- a/TestSelenium.js +++ b/TestSelenium.js @@ -28,9 +28,9 @@ var SC_GET_DATA = "return (window.__CRYPTPAD_TEST__) ? window.__CRYPTPAD_TEST__. var failed = false; var nt = nThen; [ - //'/register/#?test=test', - '/assert/#?test=test', - // '/auth/#?test=test' // TODO(cjd): Not working on automatic tests, understand why. + '/register/#?test=auto', + //'/assert/#?test=auto', + '/auth/#?test=auto' ].forEach(function (path) { if (failed) { return; } var url = 'http://localhost:3000' + path; diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 526e45678..d9b59abeb 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -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; @@ -383,6 +385,10 @@ define([ }).nThen(function (waitFor) { common.getSframeChannel().onReady(waitFor()); }).nThen(function (waitFor) { + if (common.getMetadataMgr().getPrivateData().isTesting) { + Test.registerInner(common.getSframeChannel()); + } + if (!AppConfig.displayCreationScreen) { return; } if (common.getMetadataMgr().getPrivateData().isNewFile) { common.getPadCreationScreen(waitFor()); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index fc132b8cb..8344f58aa 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -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) { diff --git a/www/common/test.js b/www/common/test.js index a0a743f2b..46416e1ad 100644 --- a/www/common/test.js +++ b/www/common/test.js @@ -1,7 +1,7 @@ define([], function () { var out = function () { }; out.passed = out.failed = out; - if (window.location.hash.indexOf("?test=test") > -1) { + if (window.location.hash.indexOf("test=auto") > -1) { var cpt = window.__CRYPTPAD_TEST__ = { data: [], getData: function () { @@ -68,8 +68,43 @@ define([], function () { error: { message: e.message, stack: e.stack } }); }; + + out.registerInner = function (sframeChan) { + sframeChan.whenReg('EV_TESTDATA', function () { + cpt.data.forEach(function (x) { sframeChan.fire('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); + } + }, + 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); }); + }; + + } else if (window.location.hash.indexOf("test=manual") > -1) { + out = function (f) { f(); }; + out.testing = true; + out.passed = function () { + window.alert("Test passed"); + }; + out.failed = function (reason) { + window.alert("Test failed [" + reason + "]"); + }; + out.registerInner = function () { }; + out.registerOuter = function () { }; } else { out.testing = false; + out.registerInner = function () { }; + out.registerOuter = function () { }; } return out; }); diff --git a/www/register/main.js b/www/register/main.js index 69e3a59a4..5337dfa87 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -57,7 +57,6 @@ define([ var logMeIn = function (result) { if (Test.testing) { Test.passed(); - window.alert("Test passed!"); return; } LocalStore.setUserHash(result.userHash);