2018-02-02 05:28:20 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 19:23:00 +01:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2018-02-02 05:28:20 +01: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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "WopiTestServer.hpp"
|
|
|
|
#include "Unit.hpp"
|
2023-05-23 13:36:26 +02:00
|
|
|
#include "lokassert.hpp"
|
2023-04-21 13:50:56 +02:00
|
|
|
|
2018-02-02 05:28:20 +01:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
/// This tests the rejection logic and messages that
|
|
|
|
/// happen when a document is connected to while
|
|
|
|
/// it is being unloaded.
|
|
|
|
/// Unfortunately, there is an inherent race here
|
|
|
|
/// in that we might have already unloaded by the
|
|
|
|
/// time we request loading via a different
|
|
|
|
/// connection. This race becomes more common the
|
|
|
|
/// faster we unload. Also, the test is poorly named.
|
2018-02-02 05:28:20 +01:00
|
|
|
class UnitWopiOwnertermination : public WopiTestServer
|
|
|
|
{
|
2023-09-11 02:04:16 +02:00
|
|
|
STATE_ENUM(Phase, Start, Load, WaitLoadStatus, WaitModifiedStatus, WaitDocClose, Done) _phase;
|
2018-02-02 05:28:20 +01:00
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
int _loadedIndex; //< The connection index that is loaded now.
|
2021-01-07 03:54:18 +01:00
|
|
|
|
2018-02-02 05:28:20 +01:00
|
|
|
public:
|
2020-12-21 04:11:33 +01:00
|
|
|
UnitWopiOwnertermination()
|
|
|
|
: WopiTestServer("UnitWOPIOwnerTermination")
|
2023-05-23 13:36:26 +02:00
|
|
|
, _phase(Phase::Start)
|
|
|
|
, _loadedIndex(0)
|
2018-02-02 05:28:20 +01:00
|
|
|
{
|
2023-05-23 13:36:26 +02:00
|
|
|
setTimeout(std::chrono::minutes(1));
|
2018-02-02 05:28:20 +01:00
|
|
|
}
|
|
|
|
|
2021-05-01 01:45:34 +02:00
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
|
2018-02-02 05:28:20 +01:00
|
|
|
{
|
2022-02-20 00:51:57 +01:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
// Load again, while we are still unloading.
|
2022-02-20 00:51:57 +01:00
|
|
|
TRANSITION_STATE(_phase, Phase::Load);
|
2021-05-01 01:45:34 +02:00
|
|
|
|
|
|
|
return nullptr;
|
2018-02-02 05:28:20 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 03:54:18 +01:00
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
2018-02-02 05:28:20 +01:00
|
|
|
{
|
2023-05-23 13:36:26 +02:00
|
|
|
LOG_TST("Loaded #" << (_loadedIndex + 1) << ": [" << message << ']');
|
2022-02-20 00:51:57 +01:00
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitModifiedStatus);
|
2021-01-07 03:54:18 +01:00
|
|
|
|
|
|
|
// Modify the document.
|
2022-02-20 00:51:57 +01:00
|
|
|
LOG_TST("Modifying");
|
2023-05-23 13:36:26 +02:00
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(_loadedIndex, "key type=input char=97 key=0");
|
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(_loadedIndex, "key type=up char=0 key=512");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The document is modified. Save, modify, and close it.
|
|
|
|
bool onDocumentModified(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOG_TST("Modified #" << (_loadedIndex + 1) << ": [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus);
|
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitDocClose);
|
2018-02-02 05:28:20 +01:00
|
|
|
|
2022-02-20 00:51:57 +01:00
|
|
|
LOG_TST("Closing");
|
2023-05-23 13:36:26 +02:00
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(_loadedIndex, "closedocument");
|
2021-01-07 03:54:18 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-20 00:51:57 +01:00
|
|
|
bool onDocumentError(const std::string& message) override
|
|
|
|
{
|
2023-05-23 13:36:26 +02:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
2022-02-20 00:51:57 +01:00
|
|
|
|
2024-03-28 10:01:39 +01:00
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Expect only documentunloading errors",
|
|
|
|
std::string("error: cmd=load kind=docunloading"), message);
|
2022-02-20 00:51:57 +01:00
|
|
|
|
2024-03-28 10:01:39 +01:00
|
|
|
TRANSITION_STATE(_phase, Phase::Done);
|
2022-02-20 00:51:57 +01:00
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
return true;
|
2022-02-20 00:51:57 +01:00
|
|
|
}
|
|
|
|
|
2021-01-07 03:54:18 +01:00
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
2018-02-02 05:28:20 +01:00
|
|
|
switch (_phase)
|
|
|
|
{
|
2023-05-23 13:36:26 +02:00
|
|
|
case Phase::Start:
|
2018-02-02 05:28:20 +01:00
|
|
|
{
|
2022-02-20 00:51:57 +01:00
|
|
|
// First time loading, transition.
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
LOG_TST("Creating first connection");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
|
|
|
|
LOG_TST("Loading through first connection");
|
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(0, "load url=" + getWopiSrc());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
++_loadedIndex;
|
2022-02-20 00:51:57 +01:00
|
|
|
|
2023-05-23 13:36:26 +02:00
|
|
|
LOG_TST("Creating connection #" << (_loadedIndex + 1));
|
|
|
|
addWebSocket();
|
|
|
|
LOG_TST("Loading through connection #" << (_loadedIndex + 1));
|
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(_loadedIndex, "load url=" + getWopiSrc());
|
2018-02-02 05:28:20 +01:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-01-07 03:54:18 +01:00
|
|
|
case Phase::WaitLoadStatus:
|
2023-05-23 13:36:26 +02:00
|
|
|
case Phase::WaitModifiedStatus:
|
2022-02-20 00:51:57 +01:00
|
|
|
case Phase::WaitDocClose:
|
2018-02-02 05:28:20 +01:00
|
|
|
break;
|
2023-09-11 02:04:16 +02:00
|
|
|
case Phase::Done:
|
|
|
|
passTest("Reload while unloading failed as expected");
|
|
|
|
break;
|
2018-02-02 05:28:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-20 00:51:57 +01:00
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWopiOwnertermination(); }
|
2018-02-02 05:28:20 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|