2021-11-28 09:18:44 -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>
|
|
|
|
|
2022-02-01 07:33:25 -06:00
|
|
|
#include <chrono>
|
|
|
|
|
2021-11-28 09:18:44 -06:00
|
|
|
#include "HttpRequest.hpp"
|
|
|
|
#include "Util.hpp"
|
|
|
|
#include "lokassert.hpp"
|
|
|
|
|
|
|
|
#include <WopiTestServer.hpp>
|
|
|
|
#include <Log.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <UnitHTTP.hpp>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
|
|
|
/// Test slow saving/uploading.
|
|
|
|
/// We modify the document, save, and immediately
|
|
|
|
/// modify again followed by closing the connection.
|
|
|
|
/// In this scenario, it's not just that the document
|
|
|
|
/// is modified at the time of unloading, which is
|
|
|
|
/// covered by the UnitWOPIAsncUpload_ModifyClose
|
|
|
|
/// test. Instead, here we close the connection
|
|
|
|
/// while the document is being saved and uploaded.
|
|
|
|
/// Unlike the failed upload scenario, this one
|
|
|
|
/// will hit "upload in progress" and will test
|
|
|
|
/// that in such a case we don't drop the latest
|
|
|
|
/// changes, which were done while save/upload
|
|
|
|
/// were in progress.
|
|
|
|
/// Modify, Save, Modify, Close -> No data loss.
|
|
|
|
class UnitWOPISlow : public WopiTestServer
|
|
|
|
{
|
2022-04-01 20:04:41 -05:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, WaitPutFile) _phase;
|
2021-11-28 09:18:44 -06:00
|
|
|
|
|
|
|
static constexpr auto LargeDocumentFilename = "large-six-hundred.odt";
|
|
|
|
|
|
|
|
/// The number of key input sent.
|
|
|
|
std::size_t _inputCount;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UnitWOPISlow()
|
2022-05-01 10:00:50 -05:00
|
|
|
: WopiTestServer("UnitWOPISlow", LargeDocumentFilename)
|
2021-11-28 09:18:44 -06:00
|
|
|
, _phase(Phase::Load)
|
|
|
|
, _inputCount(0)
|
|
|
|
{
|
|
|
|
// We need more time than the default.
|
2022-01-14 08:30:16 -06:00
|
|
|
setTimeout(std::chrono::minutes(10));
|
2021-11-28 09:18:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& request) override
|
|
|
|
{
|
|
|
|
LOG_TST("PutFile");
|
|
|
|
LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitPutFile", _phase == Phase::WaitPutFile);
|
|
|
|
|
|
|
|
// Triggered while closing.
|
|
|
|
LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsAutosave"));
|
|
|
|
|
2022-08-07 08:02:54 -05:00
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsModifiedByUser"));
|
2021-11-28 09:18:44 -06:00
|
|
|
|
|
|
|
passTest("Document uploaded on closing as expected.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDocBrokerDestroy(const std::string& docKey) override
|
|
|
|
{
|
|
|
|
passTest("Document [" + docKey + "] uploaded and closed cleanly.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The document is loaded.
|
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']');
|
|
|
|
LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitLoadStatus",
|
|
|
|
_phase == Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
// Modify and wait for the notification.
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitModifiedStatus);
|
|
|
|
|
|
|
|
LOG_TST("Sending key input #" << ++_inputCount);
|
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("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
|
|
|
|
{
|
|
|
|
// We modify the document multiple times.
|
|
|
|
// Only the first time is handled here.
|
|
|
|
if (_phase == Phase::WaitModifiedStatus)
|
|
|
|
{
|
|
|
|
LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']');
|
|
|
|
LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitModifiedStatus",
|
|
|
|
_phase == Phase::WaitModifiedStatus);
|
|
|
|
|
|
|
|
// Save and immediately modify, then close the connection.
|
|
|
|
WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 "
|
|
|
|
"extendedData=CustomFlag%3DCustom%20Value%3BAnotherFlag%3DAnotherValue");
|
|
|
|
|
|
|
|
LOG_TST("Sending key input #" << ++_inputCount);
|
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("key type=up char=0 key=512");
|
|
|
|
|
|
|
|
LOG_TST("Closing the connection.");
|
|
|
|
deleteSocketAt(0);
|
|
|
|
|
|
|
|
// Don't transition to WaitPutFile until after closing the socket.
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitPutFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
|
|
|
|
|
|
|
LOG_TST("Load: initWebsocket.");
|
|
|
|
initWebsocket("/wopi/files/large-six-hundred.odt?access_token=anything");
|
|
|
|
|
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::WaitLoadStatus:
|
|
|
|
break;
|
|
|
|
case Phase::WaitModifiedStatus:
|
|
|
|
break;
|
|
|
|
case Phase::WaitPutFile:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWOPISlow(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|