[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-4' - loleaflet/spec

Mihai Varga mihai.varga at collabora.com
Thu Aug 20 09:04:42 PDT 2015


 loleaflet/spec/loleaflet.html             |   43 ++++++
 loleaflet/spec/loleaflet/loleafletSpec.js |  193 ++++++++++++++++++++++++++++++
 2 files changed, 236 insertions(+)

New commits:
commit 08372b15acc154498caf845d51998272cf6430e1
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Thu Aug 20 19:04:06 2015 +0300

    loleaflet: unit tests - some still fail

diff --git a/loleaflet/spec/loleaflet.html b/loleaflet/spec/loleaflet.html
new file mode 100644
index 0000000..eb399b3
--- /dev/null
+++ b/loleaflet/spec/loleaflet.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title>LOOL Spec Runner</title>
+	<link rel="stylesheet" type="text/css" href="../node_modules/mocha/mocha.css">
+	<link rel="stylesheet" type="text/css" href="../dist/leaflet.css">
+	<link rel="stylesheet" type="text/css" href="../dist/dialog/vex.css" />
+	<link rel="stylesheet" type="text/css" href="../dist/dialog/vex-theme-plain.css" />
+</head>
+<body>
+	<div id="mocha"></div>
+	<script src="expect.js"></script>
+	<script type="text/javascript" src="../node_modules/mocha/mocha.js"></script>
+	<script type="text/javascript" src="../node_modules/happen/happen.js"></script>
+	<script type="text/javascript" src="sinon.js"></script>
+
+	<!-- source files -->
+	<script type="text/javascript" src="../build/deps.js"></script>
+
+	<script type="text/javascript" src="../debug/leaflet-include.js"></script>
+
+	<script>
+		mocha.setup({
+			ui: 'bdd',
+			ignoreLeaks: true
+		});
+	</script>
+
+	<!-- spec files -->
+	<script type="text/javascript" src="loleaflet/loleafletSpec.js"></script>
+
+	<div id="toolbar" style="hidden">
+	</div>
+	<div id="document-container" style="top:0px; height:400px; visibility:hidden">
+		<div id="map"></div>
+	</div>
+
+	<script>
+		(window.mochaPhantomJS || window.mocha).run();
+	</script>
+</body>
+</html>
diff --git a/loleaflet/spec/loleaflet/loleafletSpec.js b/loleaflet/spec/loleaflet/loleafletSpec.js
new file mode 100644
index 0000000..2d0edf5
--- /dev/null
+++ b/loleaflet/spec/loleaflet/loleafletSpec.js
@@ -0,0 +1,193 @@
+describe('TileBench', function () {
+	this.timeout(10000);
+	var map;
+	var timeOut
+
+	var log = function (msg) {
+		// write custom log messages
+		var cont = document.getElementById('mocha-report');
+		var li = document.createElement('li');
+		li.style.class = 'test pass';
+		li.innerHTML = '<h2>' + msg + '</h2>';
+		cont.appendChild(li);
+	}
+
+	before(function () {
+		// initialize the map and load the document
+		map = L.map('map', {
+			center: [0, 0],
+			zoom: 10,
+			minZoom: 1,
+			maxZoom: 20,
+			server: 'ws://localhost:9980',
+			doubleClickZoom: false
+		});
+
+		var docLayer = new L.TileLayer('', {
+			doc: 'file:///home/mihai/Desktop/test_docs/eval.odt',
+			useSocket : true,
+			edit: false,
+			readOnly: false
+		});
+
+		docLayer.sendMessage = L.bind(function (msg, coords) {
+			var now = Date.now();
+			if (msg.startsWith('tile')) {
+				msg += ' timestamp=' + now;
+			}
+			L.Log.log(msg, L.OUTGOING, coords, now);
+			this._map.socket.send(msg);
+		}, docLayer);
+
+		// don't pre-fetch tiles
+		docLayer._preFetchTiles = L.Util.falseFn;
+
+		map.addLayer(docLayer);
+	});
+
+	afterEach(function () {
+		map.off('statusindicator');
+	});
+
+	after(function () {
+		map.remove();
+	});
+
+	describe('Benchmarking', function () {
+		it('Load all new tiles', function (done) {
+			map.on('statusindicator', function (e) {
+				if (e.statusType === 'alltilesloaded') {
+					done();
+				}
+			});
+		});
+
+		it('Set permission to "readonly"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('readonly');
+				done();
+			});
+			map.setPermission('readonly');
+		});
+
+		it('Set permission to "edit"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('edit');
+				done();
+			});
+			map.setPermission('edit');
+		});
+
+		it('Set permission to "view"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('view');
+				done();
+			});
+			map.setPermission('view');
+		});
+
+		it('Place the coursor by clicking', function (done) {
+			map.on('statusindicator', function (e) {
+				expect(e).to.have.property('statusType');
+				if (e.statusType === 'setvalue') {
+					expect(e).to.have.property('value');
+				}
+				if (e.statusType === 'finish') {
+					done();
+				}
+			});
+			map._docLayer._postMouseEvent('buttondown', 2500, 3515, 1);
+			map._docLayer._postMouseEvent('buttonup', 2500, 3515, 1);
+			map.setPermission('edit');
+		});
+
+		it('Make a word Bold', function (done) {
+			map.once('commandstatechanged', function (e) {
+				expect(e.unoCmd).to.be('Bold');
+				expect(e.state).to.be('false');
+				done();
+			});
+			map.toggleCommandState('Bold')
+		});
+
+		it('Search backwards', function (done) {
+			map.once('scrollto', function (e) {
+				//expect(e.x).to.be(0);
+				//expect(e.y).to.be.above(0);
+				//expect(e.y).to.be(2321);
+				done();
+			});
+			map.search('document', true);
+		});
+
+		it('Search not found', function (done) {
+			map.once('search', function (e) {
+				expect(e.originalPhrase).to.be('something-not-found');
+				expect(e.count).to.be(0);
+				done();
+			});
+			map.search('something-not-found');
+		});
+
+
+		it('Get document size', function () {
+			var size = map.getDocSize();
+			// TODO assert
+			//expect(size.x).to.be();
+			//expect(size.y).to.be();
+		});
+
+		it('Get document type', function () {
+			expect(map.getDocType()).to.be('text');
+		});
+
+		it('Check pages', function () {
+			expect(map.getNumberOfPages()).to.be(2);
+			expect(map.getNumberOfParts()).to.be(1);
+			expect(map.getCurrentPageNumber()).to.be(0);
+		});
+
+		it('Go to the next page', function () {
+			map.once('pagenumberchanged', function (e) {
+				expect(e.currentPage).to.be(1);
+				expect(e.pages).to.be(2);
+				expect(e.docType).to.be('text');
+				done();
+			});
+		});
+
+		it('Scroll to the top', function (done) {
+			map.once('updatescrolloffset', function (e) {
+				expect(e.x).to.be(0);
+				expect(e.y).to.be(0);
+				done();
+			});
+			map.scrollTop(0, {update: true});
+		});
+
+		it('Scroll to the middle', function (done) {
+			var size = map.getDocSize();
+			var x = Math.round(size.x / 2);
+			var y = Math.round(size.y / 2);
+			map.once('updatescrolloffset', function (e) {
+				expect(e.x).to.be(0);
+				expect(e.y).to.be(y);
+				done();
+			});
+			map.scroll(x, y, {update: true});
+		});
+
+		it('Check if pre-fetching works', function (done) {
+			// clear the tiles
+			map._docLayer._tiles = {};
+			map._docLayer._resetPreFetching(true);
+
+			this.timeout(7000);
+			// tiles are pre-fetched after 6seconds
+			setTimeout(function () {
+				expect(Object.keys(map._docLayer._tiles).length).to.be.above(5);
+				done();
+			}, 6000);
+		});
+	});
+});


More information about the Libreoffice-commits mailing list