|
8 | 8 | #include <memory> |
9 | 9 | #include <vector> |
10 | 10 |
|
| 11 | +#include "flutter/fml/synchronization/waitable_event.h" |
11 | 12 | #include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h" |
12 | 13 | #include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h" |
13 | 14 | #include "gtest/gtest.h" |
@@ -41,13 +42,17 @@ class TestApi : public testing::StubFlutterApi { |
41 | 42 | return last_texture_id_; |
42 | 43 | } |
43 | 44 |
|
44 | | - bool TextureRegistrarUnregisterExternalTexture(int64_t texture_id) override { |
| 45 | + void TextureRegistrarUnregisterExternalTexture( |
| 46 | + int64_t texture_id, |
| 47 | + void (*callback)(void* user_data), |
| 48 | + void* user_data) override { |
45 | 49 | auto it = textures_.find(texture_id); |
46 | 50 | if (it != textures_.end()) { |
47 | 51 | textures_.erase(it); |
48 | | - return true; |
49 | 52 | } |
50 | | - return false; |
| 53 | + if (callback) { |
| 54 | + callback(user_data); |
| 55 | + } |
51 | 56 | } |
52 | 57 |
|
53 | 58 | bool TextureRegistrarMarkTextureFrameAvailable(int64_t texture_id) override { |
@@ -110,24 +115,27 @@ TEST(TextureRegistrarTest, RegisterUnregisterTexture) { |
110 | 115 | EXPECT_TRUE(success); |
111 | 116 | EXPECT_EQ(texture->mark_count, 3); |
112 | 117 |
|
113 | | - success = textures->UnregisterTexture(texture_id); |
114 | | - EXPECT_TRUE(success); |
| 118 | + fml::AutoResetWaitableEvent unregister_latch; |
| 119 | + textures->UnregisterTexture(texture_id, [&]() { unregister_latch.Signal(); }); |
| 120 | + unregister_latch.Wait(); |
115 | 121 |
|
116 | 122 | texture = test_api->GetFakeTexture(texture_id); |
117 | 123 | EXPECT_EQ(texture, nullptr); |
118 | 124 | EXPECT_EQ(test_api->textures_size(), static_cast<size_t>(0)); |
119 | 125 | } |
120 | 126 |
|
121 | | -// Tests that unregistering a texture with an unknown id returns false. |
| 127 | +// Tests that the unregister callback gets also invoked when attempting to |
| 128 | +// unregister a texture with an unknown id. |
122 | 129 | TEST(TextureRegistrarTest, UnregisterInvalidTexture) { |
123 | 130 | auto dummy_registrar_handle = |
124 | 131 | reinterpret_cast<FlutterDesktopPluginRegistrarRef>(1); |
125 | 132 | PluginRegistrar registrar(dummy_registrar_handle); |
126 | 133 |
|
127 | 134 | TextureRegistrar* textures = registrar.texture_registrar(); |
128 | 135 |
|
129 | | - bool success = textures->UnregisterTexture(42); |
130 | | - EXPECT_FALSE(success); |
| 136 | + fml::AutoResetWaitableEvent latch; |
| 137 | + textures->UnregisterTexture(42, [&]() { latch.Signal(); }); |
| 138 | + latch.Wait(); |
131 | 139 | } |
132 | 140 |
|
133 | 141 | // Tests that claiming a new frame being available for an unknown texture |
|
0 commit comments