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

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

Issue 221523003: cc: Remove all usage of GetArea() from production code in cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getarea: Created 6 years, 8 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') | 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 virtual void SetUp() { manager_.reset(new HostSharedBitmapManager()); } 13 virtual void SetUp() { 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::GetSizeInBytes(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 base::SharedMemoryHandle handle; 26 base::SharedMemoryHandle handle;
27 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 27 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
28 manager_->ChildAllocatedSharedBitmap( 28 manager_->ChildAllocatedSharedBitmap(
29 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 29 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
30 30
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 69
70 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 70 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
71 0); 71 0);
72 bitmap.reset(); 72 bitmap.reset();
73 shared_bitmap.reset(); 73 shared_bitmap.reset();
74 } 74 }
75 75
76 TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) { 76 TEST_F(HostSharedBitmapManagerTest, TestCreateForChild) {
77 gfx::Size bitmap_size(1, 1); 77 gfx::Size bitmap_size(1, 1);
78 size_t size_in_bytes; 78 size_t size_in_bytes;
79 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes)); 79 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
80 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 80 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
81 base::SharedMemoryHandle handle; 81 base::SharedMemoryHandle handle;
82 manager_->AllocateSharedBitmapForChild( 82 manager_->AllocateSharedBitmapForChild(
83 base::GetCurrentProcessHandle(), size_in_bytes, id, &handle); 83 base::GetCurrentProcessHandle(), size_in_bytes, id, &handle);
84 84
85 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle)); 85 EXPECT_TRUE(base::SharedMemory::IsHandleValid(handle));
86 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory(handle, false)); 86 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory(handle, false));
87 EXPECT_TRUE(bitmap->Map(size_in_bytes)); 87 EXPECT_TRUE(bitmap->Map(size_in_bytes));
88 memset(bitmap->memory(), 0xff, size_in_bytes); 88 memset(bitmap->memory(), 0xff, size_in_bytes);
89 89
90 scoped_ptr<cc::SharedBitmap> shared_bitmap; 90 scoped_ptr<cc::SharedBitmap> shared_bitmap;
91 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); 91 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
92 EXPECT_TRUE(shared_bitmap); 92 EXPECT_TRUE(shared_bitmap);
93 EXPECT_TRUE( 93 EXPECT_TRUE(
94 memcmp(bitmap->memory(), shared_bitmap->pixels(), size_in_bytes) == 0); 94 memcmp(bitmap->memory(), shared_bitmap->pixels(), size_in_bytes) == 0);
95 } 95 }
96 96
97 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) { 97 TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
98 gfx::Size bitmap_size(1, 1); 98 gfx::Size bitmap_size(1, 1);
99 size_t size_in_bytes; 99 size_t size_in_bytes;
100 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes)); 100 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
101 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory()); 101 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
102 bitmap->CreateAndMapAnonymous(size_in_bytes); 102 bitmap->CreateAndMapAnonymous(size_in_bytes);
103 memset(bitmap->memory(), 0xff, size_in_bytes); 103 memset(bitmap->memory(), 0xff, size_in_bytes);
104 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 104 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
105 105
106 base::SharedMemoryHandle handle; 106 base::SharedMemoryHandle handle;
107 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 107 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
108 manager_->ChildAllocatedSharedBitmap( 108 manager_->ChildAllocatedSharedBitmap(
109 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 109 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
110 110
(...skipping 13 matching lines...) Expand all
124 124
125 shared_bitmap.reset(); 125 shared_bitmap.reset();
126 126
127 // Should no-op. 127 // Should no-op.
128 manager_->ChildDeletedSharedBitmap(id); 128 manager_->ChildDeletedSharedBitmap(id);
129 } 129 }
130 130
131 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) { 131 TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
132 gfx::Size bitmap_size(1, 1); 132 gfx::Size bitmap_size(1, 1);
133 size_t size_in_bytes; 133 size_t size_in_bytes;
134 EXPECT_TRUE(cc::SharedBitmap::GetSizeInBytes(bitmap_size, &size_in_bytes)); 134 EXPECT_TRUE(cc::SharedBitmap::SizeInBytes(bitmap_size, &size_in_bytes));
135 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory()); 135 scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
136 bitmap->CreateAndMapAnonymous(size_in_bytes); 136 bitmap->CreateAndMapAnonymous(size_in_bytes);
137 memset(bitmap->memory(), 0xff, size_in_bytes); 137 memset(bitmap->memory(), 0xff, size_in_bytes);
138 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId(); 138 cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
139 139
140 base::SharedMemoryHandle handle; 140 base::SharedMemoryHandle handle;
141 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle); 141 bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
142 manager_->ChildAllocatedSharedBitmap( 142 manager_->ChildAllocatedSharedBitmap(
143 size_in_bytes, handle, base::GetCurrentProcessHandle(), id); 143 size_in_bytes, handle, base::GetCurrentProcessHandle(), id);
144 144
145 scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory()); 145 scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory());
146 bitmap2->CreateAndMapAnonymous(size_in_bytes); 146 bitmap2->CreateAndMapAnonymous(size_in_bytes);
147 memset(bitmap2->memory(), 0x00, size_in_bytes); 147 memset(bitmap2->memory(), 0x00, size_in_bytes);
148 148
149 manager_->ChildAllocatedSharedBitmap( 149 manager_->ChildAllocatedSharedBitmap(
150 size_in_bytes, bitmap2->handle(), base::GetCurrentProcessHandle(), id); 150 size_in_bytes, bitmap2->handle(), base::GetCurrentProcessHandle(), id);
151 151
152 scoped_ptr<cc::SharedBitmap> shared_bitmap; 152 scoped_ptr<cc::SharedBitmap> shared_bitmap;
153 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); 153 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
154 ASSERT_TRUE(shared_bitmap.get() != NULL); 154 ASSERT_TRUE(shared_bitmap.get() != NULL);
155 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), 155 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
156 0); 156 0);
157 } 157 }
158 158
159 } // namespace 159 } // namespace
160 } // namespace content 160 } // 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