Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / cc / surfaces / surface_display_output_surface_unittest.cc
blobdaabafec7f0e4a2cc5b370585b6664e8740e800d
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 nullptr) {
65 output_surface_ = display_client_.output_surface();
66 display_client_.set_surface_output_surface(
67 &surface_display_output_surface_);
68 surface_display_output_surface_.set_display_client(&display_client_);
69 surface_display_output_surface_.BindToClient(
70 &surface_display_output_surface_client_);
71 display_client_.display()->Resize(display_size_);
73 EXPECT_FALSE(surface_display_output_surface_client_
74 .did_lose_output_surface_called());
77 ~SurfaceDisplayOutputSurfaceTest() override {}
79 void SwapBuffersWithDamage(const gfx::Rect& damage_rect_) {
80 scoped_ptr<RenderPass> render_pass(RenderPass::Create());
81 render_pass->SetNew(RenderPassId(1, 1), display_rect_, damage_rect_,
82 gfx::Transform());
84 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
85 frame_data->render_pass_list.push_back(render_pass.Pass());
87 CompositorFrame frame;
88 frame.delegated_frame_data = frame_data.Pass();
90 surface_display_output_surface_.SwapBuffers(&frame);
93 void SetUp() override {
94 // Draw the first frame to start in an "unlocked" state.
95 SwapBuffersWithDamage(display_rect_);
97 EXPECT_EQ(0u, output_surface_->num_sent_frames());
98 task_runner_->RunUntilIdle();
99 EXPECT_EQ(1u, output_surface_->num_sent_frames());
102 protected:
103 scoped_ptr<base::SimpleTestTickClock> now_src_;
104 scoped_refptr<OrderedSimpleTaskRunner> task_runner_;
105 SurfaceIdAllocator allocator_;
107 const gfx::Size display_size_;
108 const gfx::Rect display_rect_;
109 FakeOutputSurface* output_surface_;
110 SurfaceManager surface_manager_;
111 TestSharedBitmapManager bitmap_manager_;
112 TestGpuMemoryBufferManager gpu_memory_buffer_manager_;
113 RendererSettings renderer_settings_;
114 FakeOnscreenDisplayClient display_client_;
116 scoped_refptr<TestContextProvider> context_provider_;
118 FakeOutputSurfaceClient surface_display_output_surface_client_;
119 SurfaceDisplayOutputSurface surface_display_output_surface_;
122 TEST_F(SurfaceDisplayOutputSurfaceTest, DamageTriggersSwapBuffers) {
123 SwapBuffersWithDamage(display_rect_);
124 EXPECT_EQ(1u, output_surface_->num_sent_frames());
125 task_runner_->RunUntilIdle();
126 EXPECT_EQ(2u, output_surface_->num_sent_frames());
129 TEST_F(SurfaceDisplayOutputSurfaceTest, NoDamageDoesNotTriggerSwapBuffers) {
130 SwapBuffersWithDamage(gfx::Rect());
131 EXPECT_EQ(1u, output_surface_->num_sent_frames());
132 task_runner_->RunUntilIdle();
133 EXPECT_EQ(1u, output_surface_->num_sent_frames());
136 TEST_F(SurfaceDisplayOutputSurfaceTest, SuspendedDoesNotTriggerSwapBuffers) {
137 SwapBuffersWithDamage(display_rect_);
138 EXPECT_EQ(1u, output_surface_->num_sent_frames());
139 output_surface_->set_suspended_for_recycle(true);
140 task_runner_->RunUntilIdle();
141 EXPECT_EQ(1u, output_surface_->num_sent_frames());
142 SwapBuffersWithDamage(display_rect_);
143 task_runner_->RunUntilIdle();
144 EXPECT_EQ(1u, output_surface_->num_sent_frames());
145 output_surface_->set_suspended_for_recycle(false);
146 SwapBuffersWithDamage(display_rect_);
147 task_runner_->RunUntilIdle();
148 EXPECT_EQ(2u, output_surface_->num_sent_frames());
151 TEST_F(SurfaceDisplayOutputSurfaceTest,
152 LockingResourcesDoesNotIndirectlyCauseDamage) {
153 surface_display_output_surface_.ForceReclaimResources();
154 EXPECT_EQ(1u, output_surface_->num_sent_frames());
155 task_runner_->RunPendingTasks();
156 EXPECT_EQ(1u, output_surface_->num_sent_frames());
158 SwapBuffersWithDamage(gfx::Rect());
159 EXPECT_EQ(1u, output_surface_->num_sent_frames());
160 task_runner_->RunUntilIdle();
161 EXPECT_EQ(1u, output_surface_->num_sent_frames());
164 } // namespace
165 } // namespace cc