Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ FILE: ../../../flutter/shell/platform/android/platform_view_android_delegate/pla
FILE: ../../../flutter/shell/platform/android/platform_view_android_delegate/platform_view_android_delegate_unittests.cc
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni_impl.cc
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni_impl.h
FILE: ../../../flutter/shell/platform/android/robolectric.properties
FILE: ../../../flutter/shell/platform/android/surface/android_native_window.cc
FILE: ../../../flutter/shell/platform/android/surface/android_native_window.h
FILE: ../../../flutter/shell/platform/android/surface/android_surface.cc
Expand Down
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: 42213051c23cf7aacd7319a315599219
Signature: 556bb3a9c92c7ac1fb27943070183aae

123 changes: 3 additions & 120 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -470,120 +470,9 @@ action("pom_embedding") {
]
}

# To build and run:
# testing/run_tests.py [--type=java] [--java-filter=io.flutter.TestClassName]
action("robolectric_tests") {
script = "//build/android/gyp/javac.py"
depfile = "$target_gen_dir/$target_name.d"

jar_path = "$root_out_dir/robolectric_tests.jar"

sources = [
"test/io/flutter/FlutterInjectorTest.java",
"test/io/flutter/FlutterTestSuite.java",
"test/io/flutter/SmokeTest.java",
"test/io/flutter/TestUtils.java",
"test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java",
"test/io/flutter/embedding/android/FlutterActivityTest.java",
"test/io/flutter/embedding/android/FlutterAndroidComponentTest.java",
"test/io/flutter/embedding/android/FlutterFragmentActivityTest.java",
"test/io/flutter/embedding/android/FlutterFragmentTest.java",
"test/io/flutter/embedding/android/FlutterTextureViewTest.java",
"test/io/flutter/embedding/android/FlutterViewTest.java",
"test/io/flutter/embedding/android/KeyChannelResponderTest.java",
"test/io/flutter/embedding/android/KeyboardManagerTest.java",
"test/io/flutter/embedding/android/RobolectricFlutterActivity.java",
"test/io/flutter/embedding/android/SplashShadowResources.java",
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.java",
"test/io/flutter/embedding/engine/FlutterEngineConnectionRegistryTest.java",
"test/io/flutter/embedding/engine/FlutterEngineGroupComponentTest.java",
"test/io/flutter/embedding/engine/FlutterEngineTest.java",
"test/io/flutter/embedding/engine/FlutterJNITest.java",
"test/io/flutter/embedding/engine/FlutterShellArgsTest.java",
"test/io/flutter/embedding/engine/PluginComponentTest.java",
"test/io/flutter/embedding/engine/RenderingComponentTest.java",
"test/io/flutter/embedding/engine/dart/DartExecutorTest.java",
"test/io/flutter/embedding/engine/dart/DartMessengerTest.java",
"test/io/flutter/embedding/engine/deferredcomponents/PlayStoreDeferredComponentManagerTest.java",
"test/io/flutter/embedding/engine/loader/ApplicationInfoLoaderTest.java",
"test/io/flutter/embedding/engine/loader/FlutterLoaderTest.java",
"test/io/flutter/embedding/engine/mutatorsstack/FlutterMutatorViewTest.java",
"test/io/flutter/embedding/engine/plugins/shim/ShimPluginRegistryTest.java",
"test/io/flutter/embedding/engine/renderer/FlutterRendererTest.java",
"test/io/flutter/embedding/engine/systemchannels/DeferredComponentChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/KeyEventChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java",
"test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java",
"test/io/flutter/external/FlutterLaunchTests.java",
"test/io/flutter/plugin/common/BinaryCodecTest.java",
"test/io/flutter/plugin/common/StandardMessageCodecTest.java",
"test/io/flutter/plugin/common/StandardMethodCodecTest.java",
"test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java",
"test/io/flutter/plugin/editing/ListenableEditingStateTest.java",
"test/io/flutter/plugin/editing/TextInputPluginTest.java",
"test/io/flutter/plugin/localization/LocalizationPluginTest.java",
"test/io/flutter/plugin/mouse/MouseCursorPluginTest.java",
"test/io/flutter/plugin/platform/PlatformPluginTest.java",
"test/io/flutter/plugin/platform/PlatformViewsControllerTest.java",
"test/io/flutter/plugin/platform/SingleViewPresentationTest.java",
"test/io/flutter/plugins/GeneratedPluginRegistrant.java",
"test/io/flutter/util/FakeKeyEvent.java",
"test/io/flutter/util/PreconditionsTest.java",
"test/io/flutter/util/ViewUtilsTest.java",
"test/io/flutter/view/AccessibilityBridgeTest.java",
]

outputs = [
depfile,
jar_path,
jar_path + ".md5.stamp",
]

additional_jar_files = [ "robolectric.properties" ]

_jar_dependencies = [
android_sdk_jar,
embedding_jar_path,
] + embedding_dependencies_jars

inputs = _jar_dependencies + additional_jar_files

_rebased_current_path = rebase_path(".")
_rebased_jar_path = rebase_path(jar_path, root_build_dir)
_rebased_depfile = rebase_path(depfile, root_build_dir)
_rebased_classpath = rebase_path(_jar_dependencies, root_build_dir)
_rebased_srcjars = rebase_path(_jar_dependencies, root_build_dir)
_rebased_additional_files = rebase_path(additional_jar_files, root_build_dir)

if (host_os == "mac") {
_javacbin =
rebase_path("//third_party/java/openjdk/Contents/Home/bin/javac")
_jarbin = rebase_path("//third_party/java/openjdk/Contents/Home/bin/jar")
} else if (host_os == "win") {
_javacbin = rebase_path("//third_party/java/openjdk/bin/javac.exe")
_jarbin = rebase_path("//third_party/java/openjdk/bin/jar.exe")
} else {
_javacbin = rebase_path("//third_party/java/openjdk/bin/javac")
_jarbin = rebase_path("//third_party/java/openjdk/bin/jar")
}

args = [
"--depfile=$_rebased_depfile",
"--jar-path=$_rebased_jar_path",
"--classpath=$_rebased_classpath",
"--jar-source-base-dir=$_rebased_current_path",
"--java-srcjars=$_rebased_srcjars",
"--additional-jar-files=$_rebased_additional_files",
"--jar-bin=$_jarbin",
"--javac-bin=$_javacbin",
]

args += rebase_path(sources, root_build_dir)

deps = [
":android_jar",
":flutter_shell_java",
]
# TODO(jsimmons): remove this placeholder when it is no longer used by the LUCI recipes
group("robolectric_tests") {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rule is useful to makerobolectric_tests depend on android_jar. Do you know if gn has something equivalent to bazel test :<target> or bazel run :<target>?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know of a specialized command like that. But I suppose you could create a GN target with an action that runs run_tests.py --type=java and a dependency on the Android engine JAR.

deps = [ ":android_jar" ]
}

zip_bundle("android_symbols") {
Expand Down Expand Up @@ -688,10 +577,4 @@ group("android") {
if (target_cpu != "x86") {
deps += [ ":gen_snapshot" ]
}

# We only run the robolectric tests for android_debug_unopt (arm CPU), and
# the target is relatively expensive to build.
if (flutter_runtime_mode == "debug" && current_cpu == "arm") {
deps += [ ":robolectric_tests" ]
}
}
4 changes: 0 additions & 4 deletions shell/platform/android/robolectric.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import io.flutter.embedding.engine.deferredcomponents.PlayStoreDeferredComponentManager;
import io.flutter.embedding.engine.loader.FlutterLoader;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -32,6 +33,11 @@ public void setUp() {
MockitoAnnotations.initMocks(this);
}

@After
public void tearDown() {
FlutterInjector.reset();
}

@Test
public void itHasSomeReasonableDefaults() {
// Implicitly builds when first accessed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
public class FlutterActivityTest {
@Before
public void setUp() {
FlutterInjector.reset();
GeneratedPluginRegistrant.clearRegisteredEngines();
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
when(mockFlutterJNI.isAttached()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.flutter.embedding.android;

import static android.os.Looper.getMainLooper;
import static io.flutter.embedding.android.FlutterActivityLaunchConfigs.HANDLE_DEEPLINKING_META_DATA_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -22,6 +21,7 @@
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.core.app.ActivityScenario;
import io.flutter.FlutterInjector;
import io.flutter.TestUtils;
import io.flutter.embedding.android.FlutterActivityLaunchConfigs.BackgroundMode;
Expand Down Expand Up @@ -93,29 +93,30 @@ protected RenderMode getRenderMode() {

@Test
public void itRegistersPluginsAtConfigurationTime() {
FlutterFragmentActivity activity =
Robolectric.buildActivity(FlutterFragmentActivity.class).get();
assertTrue(GeneratedPluginRegistrant.getRegisteredEngines().isEmpty());

// Calling onCreate on the FlutterFragmentActivity will create a FlutterFragment and
// commit it to the fragment manager. This attaches the fragment to the FlutterFragmentActivity
// creating and configuring the engine.
activity.onCreate(null);
shadowOf(getMainLooper()).idle();

List<FlutterEngine> registeredEngines = GeneratedPluginRegistrant.getRegisteredEngines();
assertEquals(1, registeredEngines.size());
assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
try (ActivityScenario<FlutterFragmentActivity> scenario =
ActivityScenario.launch(FlutterFragmentActivity.class)) {
scenario.onActivity(
activity -> {
List<FlutterEngine> registeredEngines =
GeneratedPluginRegistrant.getRegisteredEngines();
assertEquals(1, registeredEngines.size());
assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
});
}
}

@Test
public void itDoesNotRegisterPluginsTwiceWhenUsingACachedEngine() {
FlutterFragmentActivity activity =
Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get();
activity.onCreate(null);
shadowOf(getMainLooper()).idle();

activity.configureFlutterEngine(activity.getFlutterEngine());
try (ActivityScenario<FlutterFragmentActivity> scenario =
ActivityScenario.launch(FlutterFragmentActivity.class)) {
scenario.onActivity(
activity -> {
List<FlutterEngine> registeredEngines =
GeneratedPluginRegistrant.getRegisteredEngines();
assertEquals(1, registeredEngines.size());
assertEquals(activity.getFlutterEngine(), registeredEngines.get(0));
});
}

List<FlutterEngine> registeredEngines = GeneratedPluginRegistrant.getRegisteredEngines();
// This might cause the plugins to be registered twice, once by the FlutterEngine constructor,
Expand Down Expand Up @@ -184,16 +185,14 @@ public void itAllowsRootLayoutOverride() {

@Test
public void itCreatesAValidFlutterFragment() {
FlutterFragmentActivityWithProvidedEngine activity =
Robolectric.buildActivity(FlutterFragmentActivityWithProvidedEngine.class).get();

// Creating the FlutterFragmentActivity will create and attach the FlutterFragment, causing
// a FlutterEngine to be created.
activity.onCreate(null);
shadowOf(getMainLooper()).idle();

assertNotNull(activity.getFlutterEngine());
assertEquals(1, activity.numberOfEnginesCreated);
try (ActivityScenario<FlutterFragmentActivityWithProvidedEngine> scenario =
ActivityScenario.launch(FlutterFragmentActivityWithProvidedEngine.class)) {
scenario.onActivity(
activity -> {
assertNotNull(activity.getFlutterEngine());
assertEquals(1, activity.numberOfEnginesCreated);
});
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.flutter.embedding.engine.FlutterEngineCache;
import io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.loader.FlutterLoader;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
Expand Down Expand Up @@ -197,8 +198,14 @@ public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() {
.beginTransaction()
.add(android.R.id.content, fragment)
.commitNow();
OnBackPressedCallback callback = mock(OnBackPressedCallback.class);
when(callback.isEnabled()).thenReturn(true);
final AtomicBoolean onBackPressedCalled = new AtomicBoolean(false);
OnBackPressedCallback callback =
new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
onBackPressedCalled.set(true);
}
};
activity.getOnBackPressedDispatcher().addCallback(callback);

FlutterActivityAndFragmentDelegate mockDelegate =
Expand All @@ -208,6 +215,6 @@ public void itHandlesPopSystemNavigationAutomaticallyWhenEnabled() {
assertTrue(fragment.popSystemNavigator());

verify(mockDelegate, never()).onBackPressed();
verify(callback, times(1)).handleOnBackPressed();
assertTrue(onBackPressedCalled.get());
}
}
Loading