368 {
369
370 InputMethodSubtype inputMethodSubtype = mock(InputMethodSubtype.class);
371 TestImm testImm = Shadow.extract(ctx.getSystemService(Context.INPUT_METHOD_SERVICE));
372 testImm.setCurrentInputMethodSubtype(inputMethodSubtype);
373 View testView = new View(ctx);
374 EditorInfo outAttrs = new EditorInfo();
375 outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
376 TextInputChannel textInputChannel = spy(new TextInputChannel(mock(DartExecutor.class)));
378 new TextInputPlugin(testView, textInputChannel, mock(PlatformViewsController.class));
379 CharSequence newText = "I do not fear computers. I fear the lack of them.";
380 final TextEditingDelta expectedDelta =
381 new TextEditingDelta("", 0, 0, newText, newText.length(), newText.length(), 0, 49);
382
383
385 0,
386 new TextInputChannel.Configuration(
387 false,
388 false,
389 true,
390 true,
391 true,
392 TextInputChannel.TextCapitalization.NONE,
393 new TextInputChannel.InputType(TextInputChannel.TextInputType.TEXT, false, false),
394 null,
395 null,
396 null,
397 null,
398 null));
399
400
402 testView, new TextInputChannel.TextEditState("", 0, 0, -1, -1));
403 verify(textInputChannel,
times(0)).updateEditingStateWithDeltas(anyInt(),
any());
404 verify(textInputChannel,
times(0))
405 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
406 assertEquals(
407 0,
409 .extractBatchTextEditingDeltas()
410 .size());
411
412 InputConnection inputConnection =
413 textInputPlugin.createInputConnection(testView, mock(KeyboardManager.class), outAttrs);
414
415 inputConnection.beginBatchEdit();
416 verify(textInputChannel,
times(0)).updateEditingStateWithDeltas(anyInt(),
any());
417 verify(textInputChannel,
times(0))
418 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
419 inputConnection.setComposingText(newText, newText.length());
420 final ArrayList<TextEditingDelta> actualDeltas =
421 ((ListenableEditingState)
textInputPlugin.getEditable()).extractBatchTextEditingDeltas();
422 assertEquals(2, actualDeltas.size());
423 final TextEditingDelta
delta = actualDeltas.get(1);
424 verify(textInputChannel,
times(0)).updateEditingStateWithDeltas(anyInt(),
any());
425 verify(textInputChannel,
times(0))
426 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
427 inputConnection.endBatchEdit();
428
429 assertEquals(
430 0,
432 .extractBatchTextEditingDeltas()
433 .size());
434
435
436 assertEquals(expectedDelta.getOldText(),
delta.getOldText());
437 assertEquals(expectedDelta.getDeltaText(),
delta.getDeltaText());
438 assertEquals(expectedDelta.getDeltaStart(),
delta.getDeltaStart());
439 assertEquals(expectedDelta.getDeltaEnd(),
delta.getDeltaEnd());
440 assertEquals(expectedDelta.getNewSelectionStart(),
delta.getNewSelectionStart());
441 assertEquals(expectedDelta.getNewSelectionEnd(),
delta.getNewSelectionEnd());
442 assertEquals(expectedDelta.getNewComposingStart(),
delta.getNewComposingStart());
443 assertEquals(expectedDelta.getNewComposingEnd(),
delta.getNewComposingEnd());
444
445 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
446 verify(textInputChannel,
times(0))
447 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
448
449 inputConnection.beginBatchEdit();
450
451 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
452 verify(textInputChannel,
times(0))
453 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
454
455 inputConnection.endBatchEdit();
456
457 assertEquals(
458 0,
460 .extractBatchTextEditingDeltas()
461 .size());
462
463 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
464 verify(textInputChannel,
times(0))
465 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
466
467 inputConnection.beginBatchEdit();
468
469 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
470 verify(textInputChannel,
times(0))
471 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
472
473
474
475
476 inputConnection.setSelection(3, 4);
477 assertEquals(Selection.getSelectionStart(
textInputPlugin.getEditable()), 3);
478 assertEquals(Selection.getSelectionEnd(
textInputPlugin.getEditable()), 4);
479
480 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
481 verify(textInputChannel,
times(0))
482 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
483
484 verify(textInputChannel,
times(1)).updateEditingStateWithDeltas(anyInt(),
any());
485 verify(textInputChannel,
times(0))
486 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
487
488 inputConnection.endBatchEdit();
489
490 verify(textInputChannel,
times(2)).updateEditingStateWithDeltas(anyInt(),
any());
491 verify(textInputChannel,
times(0))
492 .updateEditingState(anyInt(),
any(), anyInt(), anyInt(), anyInt(), anyInt());
493 }