OLD | NEW |
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 |
(...skipping 12 matching lines...) Expand all Loading... |
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 |
31 scoped_ptr<cc::SharedBitmap> large_bitmap; | 31 scoped_ptr<cc::SharedBitmap> large_bitmap; |
32 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); | 32 large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); |
33 EXPECT_TRUE(large_bitmap.get() == NULL); | 33 EXPECT_TRUE(large_bitmap.get() == nullptr); |
34 | 34 |
35 scoped_ptr<cc::SharedBitmap> very_large_bitmap; | 35 scoped_ptr<cc::SharedBitmap> very_large_bitmap; |
36 very_large_bitmap = | 36 very_large_bitmap = |
37 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id); | 37 manager_->GetSharedBitmapFromId(gfx::Size(1, (1 << 30) | 1), id); |
38 EXPECT_TRUE(very_large_bitmap.get() == NULL); | 38 EXPECT_TRUE(very_large_bitmap.get() == nullptr); |
39 | 39 |
40 scoped_ptr<cc::SharedBitmap> negative_size_bitmap; | 40 scoped_ptr<cc::SharedBitmap> negative_size_bitmap; |
41 negative_size_bitmap = | 41 negative_size_bitmap = |
42 manager_->GetSharedBitmapFromId(gfx::Size(-1, 1024), id); | 42 manager_->GetSharedBitmapFromId(gfx::Size(-1, 1024), id); |
43 EXPECT_TRUE(negative_size_bitmap.get() == NULL); | 43 EXPECT_TRUE(negative_size_bitmap.get() == nullptr); |
44 | 44 |
45 cc::SharedBitmapId id2 = cc::SharedBitmap::GenerateId(); | 45 cc::SharedBitmapId id2 = cc::SharedBitmap::GenerateId(); |
46 scoped_ptr<cc::SharedBitmap> invalid_bitmap; | 46 scoped_ptr<cc::SharedBitmap> invalid_bitmap; |
47 invalid_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id2); | 47 invalid_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id2); |
48 EXPECT_TRUE(invalid_bitmap.get() == NULL); | 48 EXPECT_TRUE(invalid_bitmap.get() == nullptr); |
49 | 49 |
50 scoped_ptr<cc::SharedBitmap> shared_bitmap; | 50 scoped_ptr<cc::SharedBitmap> shared_bitmap; |
51 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); | 51 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); |
52 ASSERT_TRUE(shared_bitmap.get() != NULL); | 52 ASSERT_TRUE(shared_bitmap.get() != nullptr); |
53 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), 4), 0); | 53 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), 4), 0); |
54 | 54 |
55 scoped_ptr<cc::SharedBitmap> large_bitmap2; | 55 scoped_ptr<cc::SharedBitmap> large_bitmap2; |
56 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); | 56 large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id); |
57 EXPECT_TRUE(large_bitmap2.get() == NULL); | 57 EXPECT_TRUE(large_bitmap2.get() == nullptr); |
58 | 58 |
59 scoped_ptr<cc::SharedBitmap> shared_bitmap2; | 59 scoped_ptr<cc::SharedBitmap> shared_bitmap2; |
60 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); | 60 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); |
61 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels()); | 61 EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels()); |
62 shared_bitmap2.reset(); | 62 shared_bitmap2.reset(); |
63 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), | 63 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), |
64 0); | 64 0); |
65 | 65 |
66 manager_->ChildDeletedSharedBitmap(id); | 66 manager_->ChildDeletedSharedBitmap(id); |
67 | 67 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
111 manager_->ProcessRemoved(base::kNullProcessHandle); | 111 manager_->ProcessRemoved(base::kNullProcessHandle); |
112 | 112 |
113 scoped_ptr<cc::SharedBitmap> shared_bitmap; | 113 scoped_ptr<cc::SharedBitmap> shared_bitmap; |
114 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); | 114 shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id); |
115 ASSERT_TRUE(shared_bitmap.get() != NULL); | 115 ASSERT_TRUE(shared_bitmap.get() != nullptr); |
116 | 116 |
117 manager_->ProcessRemoved(base::GetCurrentProcessHandle()); | 117 manager_->ProcessRemoved(base::GetCurrentProcessHandle()); |
118 | 118 |
119 scoped_ptr<cc::SharedBitmap> shared_bitmap2; | 119 scoped_ptr<cc::SharedBitmap> shared_bitmap2; |
120 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); | 120 shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id); |
121 EXPECT_TRUE(shared_bitmap2.get() == NULL); | 121 EXPECT_TRUE(shared_bitmap2.get() == nullptr); |
122 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), | 122 EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes), |
123 0); | 123 0); |
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) { |
(...skipping 12 matching lines...) Expand all Loading... |
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() != nullptr); |
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 |
OLD | NEW |