Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(844)

Unified Diff: blimp/common/net/message_dispatcher_unittest.cc

Issue 1324263003: Blimp: create MessageDispatcher class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp-protos
Patch Set: Fix tryserver entries. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/common/net/message_dispatcher_unittest.cc
diff --git a/blimp/common/net/message_dispatcher_unittest.cc b/blimp/common/net/message_dispatcher_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..14c601cc7436be0c5350d668f700ac3a7255a64e
--- /dev/null
+++ b/blimp/common/net/message_dispatcher_unittest.cc
@@ -0,0 +1,51 @@
+// Copyright 2015 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.
+//
+// Uniitest for data encryption functions.
+
+#include "blimp/common/net/message_dispatcher.h"
+
+#include "base/logging.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::Ref;
+using testing::Return;
+
+namespace blimp {
+
+class MockHandler : public MessageDispatcher::Handler {
+ public:
+ MOCK_CONST_METHOD1(Validate, bool(const BlimpMessage& message));
+ MOCK_METHOD1(OnMessage, void(const BlimpMessage& message));
+};
+
+TEST(MessageDispatcherTest, AllInteractions) {
+ BlimpMessage input_msg;
+ BlimpMessage compositor_msg;
+
+ input_msg.set_type(BlimpMessage::INPUT);
+ compositor_msg.set_type(BlimpMessage::COMPOSITOR);
+
+ MessageDispatcher dispatcher;
+ MockHandler handler1;
+ MockHandler handler2;
+
+ dispatcher.AddHandler(BlimpMessage::INPUT, &handler1);
+ // Can't add >1 handler for a single type, so handler1 should continue to be
+ // the handler for INPUT.
+ dispatcher.AddHandler(BlimpMessage::INPUT, &handler2);
+ dispatcher.AddHandler(BlimpMessage::COMPOSITOR, &handler2);
+
+ // First message passes validation and is given to the handler for processing.
+ EXPECT_CALL(handler1, Validate(Ref(input_msg))).WillOnce(Return(true));
+ EXPECT_CALL(handler1, OnMessage(Ref(input_msg)));
+ dispatcher.Dispatch(input_msg);
+
+ // Second message fails validation.
+ EXPECT_CALL(handler2, Validate(Ref(compositor_msg))).WillOnce(Return(false));
+ dispatcher.Dispatch(compositor_msg);
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698