-
Notifications
You must be signed in to change notification settings - Fork 6k
Android 10+ View.getSystemGestureExclusionRects #11451
Conversation
mklim
left a comment
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.
Code changes LG. I think it's possible to add a test for the onMethodCall segment of this even with the SDK limitation, feel free to reach out if you hit any problems.
| break; | ||
| case "SystemGestures.getSystemGestureExclusionRects": | ||
| List<Rect> exclusionRects = platformMessageHandler.getSystemGestureExclusionRects(); | ||
| if (exclusionRects != null) { |
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.
subjective, optional: There could be a guard clause here and in PlatformPlugin.java#getSystemGestureExclusionRects to reduce nesting.
| case "SystemGestures.getSystemGestureExclusionRects": | ||
| List<Rect> exclusionRects = platformMessageHandler.getSystemGestureExclusionRects(); | ||
| if (exclusionRects != null) { | ||
| ArrayList<HashMap<String, Integer>> encodedExclusionRects = new ArrayList<HashMap<String, Integer>>(); |
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.
subjective, optional: I think it would be a little easier to read if this translating was split out into a helper method, like the decode ones.
…to get-exclusion-rects
mklim
left a comment
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.
This LGTM. It continues to use the testing the inner class strategy from the last PR. We've had some discussions about it being unideal with @matthew-carroll. However we still don't have a totally clear way forward other than this right now, so I think it makes sense to land this as-is for now and refactor once we have a sound alternative. Maybe file an issue with a TODO?
| } | ||
|
|
||
| /** | ||
| * Encodes a List<Rect> provided by the host platform into an ArrayList<HashMap<String, Integer>>. |
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.
In javadocs, it's ideal to express the value and/or purpose of a method rather than a purely technical statement. While this javadoc may be technically accurate, I think it's unlikely that this informs the reader of what is happening and why. Would you mind framing the javadoc in terms of why this method exists, and what encoding is taking place? You might consider mentioning when this method is expected to be called, why it is called, what encoding is taking place and why, and what is likely to happen after this. You don't necessarily need all of that, but that's how I would recommend approaching method docs.
| } | ||
|
|
||
| @Test | ||
| public void getSystemExclusionRectsSendsExclusionRectsToFrameworkOnSuccess() throws JSONException { |
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.
Please rename test as mentioned in the other PR
|
|
||
| @Test | ||
| public void getSystemExclusionRectsSendsExclusionRectsToFrameworkOnSuccess() throws JSONException { | ||
| DartExecutor dartExecutor = mock(DartExecutor.class); |
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.
Please clearly identify the areas of this test that setup the test, execute the behavior under test, and verify the expected results.
|
|
||
| ArrayList<HashMap<String, Integer>> expectedEncodedOutputRects = new ArrayList<HashMap<String, Integer>>(); | ||
| HashMap<String, Integer> rectMap = new HashMap<String, Integer>(); | ||
| rectMap.put("top", top); |
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.
In tests it is often preferable to avoid using variables for verification purposes. Developers will need to read every line of the test to understand what the expected values are. It essentially moves logic into the test, when a test should only include setup and expectations (or as close to that as possible). I would recommend putting the literal values in this map, rather than the variables.
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.
Sounds good. I was thinking it would be more clear to have both values created from the same variable so that developers know that the API output values should match the parsed values
| int bottom = 250; | ||
| int left = 0; | ||
|
|
||
| ArrayList<Rect> expectedExclusionRects = new ArrayList<Rect>(); |
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.
Are these really the "expected" exclusion rects? This looks to me like fakeExclusionRects...
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.
Yeah, in my mind, I saw it as "these are the exclusion rects that we expect returned in this test". I'll update it to fakeExclusionRects, since that is clearer.
| "SystemGestures.getSystemGestureExclusionRects", | ||
| null | ||
| ); | ||
| ResultsMock resultsMock = mock(ResultsMock.class); |
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 have the same question here about ResultsMock as the other PR. Do we need to define our own class if we're using mock()? Can Mockito just mock() the interface, instead?
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.
Yeah, I had a misunderstanding of how Mockito worked when I wrote the original tests. I've removed them in #11804
| ArrayList<Rect> expectedExclusionRects = new ArrayList<Rect>(); | ||
| Rect gestureRect = new Rect(left, top, right, bottom); | ||
| expectedExclusionRects.add(gestureRect); | ||
| when(platformMessageHandler.getSystemGestureExclusionRects()).thenReturn(expectedExclusionRects); |
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.
One stylistic recommendation that I have is to define the input and output up here at the top during the setup phase. It can often help readability. So above this comment you have the fake input (I think). Down at the bottom of the test you assemble the expected output. You might consider defining the expected output right here, just below the fake input. This allows readers to immediately see the fake input and expected output, together, without reading the rest of the test.
| null | ||
| ); | ||
| ResultsMock resultsMock = mock(ResultsMock.class); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callGetSystemGestureExclusionRects, resultsMock); |
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.
Please clearly separate the test setup from the behavior under test from the verification.
matthew-carroll
left a comment
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 for the updates. I think the tests you re-organized are now much more approachable for devs that don't necessarily know what's going on. I think just one more comment here.
| ); | ||
|
|
||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); | ||
| platformChannel.parsingMethodCallHandler.onMethodCall(callSetSystemGestureExclusionRects, resultsMock); |
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 :)
matthew-carroll
left a comment
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.
LGTM
[email protected]:flutter/engine.git/compare/e7f9ef6aa0b9...cd92039 git log e7f9ef6..cd92039 --no-merges --oneline 2019-09-04 [email protected] Handle new navigation platform messages (flutter/engine#11880) 2019-09-04 [email protected] Android 10+ View.getSystemGestureExclusionRects (flutter/engine#11451) 2019-09-04 [email protected] Fix deleting Thai vowel bug on iOS (skip string range sanitization) (flutter/engine#11807) 2019-09-04 [email protected] Roll src/third_party/dart 4bd13a74d9..c3db2e3ee0 (4 commits) 2019-09-04 [email protected] Roll src/third_party/skia c2dc9c864844..e7366841663b (2 commits) (flutter/engine#11878) 2019-09-04 [email protected] [flutter_runner] Add common libs to the test far (flutter/engine#11875) 2019-09-04 [email protected] Roll src/third_party/dart fd27e795ba..4bd13a74d9 (5 commits) 2019-09-04 [email protected] Provide dart vm initalize isolate callback so that children isolates belong to parent's isolate group. (flutter/engine#9888) 2019-09-04 [email protected] Add style guide and formatting information (flutter/engine#11669) 2019-09-04 [email protected] Roll fuchsia/sdk/core/linux-amd64 from BR_-u... to LKWtB... (flutter/engine#11874) 2019-09-04 [email protected] Roll fuchsia/sdk/core/mac-amd64 from dRCdb... to m-hNV... (flutter/engine#11873) 2019-09-04 [email protected] Roll src/third_party/skia 77743492418e..c2dc9c864844 (22 commits) (flutter/engine#11872) 2019-09-04 [email protected] Add a sample unit test target to flutter runner (flutter/engine#11847) 2019-09-04 [email protected] Support building standalone far packages with autogenerating manigests (flutter/engine#11849) 2019-09-04 [email protected] Roll src/third_party/dart 622747502e..fd27e795ba (9 commits) 2019-09-04 [email protected] Roll src/third_party/dart 54fdd559d8..622747502e (1 commits) 2019-09-04 [email protected] Roll fuchsia/sdk/core/linux-amd64 from KqidK... to BR_-u... (flutter/engine#11845) 2019-09-04 [email protected] Roll src/third_party/skia 452ce044f0db..77743492418e (12 commits) (flutter/engine#11837) 2019-09-04 [email protected] Roll fuchsia/sdk/core/mac-amd64 from -kKi5... to dRCdb... (flutter/engine#11840) 2019-09-04 [email protected] Roll src/third_party/dart 36985859e4..54fdd559d8 (65 commits) 2019-09-04 [email protected] Minor tweaks to the Doxygen theme. (flutter/engine#11576) 2019-09-04 [email protected] Updated API usage in scenario app by deleting unnecessary method. (flutter/engine#11844) 2019-09-03 [email protected] Fix RTL justification alignment with newline (flutter/engine#11842) 2019-09-03 [email protected] Rename first frame method and notify FlutterActivity when full drawn (#38714 #36796). (flutter/engine#11357) 2019-09-03 [email protected] Roll src/third_party/skia 8050d94ae227..452ce044f0db (1 commits) (flutter/engine#11834) 2019-09-03 [email protected] Roll fuchsia/sdk/core/linux-amd64 from a8wlq... to KqidK... (flutter/engine#11833) 2019-09-03 [email protected] Roll fuchsia/sdk/core/mac-amd64 from pVy4h... to -kKi5... (flutter/engine#11832) 2019-09-03 [email protected] Roll src/third_party/skia 033c4014b788..8050d94ae227 (2 commits) (flutter/engine#11831) 2019-09-03 [email protected] Roll src/third_party/skia 94c66475560d..033c4014b788 (2 commits) (flutter/engine#11830) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Description
Adds a platform channel that allows the Flutter framework to get system gesture exclusion rects for Android Q+.
Related Issues
Related to flutter/flutter#32748
Testing
Testing is blocked for Android SDK Q+ (29+). Will track for follow up updates to unit tests on flutter/flutter#38626