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

Side by Side Diff: components/display_compositor/host_shared_bitmap_manager_unittest.cc

Issue 2873243002: Move components/display_compositor to components/viz/display_compositor (Closed)
Patch Set: Rebase Created 3 years, 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 <stddef.h>
6 #include <string.h>
7
8 #include "components/display_compositor/host_shared_bitmap_manager.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace display_compositor {
12 namespace {
13
14 class HostSharedBitmapManagerTest : public testing::Test {
15 protected:
16 void SetUp() override { manager_.reset(new HostSharedBitmapManager()); }
17 std::unique_ptr<HostSharedBitmapManager> manager_;
18 };
19
20 TEST_F(HostSharedBitmapManagerTest, TestCreate) {
21 gfx::Size bitmap_size(1, 1);
22 size_t size_in_bytes;
23 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
24 std::unique_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
25 bitmap->CreateAndMapAnonymous(size_in_bytes);
26 memset(bitmap->memory(), 0xff, size_in_bytes);
27 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
28
29 HostSharedBitmapManagerClient client(manager_.get());
30 base::SharedMemoryHandle handle = bitmap->handle().Duplicate();
31 client.ChildAllocatedSharedBitmap(size_in_bytes, handle, id);
32
33 std::unique_ptr<cc::SharedBitmap> large_bitmap;
34 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
35 EXPECT_TRUE(large_bitmap.get() == NULL);
36
37 std::unique_ptr<cc::SharedBitmap> very_large_bitmap;
38 very_large_bitmap =
39 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id);
40 EXPECT_TRUE(very_large_bitmap.get() == NULL);
41
42 std::unique_ptr<cc::SharedBitmap> negative_size_bitmap;
43 negative_size_bitmap =
44 manager_->GetSharedBitmapFromId(gfx::Size(-1, 1024), id);
45 EXPECT_TRUE(negative_size_bitmap.get() == NULL);
46
47 cc::SharedBitmapId id2 = cc::SharedBitmap::GenerateId();
48 std::unique_ptr<cc::SharedBitmap> invalid_bitmap;
49 invalid_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id2);
50 EXPECT_TRUE(invalid_bitmap.get() == NULL);
51
52 std::unique_ptr<cc::SharedBitmap> shared_bitmap;
53 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
54 ASSERT_TRUE(shared_bitmap.get() != NULL);
55 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), 4), 0);
56
57 std::unique_ptr<cc::SharedBitmap> large_bitmap2;
58 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
59 EXPECT_TRUE(large_bitmap2.get() == NULL);
60
61 std::unique_ptr<cc::SharedBitmap> shared_bitmap2;
62 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
63 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels());
64 shared_bitmap2.reset();
65 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
66 0);
67
68 client.DidDeleteSharedBitmap(id);
69
70 memset(bitmap->memory(), 0, size_in_bytes);
71
72 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
73 0);
74 bitmap.reset();
75 shared_bitmap.reset();
76 }
77
78 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
79 gfx::Size bitmap_size(1, 1);
80 size_t size_in_bytes;
81 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
82 std::unique_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
83 bitmap->CreateAndMapAnonymous(size_in_bytes);
84 memset(bitmap->memory(), 0xff, size_in_bytes);
85 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
86
87 std::unique_ptr<HostSharedBitmapManagerClient> client(
88 new HostSharedBitmapManagerClient(manager_.get()));
89 base::SharedMemoryHandle handle = bitmap->handle().Duplicate();
90 client->ChildAllocatedSharedBitmap(size_in_bytes, handle, id);
91
92 std::unique_ptr<cc::SharedBitmap> shared_bitmap;
93 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
94 ASSERT_TRUE(shared_bitmap.get() != NULL);
95
96 EXPECT_EQ(1u, manager_->AllocatedBitmapCount());
97 client.reset();
98 EXPECT_EQ(0u, manager_->AllocatedBitmapCount());
99
100 std::unique_ptr<cc::SharedBitmap> shared_bitmap2;
101 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
102 EXPECT_TRUE(shared_bitmap2.get() == NULL);
103 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
104 0);
105
106 shared_bitmap.reset();
107 }
108
109 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
110 gfx::Size bitmap_size(1, 1);
111 size_t size_in_bytes;
112 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
113 std::unique_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
114 bitmap->CreateAndMapAnonymous(size_in_bytes);
115 memset(bitmap->memory(), 0xff, size_in_bytes);
116 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
117 HostSharedBitmapManagerClient client(manager_.get());
118
119 base::SharedMemoryHandle handle = bitmap->handle().Duplicate();
120 client.ChildAllocatedSharedBitmap(size_in_bytes, handle, id);
121
122 std::unique_ptr<base::SharedMemory> bitmap2(new base::SharedMemory());
123 bitmap2->CreateAndMapAnonymous(size_in_bytes);
124 memset(bitmap2->memory(), 0x00, size_in_bytes);
125
126 client.ChildAllocatedSharedBitmap(size_in_bytes, bitmap2->handle(), id);
127
128 std::unique_ptr<cc::SharedBitmap> shared_bitmap;
129 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
130 ASSERT_TRUE(shared_bitmap.get() != NULL);
131 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
132 0);
133 client.DidDeleteSharedBitmap(id);
134 }
135
136 } // namespace
137 } // namespace display_compositor
OLDNEW
« no previous file with comments | « components/display_compositor/host_shared_bitmap_manager.cc ('k') | components/display_compositor/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698