add back test itSendsTextShowPasswordToFrameworkOnAttach with new mock for display metrics (flutter/engine#55110)

Part 1/5 for re adding tests documented in flutter/flutter/issues/154746

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.
This commit is contained in:
Reid Baker
2024-09-13 13:45:37 -04:00
committed by GitHub
parent bb9035e847
commit 415f89e20a
3 changed files with 49 additions and 0 deletions

View File

@@ -21,6 +21,10 @@ integration tests in other repos.
4. Write your test.
5. Build and run with `testing/run_tests.py [--type=java] [--java-filter=<test_class_name>]`.
Example: from engine/src/flutter on a Mac
`et build -c android_debug_unopt_arm64`
`testing/run_tests.py --android-variant=android_debug_unopt_arm64 --type=java --java-filter=io.flutter.embedding.android.FlutterViewTest`
Note that `testing/run_tests.py` does not build the engine binaries; instead they
should be built prior to running this command and also when the source files
change. See [Compiling the engine](https://github.com/flutter/flutter/wiki/Compiling-the-engine)

View File

@@ -32,6 +32,7 @@ import android.media.Image.Plane;
import android.media.ImageReader;
import android.os.Build;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.view.DisplayCutout;
import android.view.Surface;
import android.view.View;
@@ -881,6 +882,47 @@ public class FlutterViewTest {
assertEquals(null, flutterView.findViewByAccessibilityIdTraversal(accessibilityViewId));
}
@SuppressWarnings("deprecation")
// Robolectric.setupActivity
@Test
public void itSendsTextShowPasswordToFrameworkOnAttach() {
// Setup test.
AtomicReference<Boolean> reportedShowPassword = new AtomicReference<>();
FlutterView flutterView = new FlutterView(Robolectric.setupActivity(Activity.class));
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));
Settings.System.putInt(
flutterView.getContext().getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 1);
SettingsChannel fakeSettingsChannel = mock(SettingsChannel.class);
SettingsChannel.MessageBuilder fakeMessageBuilder = mock(SettingsChannel.MessageBuilder.class);
when(fakeMessageBuilder.setTextScaleFactor(any(Float.class))).thenReturn(fakeMessageBuilder);
when(fakeMessageBuilder.setDisplayMetrics(any(DisplayMetrics.class)))
.thenReturn(fakeMessageBuilder);
when(fakeMessageBuilder.setNativeSpellCheckServiceDefined(any(Boolean.class)))
.thenReturn(fakeMessageBuilder);
when(fakeMessageBuilder.setPlatformBrightness(any(SettingsChannel.PlatformBrightness.class)))
.thenReturn(fakeMessageBuilder);
when(fakeMessageBuilder.setUse24HourFormat(any(Boolean.class))).thenReturn(fakeMessageBuilder);
when(fakeMessageBuilder.setBrieflyShowPassword(any(Boolean.class)))
.thenAnswer(
new Answer<SettingsChannel.MessageBuilder>() {
@Override
public SettingsChannel.MessageBuilder answer(InvocationOnMock invocation)
throws Throwable {
reportedShowPassword.set((Boolean) invocation.getArguments()[0]);
return fakeMessageBuilder;
}
});
when(fakeSettingsChannel.startMessage()).thenReturn(fakeMessageBuilder);
when(flutterEngine.getSettingsChannel()).thenReturn(fakeSettingsChannel);
flutterView.attachToFlutterEngine(flutterEngine);
// Verify results.
assertTrue(reportedShowPassword.get());
}
public void ViewportMetrics_initializedPhysicalTouchSlop() {
FlutterView flutterView = new FlutterView(ctx);
FlutterEngine flutterEngine = spy(new FlutterEngine(ctx, mockFlutterLoader, mockFlutterJni));

View File

@@ -1282,6 +1282,9 @@ Flutter Wiki page on the subject: https://github.com/flutter/flutter/wiki/Testin
else:
types = args.type.split(',')
if 'android' in args.variant:
print('Warning: using "android" in variant. Did you mean to use --android-variant?')
build_dir = os.path.join(OUT_DIR, args.variant)
if args.type != 'java' and args.type != 'android':
assert os.path.exists(build_dir), 'Build variant directory %s does not exist!' % build_dir