desktop/qa/desktop_lib/test_desktop_lib.cxx | 68 ++++++++++++++++++++++++++++ sfx2/source/control/dispatch.cxx | 2 2 files changed, 69 insertions(+), 1 deletion(-)
New commits: commit 90ab893c55b50cef2e7b936fec20864168845eb3 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 Dec 2 08:54:59 2024 +0100 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176287 Tested-by: Jenkins diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 945be7009d0a..11db3d75398b 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -192,6 +192,7 @@ public: void testCommentsImpress(); void testCommentsCallbacksWriter(); void testCommentsAddEditDeleteDraw(); + void testCommentsInReadOnlyMode(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -262,6 +263,7 @@ public: CPPUNIT_TEST(testCommentsImpress); CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testCommentsAddEditDeleteDraw); + CPPUNIT_TEST(testCommentsInReadOnlyMode); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2665,6 +2667,72 @@ 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"); + + int viewId = pDocument->m_pDocumentClass->createView(pDocument); + pDocument->m_pDocumentClass->setView(pDocument, viewId); + + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{\".uno:Author\":{\"type\":\"string\",\"value\":\"LOK User1\"}}"); + + 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 d8a24baebcc0..87dc47d8c976 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -1635,7 +1635,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 )