@@ -1341,47 +1341,53 @@ - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
1341
1341
id mockApplication = OCMClassMock ([UIApplication class ]);
1342
1342
id mockWindowScene;
1343
1343
id deviceMock;
1344
- FlutterViewController* realVC = [[FlutterViewController alloc ] initWithEngine: self .mockEngine
1345
- nibName: nil
1346
- bundle: nil ];
1347
- if (@available (iOS 16.0 , *)) {
1348
- mockWindowScene = OCMClassMock ([UIWindowScene class ]);
1349
- if (realVC.supportedInterfaceOrientations == mask) {
1350
- OCMReject ([mockWindowScene requestGeometryUpdateWithPreferences: [OCMArg any ]
1351
- errorHandler: [OCMArg any ]]);
1344
+ __block __weak id weakPreferences;
1345
+ @autoreleasepool {
1346
+ FlutterViewController* realVC = [[FlutterViewController alloc ] initWithEngine: self .mockEngine
1347
+ nibName: nil
1348
+ bundle: nil ];
1349
+ if (@available (iOS 16.0 , *)) {
1350
+ mockWindowScene = OCMClassMock ([UIWindowScene class ]);
1351
+ if (realVC.supportedInterfaceOrientations == mask) {
1352
+ OCMReject ([mockWindowScene requestGeometryUpdateWithPreferences: [OCMArg any ]
1353
+ errorHandler: [OCMArg any ]]);
1354
+ } else {
1355
+ // iOS 16 will decide whether to rotate based on the new preference, so always set it
1356
+ // when it changes.
1357
+ OCMExpect ([mockWindowScene
1358
+ requestGeometryUpdateWithPreferences: [OCMArg checkWithBlock: ^BOOL (
1359
+ UIWindowSceneGeometryPreferencesIOS*
1360
+ preferences) {
1361
+ weakPreferences = preferences;
1362
+ return preferences.interfaceOrientations == mask;
1363
+ }]
1364
+ errorHandler: [OCMArg any ]]);
1365
+ }
1366
+ OCMStub ([mockApplication sharedApplication ]).andReturn (mockApplication);
1367
+ OCMStub ([mockApplication connectedScenes ]).andReturn ([NSSet setWithObject: mockWindowScene]);
1352
1368
} else {
1353
- // iOS 16 will decide whether to rotate based on the new preference, so always set it
1354
- // when it changes.
1355
- OCMExpect ([mockWindowScene
1356
- requestGeometryUpdateWithPreferences: [OCMArg checkWithBlock: ^ BOOL (
1357
- UIWindowSceneGeometryPreferencesIOS*
1358
- preferences) {
1359
- return preferences. interfaceOrientations == mask;
1360
- }]
1361
- errorHandler: [OCMArg any ]] );
1369
+ deviceMock = OCMPartialMock ([UIDevice currentDevice ]);
1370
+ if (!didChange) {
1371
+ OCMReject ([deviceMock setValue: [OCMArg any ] forKey: @" orientation " ]);
1372
+ } else {
1373
+ OCMExpect ([deviceMock setValue: @(resultingOrientation) forKey: @" orientation " ]);
1374
+ }
1375
+
1376
+ OCMStub ([mockApplication sharedApplication ]). andReturn (mockApplication);
1377
+ OCMStub ([mockApplication statusBarOrientation ]). andReturn (currentOrientation );
1362
1378
}
1363
- OCMStub ([mockApplication sharedApplication ]).andReturn (mockApplication);
1364
- OCMStub ([mockApplication connectedScenes ]).andReturn ([NSSet setWithObject: mockWindowScene]);
1365
- } else {
1366
- deviceMock = OCMPartialMock ([UIDevice currentDevice ]);
1367
- if (!didChange) {
1368
- OCMReject ([deviceMock setValue: [OCMArg any ] forKey: @" orientation" ]);
1379
+
1380
+ [realVC performOrientationUpdate: mask];
1381
+ if (@available (iOS 16.0 , *)) {
1382
+ OCMVerifyAll (mockWindowScene);
1369
1383
} else {
1370
- OCMExpect ([ deviceMock setValue: @(resultingOrientation) forKey: @" orientation " ] );
1384
+ OCMVerifyAll ( deviceMock);
1371
1385
}
1372
-
1373
- OCMStub ([mockApplication sharedApplication ]).andReturn (mockApplication);
1374
- OCMStub ([mockApplication statusBarOrientation ]).andReturn (currentOrientation);
1375
- }
1376
-
1377
- [realVC performOrientationUpdate: mask];
1378
- if (@available (iOS 16.0 , *)) {
1379
- OCMVerifyAll (mockWindowScene);
1380
- } else {
1381
- OCMVerifyAll (deviceMock);
1382
1386
}
1387
+ [mockWindowScene stopMocking ];
1383
1388
[deviceMock stopMocking ];
1384
1389
[mockApplication stopMocking ];
1390
+ XCTAssertNil (weakPreferences);
1385
1391
}
1386
1392
1387
1393
// Creates a mocked UITraitCollection with nil values for everything except accessibilityContrast,
0 commit comments