| 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.h" | |
| 6 | |
| 7 #include "base/threading/thread_task_runner_handle.h" | |
| 8 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
| 9 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h" | |
| 10 #include "blimp/common/compositor/blimp_task_graph_runner.h" | |
| 11 #include "cc/proto/compositor_message.pb.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 using testing::_; | |
| 16 | |
| 17 namespace blimp { | |
| 18 namespace client { | |
| 19 | |
| 20 class MockBlimpCompositorClient : public BlimpCompositorClient { | |
| 21 public: | |
| 22 MockBlimpCompositorClient() : compositor_thread_("Compositor") { | |
| 23 compositor_thread_.Start(); | |
| 24 } | |
| 25 ~MockBlimpCompositorClient() override { compositor_thread_.Stop(); } | |
| 26 | |
| 27 cc::LayerTreeSettings* GetLayerTreeSettings() override { return &settings_; } | |
| 28 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() override | |
| 29 { return compositor_thread_.task_runner(); } | |
| 30 cc::TaskGraphRunner* GetTaskGraphRunner() override { | |
| 31 return &task_graph_runner_; } | |
| 32 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override { | |
| 33 return &gpu_memory_buffer_manager_; | |
| 34 } | |
| 35 cc::ImageSerializationProcessor* GetImageSerializationProcessor() override { | |
| 36 return BlobImageSerializationProcessor::current(); | |
| 37 } | |
| 38 void DidCompleteSwapBuffers() override {} | |
| 39 void DidCommitAndDrawFrame() override {} | |
| 40 | |
| 41 void SendWebGestureEvent( | |
| 42 int render_widget_id, | |
| 43 const blink::WebGestureEvent& gesture_event) override { | |
| 44 MockableSendWebGestureEvent(render_widget_id); | |
| 45 } | |
| 46 void SendCompositorMessage( | |
| 47 int render_widget_id, | |
| 48 const cc::proto::CompositorMessage& message) override { | |
| 49 MockableSendCompositorMessage(render_widget_id); | |
| 50 } | |
| 51 | |
| 52 MOCK_METHOD1(MockableSendWebGestureEvent, void(int)); | |
| 53 MOCK_METHOD1(MockableSendCompositorMessage, void(int)); | |
| 54 | |
| 55 cc::LayerTreeSettings settings_; | |
| 56 base::Thread compositor_thread_; | |
| 57 BlimpTaskGraphRunner task_graph_runner_; | |
| 58 BlimpGpuMemoryBufferManager gpu_memory_buffer_manager_; | |
| 59 BlobImageSerializationProcessor serialization_processor_; | |
| 60 | |
| 61 private: | |
| 62 DISALLOW_COPY_AND_ASSIGN(MockBlimpCompositorClient); | |
| 63 }; | |
| 64 | |
| 65 class BlimpCompositorForTesting : public BlimpCompositor { | |
| 66 public: | |
| 67 BlimpCompositorForTesting(int render_widget_id, | |
| 68 BlimpCompositorClient* client) | |
| 69 : BlimpCompositor(render_widget_id, client) {} | |
| 70 | |
| 71 void SendProto(const cc::proto::CompositorMessage& proto) { | |
| 72 SendCompositorProto(proto); | |
| 73 } | |
| 74 | |
| 75 void SendGestureEvent(const blink::WebGestureEvent& gesture_event) { | |
| 76 SendWebGestureEvent(gesture_event); | |
| 77 } | |
| 78 | |
| 79 cc::LayerTreeHost* host() const { return host_.get(); } | |
| 80 }; | |
| 81 | |
| 82 class BlimpCompositorTest : public testing::Test { | |
| 83 public: | |
| 84 BlimpCompositorTest(): | |
| 85 render_widget_id_(1), | |
| 86 loop_(new base::MessageLoop), | |
| 87 window_(42u) {} | |
| 88 | |
| 89 void SetUp() override { | |
| 90 compositor_.reset(new BlimpCompositorForTesting(render_widget_id_, | |
| 91 &compositor_client_)); | |
| 92 } | |
| 93 | |
| 94 void TearDown() override { | |
| 95 compositor_.reset(); | |
| 96 } | |
| 97 | |
| 98 ~BlimpCompositorTest() override {} | |
| 99 | |
| 100 void SendInitializeMessage() { | |
| 101 std::unique_ptr<cc::proto::CompositorMessage> message; | |
| 102 message.reset(new cc::proto::CompositorMessage); | |
| 103 cc::proto::CompositorMessageToImpl* to_impl = | |
| 104 message->mutable_to_impl(); | |
| 105 to_impl->set_message_type( | |
| 106 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL); | |
| 107 cc::proto::InitializeImpl* initialize_message = | |
| 108 to_impl->mutable_initialize_impl_message(); | |
| 109 cc::LayerTreeSettings settings; | |
| 110 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings()); | |
| 111 compositor_->OnCompositorMessageReceived(std::move(message)); | |
| 112 } | |
| 113 | |
| 114 void SendShutdownMessage() { | |
| 115 std::unique_ptr<cc::proto::CompositorMessage> message; | |
| 116 message.reset(new cc::proto::CompositorMessage); | |
| 117 cc::proto::CompositorMessageToImpl* to_impl = | |
| 118 message->mutable_to_impl(); | |
| 119 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL); | |
| 120 compositor_->OnCompositorMessageReceived(std::move(message)); | |
| 121 } | |
| 122 | |
| 123 int render_widget_id_; | |
| 124 std::unique_ptr<base::MessageLoop> loop_; | |
| 125 MockBlimpCompositorClient compositor_client_; | |
| 126 std::unique_ptr<BlimpCompositorForTesting> compositor_; | |
| 127 gfx::AcceleratedWidget window_; | |
| 128 }; | |
| 129 | |
| 130 TEST_F(BlimpCompositorTest, ToggleVisibilityAndWidgetWithHost) { | |
| 131 // Make the compositor visible and give it a widget when we don't have a host. | |
| 132 compositor_->SetVisible(true); | |
| 133 compositor_->SetAcceleratedWidget(window_); | |
| 134 SendInitializeMessage(); | |
| 135 | |
| 136 // Check that the visibility is set correctly on the host. | |
| 137 EXPECT_NE(compositor_->host(), nullptr); | |
| 138 EXPECT_TRUE(compositor_->host()->visible()); | |
| 139 | |
| 140 // Make the compositor invisible. This should drop the output surface and | |
| 141 // make the |host_| invisible. | |
| 142 compositor_->SetVisible(false); | |
| 143 EXPECT_FALSE(compositor_->host()->visible()); | |
| 144 | |
| 145 // Make the compositor visible and release the widget. This should make the | |
| 146 // |host_| invisible. | |
| 147 compositor_->SetVisible(true); | |
| 148 EXPECT_TRUE(compositor_->host()->visible()); | |
| 149 compositor_->ReleaseAcceleratedWidget(); | |
| 150 EXPECT_FALSE(compositor_->host()->visible()); | |
| 151 | |
| 152 SendShutdownMessage(); | |
| 153 EXPECT_EQ(compositor_->host(), nullptr); | |
| 154 } | |
| 155 | |
| 156 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) { | |
| 157 // Create the host and make it visible. | |
| 158 SendInitializeMessage(); | |
| 159 compositor_->SetVisible(true); | |
| 160 compositor_->SetAcceleratedWidget(window_); | |
| 161 | |
| 162 // Destroy this host and recreate a new one. Make sure that the visibility is | |
| 163 // set correctly on this host. | |
| 164 SendShutdownMessage(); | |
| 165 SendInitializeMessage(); | |
| 166 EXPECT_NE(compositor_->host(), nullptr); | |
| 167 EXPECT_TRUE(compositor_->host()->visible()); | |
| 168 } | |
| 169 | |
| 170 TEST_F(BlimpCompositorTest, MessagesHaveCorrectId) { | |
| 171 EXPECT_CALL(compositor_client_, | |
| 172 MockableSendCompositorMessage(render_widget_id_)).Times(1); | |
| 173 EXPECT_CALL(compositor_client_, | |
| 174 MockableSendWebGestureEvent(render_widget_id_)).Times(1); | |
| 175 | |
| 176 compositor_->SendProto(cc::proto::CompositorMessage()); | |
| 177 compositor_->SendGestureEvent(blink::WebGestureEvent()); | |
| 178 } | |
| 179 | |
| 180 } // namespace client | |
| 181 } // namespace blimp | |
| OLD | NEW |