[Libreoffice-commits] online.git: 12 commits - loleaflet/spec loleaflet/src
Mihai Varga
mihai.varga at collabora.com
Tue Oct 20 01:54:53 PDT 2015
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/Toolbar.js | 5
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.SlideShow.js | 2
13 files changed, 476 insertions(+), 179 deletions(-)
New commits:
commit 7785694d644fbc5f5a50de9bdc038755d209fdb9
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 4ebcc3d2d239029bc59f32f1c648114de7e9ad33
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 701f0a1ea2093a8bf9bbb4f03cfb22c7a31ae285
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 7d1918e36702e36f52347d4e1553a3542ddc92bb
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Tue Oct 20 11:09:08 2015 +0300
loleaflet: add id paramater to downloadAs method
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 da463aa..5aa146b 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -287,7 +287,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');
diff --git a/loleaflet/src/map/handler/Map.SlideShow.js b/loleaflet/src/map/handler/Map.SlideShow.js
index e4ca979..3a644a5 100644
--- a/loleaflet/src/map/handler/Map.SlideShow.js
+++ b/loleaflet/src/map/handler/Map.SlideShow.js
@@ -41,7 +41,7 @@ L.Map.SlideShow = L.Handler.extend({
this._onFullScreenChange, this);
this.fullscreen = true;
- L.Socket.sendMessage('downloadas name=slideshow.svg id=slideshow format=svg options=');
+ this._map.downloadAs('slideshow.svg', 'svg', null, 'slideshow');
},
_onFullScreenChange: function (e) {
commit 0f9263d76f5991fdf288e3aa80654239b505d130
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 4c5e61f..741d33d 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 === 'print') {
commit 80c34db3d14a0a575302c5ef5085b0d0c1587939
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 9b06a0df774b4eef9ddbe8456fcbd85c47042ad3
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 03ffa4e740c0169994fc485ae83ef70a278df92b
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 7143b86849b258479e461b4fb7901c0114e1520c
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 fa7b265..4c5e61f 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -376,7 +376,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 38718c1915c50b62de00ad863a2f9683fe02f455
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 285e625acc45a81007dbb4d8a8b906143795db7f
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 eb70050..fa7b265 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 e5ba1f3860f20925ce1212abaeb32049677dba22
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