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
hasStrings on Android #20393
Merged
Merged
hasStrings on Android #20393
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4ddb31
Implement hasStrings in terms of getClipboardData on Android
justinmc f723cfc
WIP trying and failing to test this
justinmc 5d5c9b2
Test hasStrings message
justinmc fdf79d6
Test real hasStrings call but not working due to inability to mock Cl…
justinmc d2f40f4
Fix hasStrings test and ClipboardManager mocking
justinmc 585c7e2
Formatting
justinmc 3e1eb3d
Omit 'public' and split tests so they're in the correct packages
justinmc f606805
Formatting
justinmc 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
45 changes: 45 additions & 0 deletions
45
...platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.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,45 @@ | ||
package io.flutter.embedding.engine.systemchannels; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import android.content.res.AssetManager; | ||
import io.flutter.embedding.engine.FlutterJNI; | ||
import io.flutter.embedding.engine.dart.DartExecutor; | ||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Matchers; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
@Config(manifest = Config.NONE) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class PlatformChannelTest { | ||
@Test | ||
public void platformChannel_hasStringsMessage() { | ||
MethodChannel rawChannel = mock(MethodChannel.class); | ||
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); | ||
DartExecutor dartExecutor = new DartExecutor(mockFlutterJNI, mock(AssetManager.class)); | ||
PlatformChannel fakePlatformChannel = new PlatformChannel(dartExecutor); | ||
PlatformChannel.PlatformMessageHandler mockMessageHandler = | ||
mock(PlatformChannel.PlatformMessageHandler.class); | ||
fakePlatformChannel.setPlatformMessageHandler(mockMessageHandler); | ||
Boolean returnValue = true; | ||
when(mockMessageHandler.clipboardHasStrings()).thenReturn(returnValue); | ||
MethodCall methodCall = new MethodCall("Clipboard.hasStrings", null); | ||
MethodChannel.Result mockResult = mock(MethodChannel.Result.class); | ||
fakePlatformChannel.parsingMethodCallHandler.onMethodCall(methodCall, mockResult); | ||
|
||
JSONObject expected = new JSONObject(); | ||
try { | ||
expected.put("value", returnValue); | ||
} catch (JSONException e) { | ||
} | ||
verify(mockResult).success(Matchers.refEq(expected)); | ||
} | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gaaclarke Thanks for all the help with the tests. The first test above works, but this one is failing because the engine is unable to use the clipboard internally.
I thought that my use of ShadowClipboardManager would solve this problem, but maybe I'm doing this wrong? I got this from InputConnectionAdaptorTest.
The engine is unable to get a ClipboardManager here (it's null):
engine/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java
Lines 272 to 274 in f1855fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird, you can try moving the ClipboardManager to the top of the test? I'm not sure if there is a temporal problem here. I don't see a difference between what you are doing and the other test. Worse case scenario you can make your own interface on top of the ClipboardManager that the PlatformPlugin uses. It would be nice if we could get this working though. Sorry, gotta run to a meeting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think I'm on to something with that. I'll post back later with results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's working, thank you! Let me know if it looks alright. I did have to make one protected method public at some point.