| 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/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/layers/layer.h" | |
| 12 #include "cc/proto/compositor_message.pb.h" | |
| 13 #include "cc/surfaces/surface_manager.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 using testing::_; | |
| 18 | |
| 19 namespace blimp { | |
| 20 namespace client { | |
| 21 | |
| 22 class MockBlimpCompositorClient : public BlimpCompositorClient { | |
| 23 public: | |
| 24 MockBlimpCompositorClient() = default; | |
| 25 ~MockBlimpCompositorClient() override = default; | |
| 26 | |
| 27 void SendWebGestureEvent( | |
| 28 int render_widget_id, | |
| 29 const blink::WebGestureEvent& gesture_event) override { | |
| 30 MockableSendWebGestureEvent(render_widget_id); | |
| 31 } | |
| 32 void SendCompositorMessage( | |
| 33 int render_widget_id, | |
| 34 const cc::proto::CompositorMessage& message) override { | |
| 35 MockableSendCompositorMessage(render_widget_id); | |
| 36 } | |
| 37 | |
| 38 MOCK_METHOD1(MockableSendWebGestureEvent, void(int)); | |
| 39 MOCK_METHOD1(MockableSendCompositorMessage, void(int)); | |
| 40 | |
| 41 private: | |
| 42 DISALLOW_COPY_AND_ASSIGN(MockBlimpCompositorClient); | |
| 43 }; | |
| 44 | |
| 45 class BlimpCompositorForTesting : public BlimpCompositor { | |
| 46 public: | |
| 47 BlimpCompositorForTesting( | |
| 48 int render_widget_id, | |
| 49 BlimpCompositorDependencies* compositor_dependencies, | |
| 50 BlimpCompositorClient* client) | |
| 51 : BlimpCompositor(render_widget_id, compositor_dependencies, client) {} | |
| 52 | |
| 53 void SendProto(const cc::proto::CompositorMessage& proto) { | |
| 54 SendCompositorProto(proto); | |
| 55 } | |
| 56 | |
| 57 void SendGestureEvent(const blink::WebGestureEvent& gesture_event) { | |
| 58 SendWebGestureEvent(gesture_event); | |
| 59 } | |
| 60 | |
| 61 cc::LayerTreeHost* host() const { return host_.get(); } | |
| 62 }; | |
| 63 | |
| 64 class BlimpCompositorTest : public testing::Test { | |
| 65 public: | |
| 66 BlimpCompositorTest() : render_widget_id_(1), loop_(new base::MessageLoop) {} | |
| 67 | |
| 68 void SetUp() override { | |
| 69 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | |
| 70 base::MakeUnique<MockCompositorDependencies>()); | |
| 71 | |
| 72 compositor_ = base::MakeUnique<BlimpCompositorForTesting>( | |
| 73 render_widget_id_, compositor_dependencies_.get(), &compositor_client_); | |
| 74 } | |
| 75 | |
| 76 void TearDown() override { | |
| 77 compositor_.reset(); | |
| 78 compositor_dependencies_.reset(); | |
| 79 } | |
| 80 | |
| 81 ~BlimpCompositorTest() override {} | |
| 82 | |
| 83 void SendInitializeMessage() { | |
| 84 std::unique_ptr<cc::proto::CompositorMessage> message; | |
| 85 message.reset(new cc::proto::CompositorMessage); | |
| 86 cc::proto::CompositorMessageToImpl* to_impl = | |
| 87 message->mutable_to_impl(); | |
| 88 to_impl->set_message_type( | |
| 89 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL); | |
| 90 cc::proto::InitializeImpl* initialize_message = | |
| 91 to_impl->mutable_initialize_impl_message(); | |
| 92 cc::LayerTreeSettings settings; | |
| 93 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings()); | |
| 94 compositor_->OnCompositorMessageReceived(std::move(message)); | |
| 95 } | |
| 96 | |
| 97 void SendShutdownMessage() { | |
| 98 std::unique_ptr<cc::proto::CompositorMessage> message; | |
| 99 message.reset(new cc::proto::CompositorMessage); | |
| 100 cc::proto::CompositorMessageToImpl* to_impl = | |
| 101 message->mutable_to_impl(); | |
| 102 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL); | |
| 103 compositor_->OnCompositorMessageReceived(std::move(message)); | |
| 104 } | |
| 105 | |
| 106 int render_widget_id_; | |
| 107 std::unique_ptr<base::MessageLoop> loop_; | |
| 108 MockBlimpCompositorClient compositor_client_; | |
| 109 std::unique_ptr<BlimpCompositorDependencies> compositor_dependencies_; | |
| 110 std::unique_ptr<BlimpCompositorForTesting> compositor_; | |
| 111 BlobImageSerializationProcessor blob_image_serialization_processor_; | |
| 112 }; | |
| 113 | |
| 114 TEST_F(BlimpCompositorTest, ToggleVisibilityWithHost) { | |
| 115 // Make the compositor visible when we don't have a host. | |
| 116 compositor_->SetVisible(true); | |
| 117 SendInitializeMessage(); | |
| 118 | |
| 119 // Check that the visibility is set correctly on the host. | |
| 120 EXPECT_NE(compositor_->host(), nullptr); | |
| 121 EXPECT_TRUE(compositor_->host()->visible()); | |
| 122 | |
| 123 // Make the compositor invisible. This should make the |host_| invisible. | |
| 124 compositor_->SetVisible(false); | |
| 125 EXPECT_FALSE(compositor_->host()->visible()); | |
| 126 | |
| 127 SendShutdownMessage(); | |
| 128 EXPECT_EQ(compositor_->host(), nullptr); | |
| 129 } | |
| 130 | |
| 131 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) { | |
| 132 // Create the host and make it visible. | |
| 133 SendInitializeMessage(); | |
| 134 compositor_->SetVisible(true); | |
| 135 | |
| 136 // Destroy this host and recreate a new one. Make sure that the visibility is | |
| 137 // set correctly on this host. | |
| 138 SendShutdownMessage(); | |
| 139 SendInitializeMessage(); | |
| 140 EXPECT_NE(compositor_->host(), nullptr); | |
| 141 EXPECT_TRUE(compositor_->host()->visible()); | |
| 142 } | |
| 143 | |
| 144 TEST_F(BlimpCompositorTest, MessagesHaveCorrectId) { | |
| 145 EXPECT_CALL(compositor_client_, | |
| 146 MockableSendCompositorMessage(render_widget_id_)).Times(1); | |
| 147 EXPECT_CALL(compositor_client_, | |
| 148 MockableSendWebGestureEvent(render_widget_id_)).Times(1); | |
| 149 | |
| 150 compositor_->SendProto(cc::proto::CompositorMessage()); | |
| 151 compositor_->SendGestureEvent(blink::WebGestureEvent()); | |
| 152 } | |
| 153 | |
| 154 } // namespace client | |
| 155 } // namespace blimp | |
| OLD | NEW |