desktop/qa/desktop_lib/test_desktop_lib.cxx | 67 ++++++++++++++++++++++++++++ sfx2/source/control/dispatch.cxx | 2 2 files changed, 68 insertions(+), 1 deletion(-)
New commits: commit 1a6622b2f2373c7f6ce823a41e165eff22bbf889 Author: Gökay Şatır <gokaysa...@gmail.com> AuthorDate: Tue Aug 20 15:56:50 2024 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Aug 26 10:44:39 2024 +0200 Add a test for setAllowChangeComments function. This is a follow up for: * https://gerrit.libreoffice.org/c/core/+/164570/2 Signed-off-by: Gökay Şatır <gokaysa...@gmail.com> Change-Id: If748aac779767174d14dde33efab62d980b115ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172114 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index c501f43d5315..cfacc5cc4086 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -198,6 +198,7 @@ public: void testCommentsImpress(); void testCommentsCallbacksWriter(); void testCommentsAddEditDeleteDraw(); + void testCommentsInReadOnlyMode(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -268,6 +269,7 @@ public: CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testCommentsAddEditDeleteDraw); + CPPUNIT_TEST(testCommentsInReadOnlyMode); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2670,6 +2672,71 @@ void DesktopLOKTest::testCommentsAddEditDeleteDraw() CPPUNIT_ASSERT_EQUAL(nCommentId1, aView1.m_aCommentCallbackResult.get<int>("id")); } +void DesktopLOKTest::testCommentsInReadOnlyMode() +{ + // Comments callback are emitted only if tiled annotations are off + comphelper::LibreOfficeKit::setTiledAnnotations(false); + LibLODocument_Impl* pDocument = loadDoc("blank_text.odt"); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + + int viewId = pDocument->m_pDocumentClass->createView(pDocument); + pDocument->m_pDocumentClass->setView(pDocument, viewId); + + SfxLokHelper::setViewReadOnly(viewId, true); + SfxLokHelper::setAllowChangeComments(viewId, true); + + Scheduler::ProcessEventsToIdle(); + + ViewCallback aView(pDocument); + + // Add a new comment + OString aCommandArgs; + { + tools::JsonWriter aJson; + addParameter(aJson, "Text", "string", "Comment"); + addParameter(aJson, "Author", "string", "LOK User1"); + aCommandArgs = aJson.finishAndGetAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:InsertAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action + CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView.m_aCommentCallbackResult.get<std::string>("action")); + int nCommentId = aView.m_aCommentCallbackResult.get<int>("id"); + + // Edit the previously added comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId)); + addParameter(aJson, "Text", "string", "Edited comment"); + aCommandArgs = aJson.finishAndGetAsOString(); + } + + pDocument->pClass->postUnoCommand(pDocument, ".uno:EditAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action + CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView.m_aCommentCallbackResult.get<std::string>("action")); + CPPUNIT_ASSERT_EQUAL(nCommentId, aView.m_aCommentCallbackResult.get<int>("id")); + + // Delete Comment + { + tools::JsonWriter aJson; + addParameter(aJson, "Id", "string", OString::number(nCommentId)); + aCommandArgs = aJson.finishAndGetAsOString(); + } + pDocument->pClass->postUnoCommand(pDocument, ".uno:DeleteAnnotation", aCommandArgs.getStr(), false); + Scheduler::ProcessEventsToIdle(); + + // Result is not sent for delete operation for some reason. But it is sent when debugging with online. + // TODO: Enable below 2 checks. + + // We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action + //CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView.m_aCommentCallbackResult.get<std::string>("action")); + //CPPUNIT_ASSERT_EQUAL(nCommentId, aView.m_aCommentCallbackResult.get<int>("id")); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice; diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 4f9d33227441..958f493f01a3 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1634,7 +1634,7 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, SfxSlotServer& rServer) // This check can be true only if Lokit is active and view is readonly. if (pSlot && bCheckForCommentCommands) - bReadOnly = IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand()); + bReadOnly = !IsCommandAllowedInLokReadOnlyViewMode(pSlot->GetCommand()); if ( pSlot && pSlot->nDisableFlags != SfxDisableFlags::NONE && ( static_cast<int>(pSlot->nDisableFlags) & static_cast<int>(pObjShell->GetDisableFlags()) ) != 0 )