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

Unified Diff: components/exo/buffer_unittest.cc

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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: components/exo/buffer_unittest.cc
diff --git a/components/exo/buffer_unittest.cc b/components/exo/buffer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d26934707e36d759f14727ceefda7e18a1ea6f75
--- /dev/null
+++ b/components/exo/buffer_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2015 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 "base/bind.h"
+#include "cc/resources/single_release_callback.h"
+#include "components/exo/buffer.h"
+#include "components/exo/surface.h"
+#include "components/exo/test/exo_test_base.h"
+#include "components/exo/test/exo_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/khronos/GLES2/gl2.h"
+#include "ui/gfx/gpu_memory_buffer.h"
+
+namespace exo {
+namespace {
+
+using BufferTest = test::ExoTestBase;
+
+void Release(int* release_call_count) {
+ (*release_call_count)++;
+}
+
+TEST_F(BufferTest, ReleaseCallback) {
+ gfx::Size buffer_size(256, 256);
+ scoped_ptr<Buffer> buffer(
+ new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size).Pass(),
+ GL_TEXTURE_2D));
+
+ // Set the release callback.
+ int release_call_count = 0;
+ buffer->set_release_callback(
+ base::Bind(&Release, base::Unretained(&release_call_count)));
+
+ // Acquire a texture mailbox for the contents of the buffer.
+ cc::TextureMailbox texture_mailbox;
+ scoped_ptr<cc::SingleReleaseCallback> buffer_release_callback =
+ buffer->GetTextureMailbox(&texture_mailbox);
+ ASSERT_TRUE(buffer_release_callback);
+
+ // Trying to acquire an already in-use buffer should fail.
+ EXPECT_FALSE(buffer->GetTextureMailbox(&texture_mailbox));
+
+ // Release buffer.
+ buffer_release_callback->Run(gpu::SyncToken(), false);
+
+ // Release() should have been called exactly once.
+ ASSERT_EQ(release_call_count, 1);
+}
+
+} // namespace
+} // namespace exo

Powered by Google App Engine
This is Rietveld 408576698