Skip to content

Commit

Permalink
Add support for --dart-flags in FlutterShellArgs. (flutter#44855) (fl…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll authored Nov 14, 2019
1 parent 7d6e376 commit 687a1a7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions shell/platform/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -91,6 +93,14 @@ public static FlutterShellArgs fromIntent(@NonNull Intent intent) {
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);
}

Expand Down
2 changes: 2 additions & 0 deletions shell/platform/android/test/io/flutter/FlutterTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;

Expand All @@ -36,6 +37,7 @@
FlutterEngineTest.class,
FlutterFragmentTest.class,
FlutterJNITest.class,
FlutterShellArgsTest.class,
FlutterRendererTest.class,
FlutterViewTest.class,
PlatformChannelTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -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]);
}
}

0 comments on commit 687a1a7

Please sign in to comment.