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