Add ICU message format support
[chromium-blink-merge.git] / cc / surfaces / surface_display_output_surface_unittest.cc
blob9b67f1f6f7f3a1f05026c8aa59057a4e4eea2683
1 // Copyright 2015 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.
5 #include "cc/surfaces/surface_display_output_surface.h"
7 #include "cc/surfaces/onscreen_display_client.h"
8 #include "cc/surfaces/surface_id_allocator.h"
9 #include "cc/surfaces/surface_manager.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_output_surface_client.h"
12 #include "cc/test/ordered_simple_task_runner.h"
13 #include "cc/test/test_context_provider.h"
14 #include "cc/test/test_gpu_memory_buffer_manager.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace cc {
19 namespace {
21 class FakeOnscreenDisplayClient : public OnscreenDisplayClient {
22 public:
23 FakeOnscreenDisplayClient(
24 SurfaceManager* manager,
25 SharedBitmapManager* bitmap_manager,
26 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
27 const RendererSettings& settings,
28 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
29 : OnscreenDisplayClient(FakeOutputSurface::Create3d(),
30 manager,
31 bitmap_manager,
32 gpu_memory_buffer_manager,
33 settings,
34 task_runner) {
35 // Ownership is passed to another object later, store a pointer
36 // to it now for future reference.
37 fake_output_surface_ =
38 static_cast<FakeOutputSurface*>(output_surface_.get());
41 FakeOutputSurface* output_surface() { return fake_output_surface_; }
43 protected:
44 FakeOutputSurface* fake_output_surface_;
47 class SurfaceDisplayOutputSurfaceTest : public testing::Test {
48 public:
49 SurfaceDisplayOutputSurfaceTest()
50 : now_src_(new base::SimpleTestTickClock()),
51 task_runner_(new OrderedSimpleTaskRunner(now_src_.get(), true)),
52 allocator_(0),
53 display_size_(1920, 1080),
54 display_rect_(display_size_),
55 display_client_(&surface_manager_,
56 &bitmap_manager_,
57 &gpu_memory_buffer_manager_,
58 renderer_settings_,
59 task_runner_),
60 context_provider_(TestContextProvider::Create()),
61 surface_display_output_surface_(&surface_manager_,
62 &allocator_,
63 context_provider_) {
64 output_surface_ = display_client_.output_surface();
65 display_client_.set_surface_output_surface(
66 &surface_display_output_surface_);
67 surface_display_output_surface_.set_display_client(&display_client_);
68 surface_display_output_surface_.BindToClient(
69 &surface_display_output_surface_client_);
70 display_client_.display()->Resize(display_size_);
72 EXPECT_FALSE(surface_display_output_surface_client_
73 .did_lose_output_surface_called());
76 ~SurfaceDisplayOutputSurfaceTest() override {}
78 void SwapBuffersWithDamage(const gfx::Rect& damage_rect_) {
79 scoped_ptr<RenderPass> render_pass(RenderPass::Create());
80 render_pass->SetNew(RenderPassId(1, 1), display_rect_, damage_rect_,
81 gfx::Transform());
83 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
84 frame_data->render_pass_list.push_back(render_pass.Pass());
86 CompositorFrame frame;
87 frame.delegated_frame_data = frame_data.Pass();
89 surface_display_output_surface_.SwapBuffers(&frame);
92 void SetUp() override {
93 // Draw the first frame to start in an "unlocked" state.
94 SwapBuffersWithDamage(display_rect_);
96 EXPECT_EQ(0u, output_surface_->num_sent_frames());
97 task_runner_->RunUntilIdle();
98 EXPECT_EQ(1u, output_surface_->num_sent_frames());
101 protected:
102 scoped_ptr<base::SimpleTestTickClock> now_src_;
103 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
104 SurfaceIdAllocator allocator_;
106 const gfx::Size display_size_;
107 const gfx::Rect display_rect_;
108 FakeOutputSurface* output_surface_;
109 SurfaceManager surface_manager_;
110 TestSharedBitmapManager bitmap_manager_;
111 TestGpuMemoryBufferManager gpu_memory_buffer_manager_;
112 RendererSettings renderer_settings_;
113 FakeOnscreenDisplayClient display_client_;
115 scoped_refptr<TestContextProvider> context_provider_;
117 FakeOutputSurfaceClient surface_display_output_surface_client_;
118 SurfaceDisplayOutputSurface surface_display_output_surface_;
121 TEST_F(SurfaceDisplayOutputSurfaceTest, DamageTriggersSwapBuffers) {
122 SwapBuffersWithDamage(display_rect_);
123 EXPECT_EQ(1u, output_surface_->num_sent_frames());
124 task_runner_->RunUntilIdle();
125 EXPECT_EQ(2u, output_surface_->num_sent_frames());
128 TEST_F(SurfaceDisplayOutputSurfaceTest, NoDamageDoesNotTriggerSwapBuffers) {
129 SwapBuffersWithDamage(gfx::Rect());
130 EXPECT_EQ(1u, output_surface_->num_sent_frames());
131 task_runner_->RunUntilIdle();
132 EXPECT_EQ(1u, output_surface_->num_sent_frames());
135 TEST_F(SurfaceDisplayOutputSurfaceTest,
136 LockingResourcesDoesNotIndirectlyCauseDamage) {
137 surface_display_output_surface_.ForceReclaimResources();
138 EXPECT_EQ(1u, output_surface_->num_sent_frames());
139 task_runner_->RunPendingTasks();
140 EXPECT_EQ(1u, output_surface_->num_sent_frames());
142 SwapBuffersWithDamage(gfx::Rect());
143 EXPECT_EQ(1u, output_surface_->num_sent_frames());
144 task_runner_->RunUntilIdle();
145 EXPECT_EQ(1u, output_surface_->num_sent_frames());
148 } // namespace
149 } // namespace cc