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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: content/common/host_shared_bitmap_manager_unittest.cc
diff --git a/content/common/host_shared_bitmap_manager_unittest.cc b/content/common/host_shared_bitmap_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..340d8a46dc9cf5bed69b5b3c0829ac5090d08d53
--- /dev/null
+++ b/content/common/host_shared_bitmap_manager_unittest.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/host_shared_bitmap_manager.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+namespace {
+
+class HostSharedBitmapManagerTest : public testing::Test {
+ protected:
+ virtual void SetUp() { manager_.reset(new HostSharedBitmapManager()); }
+ scoped_ptr<HostSharedBitmapManager> manager_;
+};
+
+TEST_F(HostSharedBitmapManagerTest, TestCreate) {
+ gfx::Size bitmap_size(1, 1);
+ size_t size_in_bytes = cc::SharedBitmap::GetSizeInBytes(bitmap_size);
+ scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
+ bitmap->CreateAndMapAnonymous(size_in_bytes);
+ memset(bitmap->memory(), 0xff, size_in_bytes);
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
+
+ base::SharedMemoryHandle handle;
+ bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
+ manager_->ChildAllocatedSharedBitmap(
danakj 2014/01/30 22:59:01 This test skips AllocateSharedBitmapForChild, can
+ handle, base::GetCurrentProcessHandle(), id);
+
+ scoped_ptr<cc::SharedBitmap> large_bitmap;
+ large_bitmap = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
+#if !defined(OS_POSIX)
+ EXPECT_TRUE(large_bitmap.get() == NULL);
+#endif
+ // On POSIX, the entire bitmap could be mapped, but there could be a SIGBUS
+ // if the address that's accessed is too large.
+
+ cc::SharedBitmapId id2 = cc::SharedBitmap::GenerateId();
+ scoped_ptr<cc::SharedBitmap> invalid_bitmap;
+ invalid_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id2);
+ EXPECT_TRUE(invalid_bitmap.get() == NULL);
+
+ scoped_ptr<cc::SharedBitmap> shared_bitmap;
+ shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
+ ASSERT_TRUE(shared_bitmap.get() != NULL);
+ EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), 4), 0);
+
+ scoped_ptr<cc::SharedBitmap> large_bitmap2;
+ large_bitmap2 = manager_->GetSharedBitmapFromId(gfx::Size(1024, 1024), id);
+#if !defined(OS_POSIX)
+ EXPECT_TRUE(large_bitmap2.get() == NULL);
+#endif
+
+ scoped_ptr<cc::SharedBitmap> shared_bitmap2;
+ shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
+ EXPECT_TRUE(shared_bitmap2->pixels() == shared_bitmap->pixels());
+ shared_bitmap2.reset();
+ EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
+ 0);
+
+ manager_->ChildDeletedSharedBitmap(id);
+
+ memset(bitmap->memory(), 0, size_in_bytes);
+
+ EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
+ 0);
+ bitmap.reset();
+ shared_bitmap.reset();
+}
+
+TEST_F(HostSharedBitmapManagerTest, RemoveProcess) {
+ gfx::Size bitmap_size(1, 1);
+ size_t size_in_bytes = cc::SharedBitmap::GetSizeInBytes(bitmap_size);
+ scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
+ bitmap->CreateAndMapAnonymous(size_in_bytes);
+ memset(bitmap->memory(), 0xff, size_in_bytes);
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
+
+ base::SharedMemoryHandle handle;
+ bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
+ manager_->ChildAllocatedSharedBitmap(
+ handle, base::GetCurrentProcessHandle(), id);
+
+ manager_->ProcessRemoved(base::kNullProcessHandle);
+
+ scoped_ptr<cc::SharedBitmap> shared_bitmap;
+ shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
+ ASSERT_TRUE(shared_bitmap.get() != NULL);
+
+ manager_->ProcessRemoved(base::GetCurrentProcessHandle());
+
+ scoped_ptr<cc::SharedBitmap> shared_bitmap2;
+ shared_bitmap2 = manager_->GetSharedBitmapFromId(bitmap_size, id);
+ EXPECT_TRUE(shared_bitmap2.get() == NULL);
+ EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
+ 0);
+
+ shared_bitmap.reset();
+
+ // Should no-op.
+ manager_->ChildDeletedSharedBitmap(id);
+}
+
+TEST_F(HostSharedBitmapManagerTest, AddDuplicate) {
+ gfx::Size bitmap_size(1, 1);
+ size_t size_in_bytes = cc::SharedBitmap::GetSizeInBytes(bitmap_size);
+ scoped_ptr<base::SharedMemory> bitmap(new base::SharedMemory());
+ bitmap->CreateAndMapAnonymous(size_in_bytes);
+ memset(bitmap->memory(), 0xff, size_in_bytes);
+ cc::SharedBitmapId id = cc::SharedBitmap::GenerateId();
+
+ base::SharedMemoryHandle handle;
+ bitmap->ShareToProcess(base::GetCurrentProcessHandle(), &handle);
+ manager_->ChildAllocatedSharedBitmap(
+ handle, base::GetCurrentProcessHandle(), id);
+
+ scoped_ptr<base::SharedMemory> bitmap2(new base::SharedMemory());
+ bitmap2->CreateAndMapAnonymous(size_in_bytes);
+ memset(bitmap2->memory(), 0x00, size_in_bytes);
+
+ manager_->ChildAllocatedSharedBitmap(
+ bitmap2->handle(), base::GetCurrentProcessHandle(), id);
+
+ scoped_ptr<cc::SharedBitmap> shared_bitmap;
+ shared_bitmap = manager_->GetSharedBitmapFromId(bitmap_size, id);
+ ASSERT_TRUE(shared_bitmap.get() != NULL);
+ EXPECT_EQ(memcmp(shared_bitmap->pixels(), bitmap->memory(), size_in_bytes),
+ 0);
+}
+
+} // namespace
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698