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
Android 10+ View.getSystemGestureExclusionRects #11451
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7b7fa25
(WIP) setting up setSystemGestureExclusionRects platform channel
shihaohong 361eb40
Merge branch 'master' of github.com:flutter/engine into set-exclusion…
shihaohong 5245ad3
SystemGesture.setSystemGestureExclusionRects
shihaohong b37fa16
Cleanup Log.v and unnecessary imports
shihaohong c155aec
Add Javadoc
shihaohong 53e858b
Reinclude accidentally removed log
shihaohong 009830f
View.getSystemGestureExclusionRects platform channel
shihaohong 9342b27
Handle error case for API level 28 and under
shihaohong 991ad1b
Add guard clause, split encoding logic into its own method
shihaohong b663b90
Fix merge conflicts
shihaohong ef8fe9f
Reintroduce accidentally removed getSystemExclusionRects case
shihaohong 50c6509
Add getSystemExclsionRects unit tests
shihaohong 4a230f8
Add Javadocs, improve variable naming
shihaohong 5537541
Add Javadocs
shihaohong 54f01f7
Improve helper function naming
shihaohong 1fad827
Merge branch 'get-exclusion-rects' of github.com:shihaohong/engine in…
shihaohong 024aa3a
Incorporate code review feedback
shihaohong 815d073
Add relevant context for the encodeExclusionRects javadoc
shihaohong eef30b8
Add ResultsMock back to make tests happy, will be removed in #11804
shihaohong 3c53063
Remove accidental spaces
shihaohong 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import android.graphics.Rect; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
|
|
||
| import io.flutter.embedding.engine.dart.DartExecutor; | ||
| import io.flutter.embedding.engine.systemchannels.PlatformChannel; | ||
|
|
@@ -21,6 +22,7 @@ | |
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @Config(manifest=Config.NONE) | ||
| @RunWith(RobolectricTestRunner.class) | ||
|
|
@@ -50,12 +52,12 @@ public void setSystemExclusionRectsSendsSuccessMessageToFramework() throws JSONE | |
| Rect gestureRect = new Rect(left, top, right, bottom); | ||
| expectedDecodedRects.add(gestureRect); | ||
|
|
||
| MethodCall callSystemGestureExclusionRects = new MethodCall( | ||
| MethodCall callSetSystemGestureExclusionRects = new MethodCall( | ||
| "SystemGestures.setSystemGestureExclusionRects", | ||
| inputRects | ||
| ); | ||
|
|
||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSetSystemGestureExclusionRects, resultsMock); | ||
| verify(platformMessageHandler, times(1)).setSystemGestureExclusionRects(expectedDecodedRects); | ||
| verify(resultsMock, times(1)).success(null); | ||
| } | ||
|
|
@@ -69,11 +71,11 @@ public void setSystemExclusionRectsRequiresJSONArrayInput() { | |
|
|
||
| ResultsMock resultsMock = mock(ResultsMock.class); | ||
| String nonJsonInput = "Non-JSON"; | ||
| MethodCall callSystemGestureExclusionRects = new MethodCall( | ||
| MethodCall callSetSystemGestureExclusionRects = new MethodCall( | ||
| "SystemGestures.setSystemGestureExclusionRects", | ||
| nonJsonInput | ||
| ); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSetSystemGestureExclusionRects, resultsMock); | ||
|
|
||
| String inputTypeError = "Input type is incorrect. Ensure that a List<Map<String, int>> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects."; | ||
| verify(resultsMock, times(1)).error( | ||
|
|
@@ -100,11 +102,11 @@ public void setSystemExclusionRectsSendsJSONExceptionOnIncorrectDataShape() thro | |
| JSONArray inputArray = new JSONArray(); | ||
| inputArray.put(jsonObject); | ||
|
|
||
| MethodCall callSystemGestureExclusionRects = new MethodCall( | ||
| MethodCall callSetSystemGestureExclusionRects = new MethodCall( | ||
| "SystemGestures.setSystemGestureExclusionRects", | ||
| inputArray | ||
| ); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSetSystemGestureExclusionRects, resultsMock); | ||
| verify(resultsMock, times(1)).error( | ||
| "error", | ||
| "JSON error: Incorrect JSON data shape. To set system gesture exclusion rects, \n" + | ||
|
|
@@ -113,6 +115,67 @@ public void setSystemExclusionRectsSendsJSONExceptionOnIncorrectDataShape() thro | |
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void itSendsSuccessMessageToFrameworkWhenGettingSystemGestureExclusionRects() throws JSONException { | ||
| // --- Test Setup --- | ||
| DartExecutor dartExecutor = mock(DartExecutor.class); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please clearly identify the areas of this test that setup the test, execute the behavior under test, and verify the expected results. |
||
| PlatformChannel platformChannel = new PlatformChannel(dartExecutor); | ||
| PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); | ||
| platformChannel.setPlatformMessageHandler(platformMessageHandler); | ||
| Result result = mock(Result.class); | ||
|
|
||
| // Fake API output setup | ||
| ArrayList<Rect> fakeExclusionRects = new ArrayList<Rect>(); | ||
| Rect gestureRect = new Rect(0, 0, 500, 250); | ||
| fakeExclusionRects.add(gestureRect); | ||
| when(platformMessageHandler.getSystemGestureExclusionRects()).thenReturn(fakeExclusionRects); | ||
|
|
||
| // Parsed API output that should be passed to result.success() | ||
| ArrayList<HashMap<String, Integer>> expectedEncodedOutputRects = new ArrayList<HashMap<String, Integer>>(); | ||
| HashMap<String, Integer> rectMap = new HashMap<String, Integer>(); | ||
| rectMap.put("top", 0); | ||
| rectMap.put("right", 500); | ||
| rectMap.put("bottom", 250); | ||
| rectMap.put("left", 0); | ||
| expectedEncodedOutputRects.add(rectMap); | ||
| MethodCall callGetSystemGestureExclusionRects = new MethodCall( | ||
| "SystemGestures.getSystemGestureExclusionRects", | ||
| null | ||
| ); | ||
|
|
||
| // --- Execute Test --- | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callGetSystemGestureExclusionRects, result); | ||
|
|
||
| // --- Verify Results --- | ||
| verify(result, times(1)).success(expectedEncodedOutputRects); | ||
| } | ||
|
|
||
| @Test | ||
| public void itSendsAPILevelErrorWhenAndroidVersionIsTooLowWhenGettingSystemGestureExclusionRects() { | ||
| // --- Test Setup --- | ||
| DartExecutor dartExecutor = mock(DartExecutor.class); | ||
| PlatformChannel platformChannel = new PlatformChannel(dartExecutor); | ||
| PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); | ||
| platformChannel.setPlatformMessageHandler(platformMessageHandler); | ||
| when(platformMessageHandler.getSystemGestureExclusionRects()).thenReturn(null); | ||
| Result result = mock(Result.class); | ||
|
|
||
| MethodCall callGetSystemGestureExclusionRects = new MethodCall( | ||
| "SystemGestures.getSystemGestureExclusionRects", | ||
| null | ||
| ); | ||
|
|
||
| // --- Execute Test --- | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callGetSystemGestureExclusionRects, result); | ||
|
|
||
| // --- Verify Results --- | ||
| verify(result, times(1)).error( | ||
| "error", | ||
| "Exclusion rects only exist for Android API 29+.", | ||
| null | ||
| ); | ||
| } | ||
|
|
||
| private class ResultsMock implements Result { | ||
| @Override | ||
| public void success(Object result) {} | ||
|
|
||
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.
I'm not sure how these tests overlap with the other PR, but can we separate the behavior under test from the verification? If it's already done in the other PR, then no worries.
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 think I mistakenly made this variable name update to this PR instead of the more relevant one. Should I move it over there instead? The other PR addresses separating the behavior under test from verification.
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.
Either place is fine as long as the right change is made :)