@@ -405,4 +405,93 @@ - (void)testViewControllerBasedStatusBarHiddenUpdate {
405405 [bundleMock stopMocking ];
406406}
407407
408+ - (void )testStatusBarHiddenUpdate {
409+ id bundleMock = OCMPartialMock ([NSBundle mainBundle ]);
410+ OCMStub ([bundleMock objectForInfoDictionaryKey: @" UIViewControllerBasedStatusBarAppearance" ])
411+ .andReturn (@NO );
412+ id mockApplication = OCMClassMock ([UIApplication class ]);
413+ OCMStub ([mockApplication sharedApplication ]).andReturn (mockApplication);
414+
415+ // Enabling system UI overlays to update status bar.
416+ FlutterEngine* engine = [[[FlutterEngine alloc ] initWithName: @" test" project: nil ] autorelease ];
417+ [engine runWithEntrypoint: nil ];
418+ FlutterViewController* flutterViewController =
419+ [[[FlutterViewController alloc ] initWithEngine: engine nibName: nil bundle: nil ] autorelease ];
420+ std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
421+ std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
422+
423+ // Update to hidden.
424+ FlutterPlatformPlugin* plugin = [engine platformPlugin ];
425+
426+ XCTestExpectation* enableSystemUIOverlaysCalled =
427+ [self expectationWithDescription: @" setEnabledSystemUIOverlays" ];
428+ FlutterResult resultSet = ^(id result) {
429+ [enableSystemUIOverlaysCalled fulfill ];
430+ };
431+ FlutterMethodCall* methodCallSet =
432+ [FlutterMethodCall methodCallWithMethodName: @" SystemChrome.setEnabledSystemUIOverlays"
433+ arguments: @[ @" SystemUiOverlay.bottom" ]];
434+ [plugin handleMethodCall: methodCallSet result: resultSet];
435+ [self waitForExpectationsWithTimeout: 1 handler: nil ];
436+ #if not APPLICATION_EXTENSION_API_ONLY
437+ OCMVerify ([mockApplication setStatusBarHidden: YES ]);
438+ #endif
439+
440+ // Update to shown.
441+ XCTestExpectation* enableSystemUIOverlaysCalled2 =
442+ [self expectationWithDescription: @" setEnabledSystemUIOverlays" ];
443+ FlutterResult resultSet2 = ^(id result) {
444+ [enableSystemUIOverlaysCalled2 fulfill ];
445+ };
446+ FlutterMethodCall* methodCallSet2 =
447+ [FlutterMethodCall methodCallWithMethodName: @" SystemChrome.setEnabledSystemUIOverlays"
448+ arguments: @[ @" SystemUiOverlay.top" ]];
449+ [plugin handleMethodCall: methodCallSet2 result: resultSet2];
450+ [self waitForExpectationsWithTimeout: 1 handler: nil ];
451+ #if not APPLICATION_EXTENSION_API_ONLY
452+ OCMVerify ([mockApplication setStatusBarHidden: NO ]);
453+ #endif
454+
455+ [flutterViewController deregisterNotifications ];
456+ [mockApplication stopMocking ];
457+ [bundleMock stopMocking ];
458+ }
459+
460+ - (void )testStatusBarStyle {
461+ id bundleMock = OCMPartialMock ([NSBundle mainBundle ]);
462+ OCMStub ([bundleMock objectForInfoDictionaryKey: @" UIViewControllerBasedStatusBarAppearance" ])
463+ .andReturn (@NO );
464+ id mockApplication = OCMClassMock ([UIApplication class ]);
465+ OCMStub ([mockApplication sharedApplication ]).andReturn (mockApplication);
466+
467+ FlutterEngine* engine = [[[FlutterEngine alloc ] initWithName: @" test" project: nil ] autorelease ];
468+ [engine runWithEntrypoint: nil ];
469+ FlutterViewController* flutterViewController =
470+ [[[FlutterViewController alloc ] initWithEngine: engine nibName: nil bundle: nil ] autorelease ];
471+ std::unique_ptr<fml::WeakPtrFactory<FlutterEngine>> _weakFactory =
472+ std::make_unique<fml::WeakPtrFactory<FlutterEngine>>(engine);
473+ XCTAssertFalse (flutterViewController.prefersStatusBarHidden );
474+
475+ FlutterPlatformPlugin* plugin = [engine platformPlugin ];
476+
477+ XCTestExpectation* enableSystemUIModeCalled =
478+ [self expectationWithDescription: @" setSystemUIOverlayStyle" ];
479+ FlutterResult resultSet = ^(id result) {
480+ [enableSystemUIModeCalled fulfill ];
481+ };
482+ FlutterMethodCall* methodCallSet =
483+ [FlutterMethodCall methodCallWithMethodName: @" SystemChrome.setSystemUIOverlayStyle"
484+ arguments: @{@" statusBarBrightness" : @" Brightness.dark" }];
485+ [plugin handleMethodCall: methodCallSet result: resultSet];
486+ [self waitForExpectationsWithTimeout: 1 handler: nil ];
487+
488+ #if not APPLICATION_EXTENSION_API_ONLY
489+ OCMVerify ([mockApplication setStatusBarStyle: UIStatusBarStyleLightContent]);
490+ #endif
491+
492+ [flutterViewController deregisterNotifications ];
493+ [mockApplication stopMocking ];
494+ [bundleMock stopMocking ];
495+ }
496+
408497@end
0 commit comments