Flutter macOS Embedder
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 71 of file FlutterViewTest.mm.

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

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

◆ TEST() [2/3]

TEST ( FlutterView  ,
CursorUpdateDoesNotOverridePlatformView   
)

Definition at line 113 of file FlutterViewTest.mm.

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

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  FlutterView* view = [[FlutterView alloc] initWithMTLDevice:device
33  commandQueue:queue
34  delegate:delegate
35  viewIdentifier:kImplicitViewId];
36  EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
37 }

Variable Documentation

◆ kImplicitViewId

constexpr int64_t kImplicitViewId = 0ll
constexpr

Definition at line 11 of file FlutterViewTest.mm.