5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterThreadSynchronizer.h"
7#import "flutter/fml/synchronization/waitable_event.h"
8#import "flutter/testing/testing.h"
14- (nullable instancetype)
init;
15- (void)dispatchMainTask:(nonnull
void (^)())task;
16- (void)dispatchRenderTask:(nonnull
void (^)())task;
22 dispatch_queue_t _mainQueue;
33- (nullable instancetype)
init {
36 _mainQueue = dispatch_queue_create(
"MAIN", DISPATCH_QUEUE_SERIAL);
37 _renderQueue = dispatch_queue_create(
"RENDER", DISPATCH_QUEUE_SERIAL);
43- (void)dispatchMainTask:(nonnull
void (^)())task {
44 dispatch_async(_mainQueue, task);
47- (void)dispatchRenderTask:(nonnull
void (^)())task {
54 dispatch_async(_mainQueue, ^{
71TEST(FlutterThreadSynchronizerTest, RegularCommit) {
77 __block
int notifiedResize = 0;
86 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
88 EXPECT_EQ(notifiedResize, 1);
98 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
100 EXPECT_EQ(notifiedResize, 2);
103 __block
int notifiedCommit = 0;
111 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
113 EXPECT_EQ(notifiedCommit, 1);
116TEST(FlutterThreadSynchronizerTest, ResizingBlocksRenderingUntilSizeMatches) {
135 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
145 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
152 begunResizing->Signal();
155 begunResizing->
Wait();
156 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
166 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
176 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
181TEST(FlutterThreadSynchronizerTest, ShutdownMakesEverythingNonBlocking) {
197 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
207 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
218 begunResizing->Signal();
221 begunResizing->
Wait();
222 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
233 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
236TEST(FlutterThreadSynchronizerTest, RegularCommitForMultipleViews) {
254 begunResizing->Signal();
257 begunResizing->
Wait();
258 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
266 begunResizing->Signal();
270 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
285 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
288TEST(FlutterThreadSynchronizerTest, ResizingForMultipleViews) {
309 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
323 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
330 begunResizing->Signal();
333 begunResizing->
Wait();
334 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
344 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
354 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
364 EXPECT_TRUE([synchronizer isWaitingWhenMutexIsAvailable]);
375 EXPECT_FALSE([synchronizer isWaitingWhenMutexIsAvailable]);
FlutterThreadSynchronizer * _synchronizer
std::shared_ptr< fml::AutoResetWaitableEvent > _renderLatch
std::shared_ptr< fml::AutoResetWaitableEvent > _mainLatch
dispatch_queue_t _renderQueue
TEST(FlutterThreadSynchronizerTest, RegularCommit)
void dispatchRenderTask:(nonnull void(^ task)())
nullable instancetype init()
void dispatchMainTask:(nonnull void(^ task)())
FlutterThreadSynchronizer * synchronizer
void beginResizeForView:size:notify:(FlutterViewIdentifier viewIdentifier,[size] CGSize size,[notify] nonnull dispatch_block_t notify)
void performCommitForView:size:notify:(FlutterViewIdentifier viewIdentifier,[size] CGSize size,[notify] nonnull dispatch_block_t notify)
void registerView:(FlutterViewIdentifier viewIdentifier)
#define EXPECT_TRUE(handle)