| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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/compositor/blimp_compositor_manager.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | |
| 9 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
| 10 #include "blimp/client/feature/compositor/mock_compositor_dependencies.h" | |
| 11 #include "cc/proto/compositor_message.pb.h" | |
| 12 #include "cc/surfaces/surface_manager.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "ui/events/gesture_detection/motion_event_generic.h" | |
| 16 | |
| 17 using testing::_; | |
| 18 using testing::InSequence; | |
| 19 using testing::Sequence; | |
| 20 | |
| 21 namespace blimp { | |
| 22 namespace client { | |
| 23 namespace { | |
| 24 | |
| 25 class MockRenderWidgetFeature : public RenderWidgetFeature { | |
| 26 public: | |
| 27 MOCK_METHOD3(SendCompositorMessage, | |
| 28 void(const int, | |
| 29 const int, | |
| 30 const cc::proto::CompositorMessage&)); | |
| 31 MOCK_METHOD3(SendInputEvent, void(const int, | |
| 32 const int, | |
| 33 const blink::WebInputEvent&)); | |
| 34 MOCK_METHOD2(SetDelegate, void(int, RenderWidgetFeatureDelegate*)); | |
| 35 MOCK_METHOD1(RemoveDelegate, void(const int)); | |
| 36 }; | |
| 37 | |
| 38 class MockBlimpCompositor : public BlimpCompositor { | |
| 39 public: | |
| 40 explicit MockBlimpCompositor( | |
| 41 const int render_widget_id, | |
| 42 BlimpCompositorDependencies* compositor_dependencies, | |
| 43 BlimpCompositorClient* client) | |
| 44 : BlimpCompositor(render_widget_id, compositor_dependencies, client) {} | |
| 45 | |
| 46 MOCK_METHOD1(SetVisible, void(bool)); | |
| 47 MOCK_METHOD1(OnTouchEvent, bool(const ui::MotionEvent& motion_event)); | |
| 48 | |
| 49 void OnCompositorMessageReceived( | |
| 50 std::unique_ptr<cc::proto::CompositorMessage> message) override { | |
| 51 MockableOnCompositorMessageReceived(*message); | |
| 52 } | |
| 53 MOCK_METHOD1(MockableOnCompositorMessageReceived, | |
| 54 void(const cc::proto::CompositorMessage&)); | |
| 55 }; | |
| 56 | |
| 57 class BlimpCompositorManagerForTesting : public BlimpCompositorManager { | |
| 58 public: | |
| 59 explicit BlimpCompositorManagerForTesting( | |
| 60 RenderWidgetFeature* render_widget_feature, | |
| 61 BlimpCompositorDependencies* compositor_dependencies) | |
| 62 : BlimpCompositorManager(render_widget_feature, compositor_dependencies) { | |
| 63 } | |
| 64 | |
| 65 using BlimpCompositorManager::GetCompositor; | |
| 66 | |
| 67 std::unique_ptr<BlimpCompositor> CreateBlimpCompositor( | |
| 68 int render_widget_id, | |
| 69 BlimpCompositorDependencies* compositor_dependencies, | |
| 70 BlimpCompositorClient* client) override { | |
| 71 return base::MakeUnique<MockBlimpCompositor>( | |
| 72 render_widget_id, compositor_dependencies, client); | |
| 73 } | |
| 74 }; | |
| 75 | |
| 76 class BlimpCompositorManagerTest : public testing::Test { | |
| 77 public: | |
| 78 void SetUp() override { | |
| 79 EXPECT_CALL(render_widget_feature_, SetDelegate(_, _)).Times(1); | |
| 80 EXPECT_CALL(render_widget_feature_, RemoveDelegate(_)).Times(1); | |
| 81 | |
| 82 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | |
| 83 base::MakeUnique<MockCompositorDependencies>()); | |
| 84 | |
| 85 compositor_manager_ = base::MakeUnique<BlimpCompositorManagerForTesting>( | |
| 86 &render_widget_feature_, compositor_dependencies_.get()); | |
| 87 } | |
| 88 | |
| 89 void TearDown() override { | |
| 90 mock_compositor1_ = nullptr; | |
| 91 mock_compositor2_ = nullptr; | |
| 92 compositor_manager_.reset(); | |
| 93 compositor_dependencies_.reset(); | |
| 94 } | |
| 95 | |
| 96 void SetUpCompositors() { | |
| 97 delegate()->OnRenderWidgetCreated(1); | |
| 98 delegate()->OnRenderWidgetCreated(2); | |
| 99 | |
| 100 mock_compositor1_ = static_cast<MockBlimpCompositor*> | |
| 101 (compositor_manager_->GetCompositor(1)); | |
| 102 mock_compositor2_ = static_cast<MockBlimpCompositor*> | |
| 103 (compositor_manager_->GetCompositor(2)); | |
| 104 | |
| 105 EXPECT_NE(mock_compositor1_, nullptr); | |
| 106 EXPECT_NE(mock_compositor2_, nullptr); | |
| 107 | |
| 108 EXPECT_EQ(mock_compositor1_->render_widget_id(), 1); | |
| 109 EXPECT_EQ(mock_compositor2_->render_widget_id(), 2); | |
| 110 } | |
| 111 | |
| 112 RenderWidgetFeature::RenderWidgetFeatureDelegate* delegate() const { | |
| 113 DCHECK(compositor_manager_); | |
| 114 return static_cast<RenderWidgetFeature::RenderWidgetFeatureDelegate*> | |
| 115 (compositor_manager_.get()); | |
| 116 } | |
| 117 | |
| 118 std::unique_ptr<BlimpCompositorDependencies> compositor_dependencies_; | |
| 119 std::unique_ptr<BlimpCompositorManagerForTesting> compositor_manager_; | |
| 120 BlobImageSerializationProcessor blob_image_serialization_processor_; | |
| 121 MockRenderWidgetFeature render_widget_feature_; | |
| 122 MockBlimpCompositor* mock_compositor1_; | |
| 123 MockBlimpCompositor* mock_compositor2_; | |
| 124 }; | |
| 125 | |
| 126 TEST_F(BlimpCompositorManagerTest, ForwardsMessagesToCorrectCompositor) { | |
| 127 SetUpCompositors(); | |
| 128 | |
| 129 // Ensure that the compositor messages for a render widget are forwarded to | |
| 130 // the correct compositor. | |
| 131 EXPECT_CALL(*mock_compositor1_, | |
| 132 MockableOnCompositorMessageReceived(_)).Times(2); | |
| 133 EXPECT_CALL(*mock_compositor2_, | |
| 134 MockableOnCompositorMessageReceived(_)).Times(1); | |
| 135 EXPECT_CALL(*mock_compositor1_, | |
| 136 SetVisible(false)).Times(1); | |
| 137 | |
| 138 delegate()->OnCompositorMessageReceived( | |
| 139 1, base::WrapUnique(new cc::proto::CompositorMessage)); | |
| 140 delegate()->OnRenderWidgetInitialized(1); | |
| 141 delegate()->OnCompositorMessageReceived( | |
| 142 2, base::WrapUnique(new cc::proto::CompositorMessage)); | |
| 143 delegate()->OnCompositorMessageReceived( | |
| 144 1, base::WrapUnique(new cc::proto::CompositorMessage)); | |
| 145 | |
| 146 delegate()->OnRenderWidgetDeleted(1); | |
| 147 EXPECT_EQ(compositor_manager_->GetCompositor(1), nullptr); | |
| 148 } | |
| 149 | |
| 150 TEST_F(BlimpCompositorManagerTest, ForwardsViewEventsToCorrectCompositor) { | |
| 151 InSequence sequence; | |
| 152 SetUpCompositors(); | |
| 153 | |
| 154 EXPECT_CALL(*mock_compositor1_, SetVisible(true)); | |
| 155 EXPECT_CALL(*mock_compositor1_, OnTouchEvent(_)); | |
| 156 EXPECT_CALL(*mock_compositor1_, SetVisible(false)); | |
| 157 | |
| 158 EXPECT_CALL(*mock_compositor2_, SetVisible(true)); | |
| 159 EXPECT_CALL(*mock_compositor2_, SetVisible(false)); | |
| 160 | |
| 161 // Make the compositor manager visible while we don't have any render widget | |
| 162 // initialized. | |
| 163 compositor_manager_->SetVisible(true); | |
| 164 | |
| 165 // Initialize the first render widget. This should propagate the visibility, | |
| 166 // and the touch events to the corresponding compositor. | |
| 167 delegate()->OnRenderWidgetInitialized(1); | |
| 168 compositor_manager_->OnTouchEvent( | |
| 169 ui::MotionEventGeneric(ui::MotionEvent::Action::ACTION_NONE, | |
| 170 base::TimeTicks::Now(), ui::PointerProperties())); | |
| 171 | |
| 172 // Now initialize the second render widget. This should swap the compositors | |
| 173 // and make the first one invisible. | |
| 174 delegate()->OnRenderWidgetInitialized(2); | |
| 175 | |
| 176 // Now make the compositor manager invisible. This should make the current | |
| 177 // compositor invisible. | |
| 178 compositor_manager_->SetVisible(false); | |
| 179 | |
| 180 // Destroy all the widgets. We should not be receiving any calls for the view | |
| 181 // events forwarded after this. | |
| 182 delegate()->OnRenderWidgetDeleted(1); | |
| 183 delegate()->OnRenderWidgetDeleted(2); | |
| 184 | |
| 185 compositor_manager_->SetVisible(true); | |
| 186 } | |
| 187 | |
| 188 } // namespace | |
| 189 } // namespace client | |
| 190 } // namespace blimp | |
| OLD | NEW |