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 72 of file FlutterViewTest.mm.

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

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

◆ TEST() [2/3]

TEST ( FlutterView  ,
CursorUpdateDoesNotOverridePlatformView   
)

Definition at line 115 of file FlutterViewTest.mm.

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

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  enableWideGamut:NO];
37  EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
38 }

Variable Documentation

◆ kImplicitViewId

constexpr int64_t kImplicitViewId = 0ll
constexpr

Definition at line 11 of file FlutterViewTest.mm.