This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Notify framework to clear input connection when app is backgrounded (#35054). #9498
Merged
matthew-carroll
merged 1 commit into
flutter:master
from
matthew-carroll:35054_text_input_error_when_home_and_back
Aug 19, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...latform/android/test/io/flutter/embedding/engine/systemchannels/TextInputChannelTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package io.flutter.embedding.engine.systemchannels; | ||
|
|
||
| import org.hamcrest.Description; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.ArgumentMatcher; | ||
| import org.robolectric.RobolectricTestRunner; | ||
| import org.robolectric.annotation.Config; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Collections; | ||
|
|
||
| import io.flutter.embedding.engine.dart.DartExecutor; | ||
| import io.flutter.plugin.common.JSONMethodCodec; | ||
| import io.flutter.plugin.common.MethodCall; | ||
|
|
||
| import static org.mockito.Matchers.argThat; | ||
| import static org.mockito.Matchers.eq; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| @Config(manifest=Config.NONE) | ||
| @RunWith(RobolectricTestRunner.class) | ||
| public class TextInputChannelTest { | ||
| @Test | ||
| public void itNotifiesFrameworkWhenPlatformClosesInputConnection() { | ||
| // Setup test. | ||
| final int INPUT_CLIENT_ID = 9; // Arbitrary integer. | ||
| DartExecutor dartExecutor = mock(DartExecutor.class); | ||
|
|
||
| TextInputChannel textInputChannel = new TextInputChannel(dartExecutor); | ||
|
|
||
| // Execute behavior under test. | ||
| textInputChannel.onConnectionClosed(INPUT_CLIENT_ID); | ||
|
|
||
| // Verify results. | ||
| verify(dartExecutor, times(1)).send( | ||
| eq("flutter/textinput"), | ||
| ByteBufferMatcher.eqByteBuffer(JSONMethodCodec.INSTANCE.encodeMethodCall( | ||
| new MethodCall( | ||
| "TextInputClient.onConnectionClosed", | ||
| Collections.singletonList(INPUT_CLIENT_ID) | ||
| ) | ||
| )), | ||
| eq(null) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Mockito matcher that compares two {@link ByteBuffer}s by resetting both buffers and then | ||
| * utilizing their standard {@code equals()} method. | ||
| * <p> | ||
| * This matcher will change the state of the expected and actual buffers. The exact change in | ||
| * state depends on where the comparison fails or succeeds. | ||
| */ | ||
| static class ByteBufferMatcher extends ArgumentMatcher<ByteBuffer> { | ||
|
|
||
| static ByteBuffer eqByteBuffer(ByteBuffer expected) { | ||
| return argThat(new ByteBufferMatcher(expected)); | ||
| } | ||
|
|
||
| private ByteBuffer expected; | ||
|
|
||
| ByteBufferMatcher(ByteBuffer expected) { | ||
| this.expected = expected; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean matches(Object argument) { | ||
| if (!(argument instanceof ByteBuffer)) { | ||
| return false; | ||
| } | ||
|
|
||
| // Reset the buffers for content comparison. | ||
| ((ByteBuffer) argument).position(0); | ||
| expected.position(0); | ||
|
|
||
| return expected.equals(argument); | ||
| } | ||
|
|
||
| // Implemented so that during a failure the expected value is | ||
| // shown in logs, rather than the name of this class. | ||
| @Override | ||
| public void describeTo(Description description) { | ||
| description.appendText(expected.toString()); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.