[Libreoffice-commits] online.git: 2 commits - loolwsd/LOOLKit.cpp loolwsd/MasterProcessSession.cpp loolwsd/test
Miklos Vajna
vmiklos at collabora.co.uk
Mon Jan 18 02:49:13 PST 2016
loolwsd/LOOLKit.cpp | 31 +++++++++++++++++++++++++------
loolwsd/MasterProcessSession.cpp | 1 +
loolwsd/test/data/paste.html | 1 +
loolwsd/test/httpwstest.cpp | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 65 insertions(+), 6 deletions(-)
New commits:
commit a67d73ea576cf0bc16bef241d5893e27abf2cc99
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jan 18 11:44:35 2016 +0100
loolwsd: HTML paste testcase
Fails without the previous commit.
diff --git a/loolwsd/test/data/paste.html b/loolwsd/test/data/paste.html
new file mode 100644
index 0000000..d896bc5
--- /dev/null
+++ b/loolwsd/test/data/paste.html
@@ -0,0 +1 @@
+<ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 25.6px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><li style="box-sizing: border-box;">milar to Redth's<span class="Apple-converted-space"> </span><a href="https://github.com/Redth/FiredTVLauncher" target="_blank" style="box-sizing: border-box; color: rgb(64, 120, 192); text-decoration: none; background-color: transparent;">FiredTVLauncher</a><span class="Apple-converted-space"> </span>with<span class="Apple-converted-space"> </span><strong style="box-sizing: border-box; font-weight: bold;">RE
AL HOME BUTTON CLICK DETECTION</strong></li><li style="box-sizing: border-box;">(and no "amazon home is top-application"-detection).</li><li style="box-sizing: border-box;"><strong style="box-sizing: border-box; font-weight: bold;">Even double-home-clicks are captured!!</strong></li><li style="box-sizing: border-box;">Completely configurable which app is started on startup-, home-button-single-click or home-button-double-click.</li><li style="box-sizing: border-box;">Default: Starts itself on FireTV-Startup.</li><li style="box-sizing: border-box;">Default: Starts itself when Home-Button is single-clicked.</li><li style="box-sizing: border-box;">Default: Starts amazon home when Home-Button is double-clicked (actually does nothing as amazon home is the default action for home-button clicks).</li><li style="box-sizing: border-box;">You can e.g. start Kodi on double-click and FireStarter on single-click.</li><li style="box-sizing: border-box;">Also possible is to keep up the default beh
aviour (" - No Action - ") on a single-click (amazon home is starting) and to open e.g. FireStar</li></ul>
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 65c0899..4a36c28 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -31,10 +31,12 @@ class HTTPWSTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE(HTTPWSTest);
CPPUNIT_TEST(testPaste);
+ CPPUNIT_TEST(testLargePaste);
CPPUNIT_TEST(testRenderingOptions);
CPPUNIT_TEST_SUITE_END();
void testPaste();
+ void testLargePaste();
void testRenderingOptions();
void sendTextFrame(Poco::Net::WebSocket& socket, const std::string& string);
@@ -86,6 +88,42 @@ void HTTPWSTest::testPaste()
CPPUNIT_ASSERT_EQUAL(std::string("aaa bbb ccc"), selection);
}
+void HTTPWSTest::testLargePaste()
+{
+ // Load a document and make it empty.
+ std::string documentPath = TDOC "/hello.odt";
+ std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+ sendTextFrame(_socket, "load url=" + documentURL);
+ sendTextFrame(_socket, "uno .uno:SelectAll");
+ sendTextFrame(_socket, "uno .uno:Delete");
+
+ // Paste some text into it.
+ std::ifstream documentStream(documentPath);
+ std::string documentContents((std::istreambuf_iterator<char>(documentStream)), std::istreambuf_iterator<char>());
+ sendTextFrame(_socket, "paste mimetype=text/html\n" + documentContents);
+
+ // Check if the server is still alive.
+ // This resulted first in a hang, as respose for the message never arrived, then a bit later in a Poco::TimeoutException.
+ sendTextFrame(_socket, "gettextselection mimetype=text/plain;charset=utf-8");
+ std::string selection;
+ int flags;
+ int n;
+ do
+ {
+ char buffer[100000];
+ n = _socket.receiveFrame(buffer, sizeof(buffer), flags);
+ if (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE)
+ {
+ std::string line = LOOLProtocol::getFirstLine(buffer, n);
+ std::string prefix = "textselectioncontent: ";
+ if (line.find(prefix) == 0)
+ break;
+ }
+ }
+ while (n > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE);
+ _socket.shutdown();
+}
+
void HTTPWSTest::testRenderingOptions()
{
// Load a document and get its size.
commit 201c9fb59053908aea598bf86a240f5aa39706bb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jan 18 11:32:05 2016 +0100
loolwsd: handle 'nextmessage:' in master -> prisoner traffic
ToPrisoner already generated 'nextmessage:' when it was necessary, but
the other side did not handle that message type, since previously
(before multi-line paste) only the prisoner -> master direction needed
'nextmessage:' for tile data.
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index c4a5d10..1cce089 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -354,6 +354,18 @@ public:
_thread.join();
}
+ void handle(TileQueue& queue, const std::string& firstLine, char* buffer, int n)
+ {
+ if (firstLine.find("paste") != 0)
+ {
+ // Everything else is expected to be a single line.
+ assert(firstLine.size() == static_cast<std::string::size_type>(n));
+ queue.put(firstLine);
+ }
+ else
+ queue.put(std::string(buffer, n));
+ }
+
void run() override
{
static const std::string thread_name = "kit_ws_" + _session->getId();
@@ -380,7 +392,7 @@ public:
if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
{
- const std::string firstLine = getFirstLine(buffer, n);
+ std::string firstLine = getFirstLine(buffer, n);
if (firstLine == "eof")
{
Log::info("Recieved EOF. Finishing.");
@@ -389,14 +401,21 @@ public:
StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- if (firstLine.find("paste") != 0)
+ // Check if it is a "nextmessage:" and in that case read the large
+ // follow-up message separately, and handle that only.
+ int size;
+ if (tokens.count() == 2 && tokens[0] == "nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
{
- // Everything else is expected to be a single line.
- assert(firstLine.size() == static_cast<std::string::size_type>(n));
- queue.put(firstLine);
+ char largeBuffer[size];
+ n = _ws->receiveFrame(largeBuffer, size, flags);
+ if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+ {
+ firstLine = getFirstLine(largeBuffer, n);
+ handle(queue, firstLine, largeBuffer, n);
+ }
}
else
- queue.put(std::string(buffer, n));
+ handle(queue, firstLine, buffer, n);
}
}
while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !_stop);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 0799d9a..d3b3fd9 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -668,3 +668,4 @@ void MasterProcessSession::forwardToPeer(const char *buffer, int length)
peer->sendBinaryFrame(buffer, length);
}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list