Skip to content

Commit

Permalink
Reply to accessibility method call even if semantics is not enabled (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhtai authored Feb 2, 2022
1 parent 2c6464e commit 1ab6f71
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.Log;
import io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.dart.DartExecutor;
Expand All @@ -23,14 +24,16 @@ public class AccessibilityChannel {
@NonNull public final FlutterJNI flutterJNI;
@Nullable private AccessibilityMessageHandler handler;

private final BasicMessageChannel.MessageHandler<Object> parsingMessageHandler =
@VisibleForTesting
final BasicMessageChannel.MessageHandler<Object> parsingMessageHandler =
new BasicMessageChannel.MessageHandler<Object>() {
@Override
public void onMessage(
@Nullable Object message, @NonNull BasicMessageChannel.Reply<Object> reply) {
// If there is no handler to respond to this message then we don't need to
// parse it. Return.
if (handler == null) {
reply.reply(null);
return;
}

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 @@ -26,6 +26,7 @@
import io.flutter.embedding.engine.mutatorsstack.FlutterMutatorViewTest;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistryTest;
import io.flutter.embedding.engine.renderer.FlutterRendererTest;
import io.flutter.embedding.engine.systemchannels.AccessibilityChannelTest;
import io.flutter.embedding.engine.systemchannels.DeferredComponentChannelTest;
import io.flutter.embedding.engine.systemchannels.KeyEventChannelTest;
import io.flutter.embedding.engine.systemchannels.PlatformChannelTest;
Expand Down Expand Up @@ -56,6 +57,7 @@
@RunWith(Suite.class)
@SuiteClasses({
AccessibilityBridgeTest.class,
AccessibilityChannelTest.class,
ApplicationInfoLoaderTest.class,
BinaryCodecTest.class,
DartExecutorTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.flutter.embedding.engine.systemchannels;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.annotation.TargetApi;
import io.flutter.embedding.engine.FlutterJNI;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.BasicMessageChannel;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@Config(
manifest = Config.NONE,
shadows = {})
@RunWith(RobolectricTestRunner.class)
@TargetApi(24)
public class AccessibilityChannelTest {
@Test
public void repliesWhenNoAccessibilityHandler() throws JSONException {
AccessibilityChannel accessibilityChannel =
new AccessibilityChannel(mock(DartExecutor.class), mock(FlutterJNI.class));
JSONObject arguments = new JSONObject();
arguments.put("type", "announce");
BasicMessageChannel.Reply reply = mock(BasicMessageChannel.Reply.class);
accessibilityChannel.parsingMessageHandler.onMessage(arguments, reply);
verify(reply).reply(null);
}
}

0 comments on commit 1ab6f71

Please sign in to comment.