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

Side by Side Diff: components/exo/surface_unittest.cc

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ShellSurface::SetTitle Created 5 years, 1 month 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 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.
4
5 #include "base/bind.h"
6 #include "components/exo/buffer.h"
7 #include "components/exo/surface.h"
8 #include "components/exo/test/exo_test_base.h"
9 #include "components/exo/test/exo_test_helper.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/gpu_memory_buffer.h"
12 #include "ui/views/test/widget_test.h"
13
14 namespace exo {
15 namespace {
16
17 using SurfaceTest = test::ExoTestBase;
18
19 void ReleaseBuffer(int* release_buffer_call_count) {
20 (*release_buffer_call_count)++;
21 }
22
23 TEST_F(SurfaceTest, Attach) {
24 gfx::Size buffer_size(256, 256);
25 scoped_ptr<Buffer> buffer(
26 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass()));
27
28 // Set the release callback that will be run when buffer is no longer in use.
29 int release_buffer_call_count = 0;
30 buffer->set_release_callback(
31 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count)));
32
33 scoped_ptr<Surface> surface1(new Surface);
34 scoped_ptr<Surface> surface2(new Surface);
35
36 // Attach the buffer to surface1.
37 surface1->Attach(buffer.get(), gfx::Point());
38
39 // Attaching buffer to surface2 when it is already attached to surface1
40 // should fail and buffer should remain attached to surface1.
41 surface2->Attach(buffer.get(), gfx::Point());
42
43 // Attach a null buffer to surface1 before committing it, this should
44 // release the previously attached buffer.
45 surface1->Attach(nullptr, gfx::Point());
46 ASSERT_EQ(release_buffer_call_count, 1);
47 }
48
49 TEST_F(SurfaceTest, Damage) {
50 gfx::Size buffer_size(256, 256);
51 scoped_ptr<Buffer> buffer(
52 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass()));
53 scoped_ptr<Surface> surface(new Surface);
54
55 // Attach the buffer to the surface. This will update the pending bounds of
56 // the surface to the buffer size.
57 surface->Attach(buffer.get(), gfx::Point());
58
59 // Mark area inside the bounds of the surface as damaged. This should result
60 // in pending damage.
61 surface->Damage(gfx::Rect(0, 0, 10, 10));
62 EXPECT_TRUE(surface->HasPendingDamageForTesting());
63 }
64
65 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) {
66 *result = frame_time;
67 }
68
69 TEST_F(SurfaceTest, RequestFrameCallback) {
70 scoped_ptr<Surface> surface(new Surface);
71
72 base::TimeTicks frame_time;
73 surface->RequestFrameCallback(
74 base::Bind(&SetFrameTime, base::Unretained(&frame_time)));
75 surface->Commit();
76
77 // Callback should not run synchronously.
78 EXPECT_TRUE(frame_time.is_null());
79 }
80
81 TEST_F(SurfaceTest, SetOpaqueRegion) {
82 scoped_ptr<Surface> surface(new Surface);
83
84 // Setting a non-empty opaque region should succeed.
85 surface->SetOpaqueRegion(cc::Region(gfx::Rect(0, 0, 256, 256)));
86
87 // Setting an empty opaque region should succeed.
88 surface->SetOpaqueRegion(cc::Region());
89 }
90
91 TEST_F(SurfaceTest, Commit) {
92 scoped_ptr<Surface> surface(new Surface);
93
94 // Calling commit without a buffer should succeed.
95 surface->Commit();
96 }
97
98 } // namespace
99 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698