Delete window_hooks_integration_test.dart (flutter/engine#26756)

This commit is contained in:
Dan Field
2021-06-18 12:24:02 -07:00
committed by GitHub
parent 8c208005c3
commit 255c177a14
6 changed files with 452 additions and 445 deletions

View File

@@ -329,6 +329,7 @@ FILE: ../../../flutter/lib/ui/geometry.dart
FILE: ../../../flutter/lib/ui/hash_codes.dart
FILE: ../../../flutter/lib/ui/hint_freed_delegate.h
FILE: ../../../flutter/lib/ui/hooks.dart
FILE: ../../../flutter/lib/ui/hooks_unittests.cc
FILE: ../../../flutter/lib/ui/io_manager.h
FILE: ../../../flutter/lib/ui/isolate_name_server.dart
FILE: ../../../flutter/lib/ui/isolate_name_server/isolate_name_server.cc

View File

@@ -202,6 +202,7 @@ if (enable_unittests) {
sources = [
"compositing/scene_builder_unittests.cc",
"hooks_unittests.cc",
"painting/image_dispose_unittests.cc",
"painting/image_encoding_unittests.cc",
"painting/image_generator_registry_unittests.cc",

View File

@@ -0,0 +1,11 @@
# ui_unittest Fixtures
The files in this directory are used by the ui_unittests binary.
The `ui_test.dart` file is either JIT or AOT compiled depending on the runtime
mode of the test binary. Other files in this folder are used by tests to verify
functionality.
See `//lib/ui/BUILD.gn` and `//testing/testing.gni` for the build rules and
GN template definitions that determine which files get included and compiled
here.

View File

@@ -1,4 +1,3 @@
// @dart = 2.6
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -288,3 +287,358 @@ Future<void> pumpImage() async {
}
void _captureImageAndPicture(Image image, Picture picture) native 'CaptureImageAndPicture';
Future<void> _onBeginFrameDone() native 'OnBeginFrameDone';
@pragma('vm:entry-point')
void hooksTests() {
void test(String name, VoidCallback testFunction) {
try {
testFunction();
} catch (e) {
print('Test "$name" failed!');
rethrow;
}
}
void expectEquals(Object? value, Object? expected) {
if (value != expected) {
throw 'Expected $value to be $expected.';
}
}
void expectIdentical(Zone originalZone, Zone callbackZone) {
if (!identical(callbackZone, originalZone)) {
throw 'Callback called in wrong zone.';
}
}
test('onMetricsChanged preserves callback zone', () {
late Zone originalZone;
late Zone callbackZone;
late double devicePixelRatio;
runZoned(() {
originalZone = Zone.current;
window.onMetricsChanged = () {
callbackZone = Zone.current;
devicePixelRatio = window.devicePixelRatio;
};
});
window.onMetricsChanged!();
_callHook(
'_updateWindowMetrics',
16,
0, // window Id
0.1234, // device pixel ratio
0.0, // width
0.0, // height
0.0, // padding top
0.0, // padding right
0.0, // padding bottom
0.0, // padding left
0.0, // inset top
0.0, // inset right
0.0, // inset bottom
0.0, // inset left
0.0, // system gesture inset top
0.0, // system gesture inset right
0.0, // system gesture inset bottom
0.0, // system gesture inset left
);
expectIdentical(originalZone, callbackZone);
if (devicePixelRatio != 0.1234) {
throw 'Expected devicePixelRatio to be 0.1234 but got $devicePixelRatio.';
}
});
test('updateUserSettings can handle an empty object', () {
_callHook('_updateUserSettingsData', 1, '{}');
});
test('PlatformDispatcher.locale returns unknown locale when locales is set to empty list', () {
late Locale locale;
int callCount = 0;
runZoned(() {
window.onLocaleChanged = () {
locale = PlatformDispatcher.instance.locale;
callCount += 1;
};
});
const Locale fakeLocale = Locale.fromSubtags(languageCode: '1', countryCode: '2', scriptCode: '3');
_callHook('_updateLocales', 1, <String>[fakeLocale.languageCode, fakeLocale.countryCode!, fakeLocale.scriptCode!, '']);
if (callCount != 1) {
throw 'Expected 1 call, have $callCount';
}
if (locale != fakeLocale) {
throw 'Expected $locale to match $fakeLocale';
}
_callHook('_updateLocales', 1, <String>[]);
if (callCount != 2) {
throw 'Expected 2 calls, have $callCount';
}
if (locale != const Locale.fromSubtags()) {
throw '$locale did not equal ${Locale.fromSubtags()}';
}
if (locale.languageCode != 'und') {
throw '${locale.languageCode} did not equal "und"';
}
});
test('Window padding/insets/viewPadding/systemGestureInsets', () {
_callHook(
'_updateWindowMetrics',
16,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // pattingLeft
0.0, // insetTop
0.0, // insetRight
0.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
0.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
);
expectEquals(window.viewInsets.bottom, 0.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 40.0);
expectEquals(window.systemGestureInsets.bottom, 0.0);
_callHook(
'_updateWindowMetrics',
16,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // pattingLeft
0.0, // insetTop
0.0, // insetRight
400.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
44.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
);
expectEquals(window.viewInsets.bottom, 400.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 0.0);
expectEquals(window.systemGestureInsets.bottom, 44.0);
});
test('onLocaleChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
Locale? locale;
runZoned(() {
innerZone = Zone.current;
window.onLocaleChanged = () {
runZone = Zone.current;
locale = window.locale;
};
});
_callHook('_updateLocales', 1, <String>['en', 'US', '', '']);
expectIdentical(runZone, innerZone);
expectEquals(locale, const Locale('en', 'US'));
});
test('onBeginFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late Duration start;
runZoned(() {
innerZone = Zone.current;
window.onBeginFrame = (Duration value) {
runZone = Zone.current;
start = value;
};
});
_callHook('_beginFrame', 1, 1234);
expectIdentical(runZone, innerZone);
expectEquals(start, const Duration(microseconds: 1234));
});
test('onDrawFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
runZoned(() {
innerZone = Zone.current;
window.onDrawFrame = () {
runZone = Zone.current;
};
});
_callHook('_drawFrame');
expectIdentical(runZone, innerZone);
});
test('onReportTimings preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
runZoned(() {
innerZone = Zone.current;
window.onReportTimings = (List<FrameTiming> timings) {
runZone = Zone.current;
};
});
_callHook('_reportTimings', 1, <int>[]);
expectIdentical(runZone, innerZone);
});
test('onPointerDataPacket preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late PointerDataPacket data;
runZoned(() {
innerZone = Zone.current;
window.onPointerDataPacket = (PointerDataPacket value) {
runZone = Zone.current;
data = value;
};
});
final ByteData testData = ByteData.view(Uint8List(0).buffer);
_callHook('_dispatchPointerDataPacket', 1, testData);
expectIdentical(runZone, innerZone);
expectEquals(data.data.length, 0);
});
test('onSemanticsEnabledChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late bool enabled;
runZoned(() {
innerZone = Zone.current;
window.onSemanticsEnabledChanged = () {
runZone = Zone.current;
enabled = window.semanticsEnabled;
};
});
final bool newValue = !window.semanticsEnabled; // needed?
_callHook('_updateSemanticsEnabled', 1, newValue);
expectIdentical(runZone, innerZone);
expectEquals(enabled, newValue);
});
test('onSemanticsAction preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late int id;
late int action;
runZoned(() {
innerZone = Zone.current;
window.onSemanticsAction = (int i, SemanticsAction a, ByteData? _) {
runZone = Zone.current;
action = a.index;
id = i;
};
});
_callHook('_dispatchSemanticsAction', 3, 1234, 4, null);
expectIdentical(runZone, innerZone);
expectEquals(id, 1234);
expectEquals(action, 4);
});
test('onPlatformMessage preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late String name;
runZoned(() {
innerZone = Zone.current;
window.onPlatformMessage = (String value, _, __) {
runZone = Zone.current;
name = value;
};
});
_callHook('_dispatchPlatformMessage', 3, 'testName', null, 123456789);
expectIdentical(runZone, innerZone);
expectEquals(name, 'testName');
});
test('onTextScaleFactorChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZoneTextScaleFactor;
late Zone runZonePlatformBrightness;
late double? textScaleFactor;
late Brightness? platformBrightness;
runZoned(() {
innerZone = Zone.current;
window.onTextScaleFactorChanged = () {
runZoneTextScaleFactor = Zone.current;
textScaleFactor = window.textScaleFactor;
};
window.onPlatformBrightnessChanged = () {
runZonePlatformBrightness = Zone.current;
platformBrightness = window.platformBrightness;
};
});
window.onTextScaleFactorChanged!();
_callHook('_updateUserSettingsData', 1, '{"textScaleFactor": 0.5, "platformBrightness": "light", "alwaysUse24HourFormat": true}');
expectIdentical(runZoneTextScaleFactor, innerZone);
expectEquals(textScaleFactor, 0.5);
textScaleFactor = null;
platformBrightness = null;
window.onPlatformBrightnessChanged!();
_callHook('_updateUserSettingsData', 1, '{"textScaleFactor": 0.5, "platformBrightness": "dark", "alwaysUse24HourFormat": true}');
expectIdentical(runZonePlatformBrightness, innerZone);
expectEquals(platformBrightness, Brightness.dark);
});
_finish();
}
void _callHook(
String name, [
int argCount = 0,
Object? arg0,
Object? arg1,
Object? arg2,
Object? arg3,
Object? arg4,
Object? arg5,
Object? arg6,
Object? arg8,
Object? arg9,
Object? arg10,
Object? arg11,
Object? arg12,
Object? arg13,
Object? arg14,
Object? arg15,
Object? arg16,
]) native 'CallHook';

View File

@@ -0,0 +1,84 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include "flutter/common/task_runners.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/shell_test.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/testing/testing.h"
#include "third_party/dart/runtime/include/dart_api.h"
namespace flutter {
namespace testing {
using HooksTest = ShellTest;
#define CHECK_DART_ERROR(name) \
EXPECT_FALSE(Dart_IsError(name)) << Dart_GetError(name)
TEST_F(HooksTest, HooksUnitTests) {
auto settings = CreateSettingsForFixture();
TaskRunners task_runners(GetCurrentTestName(), // label
GetCurrentTaskRunner(), // platform
CreateNewThread("raster"), // raster
CreateNewThread("ui"), // ui
CreateNewThread("io") // io
);
auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
std::unique_ptr<Shell> shell =
CreateShell(std::move(settings), std::move(task_runners));
ASSERT_TRUE(shell->IsSetup());
auto call_hook = [](Dart_NativeArguments args) {
Dart_Handle hook_name = Dart_GetNativeArgument(args, 0);
CHECK_DART_ERROR(hook_name);
Dart_Handle ui_library = Dart_LookupLibrary(tonic::ToDart("dart:ui"));
CHECK_DART_ERROR(ui_library);
Dart_Handle hook = Dart_GetField(ui_library, hook_name);
CHECK_DART_ERROR(hook);
Dart_Handle arg_count_handle = Dart_GetNativeArgument(args, 1);
CHECK_DART_ERROR(arg_count_handle);
int64_t arg_count;
Dart_IntegerToInt64(arg_count_handle, &arg_count);
Dart_Handle hook_args[arg_count];
for (int i = 0; i < static_cast<int>(arg_count); i++) {
hook_args[i] = Dart_GetNativeArgument(args, 2 + i);
CHECK_DART_ERROR(hook_args[i]);
}
Dart_Handle hook_result =
Dart_InvokeClosure(hook, static_cast<int>(arg_count), hook_args);
CHECK_DART_ERROR(hook_result);
};
auto finished = [&message_latch](Dart_NativeArguments args) {
message_latch->Signal();
};
AddNativeCallback("CallHook", CREATE_NATIVE_ENTRY(call_hook));
AddNativeCallback("Finish", CREATE_NATIVE_ENTRY(finished));
auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("hooksTests");
shell->RunEngine(std::move(configuration), [](auto result) {
ASSERT_EQ(result, Engine::RunStatus::Success);
});
message_latch->Wait();
DestroyShell(std::move(shell), std::move(task_runners));
}
} // namespace testing
} // namespace flutter

View File

@@ -1,444 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.12
// HACK: pretend to be dart.ui in order to access its internals
library dart.ui;
import 'dart:async';
// this needs to be imported because painting.dart expects it this way
import 'dart:collection' as collection;
import 'dart:convert';
import 'dart:developer' as developer;
import 'dart:math' as math;
import 'dart:io' show InternetAddress;
import 'dart:nativewrappers';
import 'dart:typed_data';
// HACK: these parts are to get access to private functions tested here.
part '../../lib/ui/annotations.dart';
part '../../lib/ui/channel_buffers.dart';
part '../../lib/ui/compositing.dart';
part '../../lib/ui/geometry.dart';
part '../../lib/ui/hash_codes.dart';
part '../../lib/ui/hooks.dart';
part '../../lib/ui/key.dart';
part '../../lib/ui/lerp.dart';
part '../../lib/ui/natives.dart';
part '../../lib/ui/painting.dart';
part '../../lib/ui/platform_dispatcher.dart';
part '../../lib/ui/pointer.dart';
part '../../lib/ui/semantics.dart';
part '../../lib/ui/text.dart';
part '../../lib/ui/window.dart';
void main() {
VoidCallback? originalOnMetricsChanged;
VoidCallback? originalOnLocaleChanged;
FrameCallback? originalOnBeginFrame;
VoidCallback? originalOnDrawFrame;
TimingsCallback? originalOnReportTimings;
PointerDataPacketCallback? originalOnPointerDataPacket;
VoidCallback? originalOnSemanticsEnabledChanged;
SemanticsActionCallback? originalOnSemanticsAction;
PlatformMessageCallback? originalOnPlatformMessage;
VoidCallback? originalOnTextScaleFactorChanged;
Object? oldWindowId;
double? oldDevicePixelRatio;
Rect? oldGeometry;
WindowPadding? oldPadding;
WindowPadding? oldInsets;
WindowPadding? oldSystemGestureInsets;
void setUp() {
PlatformDispatcher.instance._viewConfigurations.clear();
PlatformDispatcher.instance._views.clear();
PlatformDispatcher.instance._viewConfigurations[0] = const ViewConfiguration();
PlatformDispatcher.instance._views[0] = FlutterWindow._(0, PlatformDispatcher.instance);
oldWindowId = window._windowId;
oldDevicePixelRatio = window.devicePixelRatio;
oldGeometry = window.viewConfiguration.geometry;
oldPadding = window.viewPadding;
oldInsets = window.viewInsets;
oldSystemGestureInsets = window.systemGestureInsets;
originalOnMetricsChanged = window.onMetricsChanged;
originalOnLocaleChanged = window.onLocaleChanged;
originalOnBeginFrame = window.onBeginFrame;
originalOnDrawFrame = window.onDrawFrame;
originalOnReportTimings = window.onReportTimings;
originalOnPointerDataPacket = window.onPointerDataPacket;
originalOnSemanticsEnabledChanged = window.onSemanticsEnabledChanged;
originalOnSemanticsAction = window.onSemanticsAction;
originalOnPlatformMessage = window.onPlatformMessage;
originalOnTextScaleFactorChanged = window.onTextScaleFactorChanged;
}
tearDown() {
_updateWindowMetrics(
oldWindowId!, // window id
oldDevicePixelRatio!, // device pixel ratio
oldGeometry!.width, // width
oldGeometry!.height, // height
oldPadding!.top, // padding top
oldPadding!.right, // padding right
oldPadding!.bottom, // padding bottom
oldPadding!.left, // padding left
oldInsets!.top, // inset top
oldInsets!.right, // inset right
oldInsets!.bottom, // inset bottom
oldInsets!.left, // inset left
oldSystemGestureInsets!.top, // system gesture inset top
oldSystemGestureInsets!.right, // system gesture inset right
oldSystemGestureInsets!.bottom, // system gesture inset bottom
oldSystemGestureInsets!.left, // system gesture inset left
);
window.onMetricsChanged = originalOnMetricsChanged;
window.onLocaleChanged = originalOnLocaleChanged;
window.onBeginFrame = originalOnBeginFrame;
window.onDrawFrame = originalOnDrawFrame;
window.onReportTimings = originalOnReportTimings;
window.onPointerDataPacket = originalOnPointerDataPacket;
window.onSemanticsEnabledChanged = originalOnSemanticsEnabledChanged;
window.onSemanticsAction = originalOnSemanticsAction;
window.onPlatformMessage = originalOnPlatformMessage;
window.onTextScaleFactorChanged = originalOnTextScaleFactorChanged;
}
void test(String description, void Function() testFunction) {
print(description);
setUp();
testFunction();
tearDown();
}
void expectEquals(dynamic actual, dynamic expected) {
if (actual != expected) {
throw Exception('Equality check failed:\n Expected: $expected\n Actual: $actual');
}
}
void expectIterablesEqual(Iterable<dynamic> actual, Iterable<dynamic> expected) {
expectEquals(actual.length, expected.length);
final Iterator<dynamic> actualIter = actual.iterator;
final Iterator<dynamic> expectedIter = expected.iterator;
while (expectedIter.moveNext()) {
expectEquals(actualIter.moveNext(), true);
expectEquals(actualIter.current, expectedIter.current);
}
expectEquals(actualIter.moveNext(), false);
}
void expectNotEquals(dynamic actual, dynamic expected) {
if (actual == expected) {
throw Exception('Inequality check failed:\n Expected: $expected\n Actual: $actual');
}
}
void expectIdentical(dynamic actual, dynamic expected) {
if (!identical(actual, expected)) {
throw Exception('Identity check failed:\n Expected: $expected\n Actual: $actual');
}
}
test('updateUserSettings can handle an empty object', () {
// this should not throw.
_updateUserSettingsData('{}');
});
test('onMetricsChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late double devicePixelRatio;
runZoned(() {
innerZone = Zone.current;
window.onMetricsChanged = () {
runZone = Zone.current;
devicePixelRatio = window.devicePixelRatio;
};
});
window.onMetricsChanged!();
_updateWindowMetrics(
0, // window id
0.1234, // device pixel ratio
0.0, // width
0.0, // height
0.0, // padding top
0.0, // padding right
0.0, // padding bottom
0.0, // padding left
0.0, // inset top
0.0, // inset right
0.0, // inset bottom
0.0, // inset left
0.0, // system gesture inset top
0.0, // system gesture inset right
0.0, // system gesture inset bottom
0.0, // system gesture inset left
);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(devicePixelRatio, 0.1234);
});
test('onLocaleChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
Locale? locale;
runZoned(() {
innerZone = Zone.current;
window.onLocaleChanged = () {
runZone = Zone.current;
locale = window.locale;
};
});
_updateLocales(<String>['en', 'US', '', '']);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(locale, const Locale('en', 'US'));
});
test('onBeginFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late Duration start;
runZoned(() {
innerZone = Zone.current;
window.onBeginFrame = (Duration value) {
runZone = Zone.current;
start = value;
};
});
_beginFrame(1234);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(start, const Duration(microseconds: 1234));
});
test('onDrawFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
runZoned(() {
innerZone = Zone.current;
window.onDrawFrame = () {
runZone = Zone.current;
};
});
_drawFrame();
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
});
test('onReportTimings preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
PlatformDispatcher.instance._setNeedsReportTimings = (bool _) {};
runZoned(() {
innerZone = Zone.current;
window.onReportTimings = (List<FrameTiming> timings) {
runZone = Zone.current;
};
});
_reportTimings(<int>[]);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
});
test('onPointerDataPacket preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late PointerDataPacket data;
runZoned(() {
innerZone = Zone.current;
window.onPointerDataPacket = (PointerDataPacket value) {
runZone = Zone.current;
data = value;
};
});
final ByteData testData = ByteData.view(Uint8List(0).buffer);
_dispatchPointerDataPacket(testData);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectIterablesEqual(data.data, PlatformDispatcher._unpackPointerDataPacket(testData).data);
});
test('onSemanticsEnabledChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late bool enabled;
runZoned(() {
innerZone = Zone.current;
window.onSemanticsEnabledChanged = () {
runZone = Zone.current;
enabled = window.semanticsEnabled;
};
});
final bool newValue = !window.semanticsEnabled; // needed?
_updateSemanticsEnabled(newValue);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectNotEquals(enabled, null);
expectEquals(enabled, newValue);
});
test('onSemanticsAction preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late int id;
late int action;
runZoned(() {
innerZone = Zone.current;
window.onSemanticsAction = (int i, SemanticsAction a, ByteData? _) {
runZone = Zone.current;
action = a.index;
id = i;
};
});
_dispatchSemanticsAction(1234, 4, null);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(id, 1234);
expectEquals(action, 4);
});
test('onPlatformMessage preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late String name;
runZoned(() {
innerZone = Zone.current;
window.onPlatformMessage = (String value, _, __) {
runZone = Zone.current;
name = value;
};
});
_dispatchPlatformMessage('testName', null, 123456789);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(name, 'testName');
});
test('onTextScaleFactorChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZoneTextScaleFactor;
late Zone runZonePlatformBrightness;
late double? textScaleFactor;
late Brightness? platformBrightness;
runZoned(() {
innerZone = Zone.current;
window.onTextScaleFactorChanged = () {
runZoneTextScaleFactor = Zone.current;
textScaleFactor = window.textScaleFactor;
};
window.onPlatformBrightnessChanged = () {
runZonePlatformBrightness = Zone.current;
platformBrightness = window.platformBrightness;
};
});
window.onTextScaleFactorChanged!();
_updateUserSettingsData('{"textScaleFactor": 0.5, "platformBrightness": "light", "alwaysUse24HourFormat": true}');
expectNotEquals(runZoneTextScaleFactor, null);
expectIdentical(runZoneTextScaleFactor, innerZone);
expectEquals(textScaleFactor, 0.5);
textScaleFactor = null;
platformBrightness = null;
window.onPlatformBrightnessChanged!();
_updateUserSettingsData('{"textScaleFactor": 0.5, "platformBrightness": "dark", "alwaysUse24HourFormat": true}');
expectNotEquals(runZonePlatformBrightness, null);
expectIdentical(runZonePlatformBrightness, innerZone);
expectEquals(platformBrightness, Brightness.dark);
});
test('Window padding/insets/viewPadding/systemGestureInsets', () {
_updateWindowMetrics(
0, // window id
0, // screen id
800.0, // width
600.0, // height
50.0, // padding top
0.0, // padding right
40.0, // padding bottom
0.0, // padding left
0.0, // inset top
0.0, // inset right
0.0, // inset bottom
0.0, // inset left
0.0, // system gesture inset top
0.0, // system gesture inset right
0.0, // system gesture inset bottom
0.0, // system gesture inset left
);
expectEquals(window.viewInsets.bottom, 0.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 40.0);
expectEquals(window.systemGestureInsets.bottom, 0.0);
_updateWindowMetrics(
0, // window id
0, // screen id
800.0, // width
600.0, // height
50.0, // padding top
0.0, // padding right
40.0, // padding bottom
0.0, // padding left
0.0, // inset top
0.0, // inset right
400.0, // inset bottom
0.0, // inset left
0.0, // system gesture inset top
0.0, // system gesture inset right
44.0, // system gesture inset bottom
0.0, // system gesture inset left
);
expectEquals(window.viewInsets.bottom, 400.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 0.0);
expectEquals(window.systemGestureInsets.bottom, 44.0);
});
test('PlatformDispatcher.locale returns unknown locale when locales is set to empty list', () {
late Locale locale;
runZoned(() {
window.onLocaleChanged = () {
locale = PlatformDispatcher.instance.locale;
};
});
_updateLocales(<String>[]);
expectEquals(locale, const Locale.fromSubtags());
expectEquals(locale.languageCode, 'und');
});
}