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

Side by Side 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: Resync with master Created 5 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // Uniitest for data encryption functions.
6
7 #include "blimp/common/net/message_dispatcher.h"
8
9 #include "base/logging.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using testing::Ref;
14 using testing::Return;
15
16 namespace blimp {
17
18 class MockHandler : public MessageDispatcher::Handler {
19 public:
20 MOCK_CONST_METHOD1(Validate, bool(const BlimpMessage& message));
21 MOCK_METHOD1(OnMessage, void(const BlimpMessage& message));
22 };
23
24 TEST(MessageDispatcherTest, AllInteractions) {
25 BlimpMessage input_msg;
26 BlimpMessage compositor_msg;
27
28 input_msg.set_type(BlimpMessage::INPUT);
29 compositor_msg.set_type(BlimpMessage::COMPOSITOR);
30
31 MessageDispatcher dispatcher;
32 MockHandler handler1;
33 MockHandler handler2;
34
35 dispatcher.AddHandler(BlimpMessage::INPUT, &handler1);
36 // Can't add >1 handler for a single type, so handler1 should continue to be
37 // the handler for INPUT.
38 dispatcher.AddHandler(BlimpMessage::INPUT, &handler2);
39 dispatcher.AddHandler(BlimpMessage::COMPOSITOR, &handler2);
40
41 // First message passes validation and is given to the handler for processing.
42 EXPECT_CALL(handler1, Validate(Ref(input_msg))).WillOnce(Return(true));
43 EXPECT_CALL(handler1, OnMessage(Ref(input_msg)));
44 dispatcher.Dispatch(input_msg);
45
46 // Second message fails validation.
47 EXPECT_CALL(handler2, Validate(Ref(compositor_msg))).WillOnce(Return(false));
48 dispatcher.Dispatch(compositor_msg);
49 }
50
51 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698