object_test.dart 2.08 KB
Newer Older
1 2 3 4 5 6
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
7 8
import 'package:flutter_test/src/binding.dart' show TestWidgetsFlutterBinding;
import 'package:flutter_test/flutter_test.dart';
9 10

void main() {
Ian Hickson's avatar
Ian Hickson committed
11
  test('ensure frame is scheduled for markNeedsSemanticsUpdate', () {
12 13 14
    // Initialize all bindings because owner.flushSemantics() requires a window
    TestWidgetsFlutterBinding.ensureInitialized();

15
    final TestRenderObject renderObject = TestRenderObject();
16
    int onNeedVisualUpdateCallCount = 0;
17
    final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () {
18 19 20 21
      onNeedVisualUpdateCallCount +=1;
    });
    owner.ensureSemantics();
    renderObject.attach(owner);
22
    renderObject.layout(const BoxConstraints.tightForFinite());  // semantics are only calculated if layout information is up to date.
23 24 25 26 27 28
    owner.flushSemantics();

    expect(onNeedVisualUpdateCallCount, 1);
    renderObject.markNeedsSemanticsUpdate();
    expect(onNeedVisualUpdateCallCount, 2);
  });
29 30

  test('detached RenderObject does not do semantics', () {
31
    final TestRenderObject renderObject = TestRenderObject();
32 33 34 35 36 37
    expect(renderObject.attached, isFalse);
    expect(renderObject.describeSemanticsConfigurationCallCount, 0);

    renderObject.markNeedsSemanticsUpdate();
    expect(renderObject.describeSemanticsConfigurationCallCount, 0);
  });
38 39 40 41
}

class TestRenderObject extends RenderObject {
  @override
42
  void debugAssertDoesMeetConstraints() { }
43 44 45 46 47

  @override
  Rect get paintBounds => null;

  @override
48
  void performLayout() { }
49 50

  @override
51
  void performResize() { }
52 53

  @override
Dan Field's avatar
Dan Field committed
54
  Rect get semanticBounds => const Rect.fromLTWH(0.0, 0.0, 10.0, 20.0);
55

56 57
  int describeSemanticsConfigurationCallCount = 0;

58
  @override
59 60 61
  void describeSemanticsConfiguration(SemanticsConfiguration config) {
    super.describeSemanticsConfiguration(config);
    config.isSemanticBoundary = true;
62
    describeSemanticsConfigurationCallCount++;
63
  }
64
}