forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make BackgroundMode public. (flutter#45747) (flutter#14673)
- Loading branch information
1 parent
cef181f
commit a57823c
Showing
6 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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
34 changes: 34 additions & 0 deletions
34
shell/platform/android/test/io/flutter/embedding/android/RobolectricFlutterActivity.java
This file contains 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,34 @@ | ||
package io.flutter.embedding.android; | ||
|
||
import android.content.Intent; | ||
|
||
import org.robolectric.Robolectric; | ||
import org.robolectric.android.controller.ActivityController; | ||
|
||
/** | ||
* Creates a {@code FlutterActivity} for use by test code that do not sit | ||
* within the {@code io.flutter.embedding.android} package, and offers public | ||
* access to some package private properties of {@code FlutterActivity} for | ||
* testing purposes. | ||
*/ | ||
public class RobolectricFlutterActivity { | ||
/** | ||
* Creates a {@code FlutterActivity} that is controlled by Robolectric, which | ||
* otherwise can not be done in a test outside of the io.flutter.embedding.android | ||
* package. | ||
*/ | ||
public static FlutterActivity createFlutterActivity(Intent intent) { | ||
ActivityController<FlutterActivity> activityController = Robolectric.buildActivity(FlutterActivity.class, intent); | ||
FlutterActivity flutterActivity = activityController.get(); | ||
flutterActivity.setDelegate(new FlutterActivityAndFragmentDelegate(flutterActivity)); | ||
return flutterActivity; | ||
} | ||
|
||
/** | ||
* Returns a given {@code FlutterActivity}'s {@code BackgroundMode} for use by | ||
* tests that do not sit in the {@code io.flutter.embedding.android} package. | ||
*/ | ||
public static FlutterActivityLaunchConfigs.BackgroundMode getBackgroundMode(FlutterActivity activity) { | ||
return activity.getBackgroundMode(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
shell/platform/android/test/io/flutter/external/FlutterLaunchTests.java
This file contains 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,39 @@ | ||
package io.flutter.external; | ||
|
||
import android.content.Intent; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.RuntimeEnvironment; | ||
import org.robolectric.annotation.Config; | ||
|
||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.embedding.android.FlutterActivityLaunchConfigs.BackgroundMode; | ||
import io.flutter.embedding.android.FlutterView; | ||
import io.flutter.embedding.android.RobolectricFlutterActivity; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@Config(manifest=Config.NONE) | ||
@RunWith(RobolectricTestRunner.class) | ||
public class FlutterLaunchTests { | ||
@Test | ||
public void launchFlutterActivity_with_defaultIntent_expect_defaultConfiguration() { | ||
Intent intent = FlutterActivity.createDefaultIntent(RuntimeEnvironment.application); | ||
FlutterActivity flutterActivity = RobolectricFlutterActivity.createFlutterActivity(intent); | ||
|
||
assertEquals("main", flutterActivity.getDartEntrypointFunctionName()); | ||
assertEquals("/", flutterActivity.getInitialRoute()); | ||
assertArrayEquals(new String[]{}, flutterActivity.getFlutterShellArgs().toArray()); | ||
assertTrue(flutterActivity.shouldAttachEngineToActivity()); | ||
assertNull(flutterActivity.getCachedEngineId()); | ||
assertTrue(flutterActivity.shouldDestroyEngineWithHost()); | ||
assertEquals(BackgroundMode.opaque, RobolectricFlutterActivity.getBackgroundMode(flutterActivity)); | ||
assertEquals(FlutterView.RenderMode.surface, flutterActivity.getRenderMode()); | ||
assertEquals(FlutterView.TransparencyMode.opaque, flutterActivity.getTransparencyMode()); | ||
} | ||
} |
This file contains 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 @@ | ||
This `external` package exists to run tests in a package other than where the code under test is defined. This is offered for tests that need to verify that app devs, with their own packages, can reference and execute APIs that Flutter intends to be public. |