-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[integration_test] Allow capture of screenshots for FlutterFragmentActivitys
#132406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 21 commits into
flutter:master
from
gmackall:integration_test_screenshot
Sep 7, 2023
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6dcfd40
potential fix for 89683
fefac8e
add unit tests, and fix a typo
0cdd710
Merge branch 'flutter:master' into integration_test_screenshot
gmackall b5e3df7
add missing newline at end of FlutterDeviceScreenshotTest.java
3745d11
modify ci to run android unit tests for integration_test
6da10e4
fix syntax for runCommand
57e5b74
try without workingDirectory
d6eed9d
Merge branch 'master' into integration_test_screenshot
gmackall 95dc531
third time? is the charm for runCommandSyntax
d61e863
remove debugging pwd that shouldn't have been pushed in the first place
c70f7f2
debugging logs that should be removed
85e0df7
try generating gradlew
3be02a0
move debugging ls to after generation of gradlew
39d22b3
fix silly mistake in generation of gradlew
af37e60
upgrade to jdk 17
082836c
remove debugging ls
8ec9414
make command to run unit tests work on windows (gradlew vs gradlew.bat)
ad84bec
replace hack to generate gradlew with --config-only flag
6bcb3d5
fix comment for previous change
52b0ec9
Merge branch 'master' into integration_test_screenshot
gmackall 365389e
adding package element back to manifest
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
52 changes: 52 additions & 0 deletions
52
...droid/src/test/java/dev/flutter/plugins/integration_test/FlutterDeviceScreenshotTest.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,52 @@ | ||
| // Copyright 2014 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package dev.flutter.plugins.integration_test; | ||
|
|
||
| import androidx.test.runner.AndroidJUnitRunner; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.*; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import android.app.Activity; | ||
|
|
||
| import io.flutter.embedding.android.FlutterActivity; | ||
| import io.flutter.embedding.android.FlutterFragment; | ||
| import io.flutter.embedding.android.FlutterFragmentActivity; | ||
| import io.flutter.embedding.android.FlutterView; | ||
|
|
||
| public class FlutterDeviceScreenshotTest extends AndroidJUnitRunner { | ||
| @Test | ||
| public void getFlutterView_returnsNullForNonFlutterActivity() { | ||
| Activity mockActivity = mock(Activity.class); | ||
| assertNull(FlutterDeviceScreenshot.getFlutterView(mockActivity)); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFlutterView_returnsFlutterViewForFlutterActivity() { | ||
| FlutterView mockFlutterView = mock(FlutterView.class); | ||
| FlutterActivity mockFlutterActivity = mock(FlutterActivity.class); | ||
| when(mockFlutterActivity.findViewById(FlutterActivity.FLUTTER_VIEW_ID)) | ||
| .thenReturn(mockFlutterView); | ||
| assertEquals( | ||
| FlutterDeviceScreenshot.getFlutterView(mockFlutterActivity), | ||
| mockFlutterView | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void getFlutterView_returnsFlutterViewForFlutterFragmentActivity() { | ||
| FlutterView mockFlutterView = mock(FlutterView.class); | ||
| FlutterFragmentActivity mockFlutterFragmentActivity = mock(FlutterFragmentActivity.class); | ||
| when(mockFlutterFragmentActivity.findViewById(FlutterFragment.FLUTTER_VIEW_ID)) | ||
| .thenReturn(mockFlutterView); | ||
| assertEquals( | ||
| FlutterDeviceScreenshot.getFlutterView(mockFlutterFragmentActivity), | ||
| mockFlutterView | ||
| ); | ||
| } | ||
| } |
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.
Should this be ...
Is it possible to avoid the instance of check at all?
go/UnhealthyIdioms#awkward-inheritance-hierarchy
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.
No, note that the cases are indeed different here:
findViewById(FlutterActivity.FLUTTER_VIEW_ID)vsfindViewById(FlutterFragment.FLUTTER_VIEW_ID)(notably, Flutter Activity vs Flutter FragmentThere 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 am not aware of a better way to do this without
instanceof(I try to avoid it in general). Open to ideas if I'm missing something though.We could just do something like (pseudo code)
But if for whatever reason we are actually dealing with a FlutterFragmentActivity, and there is a view registered with the
FlutterActivity.FLUTTER_VIEW_ID, then we would return the wrong view.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.
After some further consideration if you want to move on feel free to file a follow-up ticket and merge this as is.
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.
#134252