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

Side by Side Diff: content/common/host_shared_bitmap_manager_unittest.cc

Issue 955523005: Add HostSharedBitmapManagerClient to organize bitmaps coming from renderers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « content/common/host_shared_bitmap_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/host_shared_bitmap_manager.h" 5 #include "content/common/host_shared_bitmap_manager.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace content { 8 namespace content {
9 namespace { 9 namespace {
10 10
11 class HostSharedBitmapManagerTest : public testing::Test { 11 class HostSharedBitmapManagerTest : public testing::Test {
12 protected: 12 protected:
13 void SetUp() override { manager_.reset(new HostSharedBitmapManager()); } 13 void SetUp() override { manager_.reset(new HostSharedBitmapManager()); }
14 scoped_ptr<HostSharedBitmapManager> manager_; 14 scoped_ptr<HostSharedBitmapManager> manager_;
15 }; 15 };
16 16
17 TEST_F(HostSharedBitmapManagerTest, TestCreate) { 17 TEST_F(HostSharedBitmapManagerTest, TestCreate) {
18 gfx::Size bitmap_size(1, 1); 18 gfx::Size bitmap_size(1, 1);
19 size_t size_in_bytes; 19 size_t size_in_bytes;
20 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes)); 20 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
21 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory()); 21 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
22 bitmap->CreateAndMapAnonymous(size_in_bytes); 22 bitmap->CreateAndMapAnonymous(size_in_bytes);
23 memset(bitmap->memory(), 0xff, size_in_bytes); 23 memset(bitmap->memory(), 0xff, size_in_bytes);
24 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 24 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
25 25
26 HostSharedBitmapManagerClient client(manager_.get());
26 base::SharedMemoryHandle handle; 27 base::SharedMemoryHandle handle;
27 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 28 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
28 manager_->ChildAllocatedSharedBitmap( 29 client.ChildAllocatedSharedBitmap(size_in_bytes, handle,
29 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 30 base::GetCurrentProcessHandle(), id);
30 31
31 scoped_ptr<cc::SharedBitmap> large_bitmap; 32 scoped_ptr<cc::SharedBitmap> large_bitmap;
32 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); 33 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
33 EXPECT_TRUE(large_bitmap.get() == NULL); 34 EXPECT_TRUE(large_bitmap.get() == NULL);
34 35
35 scoped_ptr<cc::SharedBitmap> very_large_bitmap; 36 scoped_ptr<cc::SharedBitmap> very_large_bitmap;
36 very_large_bitmap = 37 very_large_bitmap =
37 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id); 38 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id);
38 EXPECT_TRUE(very_large_bitmap.get() == NULL); 39 EXPECT_TRUE(very_large_bitmap.get() == NULL);
39 40
(...skipping 16 matching lines...) Expand all
56 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); 57 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
57 EXPECT_TRUE(large_bitmap2.get() == NULL); 58 EXPECT_TRUE(large_bitmap2.get() == NULL);
58 59
59 scoped_ptr<cc::SharedBitmap> shared_bitmap2; 60 scoped_ptr<cc::SharedBitmap> shared_bitmap2;
60 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); 61 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
61 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels()); 62 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels());
62 shared_bitmap2.reset(); 63 shared_bitmap2.reset();
63 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 64 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
64 0); 65 0);
65 66
66 manager_->ChildDeletedSharedBitmap(id); 67 client.ChildDeletedSharedBitmap(id);
67 68
68 memset(bitmap->memory(), 0, size_in_bytes); 69 memset(bitmap->memory(), 0, size_in_bytes);
69 70
70 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 71 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
71 0); 72 0);
72 bitmap.reset(); 73 bitmap.reset();
73 shared_bitmap.reset(); 74 shared_bitmap.reset();
74 } 75 }
75 76
76 TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) { 77 TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) {
77 gfx::Size bitmap_size(1, 1); 78 gfx::Size bitmap_size(1, 1);
78 size_t size_in_bytes; 79 size_t size_in_bytes;
79 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes)); 80 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
80 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 81 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
82 HostSharedBitmapManagerClient client(manager_.get());
81 base::SharedMemoryHandle handle; 83 base::SharedMemoryHandle handle;
82 manager_->AllocateSharedBitmapForChild( 84 client.AllocateSharedBitmapForChild(base::GetCurrentProcessHandle(),
83 base::GetCurrentProcessHandle(), size_in_bytes, id, &handle); 85 size_in_bytes, id, &handle);
84 86
85 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle)); 87 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle));
86 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory(handle, false)); 88 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory(handle, false));
87 EXPECT_TRUE(bitmap->Map(size_in_bytes)); 89 EXPECT_TRUE(bitmap->Map(size_in_bytes));
88 memset(bitmap->memory(), 0xff, size_in_bytes); 90 memset(bitmap->memory(), 0xff, size_in_bytes);
89 91
90 scoped_ptr<cc::SharedBitmap> shared_bitmap; 92 scoped_ptr<cc::SharedBitmap> shared_bitmap;
91 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); 93 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
92 EXPECT_TRUE(shared_bitmap); 94 EXPECT_TRUE(shared_bitmap);
93 EXPECT_TRUE( 95 EXPECT_TRUE(
94 memcmp(bitmap->memory(), shared_bitmap->pixels(), size_in_bytes) == 0); 96 memcmp(bitmap->memory(), shared_bitmap->pixels(), size_in_bytes) == 0);
95 97
96 manager_->ChildDeletedSharedBitmap(id); 98 client.ChildDeletedSharedBitmap(id);
97 } 99 }
98 100
99 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) { 101 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
100 gfx::Size bitmap_size(1, 1); 102 gfx::Size bitmap_size(1, 1);
101 size_t size_in_bytes; 103 size_t size_in_bytes;
102 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes)); 104 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
103 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory()); 105 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
104 bitmap->CreateAndMapAnonymous(size_in_bytes); 106 bitmap->CreateAndMapAnonymous(size_in_bytes);
105 memset(bitmap->memory(), 0xff, size_in_bytes); 107 memset(bitmap->memory(), 0xff, size_in_bytes);
106 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 108 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
107 109
108 base::SharedMemoryHandle handle; 110 base::SharedMemoryHandle handle;
111 scoped_ptr<HostSharedBitmapManagerClient> client(
112 new HostSharedBitmapManagerClient(manager_.get()));
109 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 113 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
110 manager_->ChildAllocatedSharedBitmap( 114 client->ChildAllocatedSharedBitmap(size_in_bytes, handle,
111 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 115 base::GetCurrentProcessHandle(), id);
112
113 manager_->ProcessRemoved(base::kNullProcessHandle);
114 116
115 scoped_ptr<cc::SharedBitmap> shared_bitmap; 117 scoped_ptr<cc::SharedBitmap> shared_bitmap;
116 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); 118 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
117 ASSERT_TRUE(shared_bitmap.get() != NULL); 119 ASSERT_TRUE(shared_bitmap.get() != NULL);
118 120
119 manager_->ProcessRemoved(base::GetCurrentProcessHandle()); 121 EXPECT_EQ(1u, manager_->AllocatedBitmapCount());
122 client.reset();
123 EXPECT_EQ(0u, manager_->AllocatedBitmapCount());
120 124
121 scoped_ptr<cc::SharedBitmap> shared_bitmap2; 125 scoped_ptr<cc::SharedBitmap> shared_bitmap2;
122 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); 126 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
123 EXPECT_TRUE(shared_bitmap2.get() == NULL); 127 EXPECT_TRUE(shared_bitmap2.get() == NULL);
124 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 128 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
125 0); 129 0);
126 130
127 shared_bitmap.reset(); 131 shared_bitmap.reset();
128
129 // Should no-op.
130 manager_->ChildDeletedSharedBitmap(id);
131 } 132 }
132 133
133 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) { 134 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
134 gfx::Size bitmap_size(1, 1); 135 gfx::Size bitmap_size(1, 1);
135 size_t size_in_bytes; 136 size_t size_in_bytes;
136 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes)); 137 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
137 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory()); 138 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
138 bitmap->CreateAndMapAnonymous(size_in_bytes); 139 bitmap->CreateAndMapAnonymous(size_in_bytes);
139 memset(bitmap->memory(), 0xff, size_in_bytes); 140 memset(bitmap->memory(), 0xff, size_in_bytes);
140 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 141 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
142 HostSharedBitmapManagerClient client(manager_.get());
141 143
142 base::SharedMemoryHandle handle; 144 base::SharedMemoryHandle handle;
143 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 145 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
144 manager_->ChildAllocatedSharedBitmap( 146 client.ChildAllocatedSharedBitmap(size_in_bytes, handle,
145 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 147 base::GetCurrentProcessHandle(), id);
146 148
147 scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory()); 149 scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory());
148 bitmap2->CreateAndMapAnonymous(size_in_bytes); 150 bitmap2->CreateAndMapAnonymous(size_in_bytes);
149 memset(bitmap2->memory(), 0x00, size_in_bytes); 151 memset(bitmap2->memory(), 0x00, size_in_bytes);
150 152
151 manager_->ChildAllocatedSharedBitmap( 153 client.ChildAllocatedSharedBitmap(size_in_bytes, bitmap2->handle(),
152 size_in_bytes, bitmap2->handle(), base::GetCurrentProcessHandle(), id); 154 base::GetCurrentProcessHandle(), id);
153 155
154 scoped_ptr<cc::SharedBitmap> shared_bitmap; 156 scoped_ptr<cc::SharedBitmap> shared_bitmap;
155 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); 157 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
156 ASSERT_TRUE(shared_bitmap.get() != NULL); 158 ASSERT_TRUE(shared_bitmap.get() != NULL);
157 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 159 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
158 0); 160 0);
159 manager_->ChildDeletedSharedBitmap(id); 161 client.ChildDeletedSharedBitmap(id);
160 } 162 }
161 163
162 } // namespace 164 } // namespace
163 } // namespace content 165 } // namespace content
OLDNEW
« no previous file with comments | « content/common/host_shared_bitmap_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698