summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2022-05-03 07:50:24 -0400
committerthebearon <19438782+thebearon@users.noreply.github.com>2022-08-05 06:49:12 +0200
commit3f7f8ce6f66e0b51fb967b53cfad63e732785afc (patch)
tree978bd7a7c05b9a429494bc0bf8ad3a3663cb77f1
parentfix selecting redline comment jumps to scroll to beginning (diff)
downloadonline-3f7f8ce6f66e0b51fb967b53cfad63e732785afc.tar.gz
online-3f7f8ce6f66e0b51fb967b53cfad63e732785afc.zip
wsd: test: handle save notifications in tests
Change-Id: Ic6b0abcd2ad2f2a895ff81acaf875147d9990c8b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit ecda47edd9e48d6b870e513e46bf025ac4958bc9)
-rw-r--r--common/Unit.cpp67
-rw-r--r--common/Unit.hpp31
2 files changed, 70 insertions, 28 deletions
diff --git a/common/Unit.cpp b/common/Unit.cpp
index 59fa2c5caa..25abe0b1be 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -17,6 +17,8 @@
#include <sysexits.h>
#include <thread>
+#include <Poco/JSON/Object.h>
+#include <Poco/JSON/Parser.h>
#include <Poco/Util/LayeredConfiguration.h>
#include "Log.hpp"
@@ -207,6 +209,71 @@ UnitBase::~UnitBase()
_socketPoll->joinThread();
}
+bool UnitBase::filterSendMessage(const char* data, const std::size_t len, const WSOpCode code,
+ const bool flush, int& unitReturn)
+{
+ const std::string message(data, len);
+ if (Util::startsWith(message, "unocommandresult:"))
+ {
+ const std::size_t index = message.find_first_of('{');
+ if (index != std::string::npos)
+ {
+ try
+ {
+ const std::string stringJSON = message.substr(index);
+ Poco::JSON::Parser parser;
+ const Poco::Dynamic::Var parsedJSON = parser.parse(stringJSON);
+ const auto& object = parsedJSON.extract<Poco::JSON::Object::Ptr>();
+ if (object->get("commandName").toString() == ".uno:Save")
+ {
+ const bool success = object->get("success").toString() == "true";
+ std::string result;
+ if (object->has("result"))
+ {
+ const Poco::Dynamic::Var parsedResultJSON = object->get("result");
+ const auto& resultObj = parsedResultJSON.extract<Poco::JSON::Object::Ptr>();
+ if (resultObj->get("type").toString() == "string")
+ result = resultObj->get("value").toString();
+ }
+
+ if (onDocumentSaved(message, success, result))
+ return false;
+ }
+ }
+ catch (const std::exception& exception)
+ {
+ LOG_TST("unocommandresult parsing failure: " << exception.what());
+ }
+ }
+ else
+ {
+ LOG_TST("Expected json unocommandresult. Ignoring: " << message);
+ }
+ }
+ else if (Util::startsWith(message, "status:"))
+ {
+ if (onDocumentLoaded(message))
+ return false;
+ }
+ else if (message == "statechanged: .uno:ModifiedStatus=true")
+ {
+ if (onDocumentModified(message))
+ return false;
+ }
+ else if (Util::startsWith(message, "statechanged:"))
+ {
+ if (onDocumentStateChanged(message))
+ return false;
+ }
+ else if (Util::startsWith(message, "error:"))
+ {
+ if (onDocumentError(message))
+ return false;
+ }
+
+ return onFilterSendMessage(data, len, code, flush, unitReturn);
+}
+
UnitWSD::UnitWSD(const std::string& name)
: UnitBase(name, UnitType::Wsd)
, _hasKitHooks(false)
diff --git a/common/Unit.hpp b/common/Unit.hpp
index c679c6aae5..3991f81a36 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -15,6 +15,7 @@
#include <vector>
#include <common/StateEnum.hpp>
+#include "Util.hpp"
#include "net/Socket.hpp"
#include <test/testlog.hpp>
@@ -153,33 +154,7 @@ public:
/// Message that is about to be sent via the websocket.
/// To override, handle onFilterSendMessage or any of the onDocument...() handlers.
bool filterSendMessage(const char* data, const std::size_t len, const WSOpCode code,
- const bool flush, int& unitReturn)
- {
- const std::string message(data, len);
-
- if (Util::startsWith(message, "status:"))
- {
- if (onDocumentLoaded(message))
- return false;
- }
- else if (message == "statechanged: .uno:ModifiedStatus=true")
- {
- if (onDocumentModified(message))
- return false;
- }
- else if (Util::startsWith(message, "statechanged:"))
- {
- if (onDocumentStateChanged(message))
- return false;
- }
- else if (Util::startsWith(message, "error:"))
- {
- if (onDocumentError(message))
- return false;
- }
-
- return onFilterSendMessage(data, len, code, flush, unitReturn);
- }
+ const bool flush, int& unitReturn);
/// Hook the disk space check
virtual bool filterCheckDiskSpace(const std::string & /* path */,
@@ -214,7 +189,7 @@ public:
/// Called when the document has been saved.
/// Return true to stop further handling of messages.
- virtual bool onDocumentSaved(const std::string&) { return false; }
+ virtual bool onDocumentSaved(const std::string&, bool, const std::string&) { return false; }
/// Called when the document issues a 'statechanged:' message.
/// Return true to stop further handling of messages.