Chromium Code Reviews| 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..7e4036d384c5db0a022b97324f7eb6dc66625db6 |
| --- /dev/null |
| +++ b/blimp/common/net/message_dispatcher_unittest.cc |
| @@ -0,0 +1,48 @@ |
| +// 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); |
| + 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); |
|
Wez
2015/10/07 00:20:15
Verify that the Dispatcher returns an error in thi
|
| +} |
| + |
| +} // namespace blimp |