1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#import <OCMock/OCMock.h> 6#import <XCTest/XCTest.h> 7#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPluginAppLifeCycleDelegate.h" 8 9#ifndef __has_feature 10#define __has_feature(x) 0 /* for non-clang compilers */ 11#endif 12 13#if !__has_feature(objc_arc) 14#error ARC must be enabled! 15#endif 16 17@interface FlutterPluginAppLifeCycleDelegateTest : XCTestCase 18 19@end 20 21@implementation FlutterPluginAppLifeCycleDelegateTest 22 23- (void)testCreate { 24 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 25 XCTAssertNotNil(delegate); 26} 27 28- (void)testDidEnterBackground { 29 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 30 id plugin = OCMProtocolMock(@protocol(FlutterPlugin)); 31 [delegate addDelegate:plugin]; 32 [[NSNotificationCenter defaultCenter] 33 postNotificationName:UIApplicationDidEnterBackgroundNotification 34 object:nil]; 35 OCMVerify([plugin applicationDidEnterBackground:[UIApplication sharedApplication]]); 36} 37 38- (void)testWillEnterForeground { 39 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 40 id plugin = OCMProtocolMock(@protocol(FlutterPlugin)); 41 [delegate addDelegate:plugin]; 42 [[NSNotificationCenter defaultCenter] 43 postNotificationName:UIApplicationWillEnterForegroundNotification 44 object:nil]; 45 OCMVerify([plugin applicationWillEnterForeground:[UIApplication sharedApplication]]); 46} 47 48- (void)testWillResignActive { 49 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 50 id plugin = OCMProtocolMock(@protocol(FlutterPlugin)); 51 [delegate addDelegate:plugin]; 52 [[NSNotificationCenter defaultCenter] 53 postNotificationName:UIApplicationWillResignActiveNotification 54 object:nil]; 55 OCMVerify([plugin applicationWillResignActive:[UIApplication sharedApplication]]); 56} 57 58- (void)testDidBecomeActive { 59 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 60 id plugin = OCMProtocolMock(@protocol(FlutterPlugin)); 61 [delegate addDelegate:plugin]; 62 [[NSNotificationCenter defaultCenter] 63 postNotificationName:UIApplicationDidBecomeActiveNotification 64 object:nil]; 65 OCMVerify([plugin applicationDidBecomeActive:[UIApplication sharedApplication]]); 66} 67 68- (void)testWillTerminate { 69 FlutterPluginAppLifeCycleDelegate* delegate = [[FlutterPluginAppLifeCycleDelegate alloc] init]; 70 id plugin = OCMProtocolMock(@protocol(FlutterPlugin)); 71 [delegate addDelegate:plugin]; 72 [[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillTerminateNotification 73 object:nil]; 74 OCMVerify([plugin applicationWillTerminate:[UIApplication sharedApplication]]); 75} 76 77@end 78