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

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
8 9
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
10
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
11 12 13
import '../widgets/semantics_tester.dart';

const String tooltipText = 'TIP';
14
const double _customPaddingValue = 10.0;
15 16 17 18 19 20 21

void main() {
  test('TooltipThemeData copyWith, ==, hashCode basics', () {
    expect(const TooltipThemeData(), const TooltipThemeData().copyWith());
    expect(const TooltipThemeData().hashCode, const TooltipThemeData().copyWith().hashCode);
  });

22 23 24 25 26 27
  test('TooltipThemeData lerp special cases', () {
    expect(TooltipThemeData.lerp(null, null, 0), null);
    const TooltipThemeData data = TooltipThemeData();
    expect(identical(TooltipThemeData.lerp(data, data, 0.5), data), true);
  });

28 29 30 31 32 33 34 35 36
  test('TooltipThemeData defaults', () {
    const TooltipThemeData theme = TooltipThemeData();
    expect(theme.height, null);
    expect(theme.padding, null);
    expect(theme.verticalOffset, null);
    expect(theme.preferBelow, null);
    expect(theme.excludeFromSemantics, null);
    expect(theme.decoration, null);
    expect(theme.textStyle, null);
37
    expect(theme.textAlign, null);
38 39
    expect(theme.waitDuration, null);
    expect(theme.showDuration, null);
40 41
    expect(theme.triggerMode, null);
    expect(theme.enableFeedback, null);
42 43
  });

44
  testWidgetsWithLeakTracking('Default TooltipThemeData debugFillProperties', (WidgetTester tester) async {
45 46 47 48 49 50 51 52 53 54 55
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
    const TooltipThemeData().debugFillProperties(builder);

    final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

    expect(description, <String>[]);
  });

56
  testWidgetsWithLeakTracking('TooltipThemeData implements debugFillProperties', (WidgetTester tester) async {
57
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
58 59
    const Duration wait = Duration(milliseconds: 100);
    const Duration show = Duration(milliseconds: 200);
60 61
    const TooltipTriggerMode triggerMode = TooltipTriggerMode.longPress;
    const bool enableFeedback = true;
62 63 64 65 66 67 68 69
    const TooltipThemeData(
      height: 15.0,
      padding: EdgeInsets.all(20.0),
      verticalOffset: 10.0,
      preferBelow: false,
      excludeFromSemantics: true,
      decoration: BoxDecoration(color: Color(0xffffffff)),
      textStyle: TextStyle(decoration: TextDecoration.underline),
70
      textAlign: TextAlign.center,
71 72
      waitDuration: wait,
      showDuration: show,
73 74
      triggerMode: triggerMode,
      enableFeedback: enableFeedback,
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    ).debugFillProperties(builder);

    final List<String> description = builder.properties
        .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
        .map((DiagnosticsNode node) => node.toString())
        .toList();

    expect(description, <String>[
      'height: 15.0',
      'padding: EdgeInsets.all(20.0)',
      'vertical offset: 10.0',
      'position: above',
      'semantics: excluded',
      'decoration: BoxDecoration(color: Color(0xffffffff))',
      'textStyle: TextStyle(inherit: true, decoration: TextDecoration.underline)',
90
      'textAlign: TextAlign.center',
91 92
      'wait duration: $wait',
      'show duration: $show',
93 94
      'triggerMode: $triggerMode',
      'enableFeedback: true',
95 96 97
    ]);
  });

98
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center prefer above fits - ThemeData.tooltipTheme', (WidgetTester tester) async {
99
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
100 101
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());
102 103 104 105 106 107 108
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              height: 100.0,
109
              padding: EdgeInsets.zero,
110 111 112 113 114 115
              verticalOffset: 100.0,
              preferBelow: false,
            ),
          ),
          child: Overlay(
            initialEntries: <OverlayEntry>[
116
              entry = OverlayEntry(
117 118 119 120 121 122 123 124 125
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 300.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
126
                          child: const SizedBox.shrink(),
127 128 129 130 131 132 133 134 135 136 137
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
138
    key.currentState!.ensureTooltipVisible();
139 140 141 142 143 144 145 146 147 148 149 150
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

    /********************* 800x600 screen
     *        ___        * }- 10.0 margin
     *       |___|       * }-100.0 height
     *         |         * }-100.0 vertical offset
     *         o         * y=300.0
     *                   *
     *                   *
     *                   *
     *********************/

151
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
152 153 154 155 156
    expect(tip.size.height, equals(100.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(100.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(200.0));
  });

157
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center prefer above fits - TooltipTheme', (WidgetTester tester) async {
158
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
159 160 161 162

    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

163 164 165 166
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: TooltipTheme(
167 168
          data: const TooltipThemeData(
            height: 100.0,
169
            padding: EdgeInsets.zero,
170 171 172
            verticalOffset: 100.0,
            preferBelow: false,
          ),
173 174
          child: Overlay(
            initialEntries: <OverlayEntry>[
175
              entry = OverlayEntry(
176 177 178 179 180 181 182 183 184
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 300.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
185
                          child: const SizedBox.shrink(),
186 187 188 189 190 191 192 193 194 195 196
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
197
    key.currentState!.ensureTooltipVisible();
198 199 200 201 202 203 204 205 206 207 208 209
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

    /********************* 800x600 screen
     *        ___        * }- 10.0 margin
     *       |___|       * }-100.0 height
     *         |         * }-100.0 vertical offset
     *         o         * y=300.0
     *                   *
     *                   *
     *                   *
     *********************/

210
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
211 212 213 214 215
    expect(tip.size.height, equals(100.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(100.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(200.0));
  });

216
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center prefer above does not fit - ThemeData.tooltipTheme', (WidgetTester tester) async {
217
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
218 219 220
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

221 222 223 224 225 226 227
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              height: 190.0,
228
              padding: EdgeInsets.zero,
229 230 231 232 233 234
              verticalOffset: 100.0,
              preferBelow: false,
            ),
          ),
          child: Overlay(
            initialEntries: <OverlayEntry>[
235
              entry = OverlayEntry(
236 237 238 239 240 241 242 243 244
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 299.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
245
                          child: const SizedBox.shrink(),
246 247 248 249 250 251 252 253 254 255 256
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
257
    key.currentState!.ensureTooltipVisible();
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

    // we try to put it here but it doesn't fit:
    /********************* 800x600 screen
     *        ___        * }- 10.0 margin
     *       |___|       * }-190.0 height (starts at y=9.0)
     *         |         * }-100.0 vertical offset
     *         o         * y=299.0
     *                   *
     *                   *
     *                   *
     *********************/

    // so we put it here:
    /********************* 800x600 screen
     *                   *
     *                   *
     *         o         * y=299.0
     *        _|_        * }-100.0 vertical offset
     *       |___|       * }-190.0 height
     *                   * }- 10.0 margin
     *********************/

281
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
282 283 284 285 286
    expect(tip.size.height, equals(190.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(399.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(589.0));
  });

287
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center prefer above does not fit - TooltipTheme', (WidgetTester tester) async {
288
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
289 290 291 292

    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

293 294 295 296
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: TooltipTheme(
297 298
          data: const TooltipThemeData(
            height: 190.0,
299
            padding: EdgeInsets.zero,
300 301 302
            verticalOffset: 100.0,
            preferBelow: false,
          ),
303 304
          child: Overlay(
            initialEntries: <OverlayEntry>[
305
              entry = OverlayEntry(
306 307 308 309 310 311 312 313 314
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 299.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
315
                          child: const SizedBox.shrink(),
316 317 318 319 320 321 322 323 324 325 326
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
327
    key.currentState!.ensureTooltipVisible();
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

    // we try to put it here but it doesn't fit:
    /********************* 800x600 screen
     *        ___        * }- 10.0 margin
     *       |___|       * }-190.0 height (starts at y=9.0)
     *         |         * }-100.0 vertical offset
     *         o         * y=299.0
     *                   *
     *                   *
     *                   *
     *********************/

    // so we put it here:
    /********************* 800x600 screen
     *                   *
     *                   *
     *         o         * y=299.0
     *        _|_        * }-100.0 vertical offset
     *       |___|       * }-190.0 height
     *                   * }- 10.0 margin
     *********************/

351
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
352 353 354 355 356
    expect(tip.size.height, equals(190.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(399.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(589.0));
  });

357
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center preferBelow fits - ThemeData.tooltipTheme', (WidgetTester tester) async {
358
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
359 360
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());
361 362 363 364 365 366 367
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              height: 190.0,
368
              padding: EdgeInsets.zero,
369 370 371 372 373 374
              verticalOffset: 100.0,
              preferBelow: true,
            ),
          ),
          child: Overlay(
            initialEntries: <OverlayEntry>[
375
              entry = OverlayEntry(
376 377 378 379 380 381 382 383 384
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 300.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
385
                          child: const SizedBox.shrink(),
386 387 388 389 390 391 392 393 394 395 396
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
397
    key.currentState!.ensureTooltipVisible();
398 399 400 401 402 403 404 405 406 407 408
    await tester.pumpAndSettle(); // faded in, show timer started (and at 0.0)

    /********************* 800x600 screen
     *                   *
     *                   *
     *         o         * y=300.0
     *        _|_        * }-100.0 vertical offset
     *       |___|       * }-190.0 height
     *                   * }- 10.0 margin
     *********************/

409
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
410 411 412 413 414
    expect(tip.size.height, equals(190.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(400.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(590.0));
  });

415
  testWidgetsWithLeakTracking('Tooltip verticalOffset, preferBelow; center prefer below fits - TooltipTheme', (WidgetTester tester) async {
416
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
417 418 419 420

    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

421 422 423 424
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: TooltipTheme(
425 426
          data: const TooltipThemeData(
            height: 190.0,
427
            padding: EdgeInsets.zero,
428 429 430
            verticalOffset: 100.0,
            preferBelow: true,
          ),
431 432
          child: Overlay(
            initialEntries: <OverlayEntry>[
433
              entry = OverlayEntry(
434 435 436 437 438 439 440 441 442
                builder: (BuildContext context) {
                  return Stack(
                    children: <Widget>[
                      Positioned(
                        left: 400.0,
                        top: 300.0,
                        child: Tooltip(
                          key: key,
                          message: tooltipText,
443
                          child: const SizedBox.shrink(),
444 445 446 447 448 449 450 451 452 453 454
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
455
    key.currentState!.ensureTooltipVisible();
456 457 458 459 460 461 462 463 464 465 466
    await tester.pumpAndSettle(); // faded in, show timer started (and at 0.0)

    /********************* 800x600 screen
     *                   *
     *                   *
     *         o         * y=300.0
     *        _|_        * }-100.0 vertical offset
     *       |___|       * }-190.0 height
     *                   * }- 10.0 margin
     *********************/

467
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent! as RenderBox;
468 469 470 471 472
    expect(tip.size.height, equals(190.0));
    expect(tip.localToGlobal(tip.size.topLeft(Offset.zero)).dy, equals(400.0));
    expect(tip.localToGlobal(tip.size.bottomRight(Offset.zero)).dy, equals(590.0));
  });

473
  testWidgetsWithLeakTracking('Tooltip margin - ThemeData', (WidgetTester tester) async {
474
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
475 476 477 478

    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

479 480 481 482 483
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Overlay(
          initialEntries: <OverlayEntry>[
484
            entry = OverlayEntry(
485 486 487 488
              builder: (BuildContext context) {
                return Theme(
                  data: ThemeData(
                    tooltipTheme: const TooltipThemeData(
489
                      padding: EdgeInsets.zero,
490 491 492 493 494 495
                      margin: EdgeInsets.all(_customPaddingValue),
                    ),
                  ),
                  child: Tooltip(
                    key: key,
                    message: tooltipText,
496
                    child: const SizedBox.shrink(),
497 498 499 500 501 502 503 504
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
505
    key.currentState!.ensureTooltipVisible();
506 507
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

508
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent!.parent! as RenderBox;
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
    final RenderBox tooltipContent = tester.renderObject(find.text(tooltipText));

    final Offset topLeftTipInGlobal = tip.localToGlobal(tip.size.topLeft(Offset.zero));
    final Offset topLeftTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.topLeft(Offset.zero));
    expect(topLeftTooltipContentInGlobal.dx, topLeftTipInGlobal.dx + _customPaddingValue);
    expect(topLeftTooltipContentInGlobal.dy, topLeftTipInGlobal.dy + _customPaddingValue);

    final Offset topRightTipInGlobal = tip.localToGlobal(tip.size.topRight(Offset.zero));
    final Offset topRightTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.topRight(Offset.zero));
    expect(topRightTooltipContentInGlobal.dx, topRightTipInGlobal.dx - _customPaddingValue);
    expect(topRightTooltipContentInGlobal.dy, topRightTipInGlobal.dy + _customPaddingValue);

    final Offset bottomLeftTipInGlobal = tip.localToGlobal(tip.size.bottomLeft(Offset.zero));
    final Offset bottomLeftTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.bottomLeft(Offset.zero));
    expect(bottomLeftTooltipContentInGlobal.dx, bottomLeftTipInGlobal.dx + _customPaddingValue);
    expect(bottomLeftTooltipContentInGlobal.dy, bottomLeftTipInGlobal.dy - _customPaddingValue);

    final Offset bottomRightTipInGlobal = tip.localToGlobal(tip.size.bottomRight(Offset.zero));
    final Offset bottomRightTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.bottomRight(Offset.zero));
    expect(bottomRightTooltipContentInGlobal.dx, bottomRightTipInGlobal.dx - _customPaddingValue);
    expect(bottomRightTooltipContentInGlobal.dy, bottomRightTipInGlobal.dy - _customPaddingValue);
  });

532
  testWidgetsWithLeakTracking('Tooltip margin - TooltipTheme', (WidgetTester tester) async {
533
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
534 535 536
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

537 538 539 540 541
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Overlay(
          initialEntries: <OverlayEntry>[
542
            entry = OverlayEntry(
543 544
              builder: (BuildContext context) {
                return TooltipTheme(
545
                  data: const TooltipThemeData(
546
                    padding: EdgeInsets.zero,
547 548
                    margin: EdgeInsets.all(_customPaddingValue),
                  ),
549 550 551
                  child: Tooltip(
                    key: key,
                    message: tooltipText,
552
                    child: const SizedBox.shrink(),
553 554 555 556 557 558 559 560
                  ),
                );
              },
            ),
          ],
        ),
      ),
    );
561
    key.currentState!.ensureTooltipVisible();
562 563
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

564
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent!.parent! as RenderBox;
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
    final RenderBox tooltipContent = tester.renderObject(find.text(tooltipText));

    final Offset topLeftTipInGlobal = tip.localToGlobal(tip.size.topLeft(Offset.zero));
    final Offset topLeftTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.topLeft(Offset.zero));
    expect(topLeftTooltipContentInGlobal.dx, topLeftTipInGlobal.dx + _customPaddingValue);
    expect(topLeftTooltipContentInGlobal.dy, topLeftTipInGlobal.dy + _customPaddingValue);

    final Offset topRightTipInGlobal = tip.localToGlobal(tip.size.topRight(Offset.zero));
    final Offset topRightTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.topRight(Offset.zero));
    expect(topRightTooltipContentInGlobal.dx, topRightTipInGlobal.dx - _customPaddingValue);
    expect(topRightTooltipContentInGlobal.dy, topRightTipInGlobal.dy + _customPaddingValue);

    final Offset bottomLeftTipInGlobal = tip.localToGlobal(tip.size.bottomLeft(Offset.zero));
    final Offset bottomLeftTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.bottomLeft(Offset.zero));
    expect(bottomLeftTooltipContentInGlobal.dx, bottomLeftTipInGlobal.dx + _customPaddingValue);
    expect(bottomLeftTooltipContentInGlobal.dy, bottomLeftTipInGlobal.dy - _customPaddingValue);

    final Offset bottomRightTipInGlobal = tip.localToGlobal(tip.size.bottomRight(Offset.zero));
    final Offset bottomRightTooltipContentInGlobal = tooltipContent.localToGlobal(tooltipContent.size.bottomRight(Offset.zero));
    expect(bottomRightTooltipContentInGlobal.dx, bottomRightTipInGlobal.dx - _customPaddingValue);
    expect(bottomRightTooltipContentInGlobal.dy, bottomRightTipInGlobal.dy - _customPaddingValue);
  });

588
  testWidgetsWithLeakTracking('Tooltip message textStyle - ThemeData.tooltipTheme', (WidgetTester tester) async {
589
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
590 591 592 593 594
    await tester.pumpWidget(MaterialApp(
      theme: ThemeData(
        tooltipTheme: const TooltipThemeData(
          textStyle: TextStyle(
            color: Colors.orange,
595
            decoration: TextDecoration.underline,
596 597 598 599 600 601 602 603 604 605 606 607 608
          ),
        ),
      ),
      home: Tooltip(
        key: key,
        message: tooltipText,
        child: Container(
          width: 100.0,
          height: 100.0,
          color: Colors.green[500],
        ),
      ),
    ));
609
    key.currentState!.ensureTooltipVisible();
610 611
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

612
    final TextStyle textStyle = tester.widget<Text>(find.text(tooltipText)).style!;
613 614 615 616 617
    expect(textStyle.color, Colors.orange);
    expect(textStyle.fontFamily, null);
    expect(textStyle.decoration, TextDecoration.underline);
  });

618
  testWidgetsWithLeakTracking('Tooltip message textStyle - TooltipTheme', (WidgetTester tester) async {
619
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
620 621
    await tester.pumpWidget(MaterialApp(
      home: TooltipTheme(
622
        data: const TooltipThemeData(),
623 624 625
        child: Tooltip(
          textStyle: const TextStyle(
            color: Colors.orange,
626
            decoration: TextDecoration.underline,
627 628 629 630 631 632 633 634 635 636 637
          ),
          key: key,
          message: tooltipText,
          child: Container(
            width: 100.0,
            height: 100.0,
            color: Colors.green[500],
          ),
        ),
      ),
    ));
638
    key.currentState!.ensureTooltipVisible();
639 640
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

641
    final TextStyle textStyle = tester.widget<Text>(find.text(tooltipText)).style!;
642 643 644 645 646
    expect(textStyle.color, Colors.orange);
    expect(textStyle.fontFamily, null);
    expect(textStyle.decoration, TextDecoration.underline);
  });

647
  testWidgetsWithLeakTracking('Tooltip message textAlign - TooltipTheme', (WidgetTester tester) async {
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
    Future<void> pumpTooltipWithTextAlign({TextAlign? textAlign}) async {
      final GlobalKey<TooltipState> tooltipKey = GlobalKey<TooltipState>();
      await tester.pumpWidget(
        MaterialApp(
          home: TooltipTheme(
            data: TooltipThemeData(
              textAlign: textAlign,
            ),
            child: Tooltip(
              key: tooltipKey,
              message: tooltipText,
              child: Container(
                width: 100.0,
                height: 100.0,
                color: Colors.green[500],
              ),
            ),
          ),
        ),
      );
      tooltipKey.currentState?.ensureTooltipVisible();
      await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)
    }

    // Default value should be TextAlign.start
    await pumpTooltipWithTextAlign();
    TextAlign textAlign = tester.widget<Text>(find.text(tooltipText)).textAlign!;
    expect(textAlign, TextAlign.start);

    await pumpTooltipWithTextAlign(textAlign: TextAlign.center);
    textAlign = tester.widget<Text>(find.text(tooltipText)).textAlign!;
    expect(textAlign, TextAlign.center);

    await pumpTooltipWithTextAlign(textAlign: TextAlign.end);
    textAlign = tester.widget<Text>(find.text(tooltipText)).textAlign!;
    expect(textAlign, TextAlign.end);
  });

686
  testWidgetsWithLeakTracking('Tooltip decoration - ThemeData.tooltipTheme', (WidgetTester tester) async {
687
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
688 689 690 691
    const Decoration customDecoration = ShapeDecoration(
      shape: StadiumBorder(),
      color: Color(0x80800000),
    );
692 693
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());
694 695 696 697 698
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: ThemeData(
699
            useMaterial3: false,
700 701 702 703 704 705
            tooltipTheme: const TooltipThemeData(
              decoration: customDecoration,
            ),
          ),
          child: Overlay(
            initialEntries: <OverlayEntry>[
706
              entry = OverlayEntry(
707 708 709 710
                builder: (BuildContext context) {
                  return Tooltip(
                    key: key,
                    message: tooltipText,
711
                    child: const SizedBox.shrink(),
712 713 714 715 716 717 718 719
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
720
    key.currentState!.ensureTooltipVisible();
721 722
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

723
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent! as RenderBox;
724 725 726

    expect(tip.size.height, equals(32.0));
    expect(tip.size.width, equals(74.0));
727
    expect(tip, paints..rrect(color: const Color(0x80800000)));
728
  });
729

730
  testWidgetsWithLeakTracking('Tooltip decoration - TooltipTheme', (WidgetTester tester) async {
731
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
732 733 734 735
    const Decoration customDecoration = ShapeDecoration(
      shape: StadiumBorder(),
      color: Color(0x80800000),
    );
736 737 738 739

    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

740
    await tester.pumpWidget(
741 742 743 744 745 746 747 748
      Theme(
        data: ThemeData(useMaterial3: false),
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: TooltipTheme(
            data: const TooltipThemeData(decoration: customDecoration),
            child: Overlay(
              initialEntries: <OverlayEntry>[
749
                entry = OverlayEntry(
750 751 752 753 754 755 756 757 758 759
                  builder: (BuildContext context) {
                    return Tooltip(
                      key: key,
                      message: tooltipText,
                      child: const SizedBox.shrink(),
                    );
                  },
                ),
              ],
            ),
760 761 762 763
          ),
        ),
      ),
    );
764
    key.currentState!.ensureTooltipVisible();
765 766
    await tester.pump(const Duration(seconds: 2)); // faded in, show timer started (and at 0.0)

767
    final RenderBox tip = tester.renderObject(find.text(tooltipText)).parent!.parent!.parent!.parent! as RenderBox;
768 769 770

    expect(tip.size.height, equals(32.0));
    expect(tip.size.width, equals(74.0));
771
    expect(tip, paints..rrect(color: const Color(0x80800000)));
772
  });
773

774
  testWidgetsWithLeakTracking('Tooltip height and padding - ThemeData.tooltipTheme', (WidgetTester tester) async {
775
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
776 777 778
    const double customTooltipHeight = 100.0;
    const double customPaddingVal = 20.0;

779 780 781
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());

782 783 784 785 786 787 788 789 790 791 792 793
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              height: customTooltipHeight,
              padding: EdgeInsets.all(customPaddingVal),
            ),
          ),
          child: Overlay(
            initialEntries: <OverlayEntry>[
794
              entry = OverlayEntry(
795 796 797 798 799 800 801 802 803 804 805 806
                builder: (BuildContext context) {
                  return Tooltip(
                    key: key,
                    message: tooltipText,
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
807
    key.currentState!.ensureTooltipVisible();
808 809 810 811
    await tester.pumpAndSettle();

    final RenderBox tip = tester.renderObject(find.ancestor(
      of: find.text(tooltipText),
812
      matching: find.byType(Padding).first, // select [Tooltip.padding] instead of [Tooltip.margin]
813 814 815 816 817 818 819 820 821
    ));
    final RenderBox content = tester.renderObject(find.ancestor(
      of: find.text(tooltipText),
      matching: find.byType(Center),
    ));

    expect(tip.size.height, equals(customTooltipHeight));
    expect(content.size.height, equals(customTooltipHeight - 2 * customPaddingVal));
    expect(content.size.width, equals(tip.size.width - 2 * customPaddingVal));
822
  });
823

824
  testWidgetsWithLeakTracking('Tooltip height and padding - TooltipTheme', (WidgetTester tester) async {
825
    final GlobalKey<TooltipState> key = GlobalKey<TooltipState>();
826
    const double customTooltipHeight = 100.0;
827
    const double customPaddingValue = 20.0;
828 829
    late final OverlayEntry entry;
    addTearDown(() => entry..remove()..dispose());
830 831 832 833 834

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: TooltipTheme(
835 836 837 838
          data: const TooltipThemeData(
            height: customTooltipHeight,
            padding: EdgeInsets.all(customPaddingValue),
          ),
839 840
          child: Overlay(
            initialEntries: <OverlayEntry>[
841
              entry = OverlayEntry(
842 843 844 845 846 847 848 849 850 851 852 853
                builder: (BuildContext context) {
                  return Tooltip(
                    key: key,
                    message: tooltipText,
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
854
    key.currentState!.ensureTooltipVisible();
855 856 857 858
    await tester.pumpAndSettle();

    final RenderBox tip = tester.renderObject(find.ancestor(
      of: find.text(tooltipText),
859
      matching: find.byType(Padding).first, // select [Tooltip.padding] instead of [Tooltip.margin]
860 861 862 863 864 865 866
    ));
    final RenderBox content = tester.renderObject(find.ancestor(
      of: find.text(tooltipText),
      matching: find.byType(Center),
    ));

    expect(tip.size.height, equals(customTooltipHeight));
867 868
    expect(content.size.height, equals(customTooltipHeight - 2 * customPaddingValue));
    expect(content.size.width, equals(tip.size.width - 2 * customPaddingValue));
869
  });
870

871
  testWidgetsWithLeakTracking('Tooltip waitDuration - ThemeData.tooltipTheme', (WidgetTester tester) async {
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
    const Duration customWaitDuration = Duration(milliseconds: 500);
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    await gesture.moveTo(const Offset(1.0, 1.0));
    await tester.pump();
    await gesture.moveTo(Offset.zero);

    await tester.pumpWidget(
      MaterialApp(
        home: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              waitDuration: customWaitDuration,
            ),
          ),
887
          child: const Center(
888 889
            child: Tooltip(
              message: tooltipText,
890
              child: SizedBox(
891 892 893 894 895 896
                width: 100.0,
                height: 100.0,
              ),
            ),
          ),
        ),
897
      ),
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913
    );

    final Finder tooltip = find.byType(Tooltip);
    await gesture.moveTo(Offset.zero);
    await tester.pump();
    await gesture.moveTo(tester.getCenter(tooltip));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 250));
    expect(find.text(tooltipText), findsNothing); // Should not appear yet
    await tester.pump(const Duration(milliseconds: 250));
    expect(find.text(tooltipText), findsOneWidget); // Should appear after customWaitDuration

    await gesture.moveTo(Offset.zero);
    await tester.pump();

    // Wait for it to disappear.
914
    await tester.pump(customWaitDuration);
915 916 917
    expect(find.text(tooltipText), findsNothing);
  });

918
  testWidgetsWithLeakTracking('Tooltip waitDuration - TooltipTheme', (WidgetTester tester) async {
919 920 921 922 923 924 925 926
    const Duration customWaitDuration = Duration(milliseconds: 500);
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    await gesture.moveTo(const Offset(1.0, 1.0));
    await tester.pump();
    await gesture.moveTo(Offset.zero);

    await tester.pumpWidget(
927
      const MaterialApp(
928
        home: TooltipTheme(
929
          data: TooltipThemeData(waitDuration: customWaitDuration),
930 931 932
          child: Center(
            child: Tooltip(
              message: tooltipText,
933
              child: SizedBox(
934 935 936 937 938 939
                width: 100.0,
                height: 100.0,
              ),
            ),
          ),
        ),
940
      ),
941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
    );

    final Finder tooltip = find.byType(Tooltip);
    await gesture.moveTo(Offset.zero);
    await tester.pump();
    await gesture.moveTo(tester.getCenter(tooltip));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 250));
    expect(find.text(tooltipText), findsNothing); // Should not appear yet
    await tester.pump(const Duration(milliseconds: 250));
    expect(find.text(tooltipText), findsOneWidget); // Should appear after customWaitDuration

    await gesture.moveTo(Offset.zero);
    await tester.pump();

    // Wait for it to disappear.
957
    await tester.pump(customWaitDuration); // Should disappear after customWaitDuration
958 959 960
    expect(find.text(tooltipText), findsNothing);
  });

961
  testWidgetsWithLeakTracking('Tooltip showDuration - ThemeData.tooltipTheme', (WidgetTester tester) async {
962 963 964 965 966 967 968 969 970
    const Duration customShowDuration = Duration(milliseconds: 3000);
    await tester.pumpWidget(
      MaterialApp(
        home: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(
              showDuration: customShowDuration,
            ),
          ),
971
          child: const Center(
972 973
            child: Tooltip(
              message: tooltipText,
974
              child: SizedBox(
975 976 977 978 979 980
                width: 100.0,
                height: 100.0,
              ),
            ),
          ),
        ),
981
      ),
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997
    );

    final Finder tooltip = find.byType(Tooltip);
    final TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip));
    await tester.pump();
    await tester.pump(kLongPressTimeout);
    await gesture.up();
    expect(find.text(tooltipText), findsOneWidget);
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 2000)); // Tooltip should remain
    expect(find.text(tooltipText), findsOneWidget);
    await tester.pump(const Duration(milliseconds: 1000));
    await tester.pumpAndSettle(); // Tooltip should fade out after
    expect(find.text(tooltipText), findsNothing);
  });

998
  testWidgetsWithLeakTracking('Tooltip showDuration - TooltipTheme', (WidgetTester tester) async {
999 1000
    const Duration customShowDuration = Duration(milliseconds: 3000);
    await tester.pumpWidget(
1001
      const MaterialApp(
1002
        home: TooltipTheme(
1003
          data: TooltipThemeData(showDuration: customShowDuration),
1004 1005 1006
          child: Center(
            child: Tooltip(
              message: tooltipText,
1007
              child: SizedBox(
1008 1009 1010 1011 1012 1013
                width: 100.0,
                height: 100.0,
              ),
            ),
          ),
        ),
1014
      ),
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
    );

    final Finder tooltip = find.byType(Tooltip);
    final TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip));
    await tester.pump();
    await tester.pump(kLongPressTimeout);
    await gesture.up();
    expect(find.text(tooltipText), findsOneWidget);
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 2000)); // Tooltip should remain
    expect(find.text(tooltipText), findsOneWidget);
    await tester.pump(const Duration(milliseconds: 1000));
    await tester.pumpAndSettle(); // Tooltip should fade out after
    expect(find.text(tooltipText), findsNothing);
  });

1031
  testWidgetsWithLeakTracking('Tooltip triggerMode - ThemeData.triggerMode', (WidgetTester tester) async {
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
    const TooltipTriggerMode triggerMode = TooltipTriggerMode.tap;
    await tester.pumpWidget(
      MaterialApp(
        home: Theme(
          data: ThemeData(
            tooltipTheme: const TooltipThemeData(triggerMode: triggerMode),
          ),
          child: const Center(
            child: Tooltip(
              message: tooltipText,
              child: SizedBox(width: 100.0, height: 100.0),
            ),
          ),
        ),
      ),
    );

    final Finder tooltip = find.byType(Tooltip);
    final TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip));
    await gesture.up();
    await tester.pump();
    expect(find.text(tooltipText), findsOneWidget); // Tooltip should show immediately after tap
  });

1056
  testWidgetsWithLeakTracking('Tooltip triggerMode - TooltipTheme', (WidgetTester tester) async {
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
    const TooltipTriggerMode triggerMode = TooltipTriggerMode.tap;
    await tester.pumpWidget(
      const MaterialApp(
        home: TooltipTheme(
          data: TooltipThemeData(triggerMode: triggerMode),
          child: Center(
            child: Tooltip(
              message: tooltipText,
              child: SizedBox(width: 100.0, height: 100.0),
            ),
          ),
        ),
      ),
    );

    final Finder tooltip = find.byType(Tooltip);
    final TestGesture gesture = await tester.startGesture(tester.getCenter(tooltip));
    await gesture.up();
    await tester.pump();
    expect(find.text(tooltipText), findsOneWidget); // Tooltip should show immediately after tap
  });

1079
  testWidgetsWithLeakTracking('Semantics included by default - ThemeData.tooltipTheme', (WidgetTester tester) async {
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData(),
        home: const Center(
          child: Tooltip(
            message: 'Foo',
            child: Text('Bar'),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(TestSemantics.root(
      children: <TestSemantics>[
        TestSemantics.rootChild(
          children: <TestSemantics>[
            TestSemantics(
              children: <TestSemantics>[
                TestSemantics(
1101 1102 1103
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
1104 1105
                      tooltip: 'Foo',
                      label: 'Bar',
1106 1107 1108
                      textDirection: TextDirection.ltr,
                    ),
                  ],
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
                ),
              ],
            ),
          ],
        ),
      ],
    ), ignoreRect: true, ignoreId: true, ignoreTransform: true));

    semantics.dispose();
  });

1120
  testWidgetsWithLeakTracking('Semantics included by default - TooltipTheme', (WidgetTester tester) async {
1121 1122 1123
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
1124
      const MaterialApp(
1125
        home: TooltipTheme(
1126 1127
          data: TooltipThemeData(),
          child: Center(
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
            child: Tooltip(
              message: 'Foo',
              child: Text('Bar'),
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(TestSemantics.root(
      children: <TestSemantics>[
        TestSemantics.rootChild(
          children: <TestSemantics>[
            TestSemantics(
              children: <TestSemantics>[
                TestSemantics(
1144 1145 1146
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
1147 1148
                      tooltip: 'Foo',
                      label: 'Bar',
1149 1150 1151
                      textDirection: TextDirection.ltr,
                    ),
                  ],
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
                ),
              ],
            ),
          ],
        ),
      ],
    ), ignoreRect: true, ignoreId: true, ignoreTransform: true));

    semantics.dispose();
  });

1163
  testWidgetsWithLeakTracking('Semantics excluded - ThemeData.tooltipTheme', (WidgetTester tester) async {
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData(
          tooltipTheme: const TooltipThemeData(
            excludeFromSemantics: true,
          ),
        ),
        home: const Center(
          child: Tooltip(
            message: 'Foo',
            child: Text('Bar'),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(TestSemantics.root(
      children: <TestSemantics>[
        TestSemantics.rootChild(
          children: <TestSemantics>[
            TestSemantics(
              children: <TestSemantics>[
                TestSemantics(
1189 1190 1191 1192 1193 1194 1195
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
                      label: 'Bar',
                      textDirection: TextDirection.ltr,
                    ),
                  ],
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
                ),
              ],
            ),
          ],
        ),
      ],
    ), ignoreRect: true, ignoreId: true, ignoreTransform: true));

    semantics.dispose();
  });

1207
  testWidgetsWithLeakTracking('Semantics excluded - TooltipTheme', (WidgetTester tester) async {
1208 1209 1210
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
1211
      const MaterialApp(
1212
        home: TooltipTheme(
1213 1214
          data: TooltipThemeData(excludeFromSemantics: true),
          child: Center(
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
            child: Tooltip(
              message: 'Foo',
              child: Text('Bar'),
            ),
          ),
        ),
      ),
    );

    expect(semantics, hasSemantics(TestSemantics.root(
      children: <TestSemantics>[
        TestSemantics.rootChild(
          children: <TestSemantics>[
            TestSemantics(
              children: <TestSemantics>[
                TestSemantics(
1231 1232 1233 1234 1235 1236 1237
                  flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                  children: <TestSemantics>[
                    TestSemantics(
                      label: 'Bar',
                      textDirection: TextDirection.ltr,
                    ),
                  ],
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
                ),
              ],
            ),
          ],
        ),
      ],
    ), ignoreRect: true, ignoreId: true, ignoreTransform: true));

    semantics.dispose();
  });

1249
  testWidgetsWithLeakTracking('has semantic events by default - ThemeData.tooltipTheme', (WidgetTester tester) async {
1250
    final List<dynamic> semanticEvents = <dynamic>[];
1251
    tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, (dynamic message) async {
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
      semanticEvents.add(message);
    });
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
      MaterialApp(
        theme: ThemeData(),
        home: Center(
          child: Tooltip(
            message: 'Foo',
            child: Container(
              width: 100.0,
              height: 100.0,
              color: Colors.green[500],
            ),
          ),
        ),
      ),
    );

    await tester.longPress(find.byType(Tooltip));
    final RenderObject object = tester.firstRenderObject(find.byType(Tooltip));

    expect(semanticEvents, unorderedEquals(<dynamic>[
      <String, dynamic>{
        'type': 'longPress',
        'nodeId': findDebugSemantics(object).id,
        'data': <String, dynamic>{},
      },
      <String, dynamic>{
        'type': 'tooltip',
        'data': <String, dynamic>{
          'message': 'Foo',
        },
      },
    ]));
    semantics.dispose();
1289
    tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, null);
1290 1291
  });

1292
  testWidgetsWithLeakTracking('has semantic events by default - TooltipTheme', (WidgetTester tester) async {
1293
    final List<dynamic> semanticEvents = <dynamic>[];
1294
    tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, (dynamic message) async {
1295 1296 1297 1298 1299 1300 1301
      semanticEvents.add(message);
    });
    final SemanticsTester semantics = SemanticsTester(tester);

    await tester.pumpWidget(
      MaterialApp(
        home: TooltipTheme(
1302
          data: const TooltipThemeData(),
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333
          child: Center(
            child: Tooltip(
              message: 'Foo',
              child: Container(
                width: 100.0,
                height: 100.0,
                color: Colors.green[500],
              ),
            ),
          ),
        ),
      ),
    );

    await tester.longPress(find.byType(Tooltip));
    final RenderObject object = tester.firstRenderObject(find.byType(Tooltip));

    expect(semanticEvents, unorderedEquals(<dynamic>[
      <String, dynamic>{
        'type': 'longPress',
        'nodeId': findDebugSemantics(object).id,
        'data': <String, dynamic>{},
      },
      <String, dynamic>{
        'type': 'tooltip',
        'data': <String, dynamic>{
          'message': 'Foo',
        },
      },
    ]));
    semantics.dispose();
1334
    tester.binding.defaultBinaryMessenger.setMockDecodedMessageHandler<dynamic>(SystemChannels.accessibility, null);
1335 1336
  });

1337
  testWidgetsWithLeakTracking('default Tooltip debugFillProperties', (WidgetTester tester) async {
1338 1339
    final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();

1340
    const Tooltip(message: 'message').debugFillProperties(builder);
1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352

    final List<String> description = builder.properties
      .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
      .map((DiagnosticsNode node) => node.toString()).toList();

    expect(description, <String>[
      '"message"',
    ]);
  });
}

SemanticsNode findDebugSemantics(RenderObject object) {
1353
  if (object.debugSemantics != null) {
1354
    return object.debugSemantics!;
1355
  }
1356
  return findDebugSemantics(object.parent!);
1357
}