2015-10-28 04:34:20 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2016-04-08 06:49:33 -05:00
|
|
|
|
2016-04-27 06:17:53 -05:00
|
|
|
#include <algorithm>
|
2016-06-13 19:31:14 -05:00
|
|
|
#include <vector>
|
2016-04-24 13:59:23 -05:00
|
|
|
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/AcceptCertificateHandler.h>
|
2016-04-13 05:19:26 -05:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/Net/HTTPResponse.h>
|
2016-03-21 03:37:39 -05:00
|
|
|
#include <Poco/Net/InvalidCertificateHandler.h>
|
|
|
|
#include <Poco/Net/SSLManager.h>
|
2016-09-26 21:29:53 -05:00
|
|
|
#include <Poco/RegularExpression.h>
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <Poco/URI.h>
|
2016-09-26 21:29:53 -05:00
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
2016-03-19 16:35:24 -05:00
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <Common.hpp>
|
|
|
|
#include <Protocol.hpp>
|
2016-11-10 02:47:25 -06:00
|
|
|
#include <LOOLWebSocket.hpp>
|
2017-01-06 09:54:19 -06:00
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <countloolkits.hpp>
|
|
|
|
#include <helpers.hpp>
|
2016-04-15 09:01:02 -05:00
|
|
|
|
2016-04-28 20:41:00 -05:00
|
|
|
using namespace helpers;
|
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
/// Tests the HTTP WebSocket API of loolwsd. The server has to be started manually before running this test.
|
|
|
|
class HTTPWSTest : public CPPUNIT_NS::TestFixture
|
|
|
|
{
|
2016-01-24 13:58:08 -06:00
|
|
|
const Poco::URI _uri;
|
2015-11-19 04:11:47 -06:00
|
|
|
Poco::Net::HTTPResponse _response;
|
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE(HTTPWSTest);
|
2016-04-13 05:22:35 -05:00
|
|
|
|
2016-10-24 21:54:07 -05:00
|
|
|
CPPUNIT_TEST(testSaveOnDisconnect);
|
2017-04-19 23:13:32 -05:00
|
|
|
CPPUNIT_TEST(testSavePassiveOnDisconnect);
|
2020-02-12 12:17:13 -06:00
|
|
|
CPPUNIT_TEST(testReloadWhileDisconnecting);
|
2016-05-08 23:48:30 -05:00
|
|
|
CPPUNIT_TEST(testInactiveClient);
|
2016-10-05 08:18:53 -05:00
|
|
|
CPPUNIT_TEST(testViewInfoMsg);
|
2017-05-30 21:26:05 -05:00
|
|
|
CPPUNIT_TEST(testUndoConflict);
|
2016-04-13 05:22:35 -05:00
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
void testSaveOnDisconnect();
|
2017-04-19 23:13:32 -05:00
|
|
|
void testSavePassiveOnDisconnect();
|
2016-04-17 22:31:17 -05:00
|
|
|
void testReloadWhileDisconnecting();
|
2016-05-08 23:48:30 -05:00
|
|
|
void testInactiveClient();
|
2016-10-05 08:18:53 -05:00
|
|
|
void testViewInfoMsg();
|
2017-05-30 21:26:05 -05:00
|
|
|
void testUndoConflict();
|
2015-10-28 04:34:20 -05:00
|
|
|
|
2015-11-19 04:11:47 -06:00
|
|
|
public:
|
|
|
|
HTTPWSTest()
|
2016-05-03 02:40:25 -05:00
|
|
|
: _uri(helpers::getTestServerURI())
|
2015-11-19 04:11:47 -06:00
|
|
|
{
|
2016-04-14 05:42:12 -05:00
|
|
|
#if ENABLE_SSL
|
2016-03-21 03:37:39 -05:00
|
|
|
Poco::Net::initializeSSL();
|
|
|
|
// Just accept the certificate anyway for testing purposes
|
|
|
|
Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::AcceptCertificateHandler(false);
|
|
|
|
Poco::Net::Context::Params sslParams;
|
|
|
|
Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams);
|
2016-12-22 08:04:07 -06:00
|
|
|
Poco::Net::SSLManager::instance().initializeClient(nullptr, invalidCertHandler, sslContext);
|
2016-04-08 04:24:52 -05:00
|
|
|
#endif
|
2016-03-21 03:37:39 -05:00
|
|
|
}
|
|
|
|
|
2016-04-14 05:42:12 -05:00
|
|
|
#if ENABLE_SSL
|
2016-03-21 03:37:39 -05:00
|
|
|
~HTTPWSTest()
|
|
|
|
{
|
|
|
|
Poco::Net::uninitializeSSL();
|
2015-11-19 04:11:47 -06:00
|
|
|
}
|
2016-04-08 04:24:52 -05:00
|
|
|
#endif
|
2016-01-24 13:58:08 -06:00
|
|
|
|
|
|
|
void setUp()
|
|
|
|
{
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2016-05-08 23:44:08 -05:00
|
|
|
testCountHowManyLoolkits();
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2016-01-24 13:58:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2016-04-28 21:01:05 -05:00
|
|
|
testNoExtraLoolKitsLeft();
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2016-01-24 13:58:08 -06:00
|
|
|
}
|
2015-10-28 04:34:20 -05:00
|
|
|
};
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
void HTTPWSTest::testSaveOnDisconnect()
|
|
|
|
{
|
2018-02-07 03:17:42 -06:00
|
|
|
const char* testname = "saveOnDisconnect ";
|
2016-10-05 23:48:16 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
const std::string text = helpers::genRandomString(40);
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Test string: [" << text << "].");
|
2016-11-05 16:26:39 -05:00
|
|
|
|
2016-04-28 05:35:56 -05:00
|
|
|
std::string documentPath, documentURL;
|
2017-02-28 15:49:24 -06:00
|
|
|
getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
2016-04-17 19:34:19 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
int kitcount = -1;
|
2016-03-29 20:29:53 -05:00
|
|
|
try
|
|
|
|
{
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
2016-03-29 20:29:53 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket2 = loadDocAndGetSocket(_uri, documentURL, testname);
|
2016-05-09 00:18:55 -05:00
|
|
|
sendTextFrame(socket2, "userinactive");
|
|
|
|
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
deleteAll(socket, testname);
|
2016-11-05 16:26:39 -05:00
|
|
|
sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\n" + text, testname);
|
2016-03-29 20:29:53 -05:00
|
|
|
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Validating what we sent before disconnecting.");
|
|
|
|
|
2016-07-27 07:17:08 -05:00
|
|
|
// Check if the document contains the pasted text.
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
const std::string selection = getAllText(socket, testname);
|
2016-11-05 16:26:39 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL("textselectioncontent: " + text, selection);
|
2016-07-27 07:17:08 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
// 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.
|
2016-10-05 23:48:16 -05:00
|
|
|
getResponseMessage(socket, "statechanged", testname);
|
2016-04-28 06:27:17 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
kitcount = getLoolKitProcessCount();
|
|
|
|
|
2016-04-17 19:34:19 -05:00
|
|
|
// Shutdown abruptly.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Closing connection after pasting.");
|
2016-11-10 02:47:25 -06:00
|
|
|
socket->shutdown();
|
|
|
|
socket2->shutdown();
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
|
2017-04-19 23:13:32 -05:00
|
|
|
// Allow time to save and destroy before we connect again.
|
|
|
|
testNoExtraLoolKitsLeft();
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Loading again.");
|
2017-04-19 23:13:32 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load the same document and check that the last changes (pasted text) is saved.
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
2017-04-19 23:13:32 -05:00
|
|
|
|
|
|
|
// Should have no new instances.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses(kitcount));
|
|
|
|
|
|
|
|
// Check if the document contains the pasted text.
|
2019-10-19 11:32:43 -05:00
|
|
|
const std::string selection = getAllText(socket, testname, text);
|
2017-04-19 23:13:32 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL("textselectioncontent: " + text, selection);
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HTTPWSTest::testSavePassiveOnDisconnect()
|
|
|
|
{
|
2019-10-16 08:12:02 -05:00
|
|
|
const char* testname = "savePassiveOnDisconnect ";
|
2017-04-19 23:13:32 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
const std::string text = helpers::genRandomString(40);
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Test string: [" << text << "].");
|
2017-04-19 23:13:32 -05:00
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
|
|
|
int kitcount = -1;
|
|
|
|
try
|
|
|
|
{
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
getResponseMessage(socket, "textselection", testname);
|
2017-04-19 23:13:32 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
2018-02-11 12:16:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket2 = connectLOKit(_uri, request, _response, testname);
|
2017-04-19 23:13:32 -05:00
|
|
|
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
deleteAll(socket, testname);
|
|
|
|
|
2017-04-19 23:13:32 -05:00
|
|
|
sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\n" + text, testname);
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
getResponseMessage(socket, "textselection:", testname);
|
2017-04-19 23:13:32 -05:00
|
|
|
|
|
|
|
// Check if the document contains the pasted text.
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
const std::string selection = getAllText(socket, testname);
|
2017-04-19 23:13:32 -05:00
|
|
|
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.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Closing connection after pasting.");
|
2017-04-19 23:13:32 -05:00
|
|
|
socket->shutdown(); // Should trigger saving.
|
|
|
|
socket2->shutdown();
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
|
2016-04-17 19:34:19 -05:00
|
|
|
// Allow time to save and destroy before we connect again.
|
2016-05-09 00:18:55 -05:00
|
|
|
testNoExtraLoolKitsLeft();
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Loading again.");
|
2016-03-29 20:29:53 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load the same document and check that the last changes (pasted text) is saved.
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
getResponseMessage(socket, "textselection", testname);
|
2016-03-29 20:29:53 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
// Should have no new instances.
|
|
|
|
CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses(kitcount));
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
// Check if the document contains the pasted text.
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
const std::string selection = getAllText(socket, testname);
|
2016-11-05 16:26:39 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL("textselectioncontent: " + text, selection);
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-17 22:31:17 -05:00
|
|
|
void HTTPWSTest::testReloadWhileDisconnecting()
|
|
|
|
{
|
2018-02-07 03:17:42 -06:00
|
|
|
const char* testname = "reloadWhileDisconnecting ";
|
2016-04-17 22:31:17 -05:00
|
|
|
try
|
|
|
|
{
|
2016-08-30 09:59:13 -05:00
|
|
|
std::string documentPath, documentURL;
|
2017-02-28 15:49:24 -06:00
|
|
|
getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
2016-04-17 22:31:17 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
2016-04-17 22:31:17 -05:00
|
|
|
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
deleteAll(socket, testname);
|
2016-10-05 23:56:37 -05:00
|
|
|
sendTextFrame(socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc", testname);
|
2016-04-17 22:31:17 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
// 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.
|
2016-10-05 23:56:37 -05:00
|
|
|
getResponseMessage(socket, "statechanged", testname);
|
2016-05-09 00:18:55 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
const int kitcount = getLoolKitProcessCount();
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Shutdown abruptly.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Closing connection after pasting.");
|
2016-11-10 02:47:25 -06:00
|
|
|
socket->shutdown();
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Load the same document and check that the last changes (pasted text) is saved.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Loading again.");
|
2016-11-10 02:47:25 -06:00
|
|
|
socket = loadDocAndGetSocket(_uri, documentURL, testname);
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Should have no new instances.
|
2016-04-29 15:00:45 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(kitcount, countLoolKitProcesses(kitcount));
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Check if the document contains the pasted text.
|
2019-10-21 10:42:03 -05:00
|
|
|
const std::string expected = "aaa bbb ccc";
|
|
|
|
const std::string selection = getAllText(socket, testname, expected);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("textselectioncontent: ") + expected, selection);
|
2016-04-17 22:31:17 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
2016-03-25 13:23:26 -05:00
|
|
|
{
|
2016-04-12 12:55:14 -05:00
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
2016-03-25 13:23:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 23:48:30 -05:00
|
|
|
void HTTPWSTest::testInactiveClient()
|
|
|
|
{
|
2018-02-07 03:17:42 -06:00
|
|
|
const char* testname = "inactiveClient ";
|
2016-05-08 23:48:30 -05:00
|
|
|
try
|
|
|
|
{
|
|
|
|
std::string documentPath, documentURL;
|
2017-02-28 15:49:24 -06:00
|
|
|
getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
2016-05-08 23:48:30 -05:00
|
|
|
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket1 = loadDocAndGetSocket(_uri, documentURL, "inactiveClient-1 ");
|
2016-05-08 23:48:30 -05:00
|
|
|
|
|
|
|
// Connect another and go inactive.
|
2018-02-11 12:16:42 -06:00
|
|
|
TST_LOG_NAME("inactiveClient-2 ", "Connecting second client.");
|
2018-02-07 03:17:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket2 = loadDocAndGetSocket(_uri, documentURL, "inactiveClient-2 ", true);
|
2016-09-17 20:48:35 -05:00
|
|
|
sendTextFrame(socket2, "userinactive", "inactiveClient-2 ");
|
2016-05-08 23:48:30 -05:00
|
|
|
|
|
|
|
// While second is inactive, make some changes.
|
test: improve stability of a number of tests
There are numerous race conditions between issuing
action and getting the events. This causes a
mismatch, such that the events from SelectAll
is received when waiting for the events for a
subsequent action (say, Delete).
To make matters worse, sometimes Core issues
an invalidation whilst sending the events for
an action, and this completely messes our
accounting of what events we expect.
This latter could also be an issue with real
clients, however it's less likely to be
disruptive. Still, it is possible that
the client doesn't get key events
because Core had a hiccup, which breaks
the tests.
For the tests at least, the solution is to
re-issue the last action, such that we make
sure that we move forward only when the correct
event is received, or we timeout waiting.
The end results is that tests now don't fail
nearly as often as they used to.
Reviewed-on: https://gerrit.libreoffice.org/80894
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
(cherry picked from commit 050403daf04d6b36ef850006ba4a15eab6be9afc)
Change-Id: Ib1a658846061990649987ca083915a49c1fb092a
Reviewed-on: https://gerrit.libreoffice.org/81565
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2019-10-12 12:47:38 -05:00
|
|
|
deleteAll(socket1, "inactiveClient-1 ");
|
2016-05-08 23:48:30 -05:00
|
|
|
|
|
|
|
// Activate second.
|
2016-09-17 20:48:35 -05:00
|
|
|
sendTextFrame(socket2, "useractive", "inactiveClient-2 ");
|
2016-05-13 07:46:39 -05:00
|
|
|
SocketProcessor("Second ", socket2, [&](const std::string& msg)
|
2016-05-08 23:48:30 -05:00
|
|
|
{
|
|
|
|
const auto token = LOOLProtocol::getFirstToken(msg);
|
2019-08-02 02:35:20 -05:00
|
|
|
// 'window:' is e.g. 'window: {"id":"4","action":"invalidate","rectangle":"0, 0,
|
|
|
|
// 0, 0"}', which is probably fine, given that other invalidations are also
|
|
|
|
// expected.
|
2016-05-08 23:48:30 -05:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("unexpected message: " + msg,
|
2016-07-21 23:30:45 -05:00
|
|
|
token == "cursorvisible:" ||
|
2016-09-19 05:09:12 -05:00
|
|
|
token == "graphicselection:" ||
|
2016-09-19 05:09:35 -05:00
|
|
|
token == "graphicviewselection:" ||
|
2016-09-19 05:09:12 -05:00
|
|
|
token == "invalidatecursor:" ||
|
|
|
|
token == "invalidatetiles:" ||
|
|
|
|
token == "invalidateviewcursor:" ||
|
|
|
|
token == "setpart:" ||
|
|
|
|
token == "statechanged:" ||
|
|
|
|
token == "textselection:" ||
|
|
|
|
token == "textselectionend:" ||
|
|
|
|
token == "textselectionstart:" ||
|
2016-08-19 22:12:28 -05:00
|
|
|
token == "textviewselection:" ||
|
2016-09-20 05:29:53 -05:00
|
|
|
token == "viewcursorvisible:" ||
|
2017-07-06 08:51:24 -05:00
|
|
|
token == "viewinfo:" ||
|
2018-11-13 02:12:03 -06:00
|
|
|
token == "editor:" ||
|
2019-08-02 02:35:20 -05:00
|
|
|
token == "context:" ||
|
2019-09-07 12:15:01 -05:00
|
|
|
token == "window:" ||
|
|
|
|
token == "tableselected:");
|
2016-05-08 23:48:30 -05:00
|
|
|
|
|
|
|
// End when we get state changed.
|
|
|
|
return (token != "statechanged:");
|
|
|
|
});
|
|
|
|
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Second client finished.");
|
2016-05-08 23:48:30 -05:00
|
|
|
socket1->shutdown();
|
|
|
|
socket2->shutdown();
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 08:18:53 -05:00
|
|
|
void HTTPWSTest::testViewInfoMsg()
|
|
|
|
{
|
|
|
|
// Load 2 documents, cross-check the viewid received by each of them in their status message
|
|
|
|
// with the one sent in viewinfo message to itself as well as to other one
|
|
|
|
|
2016-10-08 19:41:34 -05:00
|
|
|
const std::string testname = "testViewInfoMsg-";
|
2016-10-05 08:18:53 -05:00
|
|
|
std::string docPath;
|
|
|
|
std::string docURL;
|
2017-02-28 15:49:24 -06:00
|
|
|
getDocumentPathAndURL("hello.odt", docPath, docURL, testname);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
|
2018-02-11 12:16:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket0 = connectLOKit(_uri, request, _response, testname);
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket1 = connectLOKit(_uri, request, _response, testname);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
std::string response;
|
|
|
|
int part, parts, width, height;
|
|
|
|
int viewid[2];
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load first view and remember the viewid
|
|
|
|
sendTextFrame(socket0, "load url=" + docURL);
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket0, "status:", testname + "0 ");
|
2016-10-08 19:41:34 -05:00
|
|
|
parseDocSize(response.substr(7), "text", part, parts, width, height, viewid[0]);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
// Check if viewinfo message also mentions the same viewid
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket0, "viewinfo: ", testname + "0 ");
|
2016-10-05 08:18:53 -05:00
|
|
|
Poco::JSON::Parser parser0;
|
2016-10-08 19:41:34 -05:00
|
|
|
Poco::JSON::Array::Ptr array = parser0.parse(response.substr(9)).extract<Poco::JSON::Array::Ptr>();
|
2016-10-05 08:18:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), array->size());
|
|
|
|
|
|
|
|
Poco::JSON::Object::Ptr viewInfoObj0 = array->getObject(0);
|
|
|
|
int viewid0 = viewInfoObj0->get("id").convert<int>();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(viewid[0], viewid0);
|
|
|
|
|
|
|
|
// Load second view and remember the viewid
|
|
|
|
sendTextFrame(socket1, "load url=" + docURL);
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket1, "status:", testname + "1 ");
|
2016-10-08 19:41:34 -05:00
|
|
|
parseDocSize(response.substr(7), "text", part, parts, width, height, viewid[1]);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
// Check if viewinfo message in this view mentions
|
|
|
|
// viewid of both first loaded view and this view
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket1, "viewinfo: ", testname + "1 ");
|
2016-10-05 08:18:53 -05:00
|
|
|
Poco::JSON::Parser parser1;
|
2016-10-08 19:41:34 -05:00
|
|
|
array = parser1.parse(response.substr(9)).extract<Poco::JSON::Array::Ptr>();
|
2016-10-05 08:18:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), array->size());
|
|
|
|
|
|
|
|
viewInfoObj0 = array->getObject(0);
|
|
|
|
Poco::JSON::Object::Ptr viewInfoObj1 = array->getObject(1);
|
|
|
|
viewid0 = viewInfoObj0->get("id").convert<int>();
|
|
|
|
int viewid1 = viewInfoObj1->get("id").convert<int>();
|
|
|
|
|
|
|
|
if (viewid[0] == viewid0)
|
|
|
|
CPPUNIT_ASSERT_EQUAL(viewid[1], viewid1);
|
|
|
|
else if (viewid[0] == viewid1)
|
|
|
|
CPPUNIT_ASSERT_EQUAL(viewid[1], viewid0);
|
|
|
|
else
|
|
|
|
CPPUNIT_FAIL("Inconsistent viewid in viewinfo and status messages");
|
|
|
|
|
|
|
|
// Check if first view also got the same viewinfo message
|
2016-10-08 20:24:45 -05:00
|
|
|
const auto response1 = getResponseString(socket0, "viewinfo: ", testname + "0 ");
|
2016-10-05 08:18:53 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(response, response1);
|
|
|
|
}
|
|
|
|
catch(const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 21:26:05 -05:00
|
|
|
void HTTPWSTest::testUndoConflict()
|
|
|
|
{
|
|
|
|
const std::string testname = "testUndoConflict-";
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
std::string docPath;
|
|
|
|
std::string docURL;
|
|
|
|
int conflict;
|
|
|
|
|
|
|
|
getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, docURL);
|
2018-02-11 12:16:42 -06:00
|
|
|
std::shared_ptr<LOOLWebSocket> socket0 = connectLOKit(_uri, request, _response, testname);
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket1 = connectLOKit(_uri, request, _response, testname);
|
2017-05-30 21:26:05 -05:00
|
|
|
|
|
|
|
std::string response;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load first view
|
2019-10-21 10:42:03 -05:00
|
|
|
sendTextFrame(socket0, "load url=" + docURL, testname + "0 ");
|
2017-05-30 21:26:05 -05:00
|
|
|
response = getResponseString(socket0, "invalidatecursor:", testname + "0 ");
|
|
|
|
|
|
|
|
// Load second view
|
2019-10-21 10:42:03 -05:00
|
|
|
sendTextFrame(socket1, "load url=" + docURL, testname + "1 ");
|
2017-05-30 21:26:05 -05:00
|
|
|
response = getResponseString(socket1, "invalidatecursor:", testname + "1 ");
|
|
|
|
|
|
|
|
// edit first view
|
2019-10-20 23:47:55 -05:00
|
|
|
sendChar(socket0, 'A', skNone, testname + "0 ");
|
|
|
|
response = getResponseString(socket0, "invalidateviewcursor: ", testname + "0 ");
|
2019-10-21 10:42:03 -05:00
|
|
|
response = getResponseString(socket0, "invalidateviewcursor: ", testname + "0 ");
|
|
|
|
|
2017-05-30 21:26:05 -05:00
|
|
|
// edit second view
|
2019-10-20 23:47:55 -05:00
|
|
|
sendChar(socket1, 'B', skNone, testname + "1 ");
|
|
|
|
response = getResponseString(socket1, "invalidateviewcursor: ", testname + "1 ");
|
2019-10-21 10:42:03 -05:00
|
|
|
response = getResponseString(socket1, "invalidateviewcursor: ", testname + "1 ");
|
|
|
|
|
2017-05-30 21:26:05 -05:00
|
|
|
// try to undo first view
|
2019-10-21 10:42:03 -05:00
|
|
|
sendTextFrame(socket0, "uno .uno:Undo", testname + "0 ");
|
|
|
|
|
2017-05-30 21:26:05 -05:00
|
|
|
// undo conflict
|
|
|
|
response = getResponseString(socket0, "unocommandresult:", testname + "0 ");
|
2018-02-07 03:17:42 -06:00
|
|
|
Poco::JSON::Object::Ptr objJSON = parser.parse(response.substr(17)).extract<Poco::JSON::Object::Ptr>();
|
2019-10-20 23:47:55 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string(".uno:Undo"), objJSON->get("commandName").toString());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("true"), objJSON->get("success").toString());
|
2018-12-26 12:46:15 -06:00
|
|
|
CPPUNIT_ASSERT(objJSON->has("result"));
|
|
|
|
const Poco::Dynamic::Var parsedResultJSON = objJSON->get("result");
|
|
|
|
const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
|
2019-10-20 23:47:55 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("long"), resultObj->get("type").toString());
|
2018-12-26 12:46:15 -06:00
|
|
|
CPPUNIT_ASSERT(Poco::strToInt(resultObj->get("value").toString(), conflict, 10));
|
2017-05-30 21:26:05 -05:00
|
|
|
CPPUNIT_ASSERT(conflict > 0); /*UNDO_CONFLICT*/
|
|
|
|
}
|
|
|
|
catch(const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
CPPUNIT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 12:06:28 -06:00
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(HTTPWSTest);
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|