[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-5' - 14 commits - loleaflet/dist loleaflet/reference.html loleaflet/spec loleaflet/src

Mihai Varga mihai.varga at collabora.com
Wed Oct 21 09:04:14 PDT 2015


 loleaflet/dist/leaflet.css                         |    1 
 loleaflet/reference.html                           |    5 
 loleaflet/spec/loleaflet.html                      |    5 
 loleaflet/spec/loleaflet/control/PartsSpec.js      |  163 ++++++++++++++++++++
 loleaflet/spec/loleaflet/control/PermissionSpec.js |  129 ++++++++++++++++
 loleaflet/spec/loleaflet/control/SearchSpec.js     |  103 ++++++++++++
 loleaflet/spec/loleaflet/control/ToolbarSpec.js    |   61 +++++++
 loleaflet/spec/loleaflet/loleafletSpec.js          |  169 ---------------------
 loleaflet/src/control/Control.PartsPreview.js      |    2 
 loleaflet/src/control/Toolbar.js                   |   13 +
 loleaflet/src/core/Socket.js                       |    1 
 loleaflet/src/layer/tile/GridLayer.js              |    5 
 loleaflet/src/layer/tile/TileLayer.js              |    7 
 loleaflet/src/map/Map.js                           |    3 
 loleaflet/src/map/handler/Map.Keyboard.js          |    2 
 loleaflet/src/map/handler/Map.Print.js             |    4 
 16 files changed, 492 insertions(+), 181 deletions(-)

New commits:
commit 829005749b212c1456c8cc272e0a63aac46baf31
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Wed Oct 21 18:41:24 2015 +0300

    loleaflet: added a map.print() method
    
    Also renamed the print handler so that it does not interfere with the
    new method

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 07574de..4f13e94 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -1598,6 +1598,11 @@ var map = L.map('map', {
 		<td><code>undefined</code></td>
         <td>Download the document as "format" with the name "name" by applying the filter options.</td>
 	</tr>
+	<tr>
+		<td><code><b>print</b>()</code></td>
+		<td><code>undefined</code></td>
+        <td>Opens the browser's print dialog or promts the user to download a pdf version of the document.</td>
+	</tr>
 </table>
 
 <h2 id="loleaflet-page">Page oriented</h2>
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 8b04431..2b85406 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -46,6 +46,10 @@ L.Map.include({
 			'options=' + options);
 	},
 
+	print: function () {
+		this.downloadAs('print.pdf', 'pdf', null, 'print');
+	},
+
 	saveAs: function (url, format, options) {
 		if (format === undefined || format === null) {
 			format = '';
@@ -80,5 +84,9 @@ L.Map.include({
 			}
 			L.Socket.sendMessage('uno ' + unoState);
 		}
+	},
+
+	insertFile: function (file) {
+		this.fire('insertfile', {file: file});
 	}
 });
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 4d51958..1f32539 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -284,7 +284,7 @@ L.Map.Keyboard = L.Handler.extend({
 				L.Socket.sendMessage('uno .uno:LeftPara');
 				break;
 			case 80: // p
-				this._map.downloadAs('print.pdf', 'pdf', null, 'print');
+				this._map.print();
 				break;
 			case 82: // r
 				L.Socket.sendMessage('uno .uno:RightPara');
diff --git a/loleaflet/src/map/handler/Map.Print.js b/loleaflet/src/map/handler/Map.Print.js
index 1a92c8b..9adda5b 100644
--- a/loleaflet/src/map/handler/Map.Print.js
+++ b/loleaflet/src/map/handler/Map.Print.js
@@ -3,7 +3,7 @@
  */
 
 L.Map.mergeOptions({
-	print: true
+	printHandler: true
 });
 
 L.Map.Print = L.Handler.extend({
@@ -59,4 +59,4 @@ L.Map.Print = L.Handler.extend({
 	}
 });
 
-L.Map.addInitHook('addHandler', 'print', L.Map.Print);
+L.Map.addInitHook('addHandler', 'printHandler', L.Map.Print);
commit 68a159dae7fc1212810869ba8be0979354281259
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Wed Oct 21 11:22:55 2015 +0300

    loleaflet: stick the parts preview to the left

diff --git a/loleaflet/dist/leaflet.css b/loleaflet/dist/leaflet.css
index 77c0381..96a9a38 100644
--- a/loleaflet/dist/leaflet.css
+++ b/loleaflet/dist/leaflet.css
@@ -703,6 +703,7 @@ a.leaflet-control-buttons:hover:first-child {
 	background: #DFDFDF;
 	position: absolute;
 	top: 70px;
+    left: 0px;
 	bottom: 0px;
 	max-width: 195px;
 	overflow: hidden;
diff --git a/loleaflet/src/control/Control.PartsPreview.js b/loleaflet/src/control/Control.PartsPreview.js
index 5439b49..2a6c5ad 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -29,7 +29,7 @@ L.Control.PartsPreview = L.Control.extend({
 		if (!this._previewInitialized && docType === 'presentation') {
 			// make room for the preview
 			var docContainer = L.DomUtil.get('document-container');
-			L.DomUtil.setStyle(docContainer, 'left', '200px');
+			L.DomUtil.setStyle(docContainer, 'left', '195px');
 			setTimeout(L.bind(function () {
 				this._map.invalidateSize();
 				$('.scroll-container').mCustomScrollbar('update');
commit 5d88bb25917c999f46fc7ec9350fd0e3e44618ca
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 20 11:54:07 2015 +0300

    loleaflet: downloadAs unit test

diff --git a/loleaflet/spec/loleaflet.html b/loleaflet/spec/loleaflet.html
index a61707e..131d757 100644
--- a/loleaflet/spec/loleaflet.html
+++ b/loleaflet/spec/loleaflet.html
@@ -31,6 +31,7 @@
 	<script type="text/javascript" src="loleaflet/control/PermissionSpec.js"></script>
 	<script type="text/javascript" src="loleaflet/control/PartsSpec.js"></script>
 	<script type="text/javascript" src="loleaflet/control/SearchSpec.js"></script>
+	<script type="text/javascript" src="loleaflet/control/ToolbarSpec.js"></script>
 
 	<div id="toolbar" style="hidden">
 	</div>
diff --git a/loleaflet/spec/loleaflet/control/ToolbarSpec.js b/loleaflet/spec/loleaflet/control/ToolbarSpec.js
new file mode 100644
index 0000000..f83480e
--- /dev/null
+++ b/loleaflet/spec/loleaflet/control/ToolbarSpec.js
@@ -0,0 +1,61 @@
+describe('Toolbar', function () {
+	this.timeout(10000);
+	var map;
+	var url;
+
+	before(function () {
+		var htmlPath = window.location.pathname;
+		var dir = htmlPath.substring(0, htmlPath.lastIndexOf('/'));
+		var fileURL = 'file://' + dir + '/data/eval.odt';
+		// initialize the map and load the document
+		map = L.map('map', {
+			server: 'ws://localhost:9980',
+			doc: fileURL,
+			edit: false,
+			readOnly: false,
+			print: false
+		});
+	});
+
+	afterEach(function () {
+		map.off('statusindicator');
+	});
+
+	after(function () {
+		map.remove();
+	});
+
+	describe('Load the document', function () {
+		it('Loleaflet initialized', function (done) {
+			map.on('statusindicator', function (e) {
+				if (e.statusType === 'loleafletloaded') {
+					done();
+				}
+			});
+		});
+	});
+
+	describe('Download as', function () {
+		it('Request pdf export url', function (done) {
+			map.once('print', function (e) {
+				console.log(e.url);
+				url = e.url;
+				console.log(url);
+				done();
+			});
+			map.downloadAs('test.pdf', 'pdf', null, 'print');
+		});
+
+		it('Download the pdf export', function (done) {
+			var xmlHttp = new XMLHttpRequest();
+			xmlHttp.onreadystatechange = function () {
+				if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
+					done();
+				}
+			};
+			xmlHttp.open('GET', url, true);
+			xmlHttp.responseType = 'blob';
+			xmlHttp.send();
+		});
+	});
+});
commit a7e24234d3c3aada811fdc4a357123bcf6675bb9
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 20 11:53:38 2015 +0300

    loleaflet: remove event listeners after each test

diff --git a/loleaflet/spec/loleaflet/control/PartsSpec.js b/loleaflet/spec/loleaflet/control/PartsSpec.js
index e368827..c7438e5 100644
--- a/loleaflet/spec/loleaflet/control/PartsSpec.js
+++ b/loleaflet/spec/loleaflet/control/PartsSpec.js
@@ -15,6 +15,10 @@ describe('Parts and Pages', function () {
 		});
 	});
 
+	afterEach(function () {
+		map.off('statusindicator');
+	});
+
 	after(function () {
 		map.remove();
 	});
@@ -23,7 +27,6 @@ describe('Parts and Pages', function () {
 		it('All tiles loaded', function (done) {
 			map.on('statusindicator', function (e) {
 				if (e.statusType === 'alltilesloaded') {
-					map.off('statusindicator');
 					done();
 				}
 			});
diff --git a/loleaflet/spec/loleaflet/control/PermissionSpec.js b/loleaflet/spec/loleaflet/control/PermissionSpec.js
index 9c5dca1..3d8b456 100644
--- a/loleaflet/spec/loleaflet/control/PermissionSpec.js
+++ b/loleaflet/spec/loleaflet/control/PermissionSpec.js
@@ -20,6 +20,10 @@ describe('Permissions', function () {
 		});
 	});
 
+	afterEach(function () {
+		map.off('statusindicator');
+	});
+
 	after(function () {
 		map.remove();
 	});
@@ -28,7 +32,6 @@ describe('Permissions', function () {
 		it('Initialize the tile layer', function (done) {
 			map.on('statusindicator', function (e) {
 				if (e.statusType === 'loleafletloaded') {
-					map.off('statusindicator');
 					done();
 				}
 			});
diff --git a/loleaflet/spec/loleaflet/control/SearchSpec.js b/loleaflet/spec/loleaflet/control/SearchSpec.js
index 3c24354..7db5ae5 100644
--- a/loleaflet/spec/loleaflet/control/SearchSpec.js
+++ b/loleaflet/spec/loleaflet/control/SearchSpec.js
@@ -15,6 +15,10 @@ describe('Search', function () {
 		});
 	});
 
+	afterEach(function () {
+		map.off('statusindicator');
+	});
+
 	after(function () {
 		map.remove();
 	});
@@ -23,7 +27,6 @@ describe('Search', function () {
 		it('All tiles loaded', function (done) {
 			map.on('statusindicator', function (e) {
 				if (e.statusType === 'alltilesloaded') {
-					map.off('statusindicator');
 					done();
 				}
 			});
commit 6c9690cb8886e90af25bf72c321e2a77ba775003
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 20 11:48:42 2015 +0300

    loleaflet: better handle map.remove()

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 947adf5..a1c3e72 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -22,6 +22,7 @@ L.Socket = {
 	close: function () {
 		this.socket.onerror = function () {};
 		this.socket.onclose = function () {};
+		this.socket.onmessage = function () {};
 		this.socket.close();
 	},
 
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index b11a51a..df981f5 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -44,7 +44,12 @@ L.GridLayer = L.Layer.extend({
 		this._container = null;
 		this._tileZoom = null;
 		clearTimeout(this._preFetchIdle);
+		clearTimeout(this._previewInvalidator);
 		clearInterval(this._tilesPreFetcher);
+
+		if (this._selections) {
+			this._map.removeLayer(this._selections);
+		}
 		if (this._cursorMarker) {
 			this._cursorMarker.remove();
 		}
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index df230b9..a0ced6d 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -246,9 +246,6 @@ L.Map = L.Evented.extend({
 		}
 
 		if (this._docLayer) {
-			if (this._docLayer._selections) {
-				this.removeLayer(this._docLayer._selections);
-			}
 			this.removeLayer(this._docLayer);
 		}
 		this.removeControls();
commit e43f9df786cd97004967e2674593775d4cc136f8
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 20 11:09:08 2015 +0300

    loleaflet: add id paramater to downloadAs method
    
    Conflicts:
    	loleaflet/src/map/handler/Map.SlideShow.js

diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index c319926..8b04431 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -31,16 +31,17 @@ L.Map.include({
 		return this._docLayer._toolbarCommandValues[command];
 	},
 
-	downloadAs: function (name, format, options) {
+	downloadAs: function (name, format, options, id) {
 		if (format === undefined || format === null) {
 			format = '';
 		}
 		if (options === undefined || options === null) {
 			options = '';
 		}
+		id = id || -1; // not a special download
 		L.Socket.sendMessage('downloadas ' +
 			'name=' + name + ' ' +
-			'id=-1 ' + // not a special download
+			'id=' + id + ' ' +
 			'format=' + format + ' ' +
 			'options=' + options);
 	},
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index c674240..4d51958 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -284,7 +284,7 @@ L.Map.Keyboard = L.Handler.extend({
 				L.Socket.sendMessage('uno .uno:LeftPara');
 				break;
 			case 80: // p
-				L.Socket.sendMessage('downloadas name=print.pdf id=print format=pdf options=');
+				this._map.downloadAs('print.pdf', 'pdf', null, 'print');
 				break;
 			case 82: // r
 				L.Socket.sendMessage('uno .uno:RightPara');
commit a4637d4fe3aa4703030026e95d647d4fb9493190
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 17:46:49 2015 +0300

    loleaflet: if window's protocol is file: add http: to download url

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 527ae71..6f822bb 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -274,8 +274,9 @@ L.TileLayer = L.GridLayer.extend({
 	_onDownloadAsMsg: function (textMsg) {
 		var command = L.Socket.parseServerCmd(textMsg);
 		var parser = document.createElement('a');
+		var protocol = window.location.protocol === 'file:' ? 'http:' : window.location.protocol;
 		parser.href = this._map.options.server;
-		var url = window.location.protocol + '//' + parser.hostname + ':' + command.port + '/' +
+		var url = protocol + '//' + parser.hostname + ':' + command.port + '/' +
 			command.jail + '/' + command.dir + '/' + command.name;
 
 		if (command.id !== '-1') {
commit e15c31de33b9a8011e69f43c7d6e039e1379a70d
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 17:42:12 2015 +0300

    loleaflet: removed unused variable from unit test

diff --git a/loleaflet/spec/loleaflet/control/SearchSpec.js b/loleaflet/spec/loleaflet/control/SearchSpec.js
index da6f5c2..3c24354 100644
--- a/loleaflet/spec/loleaflet/control/SearchSpec.js
+++ b/loleaflet/spec/loleaflet/control/SearchSpec.js
@@ -1,7 +1,6 @@
 describe('Search', function () {
 	this.timeout(10000);
 	var map;
-    var mapSize;
 
 	before(function () {
 		var htmlPath = window.location.pathname;
@@ -25,7 +24,6 @@ describe('Search', function () {
 			map.on('statusindicator', function (e) {
 				if (e.statusType === 'alltilesloaded') {
 					map.off('statusindicator');
-                    mapSize = map.getSize();
 					done();
 				}
 			});
commit 935f936ce5505b45cd15582a27047ea9b9e2dcf2
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 17:38:02 2015 +0300

    loleaflet: removed the old unit test

diff --git a/loleaflet/spec/loleaflet/loleafletSpec.js b/loleaflet/spec/loleaflet/loleafletSpec.js
deleted file mode 100644
index 4ddba4b..0000000
--- a/loleaflet/spec/loleaflet/loleafletSpec.js
+++ /dev/null
@@ -1,112 +0,0 @@
-describe('LOLeaflet test', 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 () {
-		var htmlPath = window.location.pathname;
-		var dir = htmlPath.substring(0, htmlPath.lastIndexOf('/'));
-		var fileURL = 'file://' + dir + '/data/eval.odt';
-		// initialize the map and load the document
-		map = L.map('map', {
-			server: 'ws://localhost:9980',
-			doc: fileURL,
-			edit: false,
-			readOnly: false
-		});
-
-		map.on('scrollto', function (e) {
-			map.scrollTop(e.y);
-			map.scrollLeft(e.x);
-		});
-	});
-
-	afterEach(function () {
-		map.off('statusindicator');
-	});
-
-	after(function () {
-		map.remove();
-	});
-
-	describe('', function () {
-		it('Load all new tiles', function (done) {
-			map.on('statusindicator', function (e) {
-				if (e.statusType === 'alltilesloaded') {
-					done();
-				}
-			});
-		});
-
-		it('Make a word Bold', function (done) {
-			map.once('commandstatechanged', function (e) {
-				expect(e.commandName).to.be('.uno: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(174);
-				//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('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);
-		});
-	});
-});
commit 42da9c15db0c795b21d05719dd033e6919c95f42
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 17:37:44 2015 +0300

    loleaflet: search unit tests

diff --git a/loleaflet/spec/loleaflet.html b/loleaflet/spec/loleaflet.html
index 84df9cd..a61707e 100644
--- a/loleaflet/spec/loleaflet.html
+++ b/loleaflet/spec/loleaflet.html
@@ -30,6 +30,7 @@
 	<!-- spec files -->
 	<script type="text/javascript" src="loleaflet/control/PermissionSpec.js"></script>
 	<script type="text/javascript" src="loleaflet/control/PartsSpec.js"></script>
+	<script type="text/javascript" src="loleaflet/control/SearchSpec.js"></script>
 
 	<div id="toolbar" style="hidden">
 	</div>
diff --git a/loleaflet/spec/loleaflet/control/SearchSpec.js b/loleaflet/spec/loleaflet/control/SearchSpec.js
new file mode 100644
index 0000000..da6f5c2
--- /dev/null
+++ b/loleaflet/spec/loleaflet/control/SearchSpec.js
@@ -0,0 +1,102 @@
+describe('Search', function () {
+	this.timeout(10000);
+	var map;
+    var mapSize;
+
+	before(function () {
+		var htmlPath = window.location.pathname;
+		var dir = htmlPath.substring(0, htmlPath.lastIndexOf('/'));
+		var fileURL = 'file://' + dir + '/data/eval.odt';
+		// initialize the map and load the document
+		map = L.map('map', {
+			server: 'ws://localhost:9980',
+			doc: fileURL,
+			edit: false,
+			readOnly: false
+		});
+	});
+
+	after(function () {
+		map.remove();
+	});
+
+	describe('Load the document', function () {
+		it('All tiles loaded', function (done) {
+			map.on('statusindicator', function (e) {
+				if (e.statusType === 'alltilesloaded') {
+					map.off('statusindicator');
+                    mapSize = map.getSize();
+					done();
+				}
+			});
+		});
+	});
+
+	describe('Search', function () {
+		it('Search forward', function (done) {
+			map.once('search', function (e) {
+				expect(e.originalPhrase).to.be('doc');
+				expect(e.count).to.be(1);
+				expect(e.results[0].part).to.be(0);
+				// the first page contains the search result
+				expect(map.getPageSizes().pixels[0].contains(e.results[0].rectangles[0])).to.be.ok();
+				done();
+			});
+			map.search('doc');
+		});
+
+		it('Search backward', function (done) {
+			map.once('search', function (e) {
+				expect(e.originalPhrase).to.be('doc');
+				expect(e.count).to.be(1);
+				expect(e.results[0].part).to.be(0);
+				// the second page contains the search result
+				expect(map.getPageSizes().pixels[1].contains(e.results[0].rectangles[0])).to.be.ok();
+				done();
+			});
+			map.search('doc', 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);
+				expect(e.results).to.be(undefined);
+				done();
+			});
+			map.search('something-not-found', true);
+		});
+	});
+
+	describe('Search all', function () {
+		it('Search forward', function (done) {
+			map.once('search', function (e) {
+				expect(e.originalPhrase).to.be('doc');
+				expect(e.count).to.be(5);
+				expect(e.results.length).to.be(5);
+				done();
+			});
+			map.searchAll('doc');
+		});
+
+		it('Search backward', function (done) {
+			map.once('search', function (e) {
+				expect(e.originalPhrase).to.be('doc');
+				expect(e.count).to.be(5);
+				expect(e.results.length).to.be(5);
+				done();
+			});
+			map.searchAll('doc', 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);
+				expect(e.results).to.be(undefined);
+				done();
+			});
+			map.searchAll('something-not-found', true);
+		});
+	});
+});
commit a141760ab6b94560a74a7e78f80d22774be46574
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 17:35:39 2015 +0300

    loleaflet: parse the integer in the search result message

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 5f047b8..527ae71 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -373,7 +373,7 @@ L.TileLayer = L.GridLayer.extend({
 		var results = [];
 		for (var i = 0; i < obj.searchResultSelection.length; i++) {
 			results.push({
-				part: obj.searchResultSelection[i].part,
+				part: parseInt(obj.searchResultSelection[i].part),
 				rectangles: this._twipsRectanglesToPixelBounds(obj.searchResultSelection[i].rectangles)
 			});
 		}
commit 4216ed83db93677c8fb62db81fee2d1f5d559766
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 16:36:59 2015 +0300

    loleaflet: parts and pages unit tests

diff --git a/loleaflet/spec/loleaflet.html b/loleaflet/spec/loleaflet.html
index 135ef75..84df9cd 100644
--- a/loleaflet/spec/loleaflet.html
+++ b/loleaflet/spec/loleaflet.html
@@ -29,7 +29,7 @@
 
 	<!-- spec files -->
 	<script type="text/javascript" src="loleaflet/control/PermissionSpec.js"></script>
-	<script type="text/javascript" src="loleaflet/loleafletSpec.js"></script>
+	<script type="text/javascript" src="loleaflet/control/PartsSpec.js"></script>
 
 	<div id="toolbar" style="hidden">
 	</div>
diff --git a/loleaflet/spec/loleaflet/control/PartsSpec.js b/loleaflet/spec/loleaflet/control/PartsSpec.js
new file mode 100644
index 0000000..e368827
--- /dev/null
+++ b/loleaflet/spec/loleaflet/control/PartsSpec.js
@@ -0,0 +1,160 @@
+describe('Parts and Pages', function () {
+	this.timeout(10000);
+	var map;
+
+	before(function () {
+		var htmlPath = window.location.pathname;
+		var dir = htmlPath.substring(0, htmlPath.lastIndexOf('/'));
+		var fileURL = 'file://' + dir + '/data/eval.odt';
+		// initialize the map and load the document
+		map = L.map('map', {
+			server: 'ws://localhost:9980',
+			doc: fileURL,
+			edit: false,
+			readOnly: false
+		});
+	});
+
+	after(function () {
+		map.remove();
+	});
+
+	describe('Load the document', function () {
+		it('All tiles loaded', function (done) {
+			map.on('statusindicator', function (e) {
+				if (e.statusType === 'alltilesloaded') {
+					map.off('statusindicator');
+					done();
+				}
+			});
+		});
+	});
+
+	describe('Document preview', function () {
+		it('Page preview', function (done) {
+			map.once('tilepreview', function (e) {
+				expect(e.id).to.be('1');
+				expect(e.width).to.be.within(0, 100);
+				expect(e.height).to.be.within(0, 200);
+				expect(e.part).to.be(0);
+				expect(e.docType).to.be('text');
+				done();
+			});
+			map.getPreview(1, 0, 100, 200, {autoUpdate: true});
+		});
+
+		it('Page custom preview', function (done) {
+			map.once('tilepreview', function (e) {
+				expect(e.id).to.be('2');
+				expect(e.width).to.be(100);
+				expect(e.height).to.be(200);
+				expect(e.part).to.be(0);
+				expect(e.docType).to.be('text');
+				done();
+			});
+			map.getCustomPreview(2, 0, 100, 200, 0, 0, 3000, 6000, {autoUpdate: true});
+		});
+
+
+		it('Automatic preview invalidation', function (done) {
+			var count = 0;
+			map.on('tilepreview', function (e) {
+				if (e.id === '1' || e.id === '2') {
+					count += 1;
+				}
+				if (count === 2) {
+					// as we have 2 previews
+					map.off('tilepreview');
+					done();
+				}
+			});
+			L.Socket.sendMessage('uno .uno:LeftPara');
+		});
+
+		it('Remove the first preview', function (done) {
+			map.once('tilepreview', function (e) {
+				expect(e.id).to.be('2');
+				map.removePreviewUpdate(2);
+				done();
+			});
+			map.removePreviewUpdate(1);
+			L.Socket.sendMessage('uno .uno:CenterPara');
+		});
+	});
+
+	describe('Page navigation', function () {
+		it('Get current page number', function () {
+			expect(map.getCurrentPageNumber()).to.be(0);
+		});
+
+		it('Go to the second page', function (done) {
+			map.once('updatescrolloffset', function (e) {
+				expect(e.y).to.be.above(1000);
+				done();
+			});
+			map.goToPage(1);
+		});
+
+		it('Go to the first page by following the cursor', function (done) {
+			map.once('scrollto', function (e) {
+				expect(e.y).to.be(0);
+				done();
+			});
+			map.once('updatepermission', function (e) {
+				if (e.perm === 'edit') {
+					map.goToPage(0);
+				}
+			});
+			map.setPermission('edit');
+		});
+
+
+		it('Scroll to the first page', function (done) {
+			map.once('pagenumberchanged', function (e) {
+				expect(e.currentPage).to.be(0);
+				expect(e.pages).to.be(2);
+				expect(e.docType).to.be('text');
+				done();
+			});
+			map.scrollTop(0);
+		});
+	});
+
+	describe('Doc stats', function () {
+		it('Get number of pages', function () {
+			expect(map.getNumberOfPages()).to.be(2);
+		});
+
+		it('Get number of parts', function () {
+			expect(map.getNumberOfParts()).to.be(1);
+		});
+
+		it('Get current page number', function () {
+			expect(map.getCurrentPageNumber()).to.be(0);
+		});
+
+		it('Get current part number', function () {
+			expect(map.getCurrentPartNumber()).to.be(0);
+		});
+
+		it('Get document size', function () {
+			expect(Math.floor(map.getDocSize().x)).to.be(1064);
+			expect(Math.floor(map.getDocSize().y)).to.be(2946);
+		});
+
+		it('Get page sizes', function () {
+			var pageSizes = map.getPageSizes();
+			expect(pageSizes).to.only.have.keys(['twips', 'pixels']);
+			expect(pageSizes.twips.length).to.be(map.getNumberOfPages());
+			expect(pageSizes.pixels.length).to.be(map.getNumberOfPages());
+			expect(pageSizes.twips[0].min.equals(new L.Point(284, 284))).to.be.ok();
+			expect(pageSizes.twips[0].max.equals(new L.Point(12190, 17122))).to.be.ok();
+			expect(pageSizes.twips[1].min.equals(new L.Point(284, 17406))).to.be.ok();
+			expect(pageSizes.twips[1].max.equals(new L.Point(12190, 34244))).to.be.ok();
+		});
+
+		it('Get document type', function () {
+			expect(map.getDocType()).to.be('text');
+		});
+	});
+});
diff --git a/loleaflet/spec/loleaflet/loleafletSpec.js b/loleaflet/spec/loleaflet/loleafletSpec.js
index 9b61c43..4ddba4b 100644
--- a/loleaflet/spec/loleaflet/loleafletSpec.js
+++ b/loleaflet/spec/loleaflet/loleafletSpec.js
@@ -56,32 +56,6 @@ describe('LOLeaflet test', function () {
 			map.toggleCommandState('Bold')
 		});
 
-		it('Get document size', function () {
-			var size = map.getDocSize();
-			expect(Math.round(size.x)).to.be(1064);
-			expect(Math.round(size.y)).to.be(2946);
-		});
-
-		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 (done) {
-			map.once('pagenumberchanged', function (e) {
-				expect(e.currentPage).to.be(1);
-				expect(e.pages).to.be(2);
-				expect(e.docType).to.be('text');
-				done();
-			});
-			map.goToPage(1);
-		});
-
 		it('Search backwards', function (done) {
 			map.once('scrollto', function (e) {
 				expect(e.x).to.be(0);
@@ -101,7 +75,6 @@ describe('LOLeaflet test', function () {
 			map.search('something-not-found');
 		});
 
-
 		it('Scroll to the top', function (done) {
 			map.once('updatescrolloffset', function (e) {
 				expect(e.x).to.be(0);
commit d1cec4abebab77001819d446648b5438043b3c2a
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 15:06:51 2015 +0300

    loleaflet: initialize the part/page rectangles arrays

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 9c722fb..5f047b8 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -87,6 +87,8 @@ L.TileLayer = L.GridLayer.extend({
 		this._msgQueue = [];
 		this._toolbarCommandValues = {};
 		this._previewInvalidations = [];
+		this._partPageRectanglesTwips = [];
+		this._partPageRectanglesPixels = [];
 	},
 
     onAdd: function (map) {
commit d7025db15501082810163494fe23d3882ca7450f
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Oct 19 14:23:12 2015 +0300

    loleaflet: permissions unit tests

diff --git a/loleaflet/spec/loleaflet.html b/loleaflet/spec/loleaflet.html
index eb399b3..135ef75 100644
--- a/loleaflet/spec/loleaflet.html
+++ b/loleaflet/spec/loleaflet.html
@@ -28,6 +28,7 @@
 	</script>
 
 	<!-- spec files -->
+	<script type="text/javascript" src="loleaflet/control/PermissionSpec.js"></script>
 	<script type="text/javascript" src="loleaflet/loleafletSpec.js"></script>
 
 	<div id="toolbar" style="hidden">
diff --git a/loleaflet/spec/loleaflet/control/PermissionSpec.js b/loleaflet/spec/loleaflet/control/PermissionSpec.js
new file mode 100644
index 0000000..9c5dca1
--- /dev/null
+++ b/loleaflet/spec/loleaflet/control/PermissionSpec.js
@@ -0,0 +1,126 @@
+describe('Permissions', function () {
+	this.timeout(10000);
+	var map;
+
+	before(function () {
+		var htmlPath = window.location.pathname;
+		var dir = htmlPath.substring(0, htmlPath.lastIndexOf('/'));
+		var fileURL = 'file://' + dir + '/data/eval.odt';
+		// initialize the map and load the document
+		map = L.map('map', {
+			server: 'ws://localhost:9980',
+			doc: fileURL,
+			edit: false,
+			readOnly: false
+		});
+
+		map.on('scrollto', function (e) {
+			map.scrollTop(e.y);
+			map.scrollLeft(e.x);
+		});
+	});
+
+	after(function () {
+		map.remove();
+	});
+
+	describe('Load the document', function () {
+		it('Initialize the tile layer', function (done) {
+			map.on('statusindicator', function (e) {
+				if (e.statusType === 'loleafletloaded') {
+					map.off('statusindicator');
+					done();
+				}
+			});
+		});
+	});
+
+	describe('ReadOnly', function () {
+		it('Set permission to "readonly"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('readonly');
+				done();
+			});
+			map.setPermission('readonly');
+		});
+
+		it('Dragging is enabled', function () {
+			expect(map.dragging.enabled()).to.be(true);
+		});
+
+		it('Selection is disabled', function () {
+			expect(map.isSelectionEnabled()).to.be(false);
+		});
+
+		it('Current permission is "readonly"', function () {
+			expect(map.getPermission()).to.be('readonly');
+		});
+	});
+
+	describe('View', function () {
+		it('Set permission to "view"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('view');
+				done();
+			});
+			map.setPermission('view');
+		});
+
+		it('Dragging is enabled', function () {
+			expect(map.dragging.enabled()).to.be(true);
+		});
+
+		it('Selection is disabled', function () {
+			expect(map.isSelectionEnabled()).to.be(false);
+		});
+
+		it('Current permission is "view"', function () {
+			expect(map.getPermission()).to.be('view');
+		});
+
+		it('Click to switch to "edit"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('edit');
+				done();
+			});
+
+			// simulate a click
+			var latlng = map.unproject(new L.Point(1, 1));
+			var events = ['mousedown', 'mouseup'];
+			for (var i = 0; i < events.length; i++) {
+				map.fire(events[i], {
+					latlng: latlng,
+					layerPoint: map.latLngToLayerPoint(latlng),
+					containerPoint: map.latLngToContainerPoint(latlng),
+					originalEvent: {button:0}
+				});
+			}
+		});
+
+		it('Current permission is "edit"', function () {
+			expect(map.getPermission()).to.be('edit');
+		});
+    });
+
+	describe('Edit', function () {
+		it('Sets permission to "edit"', function (done) {
+			map.once('updatepermission', function (e) {
+				expect(e.perm).to.be('edit');
+				done();
+			});
+			map.setPermission('edit');
+		});
+
+		it('Dragging is disabled', function () {
+			expect(map.dragging.enabled()).to.be(false);
+		});
+
+		it('Selection is enabled', function () {
+			expect(map.isSelectionEnabled()).to.be(true);
+		});
+
+		it('Current permission is "edit"', function () {
+			expect(map.getPermission()).to.be('edit');
+		});
+    });
+});
diff --git a/loleaflet/spec/loleaflet/loleafletSpec.js b/loleaflet/spec/loleaflet/loleafletSpec.js
index 4efa1b9..9b61c43 100644
--- a/loleaflet/spec/loleaflet/loleafletSpec.js
+++ b/loleaflet/spec/loleaflet/loleafletSpec.js
@@ -47,36 +47,6 @@ describe('LOLeaflet test', function () {
 			});
 		});
 
-		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 () {
-			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.commandName).to.be('.uno:Bold');


More information about the Libreoffice-commits mailing list