Flutter Engine
The Flutter Engine
SettingsChannelTest.java
Go to the documentation of this file.
1package io.flutter.embedding.engine.systemchannels;
2
3import static io.flutter.Build.API_LEVELS;
4import static junit.framework.TestCase.assertEquals;
5import static org.mockito.Mockito.eq;
6import static org.mockito.Mockito.isNull;
7import static org.mockito.Mockito.mock;
8import static org.mockito.Mockito.verify;
9
10import android.annotation.TargetApi;
11import android.util.DisplayMetrics;
12import androidx.test.ext.junit.runners.AndroidJUnit4;
13import io.flutter.embedding.engine.dart.DartExecutor;
14import io.flutter.plugin.common.BasicMessageChannel;
15import java.nio.ByteBuffer;
16import org.junit.Test;
17import org.junit.runner.RunWith;
18import org.mockito.ArgumentCaptor;
19import org.robolectric.annotation.Config;
20
21@Config(manifest = Config.NONE)
22@RunWith(AndroidJUnit4.class)
23public class SettingsChannelTest {
24 @Test
25 @TargetApi(API_LEVELS.API_33)
26 @Config(sdk = API_LEVELS.API_33)
27 @SuppressWarnings("deprecation")
28 // DartExecutor.send is deprecated.
29 public void setDisplayMetricsDoesNothingOnAPILevel33() {
30 final DartExecutor executor = mock(DartExecutor.class);
31 executor.onAttachedToJNI();
32 final SettingsChannel settingsChannel = new SettingsChannel(executor);
33
34 final ArgumentCaptor<ByteBuffer> messageCaptor = ArgumentCaptor.forClass(ByteBuffer.class);
35
36 settingsChannel.startMessage().setDisplayMetrics(mock(DisplayMetrics.class)).send();
37
38 verify(executor).send(eq("flutter/settings"), messageCaptor.capture(), isNull());
39 }
40
41 @Test
43 final SettingsChannel.ConfigurationQueue queue = new SettingsChannel.ConfigurationQueue();
44 final int baseId = Integer.MIN_VALUE;
45
46 queue.enqueueConfiguration(
47 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
48 queue.enqueueConfiguration(
49 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
50 assertEquals(baseId + 0, queue.getConfiguration(baseId + 0).generationNumber);
51 assertEquals(baseId + 1, queue.getConfiguration(baseId + 1).generationNumber);
52 assertEquals(baseId + 1, queue.getConfiguration(baseId + 1).generationNumber);
53
54 queue.enqueueConfiguration(
55 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
56 queue.enqueueConfiguration(
57 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
58 assertEquals(baseId + 3, queue.getConfiguration(baseId + 3).generationNumber);
59 // Can get the same configuration more than once.
60 assertEquals(baseId + 3, queue.getConfiguration(baseId + 3).generationNumber);
61
62 final BasicMessageChannel.Reply replyFor4 =
63 queue.enqueueConfiguration(
64 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
65 final BasicMessageChannel.Reply replyFor5 =
66 queue.enqueueConfiguration(
67 new SettingsChannel.ConfigurationQueue.SentConfiguration(mock(DisplayMetrics.class)));
68 replyFor4.reply(null);
69 replyFor5.reply(null);
70 assertEquals(baseId + 5, queue.getConfiguration(baseId + 5).generationNumber);
71 assertEquals(baseId + 5, queue.getConfiguration(baseId + 5).generationNumber);
72 }
73
74 // TODO(LongCatIsLooong): add tests for API 34 code path.
75 // https://github.com/flutter/flutter/issues/128825
76}
static bool eq(const SkM44 &a, const SkM44 &b, float tol)
Definition: M44Test.cpp:18
static final int API_33
Definition: Build.java:23
MessageBuilder setDisplayMetrics(@NonNull DisplayMetrics displayMetrics)
VkQueue queue
Definition: main.cc:55