| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "cc/resources/texture_mailbox_deleter.h" | 5 #include "cc/resources/texture_mailbox_deleter.h" |
| 6 | 6 |
| 7 #include "cc/resources/single_release_callback.h" | 7 #include "cc/resources/single_release_callback.h" |
| 8 #include "cc/test/test_context_provider.h" | 8 #include "cc/test/test_context_provider.h" |
| 9 #include "cc/test/test_web_graphics_context_3d.h" | 9 #include "cc/test/test_web_graphics_context_3d.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 TEST(TextureMailboxDeleterTest, Destroy) { | 15 TEST(TextureMailboxDeleterTest, Destroy) { |
| 16 scoped_ptr<TextureMailboxDeleter> deleter(new TextureMailboxDeleter); | 16 scoped_ptr<TextureMailboxDeleter> deleter(new TextureMailboxDeleter); |
| 17 | 17 |
| 18 scoped_refptr<TestContextProvider> context_provider = | 18 scoped_refptr<TestContextProvider> context_provider = |
| 19 TestContextProvider::Create(); | 19 TestContextProvider::Create(); |
| 20 context_provider->BindToCurrentThread(); | 20 context_provider->BindToCurrentThread(); |
| 21 | 21 |
| 22 unsigned texture_id = context_provider->Context3d()->createTexture(); | 22 GLuint texture_id = 0; |
| 23 context_provider->ContextGL()->GenTextures(1, &texture_id); |
| 23 | 24 |
| 24 EXPECT_TRUE(context_provider->HasOneRef()); | 25 EXPECT_TRUE(context_provider->HasOneRef()); |
| 25 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 26 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 26 | 27 |
| 27 scoped_ptr<SingleReleaseCallback> cb = | 28 scoped_ptr<SingleReleaseCallback> cb = |
| 28 deleter->GetReleaseCallback(context_provider, texture_id).Pass(); | 29 deleter->GetReleaseCallback(context_provider, texture_id).Pass(); |
| 29 EXPECT_FALSE(context_provider->HasOneRef()); | 30 EXPECT_FALSE(context_provider->HasOneRef()); |
| 30 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); | 31 EXPECT_EQ(1u, context_provider->TestContext3d()->NumTextures()); |
| 31 | 32 |
| 32 // When the deleter is destroyed, it immediately drops its ref on the | 33 // When the deleter is destroyed, it immediately drops its ref on the |
| 33 // ContextProvider, and deletes the texture. | 34 // ContextProvider, and deletes the texture. |
| 34 deleter.reset(); | 35 deleter.reset(); |
| 35 EXPECT_TRUE(context_provider->HasOneRef()); | 36 EXPECT_TRUE(context_provider->HasOneRef()); |
| 36 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 37 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 37 | 38 |
| 38 // Run the scoped release callback before destroying it, but it won't do | 39 // Run the scoped release callback before destroying it, but it won't do |
| 39 // anything. | 40 // anything. |
| 40 cb->Run(0, false); | 41 cb->Run(0, false); |
| 41 } | 42 } |
| 42 | 43 |
| 43 } // namespace | 44 } // namespace |
| 44 } // namespace cc | 45 } // namespace cc |
| OLD | NEW |