GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / resources / texture_mailbox_deleter_unittest.cc
blob05e33a313aa923c6182628a6c6b95a0e8ca27d14
1 // Copyright 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.
5 #include "cc/resources/texture_mailbox_deleter.h"
7 #include "base/message_loop/message_loop_proxy.h"
8 #include "cc/resources/single_release_callback.h"
9 #include "cc/test/test_context_provider.h"
10 #include "cc/test/test_web_graphics_context_3d.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace cc {
14 namespace {
16 TEST(TextureMailboxDeleterTest, Destroy) {
17 scoped_ptr<TextureMailboxDeleter> deleter(
18 new TextureMailboxDeleter(base::MessageLoopProxy::current()));
20 scoped_refptr<TestContextProvider> context_provider =
21 TestContextProvider::Create();
22 context_provider->BindToCurrentThread();
24 GLuint texture_id = 0u;
25 context_provider->ContextGL()->GenTextures(1, &texture_id);
27 EXPECT_TRUE(context_provider->HasOneRef());
28 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
30 scoped_ptr<SingleReleaseCallback> cb =
31 deleter->GetReleaseCallback(context_provider, texture_id).Pass();
32 EXPECT_FALSE(context_provider->HasOneRef());
33 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures());
35 // When the deleter is destroyed, it immediately drops its ref on the
36 // ContextProvider, and deletes the texture.
37 deleter = nullptr;
38 EXPECT_TRUE(context_provider->HasOneRef());
39 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
41 // Run the scoped release callback before destroying it, but it won't do
42 // anything.
43 cb->Run(0, false);
46 } // namespace
47 } // namespace cc