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/lazy_instance.h" | |
8 #include "base/thread_task_runner_handle.h" | |
9 #include "cc/proto/compositor_message.pb.h" | |
10 #include "testing/gmock/include/gmock/gmock.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 using testing::_; | |
14 | |
15 namespace blimp { | |
16 namespace client { | |
17 | |
18 class MockRenderWidgetFeature : public RenderWidgetFeature { | |
19 public: | |
20 MOCK_METHOD2(SendCompositorMessage, | |
21 void(const int, | |
22 const cc::proto::CompositorMessage&)); | |
23 MOCK_METHOD2(SendInputEvent, void(const int, | |
24 const blink::WebInputEvent&)); | |
25 MOCK_METHOD2(SetDelegate, void(int, RenderWidgetFeatureDelegate*)); | |
26 MOCK_METHOD1(RemoveDelegate, void(const int)); | |
27 }; | |
28 | |
29 class BlimpCompositorForTesting : public BlimpCompositor { | |
30 public: | |
31 BlimpCompositorForTesting(float dp_to_px, | |
32 RenderWidgetFeature* render_widget_feature) | |
33 : BlimpCompositor(dp_to_px, render_widget_feature) {} | |
34 | |
35 cc::LayerTreeHost* host() const { return host_.get(); } | |
36 bool request() const { return output_surface_request_pending_; } | |
David Trainor- moved to gerrit
2016/02/03 17:42:57
Looks like you don't use this?
Khushal
2016/02/03 17:56:02
Oops. I'll remove this.
| |
37 }; | |
38 | |
39 class BlimpCompositorTest : public testing::Test { | |
40 public: | |
41 BlimpCompositorTest(): | |
42 loop_(new base::MessageLoop) {} | |
43 | |
44 void SetUp() override { | |
45 EXPECT_CALL(render_widget_feature_, SetDelegate(_, _)).Times(1); | |
46 EXPECT_CALL(render_widget_feature_, RemoveDelegate(_)).Times(1); | |
David Trainor- moved to gerrit
2016/02/03 17:42:57
huh. why is this called?
Khushal
2016/02/03 17:56:03
We do that in the dtor. Because the delegate is dy
| |
47 | |
48 compositor_.reset(new BlimpCompositorForTesting( | |
49 1.0f, &render_widget_feature_)); | |
50 } | |
51 | |
52 ~BlimpCompositorTest() override {} | |
53 | |
54 RenderWidgetFeature::RenderWidgetFeatureDelegate* delegate() const { | |
55 DCHECK(compositor_); | |
56 return static_cast<RenderWidgetFeature::RenderWidgetFeatureDelegate*> | |
57 (compositor_.get()); | |
58 } | |
59 | |
60 void SendInitializeMessage() { | |
61 scoped_ptr<cc::proto::CompositorMessage> message; | |
62 message.reset(new cc::proto::CompositorMessage); | |
63 cc::proto::CompositorMessageToImpl* to_impl = | |
64 message->mutable_to_impl(); | |
65 to_impl->set_message_type( | |
66 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL); | |
67 cc::proto::InitializeImpl* initialize_message = | |
68 to_impl->mutable_initialize_impl_message(); | |
69 cc::LayerTreeSettings settings; | |
70 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings()); | |
71 delegate()->OnCompositorMessageReceived(std::move(message)); | |
72 } | |
73 | |
74 void SendShutdownMessage() { | |
75 scoped_ptr<cc::proto::CompositorMessage> message; | |
76 message.reset(new cc::proto::CompositorMessage); | |
77 cc::proto::CompositorMessageToImpl* to_impl = | |
78 message->mutable_to_impl(); | |
79 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL); | |
80 delegate()->OnCompositorMessageReceived(std::move(message)); | |
81 } | |
82 | |
83 scoped_ptr<base::MessageLoop> loop_; | |
84 MockRenderWidgetFeature render_widget_feature_; | |
85 scoped_ptr<BlimpCompositorForTesting> compositor_; | |
86 gfx::AcceleratedWidget window_; | |
87 }; | |
88 | |
89 TEST_F(BlimpCompositorTest, ToggleVisibilityAndWidgetWithHost) { | |
90 // Make the compositor visible and give it a widget when we don't have a host. | |
91 compositor_->SetVisible(true); | |
92 compositor_->SetAcceleratedWidget(window_); | |
93 SendInitializeMessage(); | |
94 | |
95 // Check that the visibility is set correctly on the host. | |
96 EXPECT_NE(compositor_->host(), nullptr); | |
97 EXPECT_TRUE(compositor_->host()->visible()); | |
98 | |
99 // Make the compositor invisible. This should drop the output surface and | |
100 // make the |host_| invisible. | |
101 compositor_->SetVisible(false); | |
102 EXPECT_FALSE(compositor_->host()->visible()); | |
103 | |
104 // Make the compositor visible and release the widget. This should make the | |
105 // |host_| invisible. | |
106 compositor_->SetVisible(true); | |
107 EXPECT_TRUE(compositor_->host()->visible()); | |
108 compositor_->ReleaseAcceleratedWidget(); | |
109 EXPECT_FALSE(compositor_->host()->visible()); | |
110 | |
111 SendShutdownMessage(); | |
112 EXPECT_EQ(compositor_->host(), nullptr); | |
113 } | |
114 | |
115 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) { | |
116 // Create the host and make it visible. | |
117 SendInitializeMessage(); | |
118 compositor_->SetVisible(true); | |
119 compositor_->SetAcceleratedWidget(window_); | |
120 | |
121 // Destroy this host and recreate a new one. Make sure that the visibility is | |
122 // set correctly on this host. | |
123 SendShutdownMessage(); | |
124 SendInitializeMessage(); | |
125 EXPECT_NE(compositor_->host(), nullptr); | |
126 EXPECT_TRUE(compositor_->host()->visible()); | |
127 } | |
128 | |
129 TEST_F(BlimpCompositorTest, DestroyHostOnRenderWidgetInitialized) { | |
130 // Create the host. | |
131 compositor_->SetVisible(true); | |
132 compositor_->SetAcceleratedWidget(window_); | |
133 SendInitializeMessage(); | |
134 EXPECT_NE(compositor_->host(), nullptr); | |
135 | |
136 delegate()->OnRenderWidgetInitialized(); | |
137 EXPECT_EQ(compositor_->host(), nullptr); | |
138 | |
139 // Recreate the host. | |
140 SendInitializeMessage(); | |
141 EXPECT_NE(compositor_->host(), nullptr); | |
142 EXPECT_TRUE(compositor_->host()->visible()); | |
143 } | |
144 | |
145 } // namespace client | |
146 } // namespace blimp | |
OLD | NEW |