2019-12-20 02:04:17 -06: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
|
|
|
|
*
|
2019-12-20 02:04:17 -06: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/.
|
|
|
|
*/
|
|
|
|
|
2021-03-25 08:47:10 -05:00
|
|
|
#include <config.h>
|
|
|
|
|
2020-12-14 13:00:55 -06:00
|
|
|
#include <chrono>
|
2019-12-20 02:04:17 -06:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <Poco/Exception.h>
|
|
|
|
#include <Poco/URI.h>
|
2020-01-20 10:45:53 -06:00
|
|
|
#include <test/lokassert.hpp>
|
2019-12-20 02:04:17 -06:00
|
|
|
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2022-02-16 16:22:18 -06:00
|
|
|
std::string getFontList(const std::string& message, const std::string& testname)
|
2019-12-20 02:04:17 -06:00
|
|
|
{
|
|
|
|
Poco::JSON::Parser parser;
|
|
|
|
const Poco::Dynamic::Var result = parser.parse(message);
|
|
|
|
const auto& command = result.extract<Poco::JSON::Object::Ptr>();
|
|
|
|
std::string text = command->get("commandName").toString();
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string(".uno:CharFontName"), text);
|
2019-12-20 02:04:17 -06:00
|
|
|
text = command->get("commandValues").toString();
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test suite for closing, etc.
|
|
|
|
class UnitClose : public UnitWSD
|
|
|
|
{
|
|
|
|
TestResult testCloseAfterClose();
|
|
|
|
TestResult testFontList();
|
|
|
|
TestResult testGraphicInvalidate();
|
|
|
|
TestResult testAlertAllUsers();
|
|
|
|
|
|
|
|
public:
|
2020-02-11 02:20:13 -06:00
|
|
|
UnitClose();
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override;
|
2019-12-20 02:04:17 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitClose::testCloseAfterClose()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
TST_LOG("Connecting and loading.");
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
|
2022-07-09 09:47:45 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>("ClosePoll");
|
|
|
|
socketPoll->startThread();
|
2019-12-20 02:04:17 -06:00
|
|
|
|
2022-07-09 09:47:45 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::loadDocAndGetSession(socketPoll, "hello.odt", uri, testname);
|
2019-12-20 02:04:17 -06:00
|
|
|
|
2022-07-09 09:47:45 -05:00
|
|
|
// send normal socket shutdown
|
|
|
|
TST_LOG("Disconnecting gracefully.");
|
|
|
|
socket->asyncShutdown();
|
2019-12-20 02:04:17 -06:00
|
|
|
|
2022-07-09 09:47:45 -05:00
|
|
|
// 5 seconds timeout
|
|
|
|
LOK_ASSERT_MESSAGE("Expected successful disconnection of the WebSocket",
|
|
|
|
socket->waitForDisconnection(std::chrono::seconds(5)));
|
2019-12-20 02:04:17 -06:00
|
|
|
|
2022-07-09 09:47:45 -05:00
|
|
|
// Verify that we get back a close frame.
|
|
|
|
LOK_ASSERT_EQUAL(static_cast<int>(Poco::Net::WebSocket::FRAME_OP_CLOSE),
|
|
|
|
(socket->lastFlags() & Poco::Net::WebSocket::FRAME_OP_BITMASK));
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitClose::testFontList()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-09 09:47:45 -05:00
|
|
|
|
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>("ClosePoll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::loadDocAndGetSession(socketPoll, "setclientpart.odp", uri, testname);
|
2019-12-20 02:04:17 -06:00
|
|
|
|
|
|
|
helpers::sendTextFrame(socket, "commandvalues command=.uno:CharFontName", testname);
|
|
|
|
const std::vector<char> response
|
|
|
|
= helpers::getResponseMessage(socket, "commandvalues:", testname);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("did not receive a commandvalues: message as expected",
|
2019-12-20 02:04:17 -06:00
|
|
|
!response.empty());
|
|
|
|
|
|
|
|
std::stringstream streamResponse;
|
|
|
|
std::copy(response.begin() + std::string("commandvalues:").length() + 1, response.end(),
|
|
|
|
std::ostream_iterator<char>(streamResponse));
|
2022-02-16 16:22:18 -06:00
|
|
|
LOK_ASSERT(!getFontList(streamResponse.str(), testname).empty());
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitClose::testGraphicInvalidate()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document.
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-09 09:47:45 -05:00
|
|
|
|
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>("ClosePoll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::loadDocAndGetSession(socketPoll, "shape.ods", uri, testname);
|
2019-12-20 02:04:17 -06:00
|
|
|
|
|
|
|
// Send click message
|
|
|
|
helpers::sendTextFrame(
|
|
|
|
socket, "mouse type=buttondown x=1035 y=400 count=1 buttons=1 modifier=0", testname);
|
|
|
|
helpers::sendTextFrame(
|
|
|
|
socket, "mouse type=buttonup x=1035 y=400 count=1 buttons=1 modifier=0", testname);
|
|
|
|
helpers::getResponseString(socket, "graphicselection:", testname);
|
|
|
|
|
|
|
|
// Drag & drop graphic
|
|
|
|
helpers::sendTextFrame(
|
|
|
|
socket, "mouse type=buttondown x=1035 y=400 count=1 buttons=1 modifier=0", testname);
|
|
|
|
helpers::sendTextFrame(socket, "mouse type=move x=1035 y=450 count=1 buttons=1 modifier=0",
|
|
|
|
testname);
|
|
|
|
helpers::sendTextFrame(
|
|
|
|
socket, "mouse type=buttonup x=1035 y=450 count=1 buttons=1 modifier=0", testname);
|
|
|
|
|
|
|
|
const auto message = helpers::getResponseString(socket, "invalidatetiles:", testname);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("Drag & Drop graphic invalidate all tiles",
|
2019-12-20 02:04:17 -06:00
|
|
|
message.find("EMPTY") == std::string::npos);
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitClose::testAlertAllUsers()
|
|
|
|
{
|
|
|
|
// Load two documents, each in two sessions. Tell one session to fake a disk full
|
|
|
|
// situation. Expect to get the corresponding error back in all sessions.
|
|
|
|
static_assert(MAX_DOCUMENTS >= 2, "MAX_DOCUMENTS must be at least 2");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-09 09:47:45 -05:00
|
|
|
|
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>("ClosePoll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket[4];
|
|
|
|
socket[0] = helpers::loadDocAndGetSession(socketPoll, "hello.odt", uri, testname);
|
|
|
|
socket[1] = helpers::loadDocAndGetSession(socketPoll, "Example.odt", uri, testname);
|
2019-12-20 02:04:17 -06:00
|
|
|
|
|
|
|
// Simulate disk full.
|
|
|
|
helpers::sendTextFrame(socket[0], "uno .uno:fakeDiskFull", testname);
|
|
|
|
|
|
|
|
// Assert that both clients get the error.
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
const std::string response
|
|
|
|
= helpers::assertResponseString(socket[i], "error:", testname);
|
2022-03-29 20:37:57 -05:00
|
|
|
StringVector tokens(StringVector::tokenize(response.substr(6), ' '));
|
2019-12-20 02:04:17 -06:00
|
|
|
std::string cmd;
|
2021-11-18 06:08:14 -06:00
|
|
|
COOLProtocol::getTokenString(tokens, "cmd", cmd);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("internal"), cmd);
|
2019-12-20 02:04:17 -06:00
|
|
|
std::string kind;
|
2021-11-18 06:08:14 -06:00
|
|
|
COOLProtocol::getTokenString(tokens, "kind", kind);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("diskfull"), kind);
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-12-20 02:04:17 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
2020-02-11 02:20:13 -06:00
|
|
|
UnitClose::UnitClose()
|
2022-02-16 16:22:18 -06:00
|
|
|
: UnitWSD("UnitClose")
|
2020-02-11 02:20:13 -06:00
|
|
|
{
|
2020-12-14 13:00:55 -06:00
|
|
|
constexpr std::chrono::minutes timeout_minutes(2);
|
|
|
|
setTimeout(timeout_minutes);
|
2020-02-11 02:20:13 -06:00
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void UnitClose::invokeWSDTest()
|
2019-12-20 02:04:17 -06:00
|
|
|
{
|
|
|
|
UnitBase::TestResult result = testCloseAfterClose();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testFontList();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testGraphicInvalidate();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testAlertAllUsers();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
exitTest(TestResult::Ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitClose(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|