desktop/qa/data/validity.ods |binary desktop/qa/desktop_lib/test_desktop_lib.cxx | 78 ++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+)
New commits: commit 323dabcb96451c21aaaf5fad41099a57480b484f Author: Gökay Şatır <gokaysa...@collabora.com> AuthorDate: Tue Dec 24 11:38:39 2024 +0300 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Jan 2 11:38:47 2025 +0100 cool#10794 Test for: Don't open validity dropdown in readOnly mode. Issue: In readonly mode, validity dropdown is still usable. There are 2 tests here. 1 is to ensure that dropdown opens and it also exists as an example on dropdown events. The other is to ensure that dropdown is not opened in readonly mode. Signed-off-by: Gökay Şatır <gokaysa...@collabora.com> Change-Id: Id73c4421454af2af4f306925d6c628f776ecd2d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179303 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/desktop/qa/data/validity.ods b/desktop/qa/data/validity.ods new file mode 100644 index 000000000000..9f9677242ff0 Binary files /dev/null and b/desktop/qa/data/validity.ods differ diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index 849b79a72e07..f6429bc7f4d9 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -199,6 +199,8 @@ public: void testCommentsCallbacksWriter(); void testCommentsAddEditDeleteDraw(); void testCommentsInReadOnlyMode(); + void testCalcValidityDropdown(); + void testCalcValidityDropdownInReadonlyMode(); void testRunMacro(); void testExtractParameter(); void testGetSignatureState_NonSigned(); @@ -270,6 +272,8 @@ public: CPPUNIT_TEST(testCommentsCallbacksWriter); CPPUNIT_TEST(testCommentsAddEditDeleteDraw); CPPUNIT_TEST(testCommentsInReadOnlyMode); + CPPUNIT_TEST(testCalcValidityDropdown); + CPPUNIT_TEST(testCalcValidityDropdownInReadonlyMode); CPPUNIT_TEST(testRunMacro); CPPUNIT_TEST(testExtractParameter); CPPUNIT_TEST(testGetSignatureState_Signed); @@ -2136,6 +2140,7 @@ class ViewCallback int mnView; public: OString m_aCellFormula; + boost::property_tree::ptree m_JSONDialog; int m_nTableSelectionCount; int m_nColorPaletteCallbackCount = 0; bool m_bEmptyTableSelection; @@ -2220,6 +2225,13 @@ public: ++m_nColorPaletteCallbackCount; } break; + case LOK_CALLBACK_JSDIALOG: + { + m_JSONDialog.clear(); + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, m_JSONDialog); + } + break; } } }; @@ -2738,6 +2750,72 @@ void DesktopLOKTest::testCommentsInReadOnlyMode() //CPPUNIT_ASSERT_EQUAL(nCommentId, aView.m_aCommentCallbackResult.get<int>("id")); } +void DesktopLOKTest::testCalcValidityDropdown() +{ + LibLODocument_Impl* pDocument = loadDoc("validity.ods"); + Scheduler::ProcessEventsToIdle(); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + Scheduler::ProcessEventsToIdle(); + + ViewCallback aView(pDocument); + Scheduler::ProcessEventsToIdle(); + + // Select row 1 from column 1. + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1000, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 1000, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + + // Open dropdown. + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1380, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 1380, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + + // Select some value from dropdown. + pDocument->pClass->sendDialogEvent(pDocument, aView.m_JSONDialog.get_child("id").get_value<int>(), "{\"id\":\"list\", \"cmd\": \"select\", \"data\": \"3\", \"type\": \"treeview\"}"); + Scheduler::ProcessEventsToIdle(); + + // Activate the selected value. + pDocument->pClass->sendDialogEvent(pDocument, aView.m_JSONDialog.get_child("id").get_value<int>(), "{\"id\":\"list\", \"cmd\": \"activate\", \"data\": \"3\", \"type\": \"treeview\"}"); + Scheduler::ProcessEventsToIdle(); + + // Check the content of the current cell. The selected value of the dropdown was 1. It should be 4 now. + char* pCellContent = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", nullptr); + CPPUNIT_ASSERT_EQUAL("4"_ostr, OString(pCellContent)); + free(pCellContent); +} + +void DesktopLOKTest::testCalcValidityDropdownInReadonlyMode() +{ + LibLODocument_Impl* pDocument = loadDoc("validity.ods"); + Scheduler::ProcessEventsToIdle(); + pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}"); + Scheduler::ProcessEventsToIdle(); + + ViewCallback aView(pDocument); + Scheduler::ProcessEventsToIdle(); + + int viewId = pDocument->m_pDocumentClass->getView(pDocument); + SfxLokHelper::setViewReadOnly(viewId, true); + Scheduler::ProcessEventsToIdle(); + + // Select row 1 from column 1. + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1000, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 1000, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + + // Attempt to open dropdown. + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 1380, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + pDocument->pClass->postMouseEvent(pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, 1380, 150, 1, 1, 0); + Scheduler::ProcessEventsToIdle(); + + // Dropdown should not open in readonly mode. + CPPUNIT_ASSERT_EQUAL(true, aView.m_JSONDialog.empty()); +} + void DesktopLOKTest::testRunMacro() { LibLibreOffice_Impl aOffice;