2019-04-30 09:21:44 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2019-04-30 09:21:44 -05:00
|
|
|
* 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 UnitWOPIRenameFile : public WopiTestServer
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
STATE_ENUM(Phase, Load, RenameFile, Done)
|
|
|
|
_phase;
|
2019-04-30 09:21:44 -05:00
|
|
|
|
|
|
|
public:
|
2020-12-20 21:11:33 -06:00
|
|
|
UnitWOPIRenameFile()
|
|
|
|
: WopiTestServer("UnitWOPIRenameFile")
|
|
|
|
, _phase(Phase::Load)
|
2019-04-30 09:21:44 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void assertRenameFileRequest(const Poco::Net::HTTPRequest& request) override
|
|
|
|
{
|
|
|
|
// spec says UTF-7...
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("hello"), request.get("X-WOPI-RequestedName"));
|
2019-04-30 09:21:44 -05:00
|
|
|
}
|
|
|
|
|
2022-06-14 05:27:24 -05:00
|
|
|
bool onFilterSendWebSocketMessage(const char* data, const std::size_t len,
|
|
|
|
const WSOpCode /* code */, const bool /* flush */,
|
|
|
|
int& /*unitReturn*/) override
|
2019-04-30 09:21:44 -05:00
|
|
|
{
|
|
|
|
const std::string message(data, len);
|
|
|
|
|
|
|
|
const std::string expected("renamefile: filename=hello");
|
|
|
|
if (message.find(expected) == 0)
|
|
|
|
{
|
|
|
|
// successfully exit the test if we also got the outgoing message
|
|
|
|
// notifying about saving the file
|
|
|
|
exitTest(TestResult::Ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override
|
2019-04-30 09:21:44 -05:00
|
|
|
{
|
|
|
|
switch (_phase)
|
|
|
|
{
|
|
|
|
case Phase::Load:
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::RenameFile);
|
|
|
|
|
2019-04-30 09:21:44 -05:00
|
|
|
initWebsocket("/wopi/files/0?access_token=anything");
|
|
|
|
|
2022-07-22 18:54:44 -05:00
|
|
|
WSD_CMD("load url=" + getWopiSrc());
|
2019-04-30 09:21:44 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Phase::RenameFile:
|
|
|
|
{
|
2022-07-22 18:54:44 -05:00
|
|
|
TRANSITION_STATE(_phase, Phase::Done);
|
|
|
|
|
|
|
|
WSD_CMD("renamefile filename=hello");
|
2019-04-30 09:21:44 -05:00
|
|
|
break;
|
|
|
|
}
|
2022-07-22 18:54:44 -05:00
|
|
|
case Phase::Done:
|
2019-04-30 09:21:44 -05:00
|
|
|
{
|
|
|
|
// just wait for the results
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitWOPIRenameFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|