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
added unit tests for the android embedder that run on android devices #28784
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,11 @@ | ||
| #include <memory> | ||
| #include "flutter/shell/platform/android/android_context_gl.h" | ||
| #include "flutter/shell/platform/android/android_environment_gl.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| TEST(AndroidContextGl, Create) { | ||
| auto environment = fml::MakeRefCounted<flutter::AndroidEnvironmentGL>(); | ||
| auto context = std::make_unique<flutter::AndroidContextGL>( | ||
| flutter::AndroidRenderingAPI::kOpenGLES, environment); | ||
| EXPECT_NE(context.get(), nullptr); | ||
| } |
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,70 @@ | ||
| #include <memory> | ||
| #include "flutter/shell/platform/android/android_shell_holder.h" | ||
| #include "gmock/gmock.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace flutter { | ||
| namespace testing { | ||
| namespace { | ||
| class MockPlatformViewAndroidJNI : public PlatformViewAndroidJNI { | ||
| MOCK_METHOD2(FlutterViewHandlePlatformMessage, | ||
| void(std::unique_ptr<flutter::PlatformMessage> message, | ||
| int responseId)); | ||
| MOCK_METHOD2(FlutterViewHandlePlatformMessageResponse, | ||
| void(int responseId, std::unique_ptr<fml::Mapping> data)); | ||
| MOCK_METHOD3(FlutterViewUpdateSemantics, | ||
| void(std::vector<uint8_t> buffer, | ||
| std::vector<std::string> strings, | ||
| std::vector<std::vector<uint8_t>> string_attribute_args)); | ||
| MOCK_METHOD2(FlutterViewUpdateCustomAccessibilityActions, | ||
| void(std::vector<uint8_t> actions_buffer, | ||
| std::vector<std::string> strings)); | ||
| MOCK_METHOD0(FlutterViewOnFirstFrame, void()); | ||
| MOCK_METHOD0(FlutterViewOnPreEngineRestart, void()); | ||
| MOCK_METHOD2(SurfaceTextureAttachToGLContext, | ||
| void(JavaLocalRef surface_texture, int textureId)); | ||
| MOCK_METHOD1(SurfaceTextureUpdateTexImage, | ||
| void(JavaLocalRef surface_texture)); | ||
| MOCK_METHOD2(SurfaceTextureGetTransformMatrix, | ||
| void(JavaLocalRef surface_texture, SkMatrix& transform)); | ||
| MOCK_METHOD1(SurfaceTextureDetachFromGLContext, | ||
| void(JavaLocalRef surface_texture)); | ||
| MOCK_METHOD8(FlutterViewOnDisplayPlatformView, | ||
| void(int view_id, | ||
| int x, | ||
| int y, | ||
| int width, | ||
| int height, | ||
| int viewWidth, | ||
| int viewHeight, | ||
| MutatorsStack mutators_stack)); | ||
| MOCK_METHOD5(FlutterViewDisplayOverlaySurface, | ||
| void(int surface_id, int x, int y, int width, int height)); | ||
| MOCK_METHOD0(FlutterViewBeginFrame, void()); | ||
| MOCK_METHOD0(FlutterViewEndFrame, void()); | ||
| MOCK_METHOD0(FlutterViewCreateOverlaySurface, | ||
| std::unique_ptr<PlatformViewAndroidJNI::OverlayMetadata>()); | ||
| MOCK_METHOD0(FlutterViewDestroyOverlaySurfaces, void()); | ||
| MOCK_METHOD1(FlutterViewComputePlatformResolvedLocale, | ||
| std::unique_ptr<std::vector<std::string>>( | ||
| std::vector<std::string> supported_locales_data)); | ||
| MOCK_METHOD0(GetDisplayRefreshRate, double()); | ||
| MOCK_METHOD1(RequestDartDeferredLibrary, bool(int loading_unit_id)); | ||
| }; | ||
| } // namespace | ||
|
|
||
| TEST(AndroidShellHolder, Create) { | ||
| Settings settings; | ||
| settings.enable_software_rendering = false; | ||
| auto jni = std::make_shared<MockPlatformViewAndroidJNI>(); | ||
| auto holder = std::make_unique<AndroidShellHolder>( | ||
| settings, jni, /*is_background_view=*/false); | ||
| EXPECT_NE(holder.get(), nullptr); | ||
| EXPECT_TRUE(holder->IsValid()); | ||
| EXPECT_NE(holder->GetPlatformView().get(), nullptr); | ||
| auto window = | ||
| fml::MakeRefCounted<AndroidNativeWindow>(nullptr, /*is_offscreen=*/true); | ||
| holder->GetPlatformView()->NotifyCreated(window); | ||
| } | ||
| } // namespace testing | ||
| } // namespace flutter |
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,6 @@ | ||
| #include "gtest/gtest.h" | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| ::testing::InitGoogleTest(&argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } |
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 |
|---|---|---|
|
|
@@ -351,6 +351,14 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'): | |
| RunCmd(command, cwd=test_runner_dir, env=env) | ||
|
|
||
|
|
||
| def RunAndroidTests(android_variant='android_debug_unopt'): | ||
| test_runner_name = 'flutter_shell_native_unittests' | ||
| tests_path = os.path.join(out_dir, android_variant, test_runner_name) | ||
| remote_path = '/data/local/tmp' | ||
| remote_tests_path = os.path.join(remote_path, test_runner_name) | ||
| RunCmd(['adb', 'push', tests_path, remote_path], cwd=buildroot_dir) | ||
| RunCmd(['adb', 'shell', remote_tests_path]) | ||
|
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. How does this validate failure or pass?
Member
Author
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.
|
||
|
|
||
| def RunObjcTests(ios_variant='ios_debug_sim_unopt', test_filter=None): | ||
| """Runs Objective-C XCTest unit tests for the iOS embedding""" | ||
| AssertExpectedXcodeVersion() | ||
|
|
@@ -592,6 +600,10 @@ def main(): | |
| java_filter = None | ||
| RunJavaTests(java_filter, args.android_variant) | ||
|
|
||
| if 'android' in types: | ||
| assert not IsWindows(), "Android engine files can't be compiled on Windows." | ||
| RunAndroidTests(args.android_variant) | ||
|
|
||
| if 'objc' in types: | ||
| assert IsMac(), "iOS embedding tests can only be run on macOS." | ||
| RunObjcTests(args.ios_variant, args.objc_filter) | ||
|
|
||
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.
Why do we need to create a PBuffer surface?
How confident can we be that we're testing what we even care about here?
Is there any possible way we could avoid this code in production code?
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.
The tests in this PR are just very simple setup and teardown. This is more about setting up the infrastructure to make more interesting tests that do assert more things.
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.
As far as the IsFakeWindow question, I looked into it. I didn't see a way to do it that wasn't a significant refactor. That's sometimes the problem when you add tests after the fact versus build them up with tests.
You could transfer creating the surface to the window, but that would leak egl calls outside of the AndroidContextGL. I'm open to any suggestion I might have overlooked.
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.
The code assumes a surface, it will crash if you don't have one. We don't have a window so our only option is to make a fake pbuffer surface.