2018-02-01 22:28:20 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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 "UnitHTTP.hpp"
|
|
|
|
#include "helpers.hpp"
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
|
|
|
class UnitWopiOwnertermination : public WopiTestServer
|
|
|
|
{
|
2022-04-01 20:04:41 -05:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitDocClose) _phase;
|
2018-02-01 22:28:20 -06:00
|
|
|
|
2022-02-19 17:51:57 -06:00
|
|
|
static constexpr int RepeatCount = 2;
|
2021-01-06 20:54:18 -06:00
|
|
|
|
2022-02-19 17:51:57 -06:00
|
|
|
int _loadCount;
|
|
|
|
int _uploadCount;
|
2021-01-06 20:54:18 -06:00
|
|
|
|
2018-02-01 22:28:20 -06:00
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWopiOwnertermination()
|
|
|
|
: WopiTestServer("UnitWOPIOwnerTermination")
|
|
|
|
, _phase(Phase::Load)
|
2022-02-19 17:51:57 -06:00
|
|
|
, _loadCount(0)
|
|
|
|
, _uploadCount(0)
|
2018-02-01 22:28:20 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:45:34 -05:00
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
|
2018-02-01 22:28:20 -06:00
|
|
|
{
|
2022-02-19 17:51:57 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
|
|
|
|
++_uploadCount;
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Mismatching load and upload counts", _loadCount, _uploadCount);
|
|
|
|
|
|
|
|
LOG_TST("Disconnecting #" << _loadCount);
|
|
|
|
deleteSocketAt(0);
|
|
|
|
|
|
|
|
// Load again, while we are still uploading.
|
|
|
|
TRANSITION_STATE(_phase, Phase::Load);
|
2021-04-30 18:45:34 -05:00
|
|
|
|
|
|
|
return nullptr;
|
2018-02-01 22:28:20 -06:00
|
|
|
}
|
|
|
|
|
2021-01-06 20:54:18 -06:00
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
2018-02-01 22:28:20 -06:00
|
|
|
{
|
2022-02-19 17:51:57 -06:00
|
|
|
LOG_TST("Loaded: [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitDocClose);
|
2021-01-06 20:54:18 -06:00
|
|
|
|
|
|
|
// Modify the document.
|
2022-02-19 17:51:57 -06:00
|
|
|
LOG_TST("Modifying");
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("key type=up char=0 key=512");
|
2018-02-01 22:28:20 -06:00
|
|
|
|
2021-01-06 20:54:18 -06:00
|
|
|
// And close. We expect the document to be marked as modified and saved.
|
2022-02-19 17:51:57 -06:00
|
|
|
LOG_TST("Closing");
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("closedocument");
|
2021-01-06 20:54:18 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-02-19 17:51:57 -06:00
|
|
|
bool onDocumentError(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Mismatching load and upload counts", _loadCount,
|
|
|
|
_uploadCount + 1);
|
|
|
|
|
|
|
|
if (message != "error: cmd=internal kind=load")
|
|
|
|
{
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Expect only documentunloading errors",
|
|
|
|
std::string("error: cmd=load kind=docunloading"), message);
|
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We send out two errors when we fail to load.
|
|
|
|
// This is the second one, which is 'cmd=internal kind=load'.
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for clean unloading.
|
|
|
|
void onDocBrokerDestroy(const std::string&) override
|
|
|
|
{
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDocClose);
|
|
|
|
|
|
|
|
LOK_ASSERT_EQUAL_MESSAGE("Mismatching load and upload counts", _loadCount,
|
|
|
|
_uploadCount + 1);
|
|
|
|
|
|
|
|
passTest("Unloaded successfully.");
|
|
|
|
}
|
|
|
|
|
2021-01-06 20:54:18 -06:00
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
2018-02-01 22:28:20 -06:00
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
2022-02-19 17:51:57 -06:00
|
|
|
// First time loading, transition.
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
++_loadCount;
|
|
|
|
if (_loadCount == 1)
|
|
|
|
{
|
|
|
|
LOG_TST("Creating first connection");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_TST("Creating connection #" << _loadCount);
|
|
|
|
addWebSocket();
|
|
|
|
}
|
|
|
|
|
|
|
|
WSD_CMD_BY_CONNECTION_INDEX(_loadCount - 1, "load url=" + getWopiSrc());
|
2018-02-01 22:28:20 -06:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-01-06 20:54:18 -06:00
|
|
|
case Phase::WaitLoadStatus:
|
2022-02-19 17:51:57 -06:00
|
|
|
case Phase::WaitDocClose:
|
2018-02-01 22:28:20 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-19 17:51:57 -06:00
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWopiOwnertermination(); }
|
2018-02-01 22:28:20 -06:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|