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

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

Issue 148243013: Add shared bitmap managers for browser and renderer processes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/common/host_shared_bitmap_manager.cc ('k') | content/content_child.gypi » ('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 (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 "content/common/host_shared_bitmap_manager.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace content {
9 namespace {
10
11 class HostSharedBitmapManagerTest : public testing::Test {
12 protected:
13 virtual void SetUp() { manager_.reset(new HostSharedBitmapManager()); }
14 scoped_ptr<HostSharedBitmapManager> manager_;
15 };
16
17 TEST_F(HostSharedBitmapManagerTest, TestCreate) {
18 gfx::Size bitmap_size(1, 1);
19 size_t size_in_bytes;
20 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
21 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
22 bitmap->CreateAndMapAnonymous(size_in_bytes);
23 memset(bitmap->memory(), 0xff, size_in_bytes);
24 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
25
26 base::SharedMemoryHandle handle;
27 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
28 manager_->ChildAllocatedSharedBitmap(
29 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
30
31 scoped_ptr<cc::SharedBitmap> large_bitmap;
32 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
33 EXPECT_TRUE(large_bitmap.get() == NULL);
34
35 scoped_ptr<cc::SharedBitmap> very_large_bitmap;
36 very_large_bitmap =
37 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id);
38 EXPECT_TRUE(very_large_bitmap.get() == NULL);
39
40 scoped_ptr<cc::SharedBitmap> negative_size_bitmap;
41 negative_size_bitmap =
42 manager_->GetSharedBitmapFromId(gfx::Size(-1, 1024), id);
43 EXPECT_TRUE(negative_size_bitmap.get() == NULL);
44
45 cc::SharedBitmapId id2 = cc::SharedBitmap::GenerateId();
46 scoped_ptr<cc::SharedBitmap> invalid_bitmap;
47 invalid_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id2);
48 EXPECT_TRUE(invalid_bitmap.get() == NULL);
49
50 scoped_ptr<cc::SharedBitmap> shared_bitmap;
51 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
52 ASSERT_TRUE(shared_bitmap.get() != NULL);
53 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), 4), 0);
54
55 scoped_ptr<cc::SharedBitmap> large_bitmap2;
56 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
57 EXPECT_TRUE(large_bitmap2.get() == NULL);
58
59 scoped_ptr<cc::SharedBitmap> shared_bitmap2;
60 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
61 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels());
62 shared_bitmap2.reset();
63 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
64 0);
65
66 manager_->ChildDeletedSharedBitmap(id);
67
68 memset(bitmap->memory(), 0, size_in_bytes);
69
70 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
71 0);
72 bitmap.reset();
73 shared_bitmap.reset();
74 }
75
76 TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) {
77 gfx::Size bitmap_size(1, 1);
78 size_t size_in_bytes;
79 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
80 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
81 base::SharedMemoryHandle handle;
82 manager_->AllocateSharedBitmapForChild(
83 base::GetCurrentProcessHandle(), size_in_bytes, id, &handle);
84
85 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle));
86 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory(handle, false));
87 EXPECT_TRUE(bitmap->Map(size_in_bytes));
88 memset(bitmap->memory(), 0xff, size_in_bytes);
89
90 scoped_ptr<cc::SharedBitmap> shared_bitmap;
91 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
92 EXPECT_TRUE(shared_bitmap);
93 EXPECT_TRUE(
94 memcmp(bitmap->memory(), shared_bitmap->pixels(), size_in_bytes) == 0);
95 }
96
97 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
98 gfx::Size bitmap_size(1, 1);
99 size_t size_in_bytes;
100 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
101 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
102 bitmap->CreateAndMapAnonymous(size_in_bytes);
103 memset(bitmap->memory(), 0xff, size_in_bytes);
104 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
105
106 base::SharedMemoryHandle handle;
107 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
108 manager_->ChildAllocatedSharedBitmap(
109 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
110
111 manager_->ProcessRemoved(base::kNullProcessHandle);
112
113 scoped_ptr<cc::SharedBitmap> shared_bitmap;
114 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
115 ASSERT_TRUE(shared_bitmap.get() != NULL);
116
117 manager_->ProcessRemoved(base::GetCurrentProcessHandle());
118
119 scoped_ptr<cc::SharedBitmap> shared_bitmap2;
120 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
121 EXPECT_TRUE(shared_bitmap2.get() == NULL);
122 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
123 0);
124
125 shared_bitmap.reset();
126
127 // Should no-op.
128 manager_->ChildDeletedSharedBitmap(id);
129 }
130
131 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
132 gfx::Size bitmap_size(1, 1);
133 size_t size_in_bytes;
134 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes));
135 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
136 bitmap->CreateAndMapAnonymous(size_in_bytes);
137 memset(bitmap->memory(), 0xff, size_in_bytes);
138 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
139
140 base::SharedMemoryHandle handle;
141 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
142 manager_->ChildAllocatedSharedBitmap(
143 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
144
145 scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory());
146 bitmap2->CreateAndMapAnonymous(size_in_bytes);
147 memset(bitmap2->memory(), 0x00, size_in_bytes);
148
149 manager_->ChildAllocatedSharedBitmap(
150 size_in_bytes, bitmap2->handle(), base::GetCurrentProcessHandle(), id);
151
152 scoped_ptr<cc::SharedBitmap> shared_bitmap;
153 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
154 ASSERT_TRUE(shared_bitmap.get() != NULL);
155 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
156 0);
157 }
158
159 } // namespace
160 } // namespace content
OLDNEW
« no previous file with comments | « content/common/host_shared_bitmap_manager.cc ('k') | content/content_child.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698