2015-10-28 04:34:20 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2015-10-28 04:34:20 -05:00
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2023-04-25 17:45:53 -05:00
|
|
|
#include <chrono>
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2016-04-08 06:49:33 -05:00
|
|
|
|
2021-03-31 15:50:21 -05:00
|
|
|
#include "WebSocketSession.hpp"
|
|
|
|
|
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>
|
2017-01-06 09:54:19 -06:00
|
|
|
|
2021-03-25 13:12:05 -05:00
|
|
|
#include "lokassert.hpp"
|
2021-11-18 06:08:14 -06:00
|
|
|
#include <countcoolkits.hpp>
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <helpers.hpp>
|
2016-04-15 09:01:02 -05:00
|
|
|
|
2016-04-28 20:41:00 -05:00
|
|
|
using namespace helpers;
|
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
/// Tests the HTTP WebSocket API of coolwsd. The server has to be started manually before running this test.
|
2015-10-28 04:34:20 -05:00
|
|
|
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;
|
2021-04-12 23:48:47 -05:00
|
|
|
std::shared_ptr<SocketPoll> _socketPoll;
|
2015-11-19 04:11:47 -06:00
|
|
|
|
2015-10-28 04:34:20 -05:00
|
|
|
CPPUNIT_TEST_SUITE(HTTPWSTest);
|
2016-04-13 05:22:35 -05:00
|
|
|
|
2022-02-18 15:30:52 -06:00
|
|
|
CPPUNIT_TEST(testExoticLang);
|
2016-10-24 21:54:07 -05:00
|
|
|
CPPUNIT_TEST(testSaveOnDisconnect);
|
2020-02-14 02:03:09 -06:00
|
|
|
// This test is failing
|
|
|
|
//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();
|
|
|
|
|
2022-02-18 15:30:52 -06:00
|
|
|
void testExoticLang();
|
2016-03-29 20:29:53 -05:00
|
|
|
void testSaveOnDisconnect();
|
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())
|
2021-04-12 23:48:47 -05:00
|
|
|
, _socketPoll(std::make_shared<SocketPoll>("HttpWsPoll"))
|
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
|
|
|
}
|
|
|
|
|
|
|
|
~HTTPWSTest()
|
|
|
|
{
|
2021-03-25 13:12:05 -05:00
|
|
|
#if ENABLE_SSL
|
2016-03-21 03:37:39 -05:00
|
|
|
Poco::Net::uninitializeSSL();
|
2016-04-08 04:24:52 -05:00
|
|
|
#endif
|
2021-03-25 13:12:05 -05:00
|
|
|
}
|
2016-01-24 13:58:08 -06:00
|
|
|
|
|
|
|
void setUp()
|
|
|
|
{
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2021-11-18 06:08:14 -06:00
|
|
|
testCountHowManyCoolkits();
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2021-04-12 23:48:47 -05:00
|
|
|
_socketPoll->startThread();
|
2016-01-24 13:58:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
2021-04-12 23:48:47 -05:00
|
|
|
_socketPoll->joinThread();
|
2018-01-22 08:11:43 -06:00
|
|
|
resetTestStartTime();
|
2021-11-18 06:08:14 -06:00
|
|
|
testNoExtraCoolKitsLeft();
|
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
|
|
|
};
|
|
|
|
|
2022-02-18 15:30:52 -06:00
|
|
|
void HTTPWSTest::testExoticLang()
|
|
|
|
{
|
|
|
|
const std::string testname = "saveOnDisconnect- ";
|
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2024-02-03 15:01:48 -06:00
|
|
|
// es-419 locale takes significantly longer than the default.
|
|
|
|
// 22+ seconds has been observed.
|
|
|
|
const auto timeout = std::chrono::seconds(COMMAND_TIMEOUT_SECS * 6);
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket = loadDocAndGetSession(
|
|
|
|
_socketPoll, _uri, documentURL, "exoticlocale", /*isView=*/true, /*isAssert=*/true,
|
|
|
|
/*loadParams=*/" lang=es-419", timeout);
|
2022-02-18 15:30:52 -06:00
|
|
|
socket->asyncShutdown();
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
void HTTPWSTest::testSaveOnDisconnect()
|
|
|
|
{
|
2021-03-25 13:12:05 -05:00
|
|
|
const std::string 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
|
|
|
|
{
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket1
|
|
|
|
= loadDocAndGetSession(_socketPoll, _uri, documentURL, testname + "1 ");
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket2
|
|
|
|
= loadDocAndGetSession(_socketPoll, _uri, documentURL, testname + "2 ");
|
2016-03-29 20:29:53 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
sendTextFrame(socket2, "userinactive");
|
|
|
|
|
2023-04-25 17:45:53 -05:00
|
|
|
deleteAll(socket1, testname, std::chrono::milliseconds(100), 1);
|
2021-03-25 13:12:05 -05:00
|
|
|
sendTextFrame(socket1, "paste mimetype=text/plain;charset=utf-8\n" + text, testname);
|
2023-04-25 17:45:53 -05:00
|
|
|
getResponseMessage(socket1, "pasteresult: success", testname);
|
2016-04-28 06:27:17 -05:00
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
kitcount = getCoolKitProcessCount();
|
2016-05-09 00:18:55 -05:00
|
|
|
|
2016-04-17 19:34:19 -05:00
|
|
|
// Shutdown abruptly.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Closing connection after pasting.");
|
2021-03-25 13:12:05 -05:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
socket1->asyncShutdown(); // Should trigger saving.
|
|
|
|
socket2->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 1",
|
|
|
|
socket1->waitForDisconnection(std::chrono::seconds(5)));
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 2",
|
|
|
|
socket2->waitForDisconnection(std::chrono::seconds(5)));
|
2017-04-19 23:13:32 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2017-04-19 23:13:32 -05:00
|
|
|
}
|
|
|
|
|
2016-04-17 19:34:19 -05:00
|
|
|
// Allow time to save and destroy before we connect again.
|
2021-11-18 06:08:14 -06:00
|
|
|
testNoExtraCoolKitsLeft();
|
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.
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket
|
|
|
|
= loadDocAndGetSession(_socketPoll, _uri, documentURL, testname + "3 ");
|
2016-03-29 20:29:53 -05:00
|
|
|
|
2016-05-09 00:18:55 -05:00
|
|
|
// Should have no new instances.
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(kitcount, countCoolKitProcesses(kitcount));
|
2016-05-09 00:18:55 -05:00
|
|
|
|
2016-03-29 20:29:53 -05:00
|
|
|
// Check if the document contains the pasted text.
|
2023-04-25 17:45:53 -05:00
|
|
|
const std::string selection = getAllText(socket, testname, text);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL("textselectioncontent: " + text, selection);
|
2021-03-25 13:12:05 -05:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
socket->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 3",
|
|
|
|
socket->waitForDisconnection(std::chrono::seconds(5)));
|
2016-03-29 20:29:53 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_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
|
|
|
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket
|
|
|
|
= loadDocAndGetSession(_socketPoll, _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
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
const int kitcount = getCoolKitProcessCount();
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Shutdown abruptly.
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG("Closing connection after pasting.");
|
2021-04-12 23:48:47 -05:00
|
|
|
socket->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket",
|
|
|
|
socket->waitForDisconnection(std::chrono::seconds(5)));
|
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.");
|
2021-03-25 13:12:05 -05:00
|
|
|
socket = loadDocAndGetSession(_socketPoll, _uri, documentURL, testname);
|
2016-04-17 22:31:17 -05:00
|
|
|
|
|
|
|
// Should have no new instances.
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(kitcount, countCoolKitProcesses(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);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("textselectioncontent: ") + expected, selection);
|
2021-03-25 13:12:05 -05:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
socket->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket",
|
|
|
|
socket->waitForDisconnection(std::chrono::seconds(5)));
|
2016-04-17 22:31:17 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
2016-03-25 13:23:26 -05:00
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_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
|
|
|
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket1
|
|
|
|
= loadDocAndGetSession(_socketPoll, _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.");
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket2
|
|
|
|
= loadDocAndGetSession(_socketPoll, _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.
|
2023-04-25 17:45:53 -05:00
|
|
|
sendTextFrame(socket1, "key type=input char=97 key=0", "inactiveClient-1 ");
|
|
|
|
sendTextFrame(socket1, "key type=up char=0 key=512", "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
|
|
|
{
|
2021-11-18 06:08:14 -06:00
|
|
|
const auto token = COOLProtocol::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.
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("unexpected message: " + msg,
|
2023-04-07 03:58:09 -05:00
|
|
|
token == "a11yfocuschanged:" ||
|
2023-11-02 06:44:20 -05:00
|
|
|
token == "corelog:" ||
|
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:" ||
|
2023-04-22 11:40:06 -05:00
|
|
|
token == "rulerupdate:" ||
|
2023-06-05 08:56:05 -05:00
|
|
|
token == "tableselected:" ||
|
2023-06-19 05:34:34 -05:00
|
|
|
token == "colorpalettes:" ||
|
|
|
|
token == "jsdialog:");
|
2016-05-08 23:48:30 -05:00
|
|
|
|
|
|
|
// End when we get state changed.
|
|
|
|
return (token != "statechanged:");
|
|
|
|
});
|
|
|
|
|
2023-04-25 17:45:53 -05:00
|
|
|
TST_LOG("Second client finished. Shutting down");
|
2021-04-12 23:48:47 -05:00
|
|
|
socket2->asyncShutdown();
|
2023-04-25 17:45:53 -05:00
|
|
|
TST_LOG("Shutting down first client");
|
2021-04-12 23:48:47 -05:00
|
|
|
socket1->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 2",
|
|
|
|
socket2->waitForDisconnection(std::chrono::seconds(5)));
|
2021-03-25 13:12:05 -05:00
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 1",
|
|
|
|
socket1->waitForDisconnection(std::chrono::seconds(5)));
|
2016-05-08 23:48:30 -05:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2016-05-08 23:48:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket0
|
|
|
|
= connectLOKit(_socketPoll, _uri, docURL, testname + "0 ");
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket1
|
|
|
|
= connectLOKit(_socketPoll, _uri, docURL, testname + "1 ");
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
std::string response;
|
|
|
|
int part, parts, width, height;
|
2021-03-25 13:12:05 -05:00
|
|
|
int viewid[2] = { 0 };
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load first view and remember the viewid
|
2021-03-25 13:12:05 -05:00
|
|
|
TST_LOG("Loading the first view");
|
2016-10-05 08:18:53 -05:00
|
|
|
sendTextFrame(socket0, "load url=" + docURL);
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket0, "status:", testname + "0 ");
|
2021-03-25 13:12:05 -05:00
|
|
|
LOK_ASSERT_MESSAGE("Expected status: message", !response.empty());
|
2022-02-16 16:22:18 -06:00
|
|
|
parseDocSize(response.substr(7), "text", part, parts, width, height, viewid[0], testname);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
// Check if viewinfo message also mentions the same viewid
|
2021-03-25 13:12:05 -05:00
|
|
|
TST_LOG("Waiting for [viewinfo:] from the first view");
|
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>();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(1), array->size());
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
Poco::JSON::Object::Ptr viewInfoObj0 = array->getObject(0);
|
|
|
|
int viewid0 = viewInfoObj0->get("id").convert<int>();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(viewid[0], viewid0);
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
// Load second view and remember the viewid
|
2021-03-25 13:12:05 -05:00
|
|
|
TST_LOG("Loading the second view");
|
2016-10-05 08:18:53 -05:00
|
|
|
sendTextFrame(socket1, "load url=" + docURL);
|
2016-10-08 20:24:45 -05:00
|
|
|
response = getResponseString(socket1, "status:", testname + "1 ");
|
2022-02-16 16:22:18 -06:00
|
|
|
parseDocSize(response.substr(7), "text", part, parts, width, height, viewid[1], testname);
|
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
|
2021-03-25 13:12:05 -05:00
|
|
|
TST_LOG("Waiting for [viewinfo:] from the second 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>();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(2), array->size());
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
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)
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(viewid[1], viewid1);
|
2016-10-05 08:18:53 -05:00
|
|
|
else if (viewid[0] == viewid1)
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(viewid[1], viewid0);
|
2016-10-05 08:18:53 -05:00
|
|
|
else
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL("Inconsistent viewid in viewinfo and status messages");
|
2016-10-05 08:18:53 -05:00
|
|
|
|
|
|
|
// Check if first view also got the same viewinfo message
|
2021-03-25 13:12:05 -05:00
|
|
|
TST_LOG("Waiting for [viewinfo:] from the first view, again");
|
2016-10-08 20:24:45 -05:00
|
|
|
const auto response1 = getResponseString(socket0, "viewinfo: ", testname + "0 ");
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(response, response1);
|
2021-03-25 13:12:05 -05:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
socket1->asyncShutdown();
|
|
|
|
socket0->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 1",
|
|
|
|
socket1->waitForDisconnection(std::chrono::seconds(5)));
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 0",
|
|
|
|
socket0->waitForDisconnection(std::chrono::seconds(5)));
|
2016-10-05 08:18:53 -05:00
|
|
|
}
|
|
|
|
catch(const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2016-10-05 08:18:53 -05:00
|
|
|
}
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
TST_LOG("Done");
|
2016-10-05 08:18:53 -05:00
|
|
|
}
|
|
|
|
|
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;
|
2022-02-10 17:12:43 -06:00
|
|
|
int conflict = 0;
|
2017-05-30 21:26:05 -05:00
|
|
|
|
|
|
|
getDocumentPathAndURL("empty.odt", docPath, docURL, testname);
|
|
|
|
|
2021-03-25 13:12:05 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket0
|
|
|
|
= connectLOKit(_socketPoll, _uri, docURL, testname + "0 ");
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket1
|
|
|
|
= connectLOKit(_socketPoll, _uri, docURL, testname + "1 ");
|
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>();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string(".uno:Undo"), objJSON->get("commandName").toString());
|
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), objJSON->get("success").toString());
|
|
|
|
LOK_ASSERT(objJSON->has("result"));
|
2018-12-26 12:46:15 -06:00
|
|
|
const Poco::Dynamic::Var parsedResultJSON = objJSON->get("result");
|
|
|
|
const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("long"), resultObj->get("type").toString());
|
|
|
|
LOK_ASSERT(Poco::strToInt(resultObj->get("value").toString(), conflict, 10));
|
|
|
|
LOK_ASSERT(conflict > 0); /*UNDO_CONFLICT*/
|
2021-03-25 13:12:05 -05:00
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
socket1->asyncShutdown();
|
|
|
|
socket0->asyncShutdown();
|
2021-03-25 13:12:05 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 1",
|
|
|
|
socket1->waitForDisconnection(std::chrono::seconds(5)));
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket 0",
|
|
|
|
socket0->waitForDisconnection(std::chrono::seconds(5)));
|
|
|
|
|
2017-05-30 21:26:05 -05:00
|
|
|
}
|
|
|
|
catch(const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2017-05-30 21:26:05 -05:00
|
|
|
}
|
|
|
|
}
|
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: */
|