Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(653)

Side by Side Diff: blimp/client/feature/compositor/blimp_compositor_unittest.cc

Issue 1653553002: blimp: Use remote client LayerTreeHost in the BlimpCompositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run tests for linux only for now. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 };
37
38 class BlimpCompositorTest : public testing::Test {
39 public:
40 BlimpCompositorTest():
41 loop_(new base::MessageLoop),
42 window_(42u) {}
43
44 void SetUp() override {
45 EXPECT_CALL(render_widget_feature_, SetDelegate(_, _)).Times(1);
46 EXPECT_CALL(render_widget_feature_, RemoveDelegate(_)).Times(1);
47
48 compositor_.reset(new BlimpCompositorForTesting(
49 1.0f, &render_widget_feature_));
50 }
51
52 void TearDown() override {
53 compositor_.reset();
54 }
55
56 ~BlimpCompositorTest() override {}
57
58 RenderWidgetFeature::RenderWidgetFeatureDelegate* delegate() const {
59 DCHECK(compositor_);
60 return static_cast<RenderWidgetFeature::RenderWidgetFeatureDelegate*>
61 (compositor_.get());
62 }
63
64 void SendInitializeMessage() {
65 scoped_ptr<cc::proto::CompositorMessage> message;
66 message.reset(new cc::proto::CompositorMessage);
67 cc::proto::CompositorMessageToImpl* to_impl =
68 message->mutable_to_impl();
69 to_impl->set_message_type(
70 cc::proto::CompositorMessageToImpl::INITIALIZE_IMPL);
71 cc::proto::InitializeImpl* initialize_message =
72 to_impl->mutable_initialize_impl_message();
73 cc::LayerTreeSettings settings;
74 settings.ToProtobuf(initialize_message->mutable_layer_tree_settings());
75 delegate()->OnCompositorMessageReceived(std::move(message));
76 }
77
78 void SendShutdownMessage() {
79 scoped_ptr<cc::proto::CompositorMessage> message;
80 message.reset(new cc::proto::CompositorMessage);
81 cc::proto::CompositorMessageToImpl* to_impl =
82 message->mutable_to_impl();
83 to_impl->set_message_type(cc::proto::CompositorMessageToImpl::CLOSE_IMPL);
84 delegate()->OnCompositorMessageReceived(std::move(message));
85 }
86
87 scoped_ptr<base::MessageLoop> loop_;
88 MockRenderWidgetFeature render_widget_feature_;
89 scoped_ptr<BlimpCompositorForTesting> compositor_;
90 gfx::AcceleratedWidget window_;
91 };
92
93 TEST_F(BlimpCompositorTest, ToggleVisibilityAndWidgetWithHost) {
94 // Make the compositor visible and give it a widget when we don't have a host.
95 compositor_->SetVisible(true);
96 compositor_->SetAcceleratedWidget(window_);
97 SendInitializeMessage();
98
99 // Check that the visibility is set correctly on the host.
100 EXPECT_NE(compositor_->host(), nullptr);
101 EXPECT_TRUE(compositor_->host()->visible());
102
103 // Make the compositor invisible. This should drop the output surface and
104 // make the |host_| invisible.
105 compositor_->SetVisible(false);
106 EXPECT_FALSE(compositor_->host()->visible());
107
108 // Make the compositor visible and release the widget. This should make the
109 // |host_| invisible.
110 compositor_->SetVisible(true);
111 EXPECT_TRUE(compositor_->host()->visible());
112 compositor_->ReleaseAcceleratedWidget();
113 EXPECT_FALSE(compositor_->host()->visible());
114
115 SendShutdownMessage();
116 EXPECT_EQ(compositor_->host(), nullptr);
117 }
118
119 TEST_F(BlimpCompositorTest, DestroyAndRecreateHost) {
120 // Create the host and make it visible.
121 SendInitializeMessage();
122 compositor_->SetVisible(true);
123 compositor_->SetAcceleratedWidget(window_);
124
125 // Destroy this host and recreate a new one. Make sure that the visibility is
126 // set correctly on this host.
127 SendShutdownMessage();
128 SendInitializeMessage();
129 EXPECT_NE(compositor_->host(), nullptr);
130 EXPECT_TRUE(compositor_->host()->visible());
131 }
132
133 TEST_F(BlimpCompositorTest, DestroyHostOnRenderWidgetInitialized) {
134 // Create the host.
135 compositor_->SetVisible(true);
136 compositor_->SetAcceleratedWidget(window_);
137 SendInitializeMessage();
138 EXPECT_NE(compositor_->host(), nullptr);
139
140 delegate()->OnRenderWidgetInitialized();
141 EXPECT_EQ(compositor_->host(), nullptr);
142
143 // Recreate the host.
144 SendInitializeMessage();
145 EXPECT_NE(compositor_->host(), nullptr);
146 EXPECT_TRUE(compositor_->host()->visible());
147 }
148
149 } // namespace client
150 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/feature/compositor/blimp_compositor.cc ('k') | blimp/client/feature/compositor/test/dummy_layer_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698