From a0797ce9dc7d7ec4db00d67fb5a52e2b09b60a3b Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Fri, 30 Aug 2019 22:49:33 -0700 Subject: [PATCH 1/6] Incorporate code review feedback from #11441 --- .../systemchannels/PlatformChannel.java | 276 +++++++++--------- .../systemchannels/PlatformChannelTest.java | 50 ++-- 2 files changed, 160 insertions(+), 166 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java index 0ad84d74db89b..5a1cbd38b23d4 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java @@ -36,7 +36,140 @@ public class PlatformChannel { private PlatformMessageHandler platformMessageHandler; @NonNull @VisibleForTesting - protected final PlatformMethodCallHandler parsingMethodCallHandler = new PlatformMethodCallHandler(); + protected final MethodChannel.MethodCallHandler parsingMethodCallHandler = new MethodChannel.MethodCallHandler() { + @Override + public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { + if (platformMessageHandler == null) { + // If no explicit PlatformMessageHandler has been registered then we don't + // need to forward this call to an API. Return. + return; + } + + String method = call.method; + Object arguments = call.arguments; + Log.v(TAG, "Received '" + method + "' message."); + try { + switch (method) { + case "SystemSound.play": + try { + SoundType soundType = SoundType.fromValue((String) arguments); + platformMessageHandler.playSystemSound(soundType); + result.success(null); + } catch (NoSuchFieldException exception) { + // The desired sound type does not exist. + result.error("error", exception.getMessage(), null); + } + break; + case "HapticFeedback.vibrate": + try { + HapticFeedbackType feedbackType = HapticFeedbackType.fromValue((String) arguments); + platformMessageHandler.vibrateHapticFeedback(feedbackType); + result.success(null); + } catch (NoSuchFieldException exception) { + // The desired feedback type does not exist. + result.error("error", exception.getMessage(), null); + } + break; + case "SystemChrome.setPreferredOrientations": + try { + int androidOrientation = decodeOrientations((JSONArray) arguments); + platformMessageHandler.setPreferredOrientations(androidOrientation); + result.success(null); + } catch (JSONException | NoSuchFieldException exception) { + // JSONException: One or more expected fields were either omitted or referenced an invalid type. + // NoSuchFieldException: One or more expected fields were either omitted or referenced an invalid type. + result.error("error", exception.getMessage(), null); + } + break; + case "SystemChrome.setApplicationSwitcherDescription": + try { + AppSwitcherDescription description = decodeAppSwitcherDescription((JSONObject) arguments); + platformMessageHandler.setApplicationSwitcherDescription(description); + result.success(null); + } catch (JSONException exception) { + // One or more expected fields were either omitted or referenced an invalid type. + result.error("error", exception.getMessage(), null); + } + break; + case "SystemChrome.setEnabledSystemUIOverlays": + try { + List overlays = decodeSystemUiOverlays((JSONArray) arguments); + platformMessageHandler.showSystemOverlays(overlays); + result.success(null); + } catch (JSONException | NoSuchFieldException exception) { + // JSONException: One or more expected fields were either omitted or referenced an invalid type. + // NoSuchFieldException: One or more of the overlay names are invalid. + result.error("error", exception.getMessage(), null); + } + break; + case "SystemChrome.restoreSystemUIOverlays": + platformMessageHandler.restoreSystemUiOverlays(); + result.success(null); + break; + case "SystemChrome.setSystemUIOverlayStyle": + try { + SystemChromeStyle systemChromeStyle = decodeSystemChromeStyle((JSONObject) arguments); + platformMessageHandler.setSystemUiOverlayStyle(systemChromeStyle); + result.success(null); + } catch (JSONException | NoSuchFieldException exception) { + // JSONException: One or more expected fields were either omitted or referenced an invalid type. + // NoSuchFieldException: One or more of the brightness names are invalid. + result.error("error", exception.getMessage(), null); + } + break; + case "SystemNavigator.pop": + platformMessageHandler.popSystemNavigator(); + result.success(null); + break; + case "SystemGestures.setSystemGestureExclusionRects": + if (!(arguments instanceof JSONArray)) { + String inputTypeError = "Input type is incorrect. Ensure that a List> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects."; + result.error("inputTypeError", inputTypeError, null); + break; + } + + JSONArray inputRects = (JSONArray) arguments; + ArrayList decodedRects = decodeRects(inputRects); + platformMessageHandler.setSystemGestureExclusionRects(decodedRects); + result.success(null); + break; + case "Clipboard.getData": { + String contentFormatName = (String) arguments; + ClipboardContentFormat clipboardFormat = null; + if (contentFormatName != null) { + try { + clipboardFormat = ClipboardContentFormat.fromValue(contentFormatName); + } catch (NoSuchFieldException exception) { + // An unsupported content format was requested. Return failure. + result.error("error", "No such clipboard content format: " + contentFormatName, null); + } + } + + CharSequence clipboardContent = platformMessageHandler.getClipboardData(clipboardFormat); + if (clipboardContent != null) { + JSONObject response = new JSONObject(); + response.put("text", clipboardContent); + result.success(response); + } else { + result.success(null); + } + break; + } + case "Clipboard.setData": { + String clipboardContent = ((JSONObject) arguments).getString("text"); + platformMessageHandler.setClipboardData(clipboardContent); + result.success(null); + break; + } + default: + result.notImplemented(); + break; + } + } catch (JSONException e) { + result.error("error", "JSON error: " + e.getMessage(), null); + } + } + }; /** * Constructs a {@code PlatformChannel} that connects Android to the Dart code @@ -503,147 +636,6 @@ public SystemChromeStyle( } } - /** - * A handler of incoming platform channel method calls received from Flutter. - * It first determines the platform's API to be called. If it exists, it then - * decodes incoming arguments, if needed, into a format that is necessary for the API. - */ - @VisibleForTesting - protected class PlatformMethodCallHandler implements MethodChannel.MethodCallHandler { - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result result) { - if (platformMessageHandler == null) { - // If no explicit PlatformMessageHandler has been registered then we don't - // need to forward this call to an API. Return. - return; - } - - String method = call.method; - Object arguments = call.arguments; - Log.v(TAG, "Received '" + method + "' message."); - try { - switch (method) { - case "SystemSound.play": - try { - SoundType soundType = SoundType.fromValue((String) arguments); - platformMessageHandler.playSystemSound(soundType); - result.success(null); - } catch (NoSuchFieldException exception) { - // The desired sound type does not exist. - result.error("error", exception.getMessage(), null); - } - break; - case "HapticFeedback.vibrate": - try { - HapticFeedbackType feedbackType = HapticFeedbackType.fromValue((String) arguments); - platformMessageHandler.vibrateHapticFeedback(feedbackType); - result.success(null); - } catch (NoSuchFieldException exception) { - // The desired feedback type does not exist. - result.error("error", exception.getMessage(), null); - } - break; - case "SystemChrome.setPreferredOrientations": - try { - int androidOrientation = decodeOrientations((JSONArray) arguments); - platformMessageHandler.setPreferredOrientations(androidOrientation); - result.success(null); - } catch (JSONException | NoSuchFieldException exception) { - // JSONException: One or more expected fields were either omitted or referenced an invalid type. - // NoSuchFieldException: One or more expected fields were either omitted or referenced an invalid type. - result.error("error", exception.getMessage(), null); - } - break; - case "SystemChrome.setApplicationSwitcherDescription": - try { - AppSwitcherDescription description = decodeAppSwitcherDescription((JSONObject) arguments); - platformMessageHandler.setApplicationSwitcherDescription(description); - result.success(null); - } catch (JSONException exception) { - // One or more expected fields were either omitted or referenced an invalid type. - result.error("error", exception.getMessage(), null); - } - break; - case "SystemChrome.setEnabledSystemUIOverlays": - try { - List overlays = decodeSystemUiOverlays((JSONArray) arguments); - platformMessageHandler.showSystemOverlays(overlays); - result.success(null); - } catch (JSONException | NoSuchFieldException exception) { - // JSONException: One or more expected fields were either omitted or referenced an invalid type. - // NoSuchFieldException: One or more of the overlay names are invalid. - result.error("error", exception.getMessage(), null); - } - break; - case "SystemChrome.restoreSystemUIOverlays": - platformMessageHandler.restoreSystemUiOverlays(); - result.success(null); - break; - case "SystemChrome.setSystemUIOverlayStyle": - try { - SystemChromeStyle systemChromeStyle = decodeSystemChromeStyle((JSONObject) arguments); - platformMessageHandler.setSystemUiOverlayStyle(systemChromeStyle); - result.success(null); - } catch (JSONException | NoSuchFieldException exception) { - // JSONException: One or more expected fields were either omitted or referenced an invalid type. - // NoSuchFieldException: One or more of the brightness names are invalid. - result.error("error", exception.getMessage(), null); - } - break; - case "SystemNavigator.pop": - platformMessageHandler.popSystemNavigator(); - result.success(null); - break; - case "SystemGestures.setSystemGestureExclusionRects": - if (!(arguments instanceof JSONArray)) { - String inputTypeError = "Input type is incorrect. Ensure that a List> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects."; - result.error("inputTypeError", inputTypeError, null); - break; - } - - JSONArray inputRects = (JSONArray) arguments; - ArrayList decodedRects = decodeRects(inputRects); - platformMessageHandler.setSystemGestureExclusionRects(decodedRects); - result.success(null); - break; - case "Clipboard.getData": { - String contentFormatName = (String) arguments; - ClipboardContentFormat clipboardFormat = null; - if (contentFormatName != null) { - try { - clipboardFormat = ClipboardContentFormat.fromValue(contentFormatName); - } catch (NoSuchFieldException exception) { - // An unsupported content format was requested. Return failure. - result.error("error", "No such clipboard content format: " + contentFormatName, null); - } - } - - CharSequence clipboardContent = platformMessageHandler.getClipboardData(clipboardFormat); - if (clipboardContent != null) { - JSONObject response = new JSONObject(); - response.put("text", clipboardContent); - result.success(response); - } else { - result.success(null); - } - break; - } - case "Clipboard.setData": { - String clipboardContent = ((JSONObject) arguments).getString("text"); - platformMessageHandler.setClipboardData(clipboardContent); - result.success(null); - break; - } - default: - result.notImplemented(); - break; - } - } catch (JSONException e) { - result.error("error", "JSON error: " + e.getMessage(), null); - } - } - } - public enum Brightness { LIGHT("Brightness.light"), DARK("Brightness.dark"); diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index 31d7d71c39fd8..9d0a6a824acf6 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -26,18 +26,19 @@ @RunWith(RobolectricTestRunner.class) public class PlatformChannelTest { @Test - public void setSystemExclusionRectsSendsSuccessMessageToFramework() throws JSONException { + public void itSendsSuccessMessageToFrameworkWhenSettingSystemGestureExclusionRects() throws JSONException { + // --- Test Setup --- DartExecutor dartExecutor = mock(DartExecutor.class); PlatformChannel platformChannel = new PlatformChannel(dartExecutor); PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); platformChannel.setPlatformMessageHandler(platformMessageHandler); + Result result = mock(Result.class); int top = 0; int right = 500; int bottom = 250; int left = 0; - ResultsMock resultsMock = mock(ResultsMock.class); JSONObject JsonRect = new JSONObject(); JsonRect.put("top", top); JsonRect.put("right", right); @@ -49,34 +50,40 @@ public void setSystemExclusionRectsSendsSuccessMessageToFramework() throws JSONE ArrayList expectedDecodedRects = new ArrayList(); Rect gestureRect = new Rect(left, top, right, bottom); expectedDecodedRects.add(gestureRect); - MethodCall callSystemGestureExclusionRects = new MethodCall( "SystemGestures.setSystemGestureExclusionRects", inputRects ); - platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); + // --- Execute Test --- + platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, result); + + // --- Verify Results --- verify(platformMessageHandler, times(1)).setSystemGestureExclusionRects(expectedDecodedRects); - verify(resultsMock, times(1)).success(null); + verify(result, times(1)).success(null); } @Test - public void setSystemExclusionRectsRequiresJSONArrayInput() { + public void itSendsJSONInputErrorWhenNonJSONInputIsUsedWhenSettingSystemGestureExclusionRects() { + // --- Test Setup --- DartExecutor dartExecutor = mock(DartExecutor.class); PlatformChannel platformChannel = new PlatformChannel(dartExecutor); PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); platformChannel.setPlatformMessageHandler(platformMessageHandler); + Result result = mock(Result.class); - ResultsMock resultsMock = mock(ResultsMock.class); String nonJsonInput = "Non-JSON"; MethodCall callSystemGestureExclusionRects = new MethodCall( "SystemGestures.setSystemGestureExclusionRects", nonJsonInput ); - platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); + // --- Execute Test --- + platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, result); + + // --- Verify Results --- String inputTypeError = "Input type is incorrect. Ensure that a List> is passed as the input for SystemGestureExclusionRects.setSystemGestureExclusionRects."; - verify(resultsMock, times(1)).error( + verify(result, times(1)).error( "inputTypeError", inputTypeError, null @@ -84,16 +91,18 @@ public void setSystemExclusionRectsRequiresJSONArrayInput() { } @Test - public void setSystemExclusionRectsSendsJSONExceptionOnIncorrectDataShape() throws JSONException { + public void itSendsJSONErrorWhenIncorrectJSONShapeIsUsedWhenSettingSystemGestureExclusionRects() throws JSONException { + // --- Test Setup --- DartExecutor dartExecutor = mock(DartExecutor.class); PlatformChannel platformChannel = new PlatformChannel(dartExecutor); PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); platformChannel.setPlatformMessageHandler(platformMessageHandler); + Result result = mock(Result.class); int top = 0; int right = 500; - ResultsMock resultsMock = mock(ResultsMock.class); + // Add key/value pairs that aren't needed by exclusion rects to simulate incorrect JSON shape JSONObject jsonObject = new JSONObject(); jsonObject.put("arg1", top); jsonObject.put("arg2", right); @@ -104,23 +113,16 @@ public void setSystemExclusionRectsSendsJSONExceptionOnIncorrectDataShape() thro "SystemGestures.setSystemGestureExclusionRects", inputArray ); - platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, resultsMock); - verify(resultsMock, times(1)).error( + + // --- Execute Test --- + platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, result); + + // --- Verify Results --- + verify(result, times(1)).error( "error", "JSON error: Incorrect JSON data shape. To set system gesture exclusion rects, \n" + "a JSONObject with top, right, bottom and left values need to be set to int values.", null ); } - - private class ResultsMock implements Result { - @Override - public void success(Object result) {} - - @Override - public void error(String errorCode, String errorMessage, Object errorDetails) {} - - @Override - public void notImplemented() {} - } } From d201d4e736bb836e27a8faded01bee9b8e09bb11 Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Fri, 30 Aug 2019 23:32:16 -0700 Subject: [PATCH 2/6] Improve decodeExclusionRects naming and javadoc --- .../engine/systemchannels/PlatformChannel.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java index 5a1cbd38b23d4..495691e049aa9 100644 --- a/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java +++ b/shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformChannel.java @@ -129,7 +129,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result } JSONArray inputRects = (JSONArray) arguments; - ArrayList decodedRects = decodeRects(inputRects); + ArrayList decodedRects = decodeExclusionRects(inputRects); platformMessageHandler.setSystemGestureExclusionRects(decodedRects); result.success(null); break; @@ -275,10 +275,17 @@ private int decodeOrientations(@NonNull JSONArray encodedOrientations) throws JS /** * Decodes a JSONArray of rectangle data into an ArrayList. * + * Since View.setSystemGestureExclusionRects receives a JSONArray containing + * JSONObjects, these values need to be transformed into the expected input + * of View.setSystemGestureExclusionRects, which is ArrayList. + * + * This method is used by the SystemGestures.setSystemGestureExclusionRects + * platform channel. + * * @throws JSONException if {@code inputRects} does not contain expected keys and value types. */ @NonNull - private ArrayList decodeRects(@NonNull JSONArray inputRects) throws JSONException { + private ArrayList decodeExclusionRects(@NonNull JSONArray inputRects) throws JSONException { ArrayList exclusionRects = new ArrayList(); for (int i = 0; i < inputRects.length(); i++) { JSONObject rect = inputRects.getJSONObject(i); From 3130248a844a3c12bfd9d5661df42ed15c8f35ff Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Tue, 3 Sep 2019 11:03:27 -0700 Subject: [PATCH 3/6] Split test for two behaviors into two separate tests for setSystemGestureExclusionRects success case --- .../systemchannels/PlatformChannelTest.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index 9d0a6a824acf6..055d21a8a3766 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -47,6 +47,40 @@ public void itSendsSuccessMessageToFrameworkWhenSettingSystemGestureExclusionRec JSONArray inputRects = new JSONArray(); inputRects.put(JsonRect); + MethodCall callSystemGestureExclusionRects = new MethodCall( + "SystemGestures.setSystemGestureExclusionRects", + inputRects + ); + + // --- Execute Test --- + platformChannel.parsingMethodCallHandler.onMethodCall(callSystemGestureExclusionRects, result); + + // --- Verify Results --- + verify(result, times(1)).success(null); + } + + @Test + public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects() throws JSONException { + // --- Test Setup --- + DartExecutor dartExecutor = mock(DartExecutor.class); + PlatformChannel platformChannel = new PlatformChannel(dartExecutor); + PlatformMessageHandler platformMessageHandler = mock(PlatformMessageHandler.class); + platformChannel.setPlatformMessageHandler(platformMessageHandler); + Result result = mock(Result.class); + + int top = 0; + int right = 500; + int bottom = 250; + int left = 0; + + JSONObject JsonRect = new JSONObject(); + JsonRect.put("top", top); + JsonRect.put("right", right); + JsonRect.put("bottom", bottom); + JsonRect.put("left", left); + JSONArray inputRects = new JSONArray(); + inputRects.put(JsonRect); + ArrayList expectedDecodedRects = new ArrayList(); Rect gestureRect = new Rect(left, top, right, bottom); expectedDecodedRects.add(gestureRect); @@ -60,7 +94,6 @@ public void itSendsSuccessMessageToFrameworkWhenSettingSystemGestureExclusionRec // --- Verify Results --- verify(platformMessageHandler, times(1)).setSystemGestureExclusionRects(expectedDecodedRects); - verify(result, times(1)).success(null); } @Test From c879cbb2d45f1b98c27db39ed0fbc8314f973dbd Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Tue, 3 Sep 2019 17:01:33 -0700 Subject: [PATCH 4/6] Code review feedback: Improved variable naming and usage --- .../systemchannels/PlatformChannelTest.java | 37 ++++++++----------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index 055d21a8a3766..b679bea7f688b 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -34,22 +34,17 @@ public void itSendsSuccessMessageToFrameworkWhenSettingSystemGestureExclusionRec platformChannel.setPlatformMessageHandler(platformMessageHandler); Result result = mock(Result.class); - int top = 0; - int right = 500; - int bottom = 250; - int left = 0; - - JSONObject JsonRect = new JSONObject(); - JsonRect.put("top", top); - JsonRect.put("right", right); - JsonRect.put("bottom", bottom); - JsonRect.put("left", left); - JSONArray inputRects = new JSONArray(); - inputRects.put(JsonRect); + JSONObject jsonRect = new JSONObject(); + jsonRect.put("top", 0); + jsonRect.put("right", 500); + jsonRect.put("bottom", 250); + jsonRect.put("left", 0); + JSONArray jsonExclusionRectsFromPlatform = new JSONArray(); + jsonExclusionRectsFromPlatform.put(jsonRect); MethodCall callSystemGestureExclusionRects = new MethodCall( "SystemGestures.setSystemGestureExclusionRects", - inputRects + jsonExclusionRectsFromPlatform ); // --- Execute Test --- @@ -73,20 +68,20 @@ public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects( int bottom = 250; int left = 0; - JSONObject JsonRect = new JSONObject(); - JsonRect.put("top", top); - JsonRect.put("right", right); - JsonRect.put("bottom", bottom); - JsonRect.put("left", left); - JSONArray inputRects = new JSONArray(); - inputRects.put(JsonRect); + JSONObject jsonRect = new JSONObject(); + jsonRect.put("top", 0); + jsonRect.put("right", 500); + jsonRect.put("bottom", 250); + jsonRect.put("left", 0); + JSONArray jsonExclusionRectsFromPlatform = new JSONArray(); + jsonExclusionRectsFromPlatform.put(jsonRect); ArrayList expectedDecodedRects = new ArrayList(); Rect gestureRect = new Rect(left, top, right, bottom); expectedDecodedRects.add(gestureRect); MethodCall callSystemGestureExclusionRects = new MethodCall( "SystemGestures.setSystemGestureExclusionRects", - inputRects + jsonExclusionRectsFromPlatform ); // --- Execute Test --- From 1f7bb41c97f7ddface62f29503cebb3df29f0631 Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Wed, 4 Sep 2019 15:25:44 -0700 Subject: [PATCH 5/6] Re-include accidentally removed comments on test execution and verification blocks --- .../embedding/engine/systemchannels/PlatformChannelTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index f3eeb6b8fa9d1..8acfa99e218e9 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -148,7 +148,10 @@ public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects( jsonExclusionRectsFromPlatform ); + // --- Execute Test --- platformChannel.parsingMethodCallHandler.onMethodCall(callSetSystemGestureExclusionRects, result); + + // --- Verify Results --- verify(platformMessageHandler, times(1)).setSystemGestureExclusionRects(expectedDecodedRects); } From 482a899e565a2ce560366b03c61ee515201188f6 Mon Sep 17 00:00:00 2001 From: Shi Hao Hong Date: Wed, 4 Sep 2019 16:06:16 -0700 Subject: [PATCH 6/6] Remove variables from tests --- .../engine/systemchannels/PlatformChannelTest.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java index 8acfa99e218e9..12473426f89bf 100644 --- a/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java +++ b/shell/platform/android/test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java @@ -126,11 +126,6 @@ public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects( platformChannel.setPlatformMessageHandler(platformMessageHandler); Result result = mock(Result.class); - int top = 0; - int right = 500; - int bottom = 250; - int left = 0; - JSONObject jsonRect = new JSONObject(); jsonRect.put("top", 0); jsonRect.put("right", 500); @@ -140,7 +135,7 @@ public void itProperlyDecodesGestureRectsWhenSettingSystemGestureExclusionRects( jsonExclusionRectsFromPlatform.put(jsonRect); ArrayList expectedDecodedRects = new ArrayList(); - Rect gestureRect = new Rect(left, top, right, bottom); + Rect gestureRect = new Rect(0, 0, 500, 250); expectedDecodedRects.add(gestureRect); MethodCall callSetSystemGestureExclusionRects = new MethodCall( @@ -191,13 +186,10 @@ public void itSendsJSONErrorWhenIncorrectJSONShapeIsUsedWhenSettingSystemGesture platformChannel.setPlatformMessageHandler(platformMessageHandler); Result result = mock(Result.class); - int top = 0; - int right = 500; - // Add key/value pairs that aren't needed by exclusion rects to simulate incorrect JSON shape JSONObject jsonObject = new JSONObject(); - jsonObject.put("arg1", top); - jsonObject.put("arg2", right); + jsonObject.put("arg1", 0); + jsonObject.put("arg2", 500); JSONArray inputArray = new JSONArray(); inputArray.put(jsonObject);