2022-03-30 20:09:18 -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
|
|
|
|
*
|
2022-03-30 20:09:18 -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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <WopiTestServer.hpp>
|
|
|
|
#include <Log.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <Util.hpp>
|
|
|
|
#include <lokassert.hpp>
|
|
|
|
|
|
|
|
/// Test crashing a document after modifications.
|
|
|
|
class UnitWOPICrashModified : public WopiTestServer
|
|
|
|
{
|
2022-04-01 20:04:41 -05:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, WaitDocClose) _phase;
|
2022-03-30 20:09:18 -05:00
|
|
|
|
|
|
|
/// The PID of the Kit process.
|
|
|
|
int _pid;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UnitWOPICrashModified()
|
|
|
|
: WopiTestServer("UnitWOPICrashModified")
|
|
|
|
, _phase(Phase::Load)
|
2023-06-12 03:19:32 -05:00
|
|
|
, _pid(-1)
|
2022-03-30 20:09:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-04-27 04:35:35 -05:00
|
|
|
void kitSegfault(int /* count */) override { /* ignore */ }
|
|
|
|
|
2022-03-30 20:09:18 -05:00
|
|
|
std::unique_ptr<http::Response> assertPutFileRequest(const Poco::Net::HTTPRequest&) override
|
|
|
|
{
|
|
|
|
failTest("Unexpected PutFile when there should be no file on disk to upload");
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDocBrokerAttachKitProcess(const std::string& docBroker, int pid) override
|
|
|
|
{
|
|
|
|
LOG_TST("DocBroker [" << docBroker << "] attached to pid: " << pid);
|
|
|
|
_pid = pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The document is loaded.
|
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOG_TST("Got: [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitModifiedStatus);
|
|
|
|
|
|
|
|
LOG_TST("Modifying");
|
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("key type=up char=0 key=512");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onDocumentModified(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOG_TST("Got: [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus);
|
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
|
|
|
|
LOG_TST("Killing Kit with PID " << _pid);
|
|
|
|
if (kill(_pid, SIGKILL) == -1)
|
|
|
|
{
|
|
|
|
const int onrre = errno;
|
|
|
|
LOG_TST("kill(" << _pid << ", SIGKILL) failed: " << Util::symbolicErrno(onrre) << ": "
|
|
|
|
<< std::strerror(onrre));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-16 19:02:11 -06:00
|
|
|
bool onDataLoss(const std::string& reason) override
|
2022-03-30 20:09:18 -05:00
|
|
|
{
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
passTest("Finished with the data-loss check: " + reason);
|
2022-11-16 19:02:11 -06:00
|
|
|
return failed();
|
2022-03-30 20:09:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
LOG_TST("Load: initWebsocket.");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::WaitLoadStatus:
|
|
|
|
case Phase::WaitModifiedStatus:
|
|
|
|
case Phase::WaitDocClose:
|
|
|
|
{
|
|
|
|
// just wait for the results
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWOPICrashModified(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|