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) {
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 {
79 FlutterMenuPluginTest::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) {
157 EXPECT_TRUE(available);
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);
168 EXPECT_TRUE([firstMenu isEnabled]);
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"]);
176 EXPECT_TRUE([firstItem isEnabled]);
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);
185 EXPECT_TRUE([secondMenu isEnabled]);
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!"]);
191 EXPECT_TRUE([secondMenuFirst isEnabled]);
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);