Skip to content

Commit

Permalink
[office] Add regression tests for PDFDocumentPage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed Nov 25, 2016
1 parent 736327e commit 32560a3
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ install(FILES ${CMAKE_BINARY_DIR}/sailfish-office.ts DESTINATION ${CMAKE_INSTALL
install(FILES org.sailfish.office.service DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dbus-1/services)
install(FILES org.sailfish.office.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dbus-1/interfaces)

install(FILES tests/tst_PDFDocumentPage.qml DESTINATION /opt/tests/sailfish-office)
install(FILES tests/data/broken.pdf DESTINATION /opt/tests/sailfish-office/data)
install(FILES tests/data/protected.pdf DESTINATION /opt/tests/sailfish-office/data)
install(FILES tests/data/sample.pdf DESTINATION /opt/tests/sailfish-office/data)
2 changes: 2 additions & 0 deletions pdf/pdfjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ RenderPageJob::RenderPageJob(int index, uint width, QQuickWindow *window,
void RenderPageJob::run()
{
Q_ASSERT(m_document);
Q_ASSERT(!m_document->isLocked());
Q_ASSERT(m_index < m_document->numPages());

Poppler::Page *page = m_document->page(m_index);
QSizeF size = page->pageSizeF();
Expand Down
5 changes: 5 additions & 0 deletions pdf/pdfrenderthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,12 @@ void PDFRenderThreadQueue::processPendingJob()
case PDFJob::LoadDocumentJob:
d->loadFailure = false;
break;
case PDFJob::UnLockDocumentJob:
job->m_document = d->document;
break;
default:
if (d->document->isLocked())
return;
job->m_document = d->document;
break;
}
Expand Down
7 changes: 7 additions & 0 deletions plugin/PDFDocumentPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import "PDFStorage.js" as PDFStorage
DocumentPage {
id: base

property alias document: pdfDocument
property alias placeHolder: placeHolderLoader
property alias toolbar: toolbar

property var _settings // Handle save and restore the view settings using PDFStorage
property ContextMenu contextMenuLinks
property ContextMenu contextMenuText
Expand Down Expand Up @@ -90,6 +94,7 @@ DocumentPage {
}

Loader {
id: placeHolderLoader
parent: base
sourceComponent: (pdfDocument.failure || pdfDocument.locked) ? placeholderComponent : null
anchors.verticalCenter: parent.verticalCenter
Expand Down Expand Up @@ -170,6 +175,8 @@ DocumentPage {
id: toolbar

property Notification notice
property alias searchIconized: search.iconized
property alias searchText: search.text

width: parent.width
height: base.orientation == Orientation.Portrait
Expand Down
34 changes: 16 additions & 18 deletions plugin/PDFView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SilicaFlickable {
property alias selection: pdfSelection
property alias selectionDraggable: selectionView.draggable
property bool canMoveBack: (_contentYAtGotoLink >= 0)
property bool scrolling: focusSearchMatch.running || scrollAnimation.running || quickScrollAnimation.running

property bool scaled: pdfCanvas.width != width
property QtObject _feedbackEffect
Expand Down Expand Up @@ -123,23 +124,26 @@ SilicaFlickable {
}

function scrollTo(pt, pageId) {
if ((pt.y < base.contentY + base.height && pt.y > base.contentY - base.height)
&& (pt.x < base.contentX + base.width && pt.x > base.contentX - base.width)) {
scrollX.to = pt.x
scrollY.to = pt.y
// Ensure that pt can be reached.
var ctX = Math.max(0, Math.min(contentWidth - width, pt.x))
var ctY = Math.max(0, Math.min(contentHeight - height, pt.y))
if ((ctY < base.contentY + base.height && ctY > base.contentY - base.height)
&& (ctX < base.contentX + base.width && ctX > base.contentX - base.width)) {
scrollX.to = ctX
scrollY.to = ctY
scrollAnimation.start()
} else {
var deltaY = pt.y - base.contentY
var deltaY = ctY - base.contentY
if (deltaY < 0) {
deltaY = Math.max(deltaY / 2., -base.height / 2.)
} else {
deltaY = Math.min(deltaY / 2., base.height / 2.)
}
leaveX.to = (base.contentX + pt.x) / 2
leaveX.to = (base.contentX + ctX) / 2
leaveY.to = base.contentY + deltaY
returnX.to = pt.x
returnY.from = pt.y - deltaY
returnY.to = pt.y
returnX.to = ctX
returnY.from = ctY - deltaY
returnY.to = ctY
quickScrollAnimation.pageTo = pageId
quickScrollAnimation.start()
}
Expand Down Expand Up @@ -414,20 +418,14 @@ SilicaFlickable {
if (left !== undefined && left >= 0.) {
scrollX = rect.x + left * rect.width - ( leftSpacing !== undefined ? leftSpacing : 0.)
}
if (scrollX > contentWidth - width) {
scrollX = contentWidth - width
}
// Adjust vertical position.
scrollY = rect.y + (top === undefined ? 0. : top * rect.height) - ( topSpacing !== undefined ? topSpacing : 0.)
if (scrollY > contentHeight - height) {
scrollY = contentHeight - height
}
return Qt.point(Math.max(0, scrollX), Math.max(0, scrollY))
return Qt.point(scrollX, scrollY)
}
function goToPage(pageNumber, top, left, topSpacing, leftSpacing) {
var pt = contentAt(pageNumber, top, left, topSpacing, leftSpacing)
contentX = pt.x
contentY = pt.y
contentX = Math.max(0, Math.min(contentWidth - width, pt.x))
contentY = Math.max(0, Math.min(contentHeight - height, pt.y))
}
// This function is the inverse of goToPage(), returning (pageNumber, top, left).
function getPagePosition() {
Expand Down
1 change: 1 addition & 0 deletions plugin/SearchBarItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ BackgroundItem {
property bool iconized: true
property int modelCount: -1
property real iconizedWidth
property alias text: searchField._searchText

property real _margin: Math.max((iconizedWidth - searchIcon.width) / 2., 0.)

Expand Down
14 changes: 14 additions & 0 deletions rpm/sailfish-office.spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ Summary: Translation source for %{name}
License: GPLv2
Group: System/Base

%package tests
Summary: Unitary tests for %{name}
License: GPLv2
Group: System/Base
Requires: qt5-qtdeclarative-import-qttest
Requires: qt5-qtdeclarative-devel-tools
Requires: %{name} = %{version}-%{release}


%description
%{summary}.

%description ts-devel
%{summary}.

%description tests
%{summary}.


%files
%defattr(-,root,root,-)
Expand All @@ -52,6 +63,9 @@ Group: System/Base
%files ts-devel
%{_datadir}/translations/source/*.ts

%files tests
/opt/tests/sailfish-office/tst_PDFDocumentPage.qml
/opt/tests/sailfish-office/data/*.pdf

%prep
%setup -q -n %{name}-%{version}
Expand Down
Empty file added tests/data/broken.pdf
Empty file.
Binary file added tests/data/protected.pdf
Binary file not shown.
Binary file added tests/data/sample.pdf
Binary file not shown.
Loading

0 comments on commit 32560a3

Please sign in to comment.