summaryrefslogtreecommitdiffstats
path: root/remoting/protocol
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 22:52:40 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 22:52:40 +0000
commit750ae6bd57722802e10484b108a66f8565fedc72 (patch)
tree9022eef9e2e25ac4f897c9efd838f7b91bef17ae /remoting/protocol
parent36d12a3b65780a205369df4f81f399dc37788383 (diff)
downloadchromium_src-750ae6bd57722802e10484b108a66f8565fedc72.zip
chromium_src-750ae6bd57722802e10484b108a66f8565fedc72.tar.gz
chromium_src-750ae6bd57722802e10484b108a66f8565fedc72.tar.bz2
Allow input & clipboard filters to be disabled without NULLing target stub.
This CL also: * Adds unit tests for InputFilter and CLipboardFilter. * Updates ClientSession to enabled/disable filters for authentication. BUG=118511 Review URL: https://chromiumcodereview.appspot.com/10860033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol')
-rw-r--r--remoting/protocol/clipboard_echo_filter_unittest.cc2
-rw-r--r--remoting/protocol/clipboard_filter.cc8
-rw-r--r--remoting/protocol/clipboard_filter.h11
-rw-r--r--remoting/protocol/clipboard_filter_unittest.cc60
-rw-r--r--remoting/protocol/input_filter.cc9
-rw-r--r--remoting/protocol/input_filter.h16
-rw-r--r--remoting/protocol/input_filter_unittest.cc82
7 files changed, 175 insertions, 13 deletions
diff --git a/remoting/protocol/clipboard_echo_filter_unittest.cc b/remoting/protocol/clipboard_echo_filter_unittest.cc
index 25f5de1..6791ba4 100644
--- a/remoting/protocol/clipboard_echo_filter_unittest.cc
+++ b/remoting/protocol/clipboard_echo_filter_unittest.cc
@@ -20,7 +20,7 @@ MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
}
static ClipboardEvent MakeClipboardEvent(const std::string& mime_type,
- const std::string& data) {
+ const std::string& data) {
ClipboardEvent event;
event.set_mime_type(mime_type);
event.set_data(data);
diff --git a/remoting/protocol/clipboard_filter.cc b/remoting/protocol/clipboard_filter.cc
index 4b4be95..d82547f 100644
--- a/remoting/protocol/clipboard_filter.cc
+++ b/remoting/protocol/clipboard_filter.cc
@@ -8,7 +8,11 @@
namespace remoting {
namespace protocol {
-ClipboardFilter::ClipboardFilter() : clipboard_stub_(NULL) {
+ClipboardFilter::ClipboardFilter() : clipboard_stub_(NULL), enabled_(true) {
+}
+
+ClipboardFilter::ClipboardFilter(ClipboardStub* clipboard_stub)
+ : clipboard_stub_(clipboard_stub), enabled_(true) {
}
ClipboardFilter::~ClipboardFilter() {
@@ -19,7 +23,7 @@ void ClipboardFilter::set_clipboard_stub(ClipboardStub* clipboard_stub) {
}
void ClipboardFilter::InjectClipboardEvent(const ClipboardEvent& event) {
- if (clipboard_stub_ != NULL)
+ if (enabled_ && clipboard_stub_ != NULL)
clipboard_stub_->InjectClipboardEvent(event);
}
diff --git a/remoting/protocol/clipboard_filter.h b/remoting/protocol/clipboard_filter.h
index 5fbcda5..0cae152 100644
--- a/remoting/protocol/clipboard_filter.h
+++ b/remoting/protocol/clipboard_filter.h
@@ -12,21 +12,28 @@
namespace remoting {
namespace protocol {
-// Forwards clipboard events to |clipboard_stub|, iff |clipboard_stub| is not
-// NULL.
+// Forwards clipboard events to |clipboard_stub|, if configured. Event
+// forwarding may also be disabled independently of the configured
+// |clipboard_stub|. ClipboardFilters initially have event forwarding enabled.
class ClipboardFilter : public ClipboardStub {
public:
ClipboardFilter();
+ explicit ClipboardFilter(ClipboardStub* clipboard_stub);
virtual ~ClipboardFilter();
// Set the ClipboardStub that events will be forwarded to.
void set_clipboard_stub(ClipboardStub* clipboard_stub);
+ // Enable/disable forwarding of clipboard events to the ClipboardStub.
+ void set_enabled(bool enabled) { enabled_ = enabled; }
+ bool enabled() const { return enabled_; }
+
// ClipboardStub interface.
virtual void InjectClipboardEvent(const ClipboardEvent& event) OVERRIDE;
private:
ClipboardStub* clipboard_stub_;
+ bool enabled_;
DISALLOW_COPY_AND_ASSIGN(ClipboardFilter);
};
diff --git a/remoting/protocol/clipboard_filter_unittest.cc b/remoting/protocol/clipboard_filter_unittest.cc
new file mode 100644
index 0000000..d0cff88
--- /dev/null
+++ b/remoting/protocol/clipboard_filter_unittest.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/protocol/clipboard_filter.h"
+
+#include "remoting/proto/event.pb.h"
+#include "remoting/protocol/protocol_mock_objects.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+
+namespace remoting {
+namespace protocol {
+
+MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
+ return arg.mime_type() == mime_type && arg.data() == data;
+}
+
+static ClipboardEvent MakeClipboardEvent(const std::string& mime_type,
+ const std::string& data) {
+ ClipboardEvent event;
+ event.set_mime_type(mime_type);
+ event.set_data(data);
+ return event;
+}
+
+// Verify that the filter passes events on correctly to a configured stub.
+TEST(ClipboardFilterTest, EventsPassThroughFilter) {
+ MockClipboardStub clipboard_stub;
+ ClipboardFilter clipboard_filter(&clipboard_stub);
+
+ EXPECT_CALL(clipboard_stub,
+ InjectClipboardEvent(EqualsClipboardEvent("text", "foo")));
+
+ clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo"));
+}
+
+// Verify that the filter ignores events if disabled.
+TEST(ClipboardFilterTest, IgnoreEventsIfDisabled) {
+ MockClipboardStub clipboard_stub;
+ ClipboardFilter clipboard_filter(&clipboard_stub);
+
+ clipboard_filter.set_enabled(false);
+
+ EXPECT_CALL(clipboard_stub, InjectClipboardEvent(_)).Times(0);
+
+ clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo"));
+}
+
+// Verify that the filter ignores events if not configured.
+TEST(ClipboardFilterTest, IgnoreEventsIfNotConfigured) {
+ ClipboardFilter clipboard_filter;
+
+ clipboard_filter.InjectClipboardEvent(MakeClipboardEvent("text","foo"));
+}
+
+} // namespace protocol
+} // namespace remoting
diff --git a/remoting/protocol/input_filter.cc b/remoting/protocol/input_filter.cc
index d749391..178fde7 100644
--- a/remoting/protocol/input_filter.cc
+++ b/remoting/protocol/input_filter.cc
@@ -7,22 +7,23 @@
namespace remoting {
namespace protocol {
-InputFilter::InputFilter() : input_stub_(NULL) {
+InputFilter::InputFilter() : input_stub_(NULL), enabled_(true) {
}
-InputFilter::InputFilter(InputStub* input_stub) : input_stub_(input_stub) {
+InputFilter::InputFilter(InputStub* input_stub)
+ : input_stub_(input_stub), enabled_(true) {
}
InputFilter::~InputFilter() {
}
void InputFilter::InjectKeyEvent(const KeyEvent& event) {
- if (input_stub_ != NULL)
+ if (enabled_ && input_stub_ != NULL)
input_stub_->InjectKeyEvent(event);
}
void InputFilter::InjectMouseEvent(const MouseEvent& event) {
- if (input_stub_ != NULL)
+ if (enabled_ && input_stub_ != NULL)
input_stub_->InjectMouseEvent(event);
}
diff --git a/remoting/protocol/input_filter.h b/remoting/protocol/input_filter.h
index ba8b640..1255637 100644
--- a/remoting/protocol/input_filter.h
+++ b/remoting/protocol/input_filter.h
@@ -12,27 +12,35 @@
namespace remoting {
namespace protocol {
-// Forwards input events to |input_stub|, iif |input_stub| is not NULL.
+// Forwards input events to |input_stub|, if configured. Input forwarding may
+// also be disabled independently of the |input_stub| being set. InputFilters
+// initially have input forwarding enabled.
class InputFilter : public InputStub {
public:
InputFilter();
explicit InputFilter(InputStub* input_stub);
virtual ~InputFilter();
- // Return the InputStub that events will be forwarded to.
- InputStub* input_stub() { return input_stub_; }
-
// Set the InputStub that events will be forwarded to.
void set_input_stub(InputStub* input_stub) {
input_stub_ = input_stub;
}
+ // Enable/disable routing of events to the InputStub.
+ void set_enabled(bool enabled) {
+ enabled_ = enabled;
+ }
+ bool enabled() const {
+ return enabled_;
+ }
+
// InputStub interface.
virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE;
virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE;
private:
InputStub* input_stub_;
+ bool enabled_;
DISALLOW_COPY_AND_ASSIGN(InputFilter);
};
diff --git a/remoting/protocol/input_filter_unittest.cc b/remoting/protocol/input_filter_unittest.cc
new file mode 100644
index 0000000..97db37d
--- /dev/null
+++ b/remoting/protocol/input_filter_unittest.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/protocol/input_filter.h"
+
+#include "remoting/proto/event.pb.h"
+#include "remoting/protocol/protocol_mock_objects.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using ::testing::_;
+
+namespace remoting {
+namespace protocol {
+
+MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") {
+ return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
+ arg.pressed() == pressed;
+}
+
+MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
+ return arg.x() == x && arg.y() == y;
+}
+
+static KeyEvent NewKeyEvent(uint32 usb_keycode, bool pressed) {
+ KeyEvent event;
+ event.set_usb_keycode(usb_keycode);
+ event.set_pressed(pressed);
+ return event;
+}
+
+static MouseEvent MouseMoveEvent(int x, int y) {
+ MouseEvent event;
+ event.set_x(x);
+ event.set_y(y);
+ return event;
+}
+
+static void InjectTestSequence(protocol::InputStub* input_stub) {
+ // Inject a key event.
+ input_stub->InjectKeyEvent(NewKeyEvent(0, true));
+ input_stub->InjectKeyEvent(NewKeyEvent(0, false));
+
+ // Inject mouse movemement.
+ input_stub->InjectMouseEvent(MouseMoveEvent(10, 20));
+}
+
+// Verify that the filter passes events on correctly to a configured stub.
+TEST(InputFilterTest, EventsPassThroughFilter) {
+ MockInputStub input_stub;
+ InputFilter input_filter(&input_stub);
+
+ EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, true)));
+ EXPECT_CALL(input_stub, InjectKeyEvent(EqualsKeyEvent(0, false)));
+ EXPECT_CALL(input_stub, InjectMouseEvent(EqualsMouseMoveEvent(10, 20)));
+
+ InjectTestSequence(&input_filter);
+}
+
+// Verify that the filter ignores events if disabled.
+TEST(InputFilterTest, IgnoreEventsIfDisabled) {
+ MockInputStub input_stub;
+ InputFilter input_filter(&input_stub);
+
+ input_filter.set_enabled(false);
+
+ EXPECT_CALL(input_stub, InjectKeyEvent(_)).Times(0);
+ EXPECT_CALL(input_stub, InjectMouseEvent(_)).Times(0);
+
+ InjectTestSequence(&input_filter);
+}
+
+// Verify that the filter ignores events if not configured.
+TEST(InputFilterTest, IgnoreEventsIfNotConfigured) {
+ InputFilter input_filter;
+
+ InjectTestSequence(&input_filter);
+}
+
+} // namespace protocol
+} // namespace remoting