2019-06-20 14:20:26 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Test various copy/paste pieces ...
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <UnitHTTP.hpp>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
#include <wsd/LOOLWSD.hpp>
|
2019-06-22 05:26:42 -05:00
|
|
|
#include <wsd/Clipboard.hpp>
|
2019-06-21 06:35:17 -05:00
|
|
|
#include <wsd/ClientSession.hpp>
|
|
|
|
#include <Poco/Timestamp.h>
|
|
|
|
#include <Poco/StringTokenizer.h>
|
2019-06-21 11:48:57 -05:00
|
|
|
#include <Poco/Net/HTTPResponse.h>
|
2019-06-21 06:35:17 -05:00
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTMLForm.h>
|
|
|
|
#include <Poco/Net/StringPartSource.h>
|
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
2019-06-20 14:20:26 -05:00
|
|
|
|
|
|
|
#include <test.hpp>
|
|
|
|
|
2019-06-21 11:48:57 -05:00
|
|
|
using namespace Poco::Net;
|
|
|
|
|
2019-06-20 14:20:26 -05:00
|
|
|
// Inside the WSD process
|
|
|
|
class UnitCopyPaste : public UnitWSD
|
|
|
|
{
|
|
|
|
public:
|
2019-06-21 06:35:17 -05:00
|
|
|
UnitCopyPaste()
|
|
|
|
{
|
|
|
|
}
|
2019-06-20 14:20:26 -05:00
|
|
|
|
|
|
|
void configure(Poco::Util::LayeredConfiguration& config) override
|
|
|
|
{
|
|
|
|
UnitWSD::configure(config);
|
|
|
|
// force HTTPS - to test harder
|
|
|
|
config.setBool("ssl.enable", true);
|
|
|
|
}
|
|
|
|
|
2019-06-22 05:26:42 -05:00
|
|
|
std::shared_ptr<ClipboardData> getClipboard(const std::string &clipURIstr)
|
|
|
|
{
|
|
|
|
std::cerr << "connect to " << clipURIstr << std::endl;
|
|
|
|
Poco::URI clipURI(clipURIstr);
|
|
|
|
|
|
|
|
HTTPResponse response;
|
|
|
|
HTTPRequest request(HTTPRequest::HTTP_GET, clipURI.getPathAndQuery());
|
|
|
|
std::unique_ptr<HTTPClientSession> session(helpers::createSession(clipURI));
|
|
|
|
session->setTimeout(Poco::Timespan(10, 0)); // 10 seconds.
|
|
|
|
session->sendRequest(request);
|
|
|
|
std::istream& responseStream = session->receiveResponse(response);
|
|
|
|
|
|
|
|
if (response.getStatus() != HTTPResponse::HTTP_OK)
|
|
|
|
{
|
|
|
|
std::cerr << "Error response for clipboard " << response.getReason();
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
return std::shared_ptr<ClipboardData>();
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("application/octet-stream"), response.getContentType());
|
|
|
|
|
|
|
|
auto clipboard = std::make_shared<ClipboardData>();
|
|
|
|
clipboard->read(responseStream);
|
|
|
|
clipboard->dumpState(std::cerr);
|
|
|
|
|
|
|
|
return clipboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool assertClipboard(const std::shared_ptr<ClipboardData> &clipboard,
|
|
|
|
const std::string &mimeType, const std::string &content)
|
|
|
|
{
|
|
|
|
bool failed = false;
|
|
|
|
std::string value;
|
|
|
|
if (!clipboard || !clipboard->findType(mimeType, value))
|
|
|
|
{
|
|
|
|
std::cerr << "missing clipboard or missing clipboard mime type '" << mimeType << "'\n";
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
else if (value != content)
|
|
|
|
{
|
|
|
|
std::cerr << "clipboard contet mismatch '" << value << "' vs ' " << content << "'\n";
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
exitTest(TestResult::Failed);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-20 14:20:26 -05:00
|
|
|
void invokeTest() override
|
|
|
|
{
|
|
|
|
std::string testname = "copypaste";
|
|
|
|
|
|
|
|
// Load a doc with the cursor saved at a top row.
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("empty.ods", documentPath, documentURL, testname);
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket =
|
|
|
|
helpers::loadDocAndGetSocket(Poco::URI(helpers::getTestServerURI()), documentURL, testname);
|
2019-06-21 06:35:17 -05:00
|
|
|
|
|
|
|
std::shared_ptr<DocumentBroker> broker;
|
|
|
|
std::shared_ptr<ClientSession> clientSession;
|
|
|
|
{
|
|
|
|
std::vector<std::shared_ptr<DocumentBroker>> brokers = LOOLWSD::getBrokersTestOnly();
|
|
|
|
assert(brokers.size() > 0);
|
|
|
|
broker = brokers[0];
|
|
|
|
auto sessions = broker->getSessionsTestOnlyUnsafe();
|
|
|
|
assert(sessions.size() > 0);
|
|
|
|
clientSession = sessions[0];
|
|
|
|
}
|
|
|
|
|
2019-06-22 05:26:42 -05:00
|
|
|
std::string clipURI = clientSession->getClipboardURI(false); // nominally thread unsafe
|
|
|
|
std::shared_ptr<ClipboardData> clipboard;
|
|
|
|
try {
|
|
|
|
clipboard = getClipboard(clipURI);
|
|
|
|
} catch (ParseError &err) {
|
|
|
|
std::cerr << "parse error " << err.toString() << std::endl;
|
2019-06-21 11:48:57 -05:00
|
|
|
exitTest(TestResult::Failed);
|
2019-06-21 06:35:17 -05:00
|
|
|
return;
|
2019-06-21 11:48:57 -05:00
|
|
|
}
|
2019-06-20 14:20:26 -05:00
|
|
|
|
2019-06-22 05:26:42 -05:00
|
|
|
// Empty cell so ...
|
|
|
|
if (!assertClipboard(clipboard, "text/plain;charset=utf-16", ""))
|
|
|
|
return;
|
2019-06-21 17:56:45 -05:00
|
|
|
|
2019-06-21 11:48:57 -05:00
|
|
|
std::cerr << "CopyPaste tests succeeded" << std::endl;
|
|
|
|
exitTest(TestResult::Ok);
|
2019-06-20 14:20:26 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase *unit_create_wsd(void)
|
|
|
|
{
|
|
|
|
return new UnitCopyPaste();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|