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