7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
25 id restorationChannel;
34 [restorationChannel stopMocking];
41 - (void)testRestoratonViewControllerEncodeAndDecode {
44 allowHeadlessExecution:YES
45 restorationEnabled:YES];
51 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
52 [restorationPlugin setRestorationData:data];
54 NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initRequiringSecureCoding:YES];
55 [flutterViewController encodeRestorableStateWithCoder:archiver];
57 [restorationPlugin setRestorationData:nil];
59 NSKeyedUnarchiver* unarchiver =
60 [[NSKeyedUnarchiver alloc] initForReadingWithData:archiver.encodedData];
61 [flutterViewController decodeRestorableStateWithCoder:unarchiver];
63 XCTAssert([[restorationPlugin restorationData] isEqualToData:data],
64 "Restoration state data must be equal");
67 - (void)testRestorationEnabledWaitsForData {
72 __block
id capturedResult;
73 [restorationPlugin handleMethodCall:methodCall
74 result:^(id _Nullable result) {
75 capturedResult = result;
77 XCTAssertNil(capturedResult);
79 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
80 [restorationPlugin setRestorationData:data];
81 XCTAssertEqual([capturedResult count], 2u);
82 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);
83 XCTAssertEqualObjects([[capturedResult objectForKey:
@"data"] data], data);
86 - (void)testRestorationDisabledRespondsRightAway {
91 __block
id capturedResult;
92 [restorationPlugin handleMethodCall:methodCall
93 result:^(id _Nullable result) {
94 capturedResult = result;
96 XCTAssertEqual([capturedResult count], 1u);
97 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @NO);
100 - (void)testRespondsRightAwayWhenDataIsSet {
104 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
105 [restorationPlugin setRestorationData:data];
107 __block
id capturedResult;
109 [restorationPlugin handleMethodCall:methodCall
110 result:^(id _Nullable result) {
111 capturedResult = result;
113 XCTAssertEqual([capturedResult count], 2u);
114 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);
115 XCTAssertEqualObjects([[capturedResult objectForKey:
@"data"] data], data);
118 - (void)testRespondsWithNoDataWhenRestorationIsCompletedWithoutData {
123 __block
id capturedResult;
124 [restorationPlugin handleMethodCall:methodCall
125 result:^(id _Nullable result) {
126 capturedResult = result;
128 XCTAssertNil(capturedResult);
131 XCTAssertEqual([capturedResult count], 1u);
132 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);
135 - (void)testRespondsRightAwayWithNoDataWhenRestorationIsCompleted {
141 __block
id capturedResult;
143 [restorationPlugin handleMethodCall:methodCall
144 result:^(id _Nullable result) {
145 capturedResult = result;
147 XCTAssertEqual([capturedResult count], 1u);
148 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);
151 - (void)testReturnsDataSetByFramework {
156 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
160 [restorationPlugin handleMethodCall:methodCall
161 result:^(id _Nullable result) {
162 XCTAssertNil(result);
164 XCTAssertEqualObjects([restorationPlugin restorationData], data);
167 - (void)testRespondsWithDataSetByFramework {
172 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
176 [restorationPlugin handleMethodCall:methodCall
177 result:^(id _Nullable result) {
178 XCTAssertNil(result);
180 XCTAssertEqualObjects([restorationPlugin restorationData], data);
182 __block
id capturedResult;
184 [restorationPlugin handleMethodCall:methodCall
185 result:^(id _Nullable result) {
186 capturedResult = result;
188 XCTAssertEqual([capturedResult count], 2u);
189 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);
190 XCTAssertEqualObjects([[capturedResult objectForKey:
@"data"] data], data);
193 - (void)testResetClearsData {
198 NSData* data = [@"testrestortiondata" dataUsingEncoding:NSUTF8StringEncoding];
202 [restorationPlugin handleMethodCall:methodCall
203 result:^(id _Nullable result) {
204 XCTAssertNil(result);
206 XCTAssertEqualObjects([restorationPlugin restorationData], data);
208 [restorationPlugin
reset];
209 XCTAssertNil([restorationPlugin restorationData]);
211 __block
id capturedResult;
213 [restorationPlugin handleMethodCall:methodCall
214 result:^(id _Nullable result) {
215 capturedResult = result;
217 XCTAssertEqual([capturedResult count], 1u);
218 XCTAssertEqual([capturedResult objectForKey:
@"enabled"], @YES);