Use jsdom to load and execute our CSS, HTML and JS.

Change-Id: Ia7414e1fd19bf7ebfa29274d1acac5cee4837341
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Michael Meeks 2021-01-08 13:14:59 +00:00
parent c7d0de0877
commit 136f20b386
6 changed files with 84 additions and 48 deletions

View file

@ -1194,6 +1194,7 @@ if test "$enable_androidapp" = "yes"; then
fi
AC_CONFIG_FILES([test/run_unit.sh],[chmod +x test/run_unit.sh])
AC_CONFIG_FILES([coolstress],[chmod +x coolstress])
AC_OUTPUT

14
coolstress.in Executable file
View file

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# This is a wrapper - please edit coolstress.in
prefix="@prefix@"
datadir="@datadir@"
datarootdir="@datarootdir@"
pkgdatadir="$(datadir)/@PACKAGE@"
# to allow runnning when not installed
abs_top_builddir="@abs_top_builddir@"
abs_top_srcdir="@abs_top_srcdir@"
node --inspect $abs_top_srcdir/loleaflet/test/load.js "$abs_top_srcdir" "$abs_top_builddir" $*

View file

@ -684,10 +684,3 @@ $(abs_srcdir)/admin/jsconfig.json:
\"exclude\" : [\"node_modules\"]\n}" > $@
jsconfig: $(abs_srcdir)/jsconfig.json $(abs_srcdir)/admin/jsconfig.json
load-test: $(LOLEAFLET_JS)
@(cd test ; node ./load.js \
$(abspath $(srcdir)/js/global.js) \
$(abspath $(NODE_MODULES_JS_SRC)) \
$(abspath $(LOLEAFLET_LIBS_JS_SRC)) \
$(abspath $(LOLEAFLET_JS)))

View file

@ -170,7 +170,7 @@
if (global.mode.isChromebook())
return false;
if (L.Browser.mobile && L.Browser.cypressTest) {
if (global.L.Browser.mobile && L.Browser.cypressTest) {
return true;
}

View file

@ -39,6 +39,7 @@
],
"license": "BSD-2-Clause",
"dependencies": {
"canvas": "^2.6.1",
"jsdom": "^16.4.0"
}
}

View file

@ -1,55 +1,82 @@
console.log('Startup')
var vm = require("vm");
var fs = require("fs");
// stubs
/*navigator = {
userAgent: 'loadtest',
vendor: 'collabora',
platform: 'Linux'
}; */
var top_srcdir = process.argv[2];
var top_builddir = process.argv[3];
var to_load = top_srcdir + '/test/data/hello-world.ods';
if (process.argv.length > 4) {
to_load = process.argv[4]
}
// jsdom for browser emulation
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
window = new JSDOM(`...`).window;
window.host = 'localhost';
window.location = 'https://localhost:9980';
// cf. loleaflet.hml - Window properties:
window.host = '';
window.serviceRoot = '';
window.versionPath = '6.4.3';
window.accessToken = '';
window.accessTokenTTL = '';
window.accessHeader = '';
window.loleafletLogging = 'true';
window.enableWelcomeMessage = false;
window.enableWelcomeMessageButton = false;
window.outOfFocusTimeoutSecs = 1000000;
window.idleTimeoutSecs = 1000000;
window.reuseCookies = '';
window.protocolDebug = false;
window.frameAncestors = '';
window.socketProxy = false;
window.tileSize = 256;
window.uiDefaults = {};
var data = fs.readFileSync(top_builddir + '/loleaflet/dist/loleaflet.html', {encoding: 'utf8'});
// stub the DOM left and right:
data = data.replace(/%SERVICE_ROOT%\/loleaflet\/%VERSION%/g, top_builddir + '/loleaflet/dist');
data = data.replace(/%SERVICE_ROOT%/g, '');
data = data.replace(/%VERSION%/g, 'dist');
data = data.replace(/%HOST%/g, 'wss://localhost:9980');
data = data.replace(/%ACCESS_TOKEN%/g, '');
data = data.replace(/%ACCESS_TOKEN_TTL%/g, '0');
data = data.replace(/%ACCESS_HEADER%/g, '');
data = data.replace(/%LOLEAFLET_LOGGING%/g, 'true');
data = data.replace(/%ENABLE_WELCOME_MSG%/g, 'false');
data = data.replace(/%ENABLE_WELCOME_MSG%/g, 'false');
data = data.replace(/%ENABLE_WELCOME_MSG_BTN%/g, 'false');
data = data.replace(/%USER_INTERFACE_MODE%/g, '');
data = data.replace(/%OUT_OF_FOCUS_TIMEOUT_SECS%/g, '1000000');
data = data.replace(/%IDLE_TIMEOUT_SECS%/g, '1000000');
data = data.replace(/%REUSE_COOKIES%/g, 'false');
data = data.replace(/%PROTOCOL_DEBUG%/g, 'true');
data = data.replace(/%FRAME_ANCESTORS%/g, '');
data = data.replace(/%SOCKET_PROXY%/g, 'false');
data = data.replace(/%UI_DEFAULTS%/g, '{}');
context = vm.createContext(window, {name: 'simulation' })
window = new JSDOM(data,
{ runScripts: 'dangerously',
pretendToBeVisual: true,
includeNodeLocations: true,
url: 'file:///tmp/notthere/loleaflet.html?file_path=file:///' + to_load,
resources: 'usable',
beforeParse(window) {
console.debug('Before script parsing');
},
done(errors, window) {
console.debug('Errors ' + errors);
}
}).window;
L = { Browser: {} };
// Make it possible to mock sizing properties
Object.defineProperty(window.HTMLElement.prototype, "clientWidth", {
get: function() {
return this.___clientWidth || 0;
}
});
Object.defineProperty(window.HTMLElement.prototype, "clientHeight", {
get: function() {
return this.___clientHeight || 0;
}
});
for (var i = 2; i < process.argv.length; ++i)
{
console.log('load "' + process.argv[i] + '"');
console.log('Finished bootstrapping: ' + window.L.Browser.mobile + ' desktop ' + window.mode.isDesktop() + ' now running');
console.debug('Window size ' + window.innerWidth + 'x' + window.innerHeight);
var data = fs.readFileSync(process.argv[i]);
const script = new vm.Script(data);
script.runInContext(context);
}
window.HTMLElement.prototype.getBoundingClientRect = function() {
console.debug('getBoundingClientRect for ' + this.id);
return {
width: 0, height: 0, top: 0, left: 0
};
};
window.onload = function() {
console.debug('socket ' + window.socket);
map = window.socket._map;
console.log('Bootstrapped mobile: ' + L.Browser.mobile + ' desktop ' + window.mode.isDesktop());
console.debug('Initialize / size map pieces ' + map);
// Force some sizes onto key pieces:
map._container.___clientWidth = 1024;
map._container.___clientHeight = 768;
};