OLD | NEW |
| (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 #include "blimp/client/session/render_widget_feature.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "blimp/common/create_blimp_message.h" | |
10 #include "blimp/common/proto/blimp_message.pb.h" | |
11 #include "blimp/common/proto/compositor.pb.h" | |
12 #include "blimp/common/proto/render_widget.pb.h" | |
13 #include "blimp/net/test_common.h" | |
14 #include "cc/proto/compositor_message.pb.h" | |
15 #include "net/base/net_errors.h" | |
16 #include "net/base/test_completion_callback.h" | |
17 #include "testing/gmock/include/gmock/gmock.h" | |
18 #include "testing/gtest/include/gtest/gtest.h" | |
19 | |
20 using testing::_; | |
21 using testing::InSequence; | |
22 using testing::Sequence; | |
23 | |
24 namespace blimp { | |
25 namespace client { | |
26 | |
27 namespace { | |
28 | |
29 class MockRenderWidgetFeatureDelegate | |
30 : public RenderWidgetFeature::RenderWidgetFeatureDelegate { | |
31 public: | |
32 // RenderWidgetFeatureDelegate implementation. | |
33 void OnRenderWidgetInitialized() override { | |
34 MockableOnRenderWidgetInitialized(); | |
35 } | |
36 void OnCompositorMessageReceived( | |
37 scoped_ptr<cc::proto::CompositorMessage> message) override { | |
38 MockableOnCompositorMessageReceived(*message); | |
39 } | |
40 | |
41 MOCK_METHOD0(MockableOnRenderWidgetInitialized, void()); | |
42 MOCK_METHOD1(MockableOnCompositorMessageReceived, | |
43 void(const cc::proto::CompositorMessage& message)); | |
44 }; | |
45 | |
46 MATCHER_P2(CompMsgEquals, tab_id, rw_id, "") { | |
47 return arg.compositor().render_widget_id() == rw_id && | |
48 arg.target_tab_id() == tab_id; | |
49 } | |
50 | |
51 void SendRenderWidgetMessage(BlimpMessageProcessor* processor, | |
52 int tab_id, | |
53 uint32_t rw_id) { | |
54 RenderWidgetMessage* details; | |
55 scoped_ptr<BlimpMessage> message = CreateBlimpMessage(&details, tab_id); | |
56 details->set_type(RenderWidgetMessage::INITIALIZE); | |
57 details->set_render_widget_id(rw_id); | |
58 net::TestCompletionCallback cb; | |
59 processor->ProcessMessage(std::move(message), cb.callback()); | |
60 EXPECT_EQ(net::OK, cb.WaitForResult()); | |
61 } | |
62 | |
63 void SendCompositorMessage(BlimpMessageProcessor* processor, | |
64 int tab_id, | |
65 uint32_t rw_id) { | |
66 CompositorMessage* details; | |
67 scoped_ptr<BlimpMessage> message = CreateBlimpMessage(&details, tab_id); | |
68 details->set_render_widget_id(rw_id); | |
69 net::TestCompletionCallback cb; | |
70 processor->ProcessMessage(std::move(message), cb.callback()); | |
71 EXPECT_EQ(net::OK, cb.WaitForResult()); | |
72 } | |
73 | |
74 } // namespace | |
75 | |
76 class RenderWidgetFeatureTest : public testing::Test { | |
77 public: | |
78 RenderWidgetFeatureTest() | |
79 : out_input_processor_(nullptr), out_compositor_processor_(nullptr) {} | |
80 | |
81 void SetUp() override { | |
82 out_input_processor_ = new MockBlimpMessageProcessor(); | |
83 out_compositor_processor_ = new MockBlimpMessageProcessor(); | |
84 feature_.set_outgoing_input_message_processor( | |
85 make_scoped_ptr(out_input_processor_)); | |
86 feature_.set_outgoing_compositor_message_processor( | |
87 make_scoped_ptr(out_compositor_processor_)); | |
88 | |
89 feature_.SetDelegate(1, &delegate1_); | |
90 feature_.SetDelegate(2, &delegate2_); | |
91 } | |
92 | |
93 protected: | |
94 // These are raw pointers to classes that are owned by the | |
95 // RenderWidgetFeature. | |
96 MockBlimpMessageProcessor* out_input_processor_; | |
97 MockBlimpMessageProcessor* out_compositor_processor_; | |
98 | |
99 MockRenderWidgetFeatureDelegate delegate1_; | |
100 MockRenderWidgetFeatureDelegate delegate2_; | |
101 | |
102 RenderWidgetFeature feature_; | |
103 }; | |
104 | |
105 TEST_F(RenderWidgetFeatureTest, DelegateCallsOK) { | |
106 EXPECT_CALL(delegate1_, MockableOnRenderWidgetInitialized()).Times(1); | |
107 EXPECT_CALL(delegate1_, MockableOnCompositorMessageReceived(_)).Times(2); | |
108 EXPECT_CALL(delegate2_, MockableOnRenderWidgetInitialized()).Times(1); | |
109 EXPECT_CALL(delegate2_, MockableOnCompositorMessageReceived(_)).Times(0); | |
110 | |
111 SendRenderWidgetMessage(&feature_, 1, 1U); | |
112 SendCompositorMessage(&feature_, 1, 1U); | |
113 SendCompositorMessage(&feature_, 1, 1U); | |
114 SendRenderWidgetMessage(&feature_, 2, 2U); | |
115 } | |
116 | |
117 TEST_F(RenderWidgetFeatureTest, RepliesHaveCorrectRenderWidgetId) { | |
118 InSequence sequence; | |
119 | |
120 EXPECT_CALL(*out_compositor_processor_, | |
121 MockableProcessMessage(CompMsgEquals(1, 2U), _)); | |
122 EXPECT_CALL(*out_compositor_processor_, | |
123 MockableProcessMessage(CompMsgEquals(1, 3U), _)); | |
124 EXPECT_CALL(*out_compositor_processor_, | |
125 MockableProcessMessage(CompMsgEquals(2, 1U), _)); | |
126 | |
127 SendRenderWidgetMessage(&feature_, 1, 2U); | |
128 feature_.SendCompositorMessage(1, cc::proto::CompositorMessage()); | |
129 SendRenderWidgetMessage(&feature_, 1, 3U); | |
130 feature_.SendCompositorMessage(1, cc::proto::CompositorMessage()); | |
131 SendRenderWidgetMessage(&feature_, 2, 1U); | |
132 feature_.SendCompositorMessage(2, cc::proto::CompositorMessage()); | |
133 } | |
134 | |
135 } // namespace client | |
136 } // namespace blimp | |
OLD | NEW |