2017-09-27 07:13:43 -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/.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <config.h>
|
2017-09-27 07:13:43 -05:00
|
|
|
|
2021-03-25 08:47:10 -05:00
|
|
|
#include "lokassert.hpp"
|
|
|
|
|
2017-12-20 07:06:26 -06:00
|
|
|
#include <WopiTestServer.hpp>
|
2017-09-27 07:13:43 -05:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
|
|
|
|
class UnitWOPI : public WopiTestServer
|
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, Done) _phase;
|
|
|
|
|
|
|
|
STATE_ENUM(SavingPhase, Unmodified, Modified) _savingPhase;
|
2017-09-27 07:13:43 -05:00
|
|
|
|
|
|
|
bool _finishedSaveUnmodified;
|
|
|
|
bool _finishedSaveModified;
|
|
|
|
|
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWOPI()
|
|
|
|
: WopiTestServer("UnitWOPI")
|
2021-01-09 16:01:12 -06:00
|
|
|
, _phase(Phase::Load)
|
|
|
|
, _savingPhase(SavingPhase::Unmodified)
|
2020-12-20 21:11:33 -06:00
|
|
|
, _finishedSaveUnmodified(false)
|
|
|
|
, _finishedSaveModified(false)
|
2017-09-27 07:13:43 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
bool isAutosave() override
|
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOG_TST("In SavingPhase " << name(_savingPhase));
|
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
// we fake autosave when saving the modified document
|
2021-01-09 16:01:12 -06:00
|
|
|
const bool res = _savingPhase == SavingPhase::Modified;
|
|
|
|
LOG_TST("isAutosave: " << std::boolalpha << res);
|
|
|
|
return res;
|
2017-10-03 04:59:39 -05:00
|
|
|
}
|
|
|
|
|
2021-04-30 18:45:34 -05:00
|
|
|
std::unique_ptr<http::Response>
|
|
|
|
assertPutFileRequest(const Poco::Net::HTTPRequest& request) override
|
2017-09-27 07:13:43 -05:00
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOG_TST("In SavingPhase " << name(_savingPhase));
|
|
|
|
|
2017-09-27 07:13:43 -05:00
|
|
|
if (_savingPhase == SavingPhase::Unmodified)
|
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
2021-01-09 16:01:12 -06:00
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
// the document is not modified
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsModifiedByUser"));
|
2017-10-03 04:59:39 -05:00
|
|
|
|
|
|
|
// but the save action is an explicit user's request
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsAutosave"));
|
2017-10-03 04:59:39 -05:00
|
|
|
|
2017-09-27 07:13:43 -05:00
|
|
|
_finishedSaveUnmodified = true;
|
2022-04-03 12:29:38 -05:00
|
|
|
|
|
|
|
// Modify to test the modified phase.
|
|
|
|
TRANSITION_STATE(_phase, Phase::WaitModifiedStatus);
|
|
|
|
WSD_CMD("key type=input char=97 key=0");
|
|
|
|
WSD_CMD("key type=up char=0 key=512");
|
2017-09-27 07:13:43 -05:00
|
|
|
}
|
|
|
|
else if (_savingPhase == SavingPhase::Modified)
|
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus);
|
2021-01-09 16:01:12 -06:00
|
|
|
|
2017-10-03 04:59:39 -05:00
|
|
|
// the document is modified
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), request.get("X-COOL-WOPI-IsModifiedByUser"));
|
2017-10-03 04:59:39 -05:00
|
|
|
|
|
|
|
// and this test fakes that it's an autosave
|
2021-11-18 06:08:14 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("true"), request.get("X-COOL-WOPI-IsAutosave"));
|
2017-10-03 04:59:39 -05:00
|
|
|
|
2019-11-17 07:46:05 -06:00
|
|
|
// Check that we get the extended data.
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("CustomFlag=Custom Value;AnotherFlag=AnotherValue"),
|
2021-11-18 06:08:14 -06:00
|
|
|
request.get("X-COOL-WOPI-ExtendedData"));
|
2019-11-17 07:46:05 -06:00
|
|
|
|
2017-09-27 07:13:43 -05:00
|
|
|
_finishedSaveModified = true;
|
2022-04-03 12:29:38 -05:00
|
|
|
|
|
|
|
TRANSITION_STATE(_phase, Phase::Done);
|
2017-09-27 07:13:43 -05:00
|
|
|
}
|
2017-09-27 13:13:16 -05:00
|
|
|
|
|
|
|
if (_finishedSaveUnmodified && _finishedSaveModified)
|
2021-01-09 16:01:12 -06:00
|
|
|
passTest("Headers for both modified and unmodified received as expected.");
|
2021-04-30 18:45:34 -05:00
|
|
|
|
|
|
|
return nullptr;
|
2017-09-27 07:13:43 -05:00
|
|
|
}
|
|
|
|
|
2021-01-09 16:01:12 -06:00
|
|
|
bool onDocumentLoaded(const std::string& message) override
|
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOG_TST("In SavingPhase " << name(_savingPhase) << ": [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_savingPhase, SavingPhase::Unmodified);
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus);
|
2021-01-09 16:01:12 -06:00
|
|
|
|
2022-04-03 12:29:38 -05:00
|
|
|
// Save unmodified.
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("save dontTerminateEdit=1 dontSaveIfUnmodified=0");
|
2021-01-09 16:01:12 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onDocumentModified(const std::string& message) override
|
2017-09-27 07:13:43 -05:00
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
LOG_TST("In SavingPhase " << name(_savingPhase) << ": [" << message << ']');
|
|
|
|
LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus);
|
2021-01-09 16:01:12 -06:00
|
|
|
|
2022-04-03 12:29:38 -05:00
|
|
|
TRANSITION_STATE(_savingPhase, SavingPhase::Modified);
|
2021-01-09 16:01:12 -06:00
|
|
|
|
2022-04-03 12:29:38 -05:00
|
|
|
// Save modified.
|
|
|
|
WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 "
|
|
|
|
"extendedData=CustomFlag%3DCustom%20Value%3BAnotherFlag%3DAnotherValue");
|
2021-01-09 16:01:12 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-27 07:13:43 -05:00
|
|
|
|
2021-01-09 16:01:12 -06:00
|
|
|
void invokeWSDTest() override
|
|
|
|
{
|
2017-09-27 07:13:43 -05:00
|
|
|
switch (_phase)
|
|
|
|
{
|
2021-01-09 16:01:12 -06:00
|
|
|
case Phase::Load:
|
2017-09-27 07:13:43 -05:00
|
|
|
{
|
2022-04-03 12:29:38 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::WaitLoadStatus);
|
2017-09-27 07:13:43 -05:00
|
|
|
|
2021-01-09 16:01:12 -06:00
|
|
|
LOG_TST("Load: initWebsocket.");
|
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
2017-09-27 07:13:43 -05:00
|
|
|
|
2021-01-09 16:02:34 -06:00
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
2017-09-27 07:13:43 -05:00
|
|
|
}
|
2022-04-03 12:29:38 -05:00
|
|
|
break;
|
2021-01-09 16:01:12 -06:00
|
|
|
|
|
|
|
case Phase::WaitLoadStatus:
|
|
|
|
case Phase::WaitModifiedStatus:
|
2022-04-03 12:29:38 -05:00
|
|
|
case Phase::Done:
|
2017-09-27 07:13:43 -05:00
|
|
|
{
|
2017-09-27 13:13:16 -05:00
|
|
|
// just wait for the results
|
2017-09-27 07:13:43 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-09 16:01:12 -06:00
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitWOPI(); }
|
2017-09-27 07:13:43 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|