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

Side by Side Diff: ash/mus/non_client_frame_controller_unittest.cc

Issue 2752303002: views/mus: Install a mus-friend ContextFactory for tests. (Closed)
Patch Set: . Created 3 years, 9 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
« no previous file with comments | « ash/mus/BUILD.gn ('k') | cc/test/fake_compositor_frame_sink.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/mus/non_client_frame_controller.h" 5 #include "ash/mus/non_client_frame_controller.h"
6 6
7 #include "ash/common/ash_layout_constants.h" 7 #include "ash/common/ash_layout_constants.h"
8 #include "ash/mus/top_level_window_factory.h" 8 #include "ash/mus/top_level_window_factory.h"
9 #include "ash/mus/window_manager_application.h" 9 #include "ash/mus/window_manager_application.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/ash_test_helper.h" 11 #include "ash/test/ash_test_helper.h"
12 #include "cc/base/math_util.h" 12 #include "cc/base/math_util.h"
13 #include "cc/output/compositor_frame.h" 13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/compositor_frame_sink_client.h"
15 #include "cc/quads/solid_color_draw_quad.h" 14 #include "cc/quads/solid_color_draw_quad.h"
16 #include "cc/scheduler/begin_frame_source.h"
17 #include "cc/scheduler/delay_based_time_source.h"
18 #include "cc/test/fake_compositor_frame_sink.h"
19 #include "cc/test/test_gpu_memory_buffer_manager.h"
20 #include "cc/test/test_task_graph_runner.h"
21 #include "cc/trees/layer_tree_settings.h" 15 #include "cc/trees/layer_tree_settings.h"
22 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" 16 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
23 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
24 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
25 #include "ui/compositor/compositor.h" 19 #include "ui/compositor/compositor.h"
26 #include "ui/compositor/test/draw_waiter_for_test.h" 20 #include "ui/compositor/test/draw_waiter_for_test.h"
21 #include "ui/compositor/test/fake_context_factory.h"
27 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
28 23
29 namespace ash { 24 namespace ash {
30 namespace mus { 25 namespace mus {
31 26
32 namespace { 27 namespace {
33 28
34 gfx::Rect GetQuadBoundsInScreen(const cc::DrawQuad* quad) { 29 gfx::Rect GetQuadBoundsInScreen(const cc::DrawQuad* quad) {
35 return cc::MathUtil::MapEnclosingClippedRect( 30 return cc::MathUtil::MapEnclosingClippedRect(
36 quad->shared_quad_state->quad_to_target_transform, quad->visible_rect); 31 quad->shared_quad_state->quad_to_target_transform, quad->visible_rect);
(...skipping 22 matching lines...) Expand all
59 DCHECK_EQ(1u, frame.render_pass_list.size()); 54 DCHECK_EQ(1u, frame.render_pass_list.size());
60 const cc::QuadList& quad_list = frame.render_pass_list[0]->quad_list; 55 const cc::QuadList& quad_list = frame.render_pass_list[0]->quad_list;
61 for (const auto* quad : quad_list) { 56 for (const auto* quad : quad_list) {
62 if (quad->material == cc::DrawQuad::Material::TILED_CONTENT && 57 if (quad->material == cc::DrawQuad::Material::TILED_CONTENT &&
63 GetQuadBoundsInScreen(quad) == screen_rect) 58 GetQuadBoundsInScreen(quad) == screen_rect)
64 return true; 59 return true;
65 } 60 }
66 return false; 61 return false;
67 } 62 }
68 63
69 class FakeCompositorFrameSink : public cc::FakeCompositorFrameSink {
70 public:
71 FakeCompositorFrameSink()
72 : cc::FakeCompositorFrameSink(cc::TestContextProvider::Create(),
73 cc::TestContextProvider::CreateWorker()) {}
74 ~FakeCompositorFrameSink() override = default;
75
76 private:
77 // cc::FakeCompositorFrameSink:
78 bool BindToClient(cc::CompositorFrameSinkClient* client) override {
79 if (!cc::FakeCompositorFrameSink::BindToClient(client))
80 return false;
81 begin_frame_source_ = base::MakeUnique<cc::BackToBackBeginFrameSource>(
82 base::MakeUnique<cc::DelayBasedTimeSource>(
83 base::ThreadTaskRunnerHandle::Get().get()));
84 client_->SetBeginFrameSource(begin_frame_source_.get());
85 return true;
86 }
87
88 std::unique_ptr<cc::BeginFrameSource> begin_frame_source_;
89
90 DISALLOW_COPY_AND_ASSIGN(FakeCompositorFrameSink);
91 };
92
93 } // namespace 64 } // namespace
94 65
95 class NonClientFrameControllerTest : public test::AshTestBase, 66 class NonClientFrameControllerTest : public test::AshTestBase {
96 public ui::ContextFactory {
97 public: 67 public:
98 NonClientFrameControllerTest() = default; 68 NonClientFrameControllerTest() = default;
99 ~NonClientFrameControllerTest() override = default; 69 ~NonClientFrameControllerTest() override = default;
100 70
101 const cc::CompositorFrame& GetLastCompositorFrame() const { 71 const cc::CompositorFrame& GetLastCompositorFrame() const {
102 return *frame_sink_->last_sent_frame(); 72 return context_factory_.GetLastCompositorFrame();
103 } 73 }
104 74
105 // test::AshTestBase: 75 // test::AshTestBase:
106 void SetUp() override { 76 void SetUp() override {
107 aura::Env* env = aura::Env::GetInstance(); 77 aura::Env* env = aura::Env::GetInstance();
108 DCHECK(env); 78 DCHECK(env);
109 context_factory_to_restore_ = env->context_factory(); 79 context_factory_to_restore_ = env->context_factory();
110 env->set_context_factory(this); 80 env->set_context_factory(&context_factory_);
111 AshTestBase::SetUp(); 81 AshTestBase::SetUp();
112 } 82 }
113 83
114 void TearDown() override { 84 void TearDown() override {
115 AshTestBase::TearDown(); 85 AshTestBase::TearDown();
116 aura::Env::GetInstance()->set_context_factory(context_factory_to_restore_); 86 aura::Env::GetInstance()->set_context_factory(context_factory_to_restore_);
117 } 87 }
118 88
119 // ui::ContextFactory::
120 void CreateCompositorFrameSink(
121 base::WeakPtr<ui::Compositor> compositor) override {
122 auto frame_sink = base::MakeUnique<FakeCompositorFrameSink>();
123 frame_sink_ = frame_sink.get();
124 compositor->SetCompositorFrameSink(std::move(frame_sink));
125 }
126 scoped_refptr<cc::ContextProvider> SharedMainThreadContextProvider()
127 override {
128 return nullptr;
129 }
130 void RemoveCompositor(ui::Compositor* compositor) override {
131 frame_sink_ = nullptr;
132 }
133 bool DoesCreateTestContexts() override { return true; }
134 uint32_t GetImageTextureTarget(gfx::BufferFormat format,
135 gfx::BufferUsage usage) override {
136 return GL_TEXTURE_2D;
137 }
138 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override {
139 return &gpu_memory_buffer_manager_;
140 }
141 cc::TaskGraphRunner* GetTaskGraphRunner() override {
142 return &task_graph_runner_;
143 }
144 void AddObserver(ui::ContextFactoryObserver* observer) override {}
145 void RemoveObserver(ui::ContextFactoryObserver* observer) override {}
146
147 private: 89 private:
90 ui::FakeContextFactory context_factory_;
148 ui::ContextFactory* context_factory_to_restore_ = nullptr; 91 ui::ContextFactory* context_factory_to_restore_ = nullptr;
149 cc::FakeCompositorFrameSink* frame_sink_ = nullptr;
150 cc::TestTaskGraphRunner task_graph_runner_;
151 cc::TestGpuMemoryBufferManager gpu_memory_buffer_manager_;
152 92
153 DISALLOW_COPY_AND_ASSIGN(NonClientFrameControllerTest); 93 DISALLOW_COPY_AND_ASSIGN(NonClientFrameControllerTest);
154 }; 94 };
155 95
156 TEST_F(NonClientFrameControllerTest, ContentRegionNotDrawnForClient) { 96 TEST_F(NonClientFrameControllerTest, ContentRegionNotDrawnForClient) {
157 std::map<std::string, std::vector<uint8_t>> properties; 97 std::map<std::string, std::vector<uint8_t>> properties;
158 std::unique_ptr<aura::Window> window(mus::CreateAndParentTopLevelWindow( 98 std::unique_ptr<aura::Window> window(mus::CreateAndParentTopLevelWindow(
159 ash_test_helper()->window_manager_app()->window_manager(), 99 ash_test_helper()->window_manager_app()->window_manager(),
160 ui::mojom::WindowType::WINDOW, &properties)); 100 ui::mojom::WindowType::WINDOW, &properties));
161 ASSERT_TRUE(window); 101 ASSERT_TRUE(window);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 158
219 // And there will be a content quad for the window caption. 159 // And there will be a content quad for the window caption.
220 gfx::Rect caption_bound(widget_bound); 160 gfx::Rect caption_bound(widget_bound);
221 caption_bound.set_height(caption_height); 161 caption_bound.set_height(caption_height);
222 EXPECT_TRUE(FindTiledContentQuad(frame, caption_bound)); 162 EXPECT_TRUE(FindTiledContentQuad(frame, caption_bound));
223 } 163 }
224 } 164 }
225 165
226 } // namespace mus 166 } // namespace mus
227 } // namespace ash 167 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/BUILD.gn ('k') | cc/test/fake_compositor_frame_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698