window.dart 34.5 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:typed_data' show ByteData;
6
import 'dart:ui' as ui hide window;
7

8 9
import 'package:flutter/foundation.dart';

10 11
/// [SingletonFlutterWindow] that wraps another [SingletonFlutterWindow] and
/// allows faking of some properties for testing purposes.
12 13
///
/// Tests for certain widgets, e.g., [MaterialApp], might require faking certain
14 15 16 17 18
/// properties of a [SingletonFlutterWindow]. [TestWindow] facilitates the
/// faking of these properties by overriding the properties of a real
/// [SingletonFlutterWindow] with desired fake values. The binding used within
/// tests, [TestWidgetsFlutterBinding], contains a [TestWindow] that is used by
/// all tests.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
///
/// ## Sample Code
///
/// A test can utilize a [TestWindow] in the following way:
///
/// ```dart
/// testWidgets('your test name here', (WidgetTester tester) async {
///   // Retrieve the TestWidgetsFlutterBinding.
///   final TestWidgetsFlutterBinding testBinding = tester.binding;
///
///   // Fake the desired properties of the TestWindow. All code running
///   // within this test will perceive the following fake text scale
///   // factor as the real text scale factor of the window.
///   testBinding.window.textScaleFactorFakeValue = 2.5;
///
///   // Test code that depends on text scale factor here.
/// });
/// ```
///
/// The [TestWidgetsFlutterBinding] is recreated for each test and
/// therefore any fake values defined in one test will not persist
/// to the next.
///
42 43 44 45
/// If a test needs to override a real [SingletonFlutterWindow] property and
/// then later return to using the real [SingletonFlutterWindow] property,
/// [TestWindow] provides methods to clear each individual test value, e.g.,
/// [clearLocaleTestValue()].
46
///
47 48
/// To clear all fake test values in a [TestWindow], consider using
/// [clearAllTestValues()].
49 50 51 52 53 54
///
/// See also:
///
///   * [TestPlatformDispatcher], which wraps a [PlatformDispatcher] for
///     testing purposes and is used by the [platformDispatcher] property of
///     this class.
55 56 57
class TestWindow implements ui.SingletonFlutterWindow {
  /// Constructs a [TestWindow] that defers all behavior to the given
  /// [dart:ui.SingletonFlutterWindow] unless explicitly overridden for test purposes.
58
  TestWindow({
59
    required ui.SingletonFlutterWindow window,
60 61
  }) : _window = window,
       platformDispatcher = TestPlatformDispatcher(platformDispatcher: window.platformDispatcher);
62

63 64
  /// The [dart:ui.SingletonFlutterWindow] that is wrapped by this [TestWindow].
  final ui.SingletonFlutterWindow _window;
65

66 67 68
  @override
  final TestPlatformDispatcher platformDispatcher;

69 70
  @override
  double get devicePixelRatio => _devicePixelRatio ?? _window.devicePixelRatio;
71
  double? _devicePixelRatio;
72 73
  /// Hides the real device pixel ratio and reports the given [devicePixelRatio]
  /// instead.
74
  set devicePixelRatioTestValue(double devicePixelRatio) { // ignore: avoid_setters_without_getters
75
    _devicePixelRatio = devicePixelRatio;
76
    onMetricsChanged?.call();
77
  }
78 79
  /// Deletes any existing test device pixel ratio and returns to using the real
  /// device pixel ratio.
80 81
  void clearDevicePixelRatioTestValue() {
    _devicePixelRatio = null;
82
    onMetricsChanged?.call();
83 84 85
  }

  @override
86 87
  ui.Size get physicalSize => _physicalSizeTestValue ?? _window.physicalSize;
  ui.Size? _physicalSizeTestValue;
88 89
  /// Hides the real physical size and reports the given [physicalSizeTestValue]
  /// instead.
90
  set physicalSizeTestValue (ui.Size physicalSizeTestValue) { // ignore: avoid_setters_without_getters
91
    _physicalSizeTestValue = physicalSizeTestValue;
92
    onMetricsChanged?.call();
93
  }
94 95
  /// Deletes any existing test physical size and returns to using the real
  /// physical size.
96 97
  void clearPhysicalSizeTestValue() {
    _physicalSizeTestValue = null;
98
    onMetricsChanged?.call();
99 100 101
  }

  @override
102 103
  ui.WindowPadding get viewInsets => _viewInsetsTestValue ??  _window.viewInsets;
  ui.WindowPadding? _viewInsetsTestValue;
104 105
  /// Hides the real view insets and reports the given [viewInsetsTestValue]
  /// instead.
106
  set viewInsetsTestValue(ui.WindowPadding viewInsetsTestValue) { // ignore: avoid_setters_without_getters
107
    _viewInsetsTestValue = viewInsetsTestValue;
108
    onMetricsChanged?.call();
109
  }
110 111
  /// Deletes any existing test view insets and returns to using the real view
  /// insets.
112 113
  void clearViewInsetsTestValue() {
    _viewInsetsTestValue = null;
114
    onMetricsChanged?.call();
115 116
  }

117
  @override
118 119
  ui.WindowPadding get viewPadding => _viewPaddingTestValue ?? _window.padding;
  ui.WindowPadding? _viewPaddingTestValue;
120 121
  /// Hides the real view padding and reports the given [paddingTestValue]
  /// instead.
122
  set viewPaddingTestValue(ui.WindowPadding viewPaddingTestValue) { // ignore: avoid_setters_without_getters
123
    _viewPaddingTestValue = viewPaddingTestValue;
124
    onMetricsChanged?.call();
125
  }
126 127
  /// Deletes any existing test view padding and returns to using the real
  /// viewPadding.
128 129
  void clearViewPaddingTestValue() {
    _viewPaddingTestValue = null;
130
    onMetricsChanged?.call();
131 132
  }

133
  @override
134 135
  ui.WindowPadding get padding => _paddingTestValue ?? _window.padding;
  ui.WindowPadding? _paddingTestValue;
136
  /// Hides the real padding and reports the given [paddingTestValue] instead.
137
  set paddingTestValue(ui.WindowPadding paddingTestValue) { // ignore: avoid_setters_without_getters
138
    _paddingTestValue = paddingTestValue;
139
    onMetricsChanged?.call();
140 141 142 143
  }
  /// Deletes any existing test padding and returns to using the real padding.
  void clearPaddingTestValue() {
    _paddingTestValue = null;
144
    onMetricsChanged?.call();
145 146
  }

147 148 149 150 151 152 153 154 155 156 157 158 159 160
  @override
  List<ui.DisplayFeature> get displayFeatures => _displayFeaturesTestValue ?? _window.displayFeatures;
  List<ui.DisplayFeature>? _displayFeaturesTestValue;
  /// Hides the real displayFeatures and reports the given [displayFeaturesTestValue] instead.
  set displayFeaturesTestValue(List<ui.DisplayFeature> displayFeaturesTestValue) { // ignore: avoid_setters_without_getters
    _displayFeaturesTestValue = displayFeaturesTestValue;
    onMetricsChanged?.call();
  }
  /// Deletes any existing test padding and returns to using the real padding.
  void clearDisplayFeaturesTestValue() {
    _displayFeaturesTestValue = null;
    onMetricsChanged?.call();
  }

161
  @override
162 163
  ui.WindowPadding get systemGestureInsets => _systemGestureInsetsTestValue ?? _window.systemGestureInsets;
  ui.WindowPadding? _systemGestureInsetsTestValue;
164
  /// Hides the real system gesture insets and reports the given [systemGestureInsetsTestValue] instead.
165
  set systemGestureInsetsTestValue(ui.WindowPadding systemGestureInsetsTestValue) { // ignore: avoid_setters_without_getters
166
    _systemGestureInsetsTestValue = systemGestureInsetsTestValue;
167
    onMetricsChanged?.call();
168 169 170 171
  }
  /// Deletes any existing test system gesture insets and returns to using the real system gesture insets.
  void clearSystemGestureInsetsTestValue() {
    _systemGestureInsetsTestValue = null;
172
    onMetricsChanged?.call();
173 174
  }

175
  @override
176
  ui.VoidCallback? get onMetricsChanged => platformDispatcher.onMetricsChanged;
177
  @override
178 179
  set onMetricsChanged(ui.VoidCallback? callback) {
    platformDispatcher.onMetricsChanged = callback;
180 181 182
  }

  @override
183
  ui.Locale get locale => platformDispatcher.locale;
184
  /// Hides the real locale and reports the given [localeTestValue] instead.
185 186 187 188
  @Deprecated(
    'Use platformDispatcher.localeTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
189
  set localeTestValue(ui.Locale localeTestValue) { // ignore: avoid_setters_without_getters
190
    platformDispatcher.localeTestValue = localeTestValue;
191
  }
192 193 194 195
  @Deprecated(
    'Use platformDispatcher.clearLocaleTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
196 197
  /// Deletes any existing test locale and returns to using the real locale.
  void clearLocaleTestValue() {
198
    platformDispatcher.clearLocaleTestValue();
199 200 201
  }

  @override
202
  List<ui.Locale> get locales => platformDispatcher.locales;
203
  /// Hides the real locales and reports the given [localesTestValue] instead.
204 205 206 207
  @Deprecated(
    'Use platformDispatcher.localesTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
208
  set localesTestValue(List<ui.Locale> localesTestValue) { // ignore: avoid_setters_without_getters
209
    platformDispatcher.localesTestValue = localesTestValue;
210 211
  }
  /// Deletes any existing test locales and returns to using the real locales.
212 213 214 215
  @Deprecated(
    'Use platformDispatcher.clearLocalesTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
216
  void clearLocalesTestValue() {
217
    platformDispatcher.clearLocalesTestValue();
218 219 220
  }

  @override
221
  ui.VoidCallback? get onLocaleChanged => platformDispatcher.onLocaleChanged;
222
  @override
223 224
  set onLocaleChanged(ui.VoidCallback? callback) {
    platformDispatcher.onLocaleChanged = callback;
225 226
  }

227
  @override
228
  String get initialLifecycleState => platformDispatcher.initialLifecycleState;
229
  /// Sets a faked initialLifecycleState for testing.
230 231 232 233
  @Deprecated(
    'Use platformDispatcher.initialLifecycleStateTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
234
  set initialLifecycleStateTestValue(String state) { // ignore: avoid_setters_without_getters
235
    platformDispatcher.initialLifecycleStateTestValue = state;
236 237
  }

238
  @override
239
  double get textScaleFactor => platformDispatcher.textScaleFactor;
240 241
  /// Hides the real text scale factor and reports the given
  /// [textScaleFactorTestValue] instead.
242 243 244 245
  @Deprecated(
    'Use platformDispatcher.textScaleFactorTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
246
  set textScaleFactorTestValue(double textScaleFactorTestValue) { // ignore: avoid_setters_without_getters
247
    platformDispatcher.textScaleFactorTestValue = textScaleFactorTestValue;
248
  }
249 250
  /// Deletes any existing test text scale factor and returns to using the real
  /// text scale factor.
251 252 253 254
  @Deprecated(
    'Use platformDispatcher.clearTextScaleFactorTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
255
  void clearTextScaleFactorTestValue() {
256
    platformDispatcher.clearTextScaleFactorTestValue();
257 258
  }

259
  @override
260
  ui.Brightness get platformBrightness => platformDispatcher.platformBrightness;
261
  @override
262
  ui.VoidCallback? get onPlatformBrightnessChanged => platformDispatcher.onPlatformBrightnessChanged;
263
  @override
264 265
  set onPlatformBrightnessChanged(ui.VoidCallback? callback) {
    platformDispatcher.onPlatformBrightnessChanged = callback;
266
  }
267 268
  /// Hides the real text scale factor and reports the given
  /// [platformBrightnessTestValue] instead.
269 270 271 272
  @Deprecated(
    'Use platformDispatcher.platformBrightnessTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
273
  set platformBrightnessTestValue(ui.Brightness platformBrightnessTestValue) { // ignore: avoid_setters_without_getters
274
    platformDispatcher.platformBrightnessTestValue = platformBrightnessTestValue;
275
  }
276 277
  /// Deletes any existing test platform brightness and returns to using the
  /// real platform brightness.
278 279 280 281
  @Deprecated(
    'Use platformDispatcher.clearPlatformBrightnessTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
282
  void clearPlatformBrightnessTestValue() {
283
    platformDispatcher.clearPlatformBrightnessTestValue();
284 285
  }

286
  @override
287
  bool get alwaysUse24HourFormat => platformDispatcher.alwaysUse24HourFormat;
288 289
  /// Hides the real clock format and reports the given
  /// [alwaysUse24HourFormatTestValue] instead.
290 291 292 293
  @Deprecated(
    'Use platformDispatcher.alwaysUse24HourFormatTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
294
  set alwaysUse24HourFormatTestValue(bool alwaysUse24HourFormatTestValue) { // ignore: avoid_setters_without_getters
295
    platformDispatcher.alwaysUse24HourFormatTestValue = alwaysUse24HourFormatTestValue;
296
  }
297 298
  /// Deletes any existing test clock format and returns to using the real clock
  /// format.
299 300 301 302
  @Deprecated(
    'Use platformDispatcher.clearAlwaysUse24HourTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
303
  void clearAlwaysUse24HourTestValue() {
304
    platformDispatcher.clearAlwaysUse24HourTestValue();
305 306 307
  }

  @override
308
  ui.VoidCallback? get onTextScaleFactorChanged => platformDispatcher.onTextScaleFactorChanged;
309
  @override
310 311
  set onTextScaleFactorChanged(ui.VoidCallback? callback) {
    platformDispatcher.onTextScaleFactorChanged = callback;
312 313
  }

314
  @override
315
  bool get brieflyShowPassword => platformDispatcher.brieflyShowPassword;
316 317
  /// Hides the real [brieflyShowPassword] and reports the given
  /// `brieflyShowPasswordTestValue` instead.
318 319 320 321
  @Deprecated(
    'Use platformDispatcher.brieflyShowPasswordTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
322
  set brieflyShowPasswordTestValue(bool brieflyShowPasswordTestValue) { // ignore: avoid_setters_without_getters
323
    platformDispatcher.brieflyShowPasswordTestValue = brieflyShowPasswordTestValue;
324 325
  }

326
  @override
327
  ui.FrameCallback? get onBeginFrame => platformDispatcher.onBeginFrame;
328
  @override
329 330
  set onBeginFrame(ui.FrameCallback? callback) {
    platformDispatcher.onBeginFrame = callback;
331 332 333
  }

  @override
334
  ui.VoidCallback? get onDrawFrame => platformDispatcher.onDrawFrame;
335
  @override
336 337
  set onDrawFrame(ui.VoidCallback? callback) {
    platformDispatcher.onDrawFrame = callback;
338 339
  }

340
  @override
341
  ui.TimingsCallback? get onReportTimings => platformDispatcher.onReportTimings;
342
  @override
343 344
  set onReportTimings(ui.TimingsCallback? callback) {
    platformDispatcher.onReportTimings = callback;
345
  }
346

347
  @override
348
  ui.PointerDataPacketCallback? get onPointerDataPacket => platformDispatcher.onPointerDataPacket;
349
  @override
350 351
  set onPointerDataPacket(ui.PointerDataPacketCallback? callback) {
    platformDispatcher.onPointerDataPacket = callback;
352 353 354
  }

  @override
355
  String get defaultRouteName => platformDispatcher.defaultRouteName;
356 357
  /// Hides the real default route name and reports the given
  /// [defaultRouteNameTestValue] instead.
358 359 360 361
  @Deprecated(
    'Use platformDispatcher.defaultRouteNameTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
362
  set defaultRouteNameTestValue(String defaultRouteNameTestValue) { // ignore: avoid_setters_without_getters
363
    platformDispatcher.defaultRouteNameTestValue = defaultRouteNameTestValue;
364
  }
365 366
  /// Deletes any existing test default route name and returns to using the real
  /// default route name.
367 368 369 370
  @Deprecated(
    'Use platformDispatcher.clearDefaultRouteNameTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
371
  void clearDefaultRouteNameTestValue() {
372
    platformDispatcher.clearDefaultRouteNameTestValue();
373 374 375 376
  }

  @override
  void scheduleFrame() {
377
    platformDispatcher.scheduleFrame();
378 379 380
  }

  @override
381
  void render(ui.Scene scene) {
382 383 384 385
    _window.render(scene);
  }

  @override
386
  bool get semanticsEnabled => platformDispatcher.semanticsEnabled;
387 388
  /// Hides the real semantics enabled and reports the given
  /// [semanticsEnabledTestValue] instead.
389 390 391 392
  @Deprecated(
    'Use platformDispatcher.semanticsEnabledTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
393
  set semanticsEnabledTestValue(bool semanticsEnabledTestValue) { // ignore: avoid_setters_without_getters
394
    platformDispatcher.semanticsEnabledTestValue = semanticsEnabledTestValue;
395
  }
396 397
  /// Deletes any existing test semantics enabled and returns to using the real
  /// semantics enabled.
398 399 400 401
  @Deprecated(
    'Use platformDispatcher.clearSemanticsEnabledTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
402
  void clearSemanticsEnabledTestValue() {
403
    platformDispatcher.clearSemanticsEnabledTestValue();
404 405 406
  }

  @override
407
  ui.VoidCallback? get onSemanticsEnabledChanged => platformDispatcher.onSemanticsEnabledChanged;
408
  @override
409 410
  set onSemanticsEnabledChanged(ui.VoidCallback? callback) {
    platformDispatcher.onSemanticsEnabledChanged = callback;
411 412 413
  }

  @override
414
  ui.SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction;
415
  @override
416 417
  set onSemanticsAction(ui.SemanticsActionCallback? callback) {
    platformDispatcher.onSemanticsAction = callback;
418 419 420
  }

  @override
421
  ui.AccessibilityFeatures get accessibilityFeatures => platformDispatcher.accessibilityFeatures;
422 423
  /// Hides the real accessibility features and reports the given
  /// [accessibilityFeaturesTestValue] instead.
424 425 426
  ///
  /// Consider using [FakeAccessibilityFeatures] to provide specific
  /// values for the various accessibility features under test.
427 428 429 430
  @Deprecated(
    'Use platformDispatcher.accessibilityFeaturesTestValue instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
431
  set accessibilityFeaturesTestValue(ui.AccessibilityFeatures accessibilityFeaturesTestValue) { // ignore: avoid_setters_without_getters
432
    platformDispatcher.accessibilityFeaturesTestValue = accessibilityFeaturesTestValue;
433
  }
434 435
  /// Deletes any existing test accessibility features and returns to using the
  /// real accessibility features.
436 437 438 439
  @Deprecated(
    'Use platformDispatcher.clearAccessibilityFeaturesTestValue() instead. '
    'This feature was deprecated after v2.11.0-0.0.pre.'
  )
440
  void clearAccessibilityFeaturesTestValue() {
441
    platformDispatcher.clearAccessibilityFeaturesTestValue();
442 443
  }

444 445 446 447 448
  @override
  ui.ViewConfiguration get viewConfiguration => _viewConfiguration ?? _window.viewConfiguration;
  ui.ViewConfiguration? _viewConfiguration;

  /// Hide the real view configuration and report the provided [value] instead.
449
  set viewConfigurationTestValue(ui.ViewConfiguration? value) { // ignore: avoid_setters_without_getters
450 451 452 453
    _viewConfiguration = value;
    onMetricsChanged?.call();
  }

454
  @override
455
  ui.VoidCallback? get onAccessibilityFeaturesChanged => platformDispatcher.onAccessibilityFeaturesChanged;
456
  @override
457 458
  set onAccessibilityFeaturesChanged(ui.VoidCallback? callback) {
    platformDispatcher.onAccessibilityFeaturesChanged = callback;
459 460 461
  }

  @override
462 463
  void updateSemantics(ui.SemanticsUpdate update) {
    platformDispatcher.updateSemantics(update);
464 465 466 467
  }

  @override
  void setIsolateDebugName(String name) {
468
    platformDispatcher.setIsolateDebugName(name);
469 470 471
  }

  @override
472 473
  void sendPlatformMessage(
    String name,
474
    ByteData? data,
475
    ui.PlatformMessageResponseCallback? callback,
476
  ) {
477
    platformDispatcher.sendPlatformMessage(name, data, callback);
478 479
  }

480 481 482 483
  @Deprecated(
    'Instead of calling this callback, use ServicesBinding.instance.channelBuffers.push. '
    'This feature was deprecated after v2.1.0-10.0.pre.'
  )
484
  @override
485
  ui.PlatformMessageCallback? get onPlatformMessage => platformDispatcher.onPlatformMessage;
486 487 488 489
  @Deprecated(
    'Instead of setting this callback, use ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler. '
    'This feature was deprecated after v2.1.0-10.0.pre.'
  )
490
  @override
491 492
  set onPlatformMessage(ui.PlatformMessageCallback? callback) {
    platformDispatcher.onPlatformMessage = callback;
493 494 495
  }

  /// Delete any test value properties that have been set on this [TestWindow]
496 497 498 499
  /// as well as its [platformDispatcher].
  ///
  /// After calling this, the real [SingletonFlutterWindow] and
  /// [ui.PlatformDispatcher] values are reported again.
500
  ///
501 502
  /// If desired, clearing of properties can be done on an individual basis,
  /// e.g., [clearLocaleTestValue()].
503 504 505
  void clearAllTestValues() {
    clearDevicePixelRatioTestValue();
    clearPaddingTestValue();
506
    clearDisplayFeaturesTestValue();
507 508
    clearPhysicalSizeTestValue();
    clearViewInsetsTestValue();
509
    platformDispatcher.clearAllTestValues();
510
  }
511 512

  /// This gives us some grace time when the dart:ui side adds something to
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
  /// [SingletonFlutterWindow], and makes things easier when we do rolls to give
  /// us time to catch up.
  @override
  dynamic noSuchMethod(Invocation invocation) {
    return null;
  }
}

/// Test version of [AccessibilityFeatures] in which specific features may
/// be set to arbitrary values.
///
/// By default, all features are disabled. For an instance where all the
/// features are enabled, consider the [FakeAccessibilityFeatures.allOn]
/// constant.
@immutable
// ignore: avoid_implementing_value_types
class FakeAccessibilityFeatures implements ui.AccessibilityFeatures {
  /// Creates a test instance of [AccessibilityFeatures].
  ///
  /// By default, all features are disabled.
  const FakeAccessibilityFeatures({
    this.accessibleNavigation = false,
    this.invertColors = false,
    this.disableAnimations = false,
    this.boldText = false,
    this.reduceMotion = false,
    this.highContrast = false,
  });

  /// An instance of [AccessibilityFeatures] where all the features are enabled.
  static const FakeAccessibilityFeatures allOn = FakeAccessibilityFeatures(
    accessibleNavigation: true,
    invertColors: true,
    disableAnimations: true,
    boldText: true,
    reduceMotion: true,
    highContrast: true,
  );

  @override
  final bool accessibleNavigation;

  @override
  final bool invertColors;

  @override
  final bool disableAnimations;

  @override
  final bool boldText;

  @override
  final bool reduceMotion;

  @override
  final bool highContrast;

  @override
  bool operator ==(Object other) {
    if (other.runtimeType != runtimeType)
      return false;
    return other is FakeAccessibilityFeatures
        && other.accessibleNavigation == accessibleNavigation
        && other.invertColors == invertColors
        && other.disableAnimations == disableAnimations
        && other.boldText == boldText
        && other.reduceMotion == reduceMotion
        && other.highContrast == highContrast;
  }

  @override
584
  int get hashCode => Object.hash(accessibleNavigation, invertColors, disableAnimations, boldText, reduceMotion, highContrast);
585 586 587 588 589 590 591

  /// This gives us some grace time when the dart:ui side adds something to
  /// [AccessibilityFeatures], and makes things easier when we do rolls to
  /// give us time to catch up.
  ///
  /// If you would like to add to this class, changes must first be made in the
  /// engine, followed by the framework.
592 593 594 595
  @override
  dynamic noSuchMethod(Invocation invocation) {
    return null;
  }
596
}
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932

/// [PlatformDispatcher] that wraps another [PlatformDispatcher] and
/// allows faking of some properties for testing purposes.
///
/// See also:
///
///   * [TestWindow], which wraps a [SingletonFlutterWindow] for
///     testing and mocking purposes.
class TestPlatformDispatcher implements ui.PlatformDispatcher {
  /// Constructs a [TestPlatformDispatcher] that defers all behavior to the given
  /// [dart:ui.PlatformDispatcher] unless explicitly overridden for test purposes.
  TestPlatformDispatcher({
    required ui.PlatformDispatcher platformDispatcher,
  }) : _platformDispatcher = platformDispatcher;

  /// The [dart:ui.PlatformDispatcher] that is wrapped by this [TestPlatformDispatcher].
  final ui.PlatformDispatcher _platformDispatcher;

  @override
  ui.VoidCallback? get onMetricsChanged => _platformDispatcher.onMetricsChanged;
  @override
  set onMetricsChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onMetricsChanged = callback;
  }

  @override
  ui.Locale get locale => _localeTestValue ?? _platformDispatcher.locale;
  ui.Locale? _localeTestValue;
  /// Hides the real locale and reports the given [localeTestValue] instead.
  set localeTestValue(ui.Locale localeTestValue) { // ignore: avoid_setters_without_getters
    _localeTestValue = localeTestValue;
    onLocaleChanged?.call();
  }
  /// Deletes any existing test locale and returns to using the real locale.
  void clearLocaleTestValue() {
    _localeTestValue = null;
    onLocaleChanged?.call();
  }

  @override
  List<ui.Locale> get locales => _localesTestValue ?? _platformDispatcher.locales;
  List<ui.Locale>? _localesTestValue;
  /// Hides the real locales and reports the given [localesTestValue] instead.
  set localesTestValue(List<ui.Locale> localesTestValue) { // ignore: avoid_setters_without_getters
    _localesTestValue = localesTestValue;
    onLocaleChanged?.call();
  }
  /// Deletes any existing test locales and returns to using the real locales.
  void clearLocalesTestValue() {
    _localesTestValue = null;
    onLocaleChanged?.call();
  }

  @override
  ui.VoidCallback? get onLocaleChanged => _platformDispatcher.onLocaleChanged;
  @override
  set onLocaleChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onLocaleChanged = callback;
  }

  @override
  String get initialLifecycleState => _initialLifecycleStateTestValue;
  String _initialLifecycleStateTestValue = '';
  /// Sets a faked initialLifecycleState for testing.
  set initialLifecycleStateTestValue(String state) { // ignore: avoid_setters_without_getters
    _initialLifecycleStateTestValue = state;
  }

  @override
  double get textScaleFactor => _textScaleFactorTestValue ?? _platformDispatcher.textScaleFactor;
  double? _textScaleFactorTestValue;
  /// Hides the real text scale factor and reports the given
  /// [textScaleFactorTestValue] instead.
  set textScaleFactorTestValue(double textScaleFactorTestValue) { // ignore: avoid_setters_without_getters
    _textScaleFactorTestValue = textScaleFactorTestValue;
    onTextScaleFactorChanged?.call();
  }
  /// Deletes any existing test text scale factor and returns to using the real
  /// text scale factor.
  void clearTextScaleFactorTestValue() {
    _textScaleFactorTestValue = null;
    onTextScaleFactorChanged?.call();
  }

  @override
  ui.Brightness get platformBrightness => _platformBrightnessTestValue ?? _platformDispatcher.platformBrightness;
  ui.Brightness? _platformBrightnessTestValue;
  @override
  ui.VoidCallback? get onPlatformBrightnessChanged => _platformDispatcher.onPlatformBrightnessChanged;
  @override
  set onPlatformBrightnessChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onPlatformBrightnessChanged = callback;
  }
  /// Hides the real text scale factor and reports the given
  /// [platformBrightnessTestValue] instead.
  set platformBrightnessTestValue(ui.Brightness platformBrightnessTestValue) { // ignore: avoid_setters_without_getters
    _platformBrightnessTestValue = platformBrightnessTestValue;
    onPlatformBrightnessChanged?.call();
  }
  /// Deletes any existing test platform brightness and returns to using the
  /// real platform brightness.
  void clearPlatformBrightnessTestValue() {
    _platformBrightnessTestValue = null;
    onPlatformBrightnessChanged?.call();
  }

  @override
  bool get alwaysUse24HourFormat => _alwaysUse24HourFormatTestValue ?? _platformDispatcher.alwaysUse24HourFormat;
  bool? _alwaysUse24HourFormatTestValue;
  /// Hides the real clock format and reports the given
  /// [alwaysUse24HourFormatTestValue] instead.
  set alwaysUse24HourFormatTestValue(bool alwaysUse24HourFormatTestValue) { // ignore: avoid_setters_without_getters
    _alwaysUse24HourFormatTestValue = alwaysUse24HourFormatTestValue;
  }
  /// Deletes any existing test clock format and returns to using the real clock
  /// format.
  void clearAlwaysUse24HourTestValue() {
    _alwaysUse24HourFormatTestValue = null;
  }

  @override
  ui.VoidCallback? get onTextScaleFactorChanged => _platformDispatcher.onTextScaleFactorChanged;
  @override
  set onTextScaleFactorChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onTextScaleFactorChanged = callback;
  }

  @override
  bool get brieflyShowPassword => _brieflyShowPasswordTestValue ?? _platformDispatcher.brieflyShowPassword;
  bool? _brieflyShowPasswordTestValue;
  /// Hides the real [brieflyShowPassword] and reports the given
  /// `brieflyShowPasswordTestValue` instead.
  set brieflyShowPasswordTestValue(bool brieflyShowPasswordTestValue) { // ignore: avoid_setters_without_getters
    _brieflyShowPasswordTestValue = brieflyShowPasswordTestValue;
  }

  @override
  ui.FrameCallback? get onBeginFrame => _platformDispatcher.onBeginFrame;
  @override
  set onBeginFrame(ui.FrameCallback? callback) {
    _platformDispatcher.onBeginFrame = callback;
  }

  @override
  ui.VoidCallback? get onDrawFrame => _platformDispatcher.onDrawFrame;
  @override
  set onDrawFrame(ui.VoidCallback? callback) {
    _platformDispatcher.onDrawFrame = callback;
  }

  @override
  ui.TimingsCallback? get onReportTimings => _platformDispatcher.onReportTimings;
  @override
  set onReportTimings(ui.TimingsCallback? callback) {
    _platformDispatcher.onReportTimings = callback;
  }

  @override
  ui.PointerDataPacketCallback? get onPointerDataPacket => _platformDispatcher.onPointerDataPacket;
  @override
  set onPointerDataPacket(ui.PointerDataPacketCallback? callback) {
    _platformDispatcher.onPointerDataPacket = callback;
  }

  @override
  String get defaultRouteName => _defaultRouteNameTestValue ?? _platformDispatcher.defaultRouteName;
  String? _defaultRouteNameTestValue;
  /// Hides the real default route name and reports the given
  /// [defaultRouteNameTestValue] instead.
  set defaultRouteNameTestValue(String defaultRouteNameTestValue) { // ignore: avoid_setters_without_getters
    _defaultRouteNameTestValue = defaultRouteNameTestValue;
  }
  /// Deletes any existing test default route name and returns to using the real
  /// default route name.
  void clearDefaultRouteNameTestValue() {
    _defaultRouteNameTestValue = null;
  }

  @override
  void scheduleFrame() {
    _platformDispatcher.scheduleFrame();
  }

  @override
  bool get semanticsEnabled => _semanticsEnabledTestValue ?? _platformDispatcher.semanticsEnabled;
  bool? _semanticsEnabledTestValue;
  /// Hides the real semantics enabled and reports the given
  /// [semanticsEnabledTestValue] instead.
  set semanticsEnabledTestValue(bool semanticsEnabledTestValue) { // ignore: avoid_setters_without_getters
    _semanticsEnabledTestValue = semanticsEnabledTestValue;
    onSemanticsEnabledChanged?.call();
  }
  /// Deletes any existing test semantics enabled and returns to using the real
  /// semantics enabled.
  void clearSemanticsEnabledTestValue() {
    _semanticsEnabledTestValue = null;
    onSemanticsEnabledChanged?.call();
  }

  @override
  ui.VoidCallback? get onSemanticsEnabledChanged => _platformDispatcher.onSemanticsEnabledChanged;
  @override
  set onSemanticsEnabledChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onSemanticsEnabledChanged = callback;
  }

  @override
  ui.SemanticsActionCallback? get onSemanticsAction => _platformDispatcher.onSemanticsAction;
  @override
  set onSemanticsAction(ui.SemanticsActionCallback? callback) {
    _platformDispatcher.onSemanticsAction = callback;
  }

  @override
  ui.AccessibilityFeatures get accessibilityFeatures => _accessibilityFeaturesTestValue ?? _platformDispatcher.accessibilityFeatures;
  ui.AccessibilityFeatures? _accessibilityFeaturesTestValue;
  /// Hides the real accessibility features and reports the given
  /// [accessibilityFeaturesTestValue] instead.
  ///
  /// Consider using [FakeAccessibilityFeatures] to provide specific
  /// values for the various accessibility features under test.
  set accessibilityFeaturesTestValue(ui.AccessibilityFeatures accessibilityFeaturesTestValue) { // ignore: avoid_setters_without_getters
    _accessibilityFeaturesTestValue = accessibilityFeaturesTestValue;
    onAccessibilityFeaturesChanged?.call();
  }
  /// Deletes any existing test accessibility features and returns to using the
  /// real accessibility features.
  void clearAccessibilityFeaturesTestValue() {
    _accessibilityFeaturesTestValue = null;
    onAccessibilityFeaturesChanged?.call();
  }

  @override
  ui.VoidCallback? get onAccessibilityFeaturesChanged => _platformDispatcher.onAccessibilityFeaturesChanged;
  @override
  set onAccessibilityFeaturesChanged(ui.VoidCallback? callback) {
    _platformDispatcher.onAccessibilityFeaturesChanged = callback;
  }

  @override
  void updateSemantics(ui.SemanticsUpdate update) {
    _platformDispatcher.updateSemantics(update);
  }

  @override
  void setIsolateDebugName(String name) {
    _platformDispatcher.setIsolateDebugName(name);
  }

  @override
  void sendPlatformMessage(
      String name,
      ByteData? data,
      ui.PlatformMessageResponseCallback? callback,
      ) {
    _platformDispatcher.sendPlatformMessage(name, data, callback);
  }

  @Deprecated(
    'Instead of calling this callback, use ServicesBinding.instance.channelBuffers.push. '
    'This feature was deprecated after v2.1.0-10.0.pre.'
  )
  @override
  ui.PlatformMessageCallback? get onPlatformMessage => _platformDispatcher.onPlatformMessage;
  @Deprecated(
    'Instead of setting this callback, use ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler. '
    'This feature was deprecated after v2.1.0-10.0.pre.'
  )
  @override
  set onPlatformMessage(ui.PlatformMessageCallback? callback) {
    _platformDispatcher.onPlatformMessage = callback;
  }

  /// Delete any test value properties that have been set on this [TestPlatformDispatcher]
  /// and return to reporting the real [ui.PlatformDispatcher] values for all
  /// [PlatformDispatcher] properties.
  ///
  /// If desired, clearing of properties can be done on an individual basis,
  /// e.g., [clearLocaleTestValue()].
  void clearAllTestValues() {
    clearAccessibilityFeaturesTestValue();
    clearAlwaysUse24HourTestValue();
    clearDefaultRouteNameTestValue();
    clearPlatformBrightnessTestValue();
    clearLocaleTestValue();
    clearLocalesTestValue();
    clearSemanticsEnabledTestValue();
    clearTextScaleFactorTestValue();
  }

  @override
  ui.VoidCallback? get onFrameDataChanged => _platformDispatcher.onFrameDataChanged;
  @override
  set onFrameDataChanged(ui.VoidCallback? value) {
    _platformDispatcher.onFrameDataChanged = value;
  }

  @override
  ui.KeyDataCallback? get onKeyData => _platformDispatcher.onKeyData;

  @override
  set onKeyData(ui.KeyDataCallback? onKeyData) {
    _platformDispatcher.onKeyData = onKeyData;
  }

  @override
  ui.VoidCallback? get onPlatformConfigurationChanged => _platformDispatcher.onPlatformConfigurationChanged;

  @override
  set onPlatformConfigurationChanged(ui.VoidCallback? onPlatformConfigurationChanged) {
    _platformDispatcher.onPlatformConfigurationChanged = onPlatformConfigurationChanged;
  }

  @override
  ui.Locale? computePlatformResolvedLocale(List<ui.Locale> supportedLocales) => _platformDispatcher.computePlatformResolvedLocale(supportedLocales);

  @override
  ui.PlatformConfiguration get configuration => _platformDispatcher.configuration;

  @override
  ui.FrameData get frameData => _platformDispatcher.frameData;

  @override
  ByteData? getPersistentIsolateData() => _platformDispatcher.getPersistentIsolateData();

  @override
  Iterable<ui.FlutterView> get views => _platformDispatcher.views;

  /// This gives us some grace time when the dart:ui side adds something to
  /// [PlatformDispatcher], and makes things easier when we do rolls to give
  /// us time to catch up.
  @override
  dynamic noSuchMethod(Invocation invocation) {
    return null;
  }
}