test/httpwstest.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+)
New commits: commit b0a21ae1b349a4eb52d93f1b63a4f8f10463b0f2 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Thu Apr 20 00:13:32 2017 -0400 wsd: unittest for correctly saving in presence of passive clients Passive clients that don't load the document can be disruptive as they are not useful for saving the document, so we need to ignore them and use reliable sessions. Change-Id: I162ec00823ba5af776fcb55f6d58149f2a56d7bb Reviewed-on: https://gerrit.libreoffice.org/36712 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> (cherry picked from commit 876e4098357df8319bf6c721aca359cb94be9fb7) Reviewed-on: https://gerrit.libreoffice.org/36715 Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/test/httpwstest.cpp b/test/httpwstest.cpp index 78d717fb..917a41dd 100644 --- a/test/httpwstest.cpp +++ b/test/httpwstest.cpp @@ -70,6 +70,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testReload); CPPUNIT_TEST(testGetTextSelection); CPPUNIT_TEST(testSaveOnDisconnect); + CPPUNIT_TEST(testSavePassiveOnDisconnect); CPPUNIT_TEST(testReloadWhileDisconnecting); CPPUNIT_TEST(testExcelLoad); CPPUNIT_TEST(testPaste); @@ -123,6 +124,7 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture void testReload(); void testGetTextSelection(); void testSaveOnDisconnect(); + void testSavePassiveOnDisconnect(); void testReloadWhileDisconnecting(); void testExcelLoad(); void testPaste(); @@ -711,6 +713,74 @@ void HTTPWSTest::testSaveOnDisconnect() } } +void HTTPWSTest::testSavePassiveOnDisconnect() +{ + const auto testname = "saveOnPassiveDisconnect "; + + const auto text = helpers::genRandomString(40); + std::cerr << "Test string: [" << text << "]." << std::endl; + + std::string documentPath, documentURL; + getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname); + + int kitcount = -1; + try + { + auto socket = loadDocAndGetSocket(_uri, documentURL, testname); + + Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL); + auto socket2 = connectLOKit(_uri, request, _response); + + sendTextFrame(socket, "uno .uno:SelectAll", testname); + sendTextFrame(socket, "uno .uno:Delete", testname); + sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\n" + text, testname); + + // Check if the document contains the pasted text. + sendTextFrame(socket, "uno .uno:SelectAll", testname); + sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8", testname); + const auto selection = assertResponseString(socket, "textselectioncontent:", testname); + CPPUNIT_ASSERT_EQUAL("textselectioncontent: " + text, selection); + + // Closing connection too fast might not flush buffers. + // Often nothing more than the SelectAll reaches the server before + // the socket is closed, when the doc is not even modified yet. + getResponseMessage(socket, "statechanged", testname); + + kitcount = getLoolKitProcessCount(); + + // Shutdown abruptly. + std::cerr << "Closing connection after pasting." << std::endl; + socket->shutdown(); // Should trigger saving. + socket2->shutdown(); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } + + // Allow time to save and destroy before we connect again. + testNoExtraLoolKitsLeft(); + std::cerr << "Loading again." << std::endl; + try + { + // Load the same document and check that the last changes (pasted text) is saved. + auto socket = loadDocAndGetSocket(_uri, documentURL, testname); + + // Should have no new instances. + CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses(kitcount)); + + // Check if the document contains the pasted text. + sendTextFrame(socket, "uno .uno:SelectAll", testname); + sendTextFrame(socket, "gettextselection mimetype=text/plain;charset=utf-8", testname); + const auto selection = assertResponseString(socket, "textselectioncontent:", testname); + CPPUNIT_ASSERT_EQUAL("textselectioncontent: " + text, selection); + } + catch (const Poco::Exception& exc) + { + CPPUNIT_FAIL(exc.displayText()); + } +} + void HTTPWSTest::testReloadWhileDisconnecting() { const auto testname = "reloadWhileDisconnecting "; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits