2018-02-08 08:24:37 -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"
|
2021-01-07 11:49:38 -06:00
|
|
|
#include "lokassert.hpp"
|
2018-02-08 08:24:37 -06:00
|
|
|
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 1) Modifies a current document
|
|
|
|
* 2) Issue a version restore request
|
|
|
|
* 3) Wait for the ack from wsd
|
|
|
|
* 4) checks, after getting ack from wsd, if it saved our unsaved changes
|
|
|
|
*/
|
|
|
|
class UnitWOPIVersionRestore : public WopiTestServer
|
|
|
|
{
|
2022-04-01 20:04:41 -05:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitPutFile) _phase;
|
2018-02-08 08:24:37 -06:00
|
|
|
|
|
|
|
bool _isDocumentSaved = false;
|
|
|
|
|
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWOPIVersionRestore()
|
|
|
|
: WopiTestServer("UnitWOPIVersionRestore")
|
|
|
|
, _phase(Phase::Load)
|
2021-01-07 11:49:38 -06:00
|
|
|
, _isDocumentSaved(false)
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:45:34 -05:00
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& /*request*/) override
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
2022-02-16 05:22:45 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitPutFile);
|
|
|
|
|
|
|
|
LOG_TST("Document uploaded.");
|
|
|
|
_isDocumentSaved = true;
|
2021-04-30 18:45:34 -05:00
|
|
|
|
|
|
|
return nullptr;
|
2018-02-08 08:24:37 -06:00
|
|
|
}
|
|
|
|
|
2021-01-07 11:49:38 -06:00
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
|
|
|
{
|
2022-02-16 05:22:45 -06:00
|
|
|
LOG_TST("Got [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
2021-01-07 11:49:38 -06:00
|
|
|
|
2022-02-16 05:22:45 -06:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitPutFile);
|
2021-01-07 11:49:38 -06:00
|
|
|
|
|
|
|
// Modify the document.
|
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");
|
2021-01-07 11:49:38 -06:00
|
|
|
|
|
|
|
// tell wsd that we are about to restore
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("versionrestore prerestore");
|
2021-01-07 11:49:38 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-04 17:35:43 -06:00
|
|
|
bool onFilterSendMessage(const char* data, const size_t len, const WSOpCode /* code */,
|
|
|
|
const bool /* flush */, int& /*unitReturn*/) override
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
|
|
|
std::string message(data, len);
|
|
|
|
if (message == "close: versionrestore: prerestore_ack")
|
|
|
|
{
|
2022-02-16 05:22:45 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitPutFile);
|
2021-01-07 11:49:38 -06:00
|
|
|
LOK_ASSERT_MESSAGE("Must have already saved the file", _isDocumentSaved);
|
|
|
|
|
|
|
|
if (_isDocumentSaved)
|
|
|
|
passTest("Document saved on version restore as expected.");
|
|
|
|
else
|
|
|
|
failTest("Document failed to save on version restore.");
|
2018-02-08 08:24:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
2022-02-16 05:22:45 -06:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
2018-02-08 08:24:37 -06:00
|
|
|
|
2021-01-07 11:49:38 -06:00
|
|
|
LOG_TST("Load: initWebsocket.");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
2018-02-08 08:24:37 -06:00
|
|
|
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
2018-02-08 08:24:37 -06:00
|
|
|
break;
|
|
|
|
}
|
2021-01-07 11:49:38 -06:00
|
|
|
case Phase::WaitLoadStatus:
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
2021-01-07 11:49:38 -06:00
|
|
|
break; // Nothing to do.
|
2018-02-08 08:24:37 -06:00
|
|
|
}
|
2021-01-07 11:49:38 -06:00
|
|
|
case Phase::WaitPutFile:
|
2018-02-08 08:24:37 -06:00
|
|
|
{
|
2021-01-07 11:49:38 -06:00
|
|
|
break; // Nothing to do.
|
2018-02-08 08:24:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitWOPIVersionRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|