Add support for --dart-flags in FlutterShellArgs. (#44855) (flutter/engine#13855)

This commit is contained in:
Matt Carroll
2019-11-14 04:09:08 +00:00
committed by GitHub
parent 67646517b9
commit be849d1363
4 changed files with 43 additions and 0 deletions

View File

@@ -422,6 +422,7 @@ action("robolectric_tests") {
"test/io/flutter/embedding/engine/FlutterEngineCacheTest.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",

View File

@@ -44,6 +44,8 @@ public class FlutterShellArgs {
public static final String ARG_VERBOSE_LOGGING = "--verbose-logging";
public static final String ARG_KEY_OBSERVATORY_PORT = "observatory-port";
public static final String ARG_OBSERVATORY_PORT = "--observatory-port=";
public static final String ARG_KEY_DART_FLAGS = "dart-flags";
public static final String ARG_DART_FLAGS = "--dart-flags";
@NonNull
public static FlutterShellArgs fromIntent(@NonNull Intent intent) {
@@ -91,6 +93,14 @@ public class FlutterShellArgs {
args.add(ARG_VERBOSE_LOGGING);
}
// NOTE: all flags provided with this argument are subject to filtering
// based on a whitelist in shell/common/switches.cc. If any flag provided
// is not present in the whitelist, the process will immediately
// terminate.
if (intent.hasExtra(ARG_KEY_DART_FLAGS)) {
args.add(ARG_DART_FLAGS + "=" + intent.getStringExtra(ARG_KEY_DART_FLAGS));
}
return new FlutterShellArgs(args);
}

View File

@@ -23,6 +23,7 @@ import io.flutter.plugin.editing.TextInputPluginTest;
import io.flutter.plugin.platform.SingleViewPresentationTest;
import io.flutter.util.PreconditionsTest;
import test.io.flutter.embedding.engine.FlutterEngineTest;
import test.io.flutter.embedding.engine.FlutterShellArgsTest;
import test.io.flutter.embedding.engine.PluginComponentTest;
import test.io.flutter.embedding.engine.dart.DartExecutorTest;
@@ -36,6 +37,7 @@ import test.io.flutter.embedding.engine.dart.DartExecutorTest;
FlutterEngineTest.class,
FlutterFragmentTest.class,
FlutterJNITest.class,
FlutterShellArgsTest.class,
FlutterRendererTest.class,
FlutterViewTest.class,
PlatformChannelTest.class,

View File

@@ -0,0 +1,30 @@
package test.io.flutter.embedding.engine;
import android.content.Intent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import io.flutter.embedding.engine.FlutterShellArgs;
import static org.junit.Assert.assertEquals;
@Config(manifest=Config.NONE)
@RunWith(RobolectricTestRunner.class)
public class FlutterShellArgsTest {
@Test
public void itProcessesDartFlags() {
// Setup the test.
Intent intent = new Intent();
intent.putExtra("dart-flags", "--observe --no-hot --no-pub");
// Execute the behavior under test.
FlutterShellArgs args = FlutterShellArgs.fromIntent(intent);
// Verify results.
assertEquals(1, args.toArray().length);
assertEquals("--dart-flags=--observe --no-hot --no-pub", args.toArray()[0]);
}
}