5#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.h"
6#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin_Internal.h"
8#import "flutter/shell/platform/common/platform_provided_menu.h"
9#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
10#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h"
11#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterPluginRegistrarMacOS.h"
12#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h"
13#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
14#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
15#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputPlugin.h"
16#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterTextInputSemanticsObject.h"
17#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
18#include "flutter/testing/autoreleasepool_test.h"
19#include "flutter/testing/testing.h"
20#include "gtest/gtest.h"
23@property(nonatomic, readonly) id<FlutterPlugin>
plugin;
32- (void)addMethodCallDelegate:(nonnull
id<FlutterPlugin>)delegate
36 [_channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
37 [delegate handleMethodCall:call result:result];
45 withId:(nonnull NSString*)factoryId {
48- (void)publish:(nonnull NSObject*)value {
51- (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset {
55- (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset
56 fromPackage:(nonnull NSString*)package {
79FlutterMenuPluginTest::FlutterMenuPluginTest() {
80 view_ = [[NSView alloc] initWithFrame:NSZeroRect];
81 view_.wantsLayer = YES;
86 NSMenu* mainMenu = [[NSMenu alloc] init];
87 NSMenuItem* appNameMenu = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"APP_NAME", nil)
91 [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Prexisting APP_NAME menu", nil)];
92 [submenu addItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"About APP_NAME", nil)
95 appNameMenu.submenu = submenu;
96 [mainMenu addItem:appNameMenu];
97 [NSApp setMainMenu:mainMenu];
103 NSDictionary* testMenus = @{
106 @"id" : [NSNumber numberWithInt:1],
107 @"label" : @"APP_NAME",
111 @"id" : [NSNumber numberWithInt:3],
112 @"platformProvidedMenu" : @(static_cast<int>(flutter::PlatformProvidedMenu::kQuit)),
116 @"id" : [NSNumber numberWithInt:2],
117 @"label" : @"APP_NAME Info",
119 @"shortcutTrigger" : [NSNumber numberWithUnsignedLongLong:0x61],
120 @"shortcutModifiers" : [NSNumber numberWithUnsignedInt:0],
125 @"id" : [NSNumber numberWithInt:4],
126 @"label" : @"Help for APP_NAME",
130 @"id" : [NSNumber numberWithInt:5],
131 @"label" : @"Help me!",
135 @"id" : [NSNumber numberWithInt:6],
138 @"isDivider" : @(YES),
141 @"id" : [NSNumber numberWithInt:7],
142 @"label" : @"Search help",
150 __block
id available = @NO;
153 result:^(id _Nullable result) {
161 result:^(id _Nullable result){
164 EXPECT_EQ([NSApp.mainMenu numberOfItems], 2);
165 NSMenuItem* firstMenu = [NSApp.mainMenu itemAtIndex:0];
166 EXPECT_TRUE([[firstMenu title] isEqualToString:
@"flutter_desktop_darwin_unittests"]);
167 EXPECT_EQ([firstMenu tag], 1);
169 EXPECT_FALSE([firstMenu isHidden]);
170 EXPECT_TRUE([[firstMenu keyEquivalent] isEqualToString:
@"\0"]);
172 EXPECT_EQ([[firstMenu submenu] numberOfItems], 1);
173 NSMenuItem* firstItem = [[firstMenu submenu] itemAtIndex:0];
174 EXPECT_TRUE([[firstItem title] isEqualToString:
@"flutter_desktop_darwin_unittests Info"]);
175 EXPECT_TRUE([[firstItem keyEquivalent] isEqualToString:
@"a"]);
177 EXPECT_FALSE([firstItem isHidden]);
179 [NSStringFromSelector([firstItem
action]) isEqualToString:
@"flutterMenuItemSelected:"]);
180 EXPECT_EQ([firstItem tag], 2);
182 NSMenuItem* secondMenu = [NSApp.mainMenu itemAtIndex:1];
183 EXPECT_TRUE([[secondMenu title] isEqualToString:
@"Help for flutter_desktop_darwin_unittests"]);
184 EXPECT_EQ([secondMenu tag], 4);
186 EXPECT_FALSE([secondMenu isHidden]);
188 EXPECT_EQ([[secondMenu submenu] numberOfItems], 3);
189 NSMenuItem* secondMenuFirst = [[secondMenu submenu] itemAtIndex:0];
190 EXPECT_TRUE([[secondMenuFirst title] isEqualToString:
@"Help me!"]);
192 EXPECT_FALSE([secondMenuFirst isHidden]);
194 [NSStringFromSelector([secondMenuFirst
action]) isEqualToString:
@"flutterMenuItemSelected:"]);
195 EXPECT_EQ([secondMenuFirst tag], 5);
197 NSMenuItem* secondMenuDivider = [[secondMenu submenu] itemAtIndex:1];
198 EXPECT_TRUE([[secondMenuDivider title] isEqualToString:
@""]);
199 EXPECT_TRUE([[secondMenuDivider keyEquivalent] isEqualToString:
@""]);
200 EXPECT_FALSE([secondMenuDivider isEnabled]);
201 EXPECT_FALSE([secondMenuDivider isHidden]);
202 EXPECT_EQ([secondMenuDivider
action], nil);
203 EXPECT_EQ([secondMenuDivider tag], 0);
205 NSMenuItem* secondMenuLast = [[secondMenu submenu] itemAtIndex:2];
206 EXPECT_TRUE([[secondMenuLast title] isEqualToString:
@"Search help"]);
207 EXPECT_FALSE([secondMenuLast isEnabled]);
208 EXPECT_FALSE([secondMenuLast isHidden]);
210 [NSStringFromSelector([secondMenuLast
action]) isEqualToString:
@"flutterMenuItemSelected:"]);
211 EXPECT_EQ([secondMenuLast tag], 7);
FlutterTextInputPlugin * _plugin
FlutterMethodChannel * _channel
HWND(* FlutterPlatformViewFactory)(const FlutterPlatformViewCreationParameters *)
FlutterMethodChannel * channel
id< FlutterPlugin > plugin
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
TEST_F(FlutterMenuPluginTest, TestSetMenu)
id< FlutterBinaryMessenger > messenger
id< FlutterTextureRegistry > textures
#define EXPECT_TRUE(handle)