@@ -174,19 +174,13 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
174
174
FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] init ];
175
175
inputView.textInputDelegate = engine;
176
176
177
- XCTestExpectation* expectation2 = [self expectationWithDescription: @" called updateEditingClient twice" ];
178
- XCTestExpectation* expectation4 = [self expectationWithDescription: @" called updateEditingClient four times" ];
179
- XCTestExpectation* expectation6 = [self expectationWithDescription: @" called updateEditingClient six times" ];
177
+ __block XCTestExpectation* expectation;
180
178
__block int updateCount = 0 ;
181
179
OCMStub ([engine updateEditingClient: 0 withState: [OCMArg isNotNil ]])
182
180
.andDo (^(NSInvocation * invocation) {
183
181
updateCount++;
184
- if (updateCount == 2 ) {
185
- [expectation2 fulfill ];
186
- } else if (updateCount == 4 ) {
187
- [expectation4 fulfill ];
188
- } else if (updateCount == 6 ) {
189
- [expectation6 fulfill ];
182
+ if (expectation != nil ) {
183
+ [expectation fulfill ];
190
184
}
191
185
});
192
186
@@ -195,10 +189,12 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
195
189
// because calls to updateEditingState are debounced on the leading edge.
196
190
XCTAssertEqual (updateCount, 1 );
197
191
192
+ expectation = [self expectationWithDescription: @" called updateEditingClient" ];
198
193
[inputView deleteBackward ];
199
194
// Due to the debouncing, this call will happen after a short delay.
200
195
XCTAssertEqual (updateCount, 1 );
201
- [self waitForExpectations: @[expectation2] timeout: 1 ];
196
+ [self waitForExpectations: @[expectation] timeout: 1 ];
197
+ expectation = nil ;
202
198
XCTAssertEqual (updateCount, 2 );
203
199
204
200
// Subsequent calls follow this pattern of leading edge debouncing. Now that
@@ -208,32 +204,36 @@ - (void)testUITextInputCallsUpdateEditingStateOnce {
208
204
inputView.selectedTextRange = [FlutterTextRange rangeWithNSRange: NSMakeRange (0 , 1 )];
209
205
XCTAssertEqual (updateCount, 3 );
210
206
207
+ expectation = [self expectationWithDescription: @" called updateEditingClient" ];
211
208
[inputView replaceRange: [FlutterTextRange rangeWithNSRange: NSMakeRange (0 , 1 )]
212
209
withText: @" replace text" ];
213
210
XCTAssertEqual (updateCount, 3 );
214
- [self waitForExpectations: @[expectation4] timeout: 1 ];
211
+ [self waitForExpectations: @[expectation] timeout: 1 ];
212
+ expectation = nil ;
215
213
XCTAssertEqual (updateCount, 4 );
216
214
217
215
[inputView setMarkedText: @" marked text" selectedRange: NSMakeRange (0 , 1 )];
218
216
XCTAssertEqual (updateCount, 5 );
219
217
218
+ expectation = [self expectationWithDescription: @" called updateEditingClient" ];
220
219
[inputView unmarkText ];
221
220
XCTAssertEqual (updateCount, 5 );
222
- [self waitForExpectations: @[expectation6] timeout: 1 ];
221
+ [self waitForExpectations: @[expectation] timeout: 1 ];
222
+ expectation = nil ;
223
223
XCTAssertEqual (updateCount, 6 );
224
224
}
225
225
226
226
- (void )testUITextInputCallsToUpdateEditingStateAreDebounced {
227
227
FlutterTextInputView* inputView = [[FlutterTextInputView alloc ] init ];
228
228
inputView.textInputDelegate = engine;
229
229
230
- XCTestExpectation* expectation2 = [ self expectationWithDescription: @" called updateEditingClient twice " ] ;
230
+ __block XCTestExpectation* expectation ;
231
231
__block int updateCount = 0 ;
232
232
OCMStub ([engine updateEditingClient: 0 withState: [OCMArg isNotNil ]])
233
233
.andDo (^(NSInvocation * invocation) {
234
234
updateCount++;
235
- if (updateCount == 2 ) {
236
- [expectation2 fulfill ];
235
+ if (expectation != nil ) {
236
+ [expectation fulfill ];
237
237
}
238
238
});
239
239
@@ -243,11 +243,12 @@ - (void)testUITextInputCallsToUpdateEditingStateAreDebounced {
243
243
XCTAssertEqual (updateCount, 1 );
244
244
245
245
// These calls will be batched and come through after a short delay.
246
+ expectation = [self expectationWithDescription: @" called updateEditingClient twice" ];
246
247
[inputView deleteBackward ];
247
248
[inputView deleteBackward ];
248
249
[inputView deleteBackward ];
249
250
XCTAssertEqual (updateCount, 1 );
250
- [self waitForExpectations: @[expectation2 ] timeout: 1 ];
251
+ [self waitForExpectations: @[expectation ] timeout: 1 ];
251
252
XCTAssertEqual (updateCount, 2 );
252
253
XCTAssertTrue ([inputView.text isEqualToString: @" text to ins" ]);
253
254
}
@@ -366,16 +367,13 @@ - (void)testUpdateEditingClientSelectionClamping {
366
367
inputView.textInputDelegate = engine;
367
368
368
369
// Debounced calls need to be waited for using these expectations.
369
- XCTestExpectation* expectation2 = [self expectationWithDescription: @" called updateEditingClient twice" ];
370
- XCTestExpectation* expectation4 = [self expectationWithDescription: @" called updateEditingClient four times" ];
370
+ __block XCTestExpectation* expectation;
371
371
__block int updateCount = 0 ;
372
372
OCMStub ([engine updateEditingClient: 0 withState: [OCMArg isNotNil ]])
373
373
.andDo (^(NSInvocation * invocation) {
374
374
updateCount++;
375
- if (updateCount == 2 ) {
376
- [expectation2 fulfill ];
377
- } else if (updateCount == 4 ) {
378
- [expectation4 fulfill ];
375
+ if (expectation != nil ) {
376
+ [expectation fulfill ];
379
377
}
380
378
});
381
379
@@ -393,14 +391,16 @@ - (void)testUpdateEditingClientSelectionClamping {
393
391
}]]);
394
392
395
393
// Needs clamping.
394
+ expectation = [self expectationWithDescription: @" called updateEditingClient" ];
396
395
[inputView setTextInputState: @{
397
396
@" text" : @" SELECTION" ,
398
397
@" selectionBase" : @0 ,
399
398
@" selectionExtent" : @9999
400
399
}];
401
400
[inputView updateEditingState ];
402
401
403
- [self waitForExpectations: @[expectation2] timeout: 1 ];
402
+ [self waitForExpectations: @[expectation] timeout: 1 ];
403
+ expectation = nil ;
404
404
OCMVerify ([engine updateEditingClient: 0
405
405
withState: [OCMArg checkWithBlock: ^BOOL (NSDictionary * state) {
406
406
return ([state[@" selectionBase" ] intValue ]) == 0 &&
@@ -418,13 +418,15 @@ - (void)testUpdateEditingClientSelectionClamping {
418
418
}]]);
419
419
420
420
// Both ends need clamping.
421
+ expectation = [self expectationWithDescription: @" called updateEditingClient" ];
421
422
[inputView setTextInputState: @{
422
423
@" text" : @" SELECTION" ,
423
424
@" selectionBase" : @9999 ,
424
425
@" selectionExtent" : @9999
425
426
}];
426
427
[inputView updateEditingState ];
427
- [self waitForExpectations: @[expectation4] timeout: 1 ];
428
+ [self waitForExpectations: @[expectation] timeout: 1 ];
429
+ expectation = nil ;
428
430
OCMVerify ([engine updateEditingClient: 0
429
431
withState: [OCMArg checkWithBlock: ^BOOL (NSDictionary * state) {
430
432
return ([state[@" selectionBase" ] intValue ]) == 9 &&
0 commit comments