From 454a53ff72d06f6c2e2b7af2447d374e73cf56bb Mon Sep 17 00:00:00 2001 From: Henrik Fehlauer Date: Tue, 2 Jan 2018 21:28:16 +0100 Subject: [PATCH] Fix testSaveAsUndoStackAnnotations autotest Summary: Okular allows to drop changes when saving to a file format not supporting those. However, this is only sensible for {nav Save As}, while for {nav Save} the {nav Continue} button is not needed. When this behaviour was introduced in 481676dcedf1, the `jpg` test row failed subsequently, because `closeDialogHelper` relies on the availability of the {nav Continue} button. The `epub` test row is similar, but `returns` early because it does not allow `canSwapBackingFile` and therefore does not fail the test afterwards. As the test progresses, the initial {nav Save As} (`potato.jpg` to `/tmp/123.jpg`) is implicitly followed by {nav Save} (`/tmp/123.jpg` to `/tmp/123.jpg`) for each subsequent `part.saveAs`. This causes the {nav Continue} button to vanish, so eventually the test will fail. Forcing {nav Save As} so the {nav Continue} button continues to exist could be done in multiple ways, but just alternating between two different files to save seems like the most efficient and most readable approach. Test Plan: - `./autotests/parttest testSaveAsUndoStackAnnotations:jpg` now passes. - Other test rows still pass. - No changes to non-test code needed. Reviewers: aacid, #okular Reviewed By: aacid, #okular Subscribers: #okular Tags: #okular Differential Revision: https://phabricator.kde.org/D9579 --- autotests/parttest.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/autotests/parttest.cpp b/autotests/parttest.cpp index 0b25f4423..503e0a8bb 100644 --- a/autotests/parttest.cpp +++ b/autotests/parttest.cpp @@ -911,9 +911,16 @@ void PartTest::testSaveAsUndoStackAnnotations() QScopedPointer closeDialogHelper; - QTemporaryFile saveFile( QString( "%1/okrXXXXXX.%2" ).arg( QDir::tempPath() ).arg ( extension ) ); - QVERIFY( saveFile.open() ); - saveFile.close(); + // closeDialogHelper relies on the availability of the "Continue" button to drop changes + // when saving to a file format not supporting those. However, this button is only sensible + // and available for "Save As", but not for "Save". By alternately saving to saveFile1 and + // saveFile2 we always force "Save As", so closeDialogHelper keeps working. + QTemporaryFile saveFile1( QString( "%1/okrXXXXXX_1.%2" ).arg( QDir::tempPath() ).arg ( extension ) ); + QVERIFY( saveFile1.open() ); + saveFile1.close(); + QTemporaryFile saveFile2( QString( "%1/okrXXXXXX_2.%2" ).arg( QDir::tempPath() ).arg ( extension ) ); + QVERIFY( saveFile2.open() ); + saveFile2.close(); Okular::Part part(nullptr, nullptr, QVariantList()); part.openDocument( file ); @@ -930,7 +937,7 @@ void PartTest::testSaveAsUndoStackAnnotations() closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); if (!canSwapBackingFile) { // The undo/redo stack gets lost if you can not swap the backing file @@ -944,7 +951,7 @@ void PartTest::testSaveAsUndoStackAnnotations() part.m_document->undo(); QVERIFY( !part.m_document->canUndo() ); - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->page( 0 )->annotations().isEmpty() ); // Check we can redo the annot add after save @@ -966,7 +973,7 @@ void PartTest::testSaveAsUndoStackAnnotations() QVERIFY( part.m_document->page( 0 )->annotations().isEmpty() ); // Check we can still undo the annot remove after save - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( part.m_document->canUndo() ); @@ -976,7 +983,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile2.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( !part.m_document->canUndo() ); @@ -984,7 +991,7 @@ void PartTest::testSaveAsUndoStackAnnotations() // Redo the add annotation - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canRedo() ); part.m_document->redo(); QVERIFY( part.m_document->canUndo() ); @@ -1007,7 +1014,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile2.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( part.m_document->canUndo() ); @@ -1015,7 +1022,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( part.m_document->canUndo() ); @@ -1023,7 +1030,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile2.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( part.m_document->canUndo() ); @@ -1031,14 +1038,14 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canUndo() ); part.m_document->undo(); QVERIFY( !part.m_document->canUndo() ); QVERIFY( part.m_document->canRedo() ); QVERIFY( part.m_document->page( 0 )->annotations().isEmpty() ); - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canRedo() ); part.m_document->redo(); QVERIFY( part.m_document->canRedo() ); @@ -1046,7 +1053,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile2.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canRedo() ); part.m_document->redo(); QVERIFY( part.m_document->canRedo() ); @@ -1054,7 +1061,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile1.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canRedo() ); part.m_document->redo(); QVERIFY( part.m_document->canRedo() ); @@ -1062,7 +1069,7 @@ void PartTest::testSaveAsUndoStackAnnotations() if ( !nativelySupportsAnnotations && !saveToArchive ) { closeDialogHelper.reset(new CloseDialogHelper( &part, QDialogButtonBox::No )); // this is the "you're going to lose the annotations" dialog } - QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile.fileName() ), saveFlags ) ); + QVERIFY( part.saveAs( QUrl::fromLocalFile( saveFile2.fileName() ), saveFlags ) ); QVERIFY( part.m_document->canRedo() ); part.m_document->redo(); QVERIFY( !part.m_document->canRedo() );