2021-07-11 08:33:45 -05: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 "HttpRequest.hpp"
|
|
|
|
#include "Util.hpp"
|
|
|
|
#include "lokassert.hpp"
|
|
|
|
|
|
|
|
#include <WopiTestServer.hpp>
|
|
|
|
#include <Log.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <UnitHTTP.hpp>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
|
|
|
|
/// Test Saving and Async uploading after modifying and immediately closing.
|
|
|
|
/// We modify the document and close immediately.
|
|
|
|
class UnitWOPIAsyncUpload_ModifyClose : public WopiTestServer
|
|
|
|
{
|
2022-12-18 05:19:43 -06:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitPutFile, WaitDestroy) _phase;
|
2021-07-11 08:33:45 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
UnitWOPIAsyncUpload_ModifyClose()
|
|
|
|
: WopiTestServer("UnitWOPIAsyncUpload_ModifyClose")
|
|
|
|
, _phase(Phase::Load)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& request) override
|
|
|
|
{
|
2022-12-18 05:19:43 -06:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitPutFile);
|
|
|
|
|
2021-07-11 08:33:45 -05:00
|
|
|
// Expect PutFile after closing, since the document is modified.
|
|
|
|
if (_phase == Phase::WaitPutFile)
|
|
|
|
{
|
2022-12-18 05:19:43 -06:00
|
|
|
// The document is modified.
|
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), request.get("X-COOL-WOPI-IsModifiedByUser"));
|
2023-01-14 10:09:51 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsModifiedByUser"));
|
2021-07-11 08:33:45 -05:00
|
|
|
|
2022-12-18 05:19:43 -06:00
|
|
|
// Triggered manually or during closing, not auto-save.
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsAutosave"));
|
2023-01-14 10:09:51 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsAutosave"));
|
2021-07-11 08:33:45 -05:00
|
|
|
|
2022-12-18 05:19:43 -06:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitDestroy);
|
2021-07-11 08:33:45 -05:00
|
|
|
|
2023-08-01 06:21:20 -05:00
|
|
|
return std::make_unique<http::Response>(http::StatusCode::OK);
|
2021-07-11 08:33:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// This during closing the document.
|
2022-12-18 05:19:43 -06:00
|
|
|
LOG_TST("assertPutFileRequest: unexpected");
|
2021-07-11 08:33:45 -05:00
|
|
|
failTest("PutFile multiple times.");
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The document is loaded.
|
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
|
|
|
{
|
|
|
|
LOG_TST("onDocumentLoaded: [" << message << ']');
|
2022-08-01 10:06:43 -05:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
2021-07-11 08:33:45 -05:00
|
|
|
|
2022-12-18 05:19:43 -06:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitPutFile);
|
|
|
|
|
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("key type=up char=0 key=512");
|
|
|
|
WSD_CMD("closedocument");
|
2021-07-11 08:33:45 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-18 05:19:43 -06:00
|
|
|
// Wait for clean unloading.
|
|
|
|
void onDocBrokerDestroy(const std::string& docKey) override
|
|
|
|
{
|
|
|
|
LOG_TST("Destroyed dockey [" << docKey << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitDestroy);
|
|
|
|
|
|
|
|
passTest("Document unloaded as expected.");
|
|
|
|
}
|
|
|
|
|
2021-07-11 08:33:45 -05:00
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
2022-08-01 10:06:43 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
2021-07-11 08:33:45 -05:00
|
|
|
|
|
|
|
LOG_TST("Load: initWebsocket.");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
|
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::WaitLoadStatus:
|
|
|
|
case Phase::WaitPutFile:
|
2022-12-18 05:19:43 -06:00
|
|
|
case Phase::WaitDestroy:
|
2021-07-11 08:33:45 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWOPIAsyncUpload_ModifyClose(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|