| Flutter macOS Embedder |

Functions
FlutterResizeSynchronizerTest.mm File Reference
`#include "flutter/fml/synchronization/waitable_event.h"`
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterResizeSynchronizer.h"`
`#import "flutter/testing/testing.h"`

Go to the source code of this file.

## Functions
| TEST (FlutterThreadSynchronizerTest, NotBlocked)
| TEST (FlutterThreadSynchronizerTest, WaitForResize)
| TEST (FlutterThreadSynchronizerTest, UnblocksOnShutDown)

## Function Documentation

## ◆ TEST() [1/3]

TEST | ( | FlutterThreadSynchronizerTest | ,
|  | NotBlocked |
| ) |  |

Definition at line 9 of file FlutterResizeSynchronizerTest.mm.

9 {
10 [FlutterRunLoop ensureMainLoopInitialized];
11
12 FlutterResizeSynchronizer* synchronizer = [[FlutterResizeSynchronizer alloc] init];
13 __block BOOL performed = NO;
14
15 [NSThread detachNewThreadWithBlock:^{
16 [synchronizer performCommitForSize:CGSizeMake(100, 100)
17 notify:^{
18 performed = YES;
19 }
20 delay:0];
21 }];
22
23 CFTimeInterval start = CFAbsoluteTimeGetCurrent();
24
25 while (!performed && CFAbsoluteTimeGetCurrent() - start < 1.0) {
26 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
27 }
28 EXPECT_EQ(performed, YES);
29 }
FlutterResizeSynchronizer
Definition: FlutterResizeSynchronizer.h:17
FlutterRunLoop
Definition: FlutterRunLoop.h:16
+[FlutterRunLoop mainRunLoop]
FlutterRunLoop * mainRunLoop()
Definition: FlutterRunLoop.mm:118

References FlutterRunLoop::mainRunLoop.

## ◆ TEST() [2/3]

TEST | ( | FlutterThreadSynchronizerTest | ,
|  | UnblocksOnShutDown |
| ) |  |

Definition at line 84 of file FlutterResizeSynchronizerTest.mm.

84 {
85 [FlutterRunLoop ensureMainLoopInitialized];
86
87 FlutterResizeSynchronizer* synchronizer = [[FlutterResizeSynchronizer alloc] init];
88
89 // Resize synchronizer must have at received one frame in order to block.
90 __block BOOL didReceiveFrame = NO;
91 [synchronizer performCommitForSize:CGSizeMake(10, 10)
92 notify:^{
93 didReceiveFrame = YES;
94 }
95 delay:0];
96
97 CFTimeInterval start = CFAbsoluteTimeGetCurrent();
98 while (!didReceiveFrame && CFAbsoluteTimeGetCurrent() - start < 1.0) {
99 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
100 }
101
102 fml::AutoResetWaitableEvent latch_;
103 fml::AutoResetWaitableEvent& latch = latch_;
104
105 [NSThread detachNewThreadWithBlock:^{
106 latch.Wait();
107
108 [synchronizer shutDown];
109 }];
110
111 [synchronizer beginResizeForSize:CGSizeMake(100, 100)
112 notify:^{
113 // Unblock resize
114 latch.Signal();
115 }];
116
117 // Subsequent calls should not block.
118 [synchronizer beginResizeForSize:CGSizeMake(100, 100)
119 notify:^{
120 }];
121 }

References FlutterRunLoop::mainRunLoop.

## ◆ TEST() [3/3]

TEST | ( | FlutterThreadSynchronizerTest | ,
|  | WaitForResize |
| ) |  |

Definition at line 31 of file FlutterResizeSynchronizerTest.mm.

31 {
32 [FlutterRunLoop ensureMainLoopInitialized];
33
34 FlutterResizeSynchronizer* synchronizer = [[FlutterResizeSynchronizer alloc] init];
35
36 __block BOOL commit1 = NO;
37 __block BOOL commit2 = NO;
38
39 // Capturing c++ objects in blocks requires copy constructor, that also applies
40 // to __block variables where the copy is made on heap.
41 fml::AutoResetWaitableEvent latch_;
42 fml::AutoResetWaitableEvent& latch = latch_;
43
44 // Resize synchronizer must have at received one frame in order to block.
45 __block BOOL didReceiveFrame = NO;
46 [synchronizer performCommitForSize:CGSizeMake(10, 10)
47 notify:^{
48 didReceiveFrame = YES;
49 }
50 delay:0];
51
52 CFTimeInterval start = CFAbsoluteTimeGetCurrent();
53 while (!didReceiveFrame && CFAbsoluteTimeGetCurrent() - start < 1.0) {
54 [FlutterRunLoop.mainRunLoop pollFlutterMessagesOnce];
55 }
56
57 // Now resize should block until it has received expected size.
58
59 [NSThread detachNewThreadWithBlock:^{
60 latch.Wait();
61
62 [synchronizer performCommitForSize:CGSizeMake(50, 100)
63 notify:^{
64 commit1 = YES;
65 }
66 delay:0];
67
68 [synchronizer performCommitForSize:CGSizeMake(100, 100)
69 notify:^{
70 commit2 = YES;
71 }
72 delay:0];
73 }];
74
75 [synchronizer beginResizeForSize:CGSizeMake(100, 100)
76 notify:^{
77 latch.Signal();
78 }];
79
80 EXPECT_EQ(commit1, YES);
81 EXPECT_EQ(commit2, YES);
82 }

References FlutterRunLoop::mainRunLoop.