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

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: remove some ifdefs 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
« no previous file with comments | « components/exo/surface_delegate.h ('k') | components/exo/test/exo_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "third_party/khronos/GLES2/gl2.h"
12 #include "ui/gfx/gpu_memory_buffer.h"
13 #include "ui/views/test/widget_test.h"
14
15 namespace exo {
16 namespace {
17
18 using SurfaceTest = test::ExoTestBase;
19
20 void ReleaseBuffer(int* release_buffer_call_count) {
21 (*release_buffer_call_count)++;
22 }
23
24 TEST_F(SurfaceTest, Attach) {
25 gfx::Size buffer_size(256, 256);
26 scoped_ptr<Buffer> buffer(
27 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(),
28 GL_TEXTURE_2D));
29
30 // Set the release callback that will be run when buffer is no longer in use.
31 int release_buffer_call_count = 0;
32 buffer->set_release_callback(
33 base::Bind(&ReleaseBuffer, base::Unretained(&release_buffer_call_count)));
34
35 scoped_ptr<Surface> surface1(new Surface);
36 scoped_ptr<Surface> surface2(new Surface);
37
38 // Attach the buffer to surface1.
39 surface1->Attach(buffer.get());
40 surface1->Commit();
41
42 // Attaching buffer to surface2 when it is already attached to surface1
43 // should fail and buffer should remain attached to surface1.
44 surface2->Attach(buffer.get());
45 surface2->Commit();
46
47 // Attach a null buffer to surface1, this should release the previously
48 // attached buffer.
49 surface1->Attach(nullptr);
50 surface1->Commit();
51 ASSERT_EQ(release_buffer_call_count, 1);
52 }
53
54 TEST_F(SurfaceTest, Damage) {
55 gfx::Size buffer_size(256, 256);
56 scoped_ptr<Buffer> buffer(
57 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(),
58 GL_TEXTURE_2D));
59 scoped_ptr<Surface> surface(new Surface);
60
61 // Attach the buffer to the surface. This will update the pending bounds of
62 // the surface to the buffer size.
63 surface->Attach(buffer.get());
64
65 // Mark area inside the bounds of the surface as damaged. This should result
66 // in pending damage.
67 surface->Damage(gfx::Rect(0, 0, 10, 10));
68 EXPECT_TRUE(surface->HasPendingDamageForTesting());
69 }
70
71 void SetFrameTime(base::TimeTicks* result, base::TimeTicks frame_time) {
72 *result = frame_time;
73 }
74
75 TEST_F(SurfaceTest, RequestFrameCallback) {
76 scoped_ptr<Surface> surface(new Surface);
77
78 base::TimeTicks frame_time;
79 surface->RequestFrameCallback(
80 base::Bind(&SetFrameTime, base::Unretained(&frame_time)));
81 surface->Commit();
82
83 // Callback should not run synchronously.
84 EXPECT_TRUE(frame_time.is_null());
85 }
86
87 TEST_F(SurfaceTest, SetOpaqueRegion) {
88 scoped_ptr<Surface> surface(new Surface);
89
90 // Setting a non-empty opaque region should succeed.
91 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeWH(256, 256)));
92
93 // Setting an empty opaque region should succeed.
94 surface->SetOpaqueRegion(SkRegion(SkIRect::MakeEmpty()));
95 }
96
97 TEST_F(SurfaceTest, Commit) {
98 scoped_ptr<Surface> surface(new Surface);
99
100 // Calling commit without a buffer should succeed.
101 surface->Commit();
102 }
103
104 } // namespace
105 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/surface_delegate.h ('k') | components/exo/test/exo_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698