| Flutter macOS Embedder |

Classes | Functions | Variables
FlutterViewTest.mm File Reference
`#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h"`
`#import <Metal/Metal.h>`
`#import "flutter/testing/testing.h"`

Go to the source code of this file.

## Classes
class | TestFlutterViewDelegate
class | TestFlutterView
class | TestCursor

## Functions
| TEST (FlutterView, ShouldInheritContentsScaleReturnsYes)
| TEST (FlutterView, CursorUpdateDoesHitTest)
| TEST (FlutterView, CursorUpdateDoesNotOverridePlatformView)

## Variables
constexpr int64_t | kImplicitViewId = 0ll

## Function Documentation

## ◆ TEST() [1/3]

TEST | ( | FlutterView | ,
|  | CursorUpdateDoesHitTest |
| ) |  |

Definition at line 73 of file FlutterViewTest.mm.

73 {
74 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
75 id<MTLCommandQueue> queue = [device newCommandQueue];
76 TestFlutterViewDelegate* delegate = [[TestFlutterViewDelegate alloc] init];
77 FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
78 TestFlutterView* view = [[TestFlutterView alloc] initWithMTLDevice:device
79 commandQueue:queue
80 delegate:delegate
81 threadSynchronizer:threadSynchronizer
82 viewIdentifier:kImplicitViewId];
83 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
84 styleMask:NSBorderlessWindowMask
85 backing:NSBackingStoreBuffered
86 defer:NO];
87
88 TestCursor* cursor = [[TestCursor alloc] init];
89
90 window.contentView = view;
91 __weak NSView* weakView = view;
92 __block BOOL hitTestCalled = NO;
93 __block NSPoint hitTestCoordinate = NSZeroPoint;
94 view.onHitTest = ^NSView*(NSPoint point) {
95 hitTestCalled = YES;
96 hitTestCoordinate = point;
97 return weakView;
98 };
99 NSEvent* mouseEvent = [NSEvent mouseEventWithType:NSEventTypeMouseMoved
100 location:NSMakePoint(100, 100)
101 modifierFlags:0
102 timestamp:0
103 windowNumber:0
104 context:nil
105 eventNumber:0
106 clickCount:0
107 pressure:0];
108 [view didUpdateMouseCursor:cursor];
109 [view cursorUpdate:mouseEvent];
110
111 EXPECT_TRUE(hitTestCalled);
112 // The hit test coordinate should be in the window coordinate system.
113 EXPECT_TRUE(CGPointEqualToPoint(hitTestCoordinate, CGPointMake(100, 100)));
114 EXPECT_TRUE(cursor.setCalled);
115 }
kImplicitViewId
constexpr int64_t kImplicitViewId
Definition: FlutterViewTest.mm:11
FlutterThreadSynchronizer
Definition: FlutterThreadSynchronizer.h:19
TestCursor
Definition: FlutterViewTest.mm:62
TestFlutterViewDelegate
Definition: FlutterViewTest.mm:13
TestFlutterView
Definition: FlutterViewTest.mm:42

References FlutterView::didUpdateMouseCursor:, TestFlutterView::onHitTest, and TestCursor::setCalled.

## ◆ TEST() [2/3]

TEST | ( | FlutterView | ,
|  | CursorUpdateDoesNotOverridePlatformView |
| ) |  |

Definition at line 117 of file FlutterViewTest.mm.

117 {
118 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
119 id<MTLCommandQueue> queue = [device newCommandQueue];
120 TestFlutterViewDelegate* delegate = [[TestFlutterViewDelegate alloc] init];
121 FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
122 TestFlutterView* view = [[TestFlutterView alloc] initWithMTLDevice:device
123 commandQueue:queue
124 delegate:delegate
125 threadSynchronizer:threadSynchronizer
126 viewIdentifier:kImplicitViewId];
127 NSWindow* window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
128 styleMask:NSBorderlessWindowMask
129 backing:NSBackingStoreBuffered
130 defer:NO];
131
132 TestCursor* cursor = [[TestCursor alloc] init];
133
134 NSView* platformView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
135
136 window.contentView = view;
137 __block BOOL hitTestCalled = NO;
138 __block NSPoint hitTestCoordinate = NSZeroPoint;
139 view.onHitTest = ^NSView*(NSPoint point) {
140 hitTestCalled = YES;
141 hitTestCoordinate = point;
142 return platformView;
143 };
144 NSEvent* mouseEvent = [NSEvent mouseEventWithType:NSEventTypeMouseMoved
145 location:NSMakePoint(100, 100)
146 modifierFlags:0
147 timestamp:0
148 windowNumber:0
149 context:nil
150 eventNumber:0
151 clickCount:0
152 pressure:0];
153 [view didUpdateMouseCursor:cursor];
154 [view cursorUpdate:mouseEvent];
155
156 EXPECT_TRUE(hitTestCalled);
157 // The hit test coordinate should be in the window coordinate system.
158 EXPECT_TRUE(CGPointEqualToPoint(hitTestCoordinate, CGPointMake(100, 100)));
159 EXPECT_FALSE(cursor.setCalled);
160 }

References FlutterView::didUpdateMouseCursor:, TestFlutterView::onHitTest, and TestCursor::setCalled.

## ◆ TEST() [3/3]

TEST | ( | FlutterView | ,
|  | ShouldInheritContentsScaleReturnsYes |
| ) |  |

Definition at line 28 of file FlutterViewTest.mm.

28 {
29 id<MTLDevice> device = MTLCreateSystemDefaultDevice();
30 id<MTLCommandQueue> queue = [device newCommandQueue];
31 TestFlutterViewDelegate* delegate = [[TestFlutterViewDelegate alloc] init];
32 FlutterThreadSynchronizer* threadSynchronizer = [[FlutterThreadSynchronizer alloc] init];
33 FlutterView* view = [[FlutterView alloc] initWithMTLDevice:device
34 commandQueue:queue
35 delegate:delegate
36 threadSynchronizer:threadSynchronizer
37 viewIdentifier:kImplicitViewId];
38 EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
39 }
FlutterView
Definition: FlutterView.h:36

## Variable Documentation

## ◆ kImplicitViewId

constexpr int64_t kImplicitViewId = 0ll
| constexpr

Definition at line 11 of file FlutterViewTest.mm.