2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-02-15 06:49:49 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-07-27 06:40:49 +00:00
|
|
|
// TODO(gspencergoog): Remove this tag once this test's state leaks/test
|
|
|
|
// dependencies have been fixed.
|
|
|
|
// https://github.com/flutter/flutter/issues/85160
|
|
|
|
// Fails with "flutter test --test-randomize-ordering-seed=20210721"
|
|
|
|
@Tags(<String>['no-shuffle'])
|
2022-12-21 00:03:21 +00:00
|
|
|
library;
|
|
|
|
|
2022-10-05 16:35:58 +00:00
|
|
|
import 'dart:async';
|
2020-05-29 18:50:12 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-08-14 23:24:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-11-12 01:36:05 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2019-02-15 06:49:49 +00:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2019-11-14 17:31:36 +00:00
|
|
|
|
2019-02-15 06:49:49 +00:00
|
|
|
void main() {
|
2021-05-21 22:09:03 +00:00
|
|
|
final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding();
|
|
|
|
|
2019-02-15 06:49:49 +00:00
|
|
|
group(TestViewConfiguration, () {
|
|
|
|
test('is initialized with top-level window if one is not provided', () {
|
|
|
|
// The code below will throw without the default.
|
|
|
|
TestViewConfiguration(size: const Size(1280.0, 800.0));
|
|
|
|
});
|
|
|
|
});
|
2019-09-24 23:53:40 +00:00
|
|
|
|
|
|
|
group(AutomatedTestWidgetsFlutterBinding, () {
|
|
|
|
test('allows setting defaultTestTimeout to 5 minutes', () {
|
2023-04-20 20:55:28 +00:00
|
|
|
binding.defaultTestTimeout = const Timeout(Duration(minutes: 5));
|
2019-09-24 23:53:40 +00:00
|
|
|
expect(binding.defaultTestTimeout.duration, const Duration(minutes: 5));
|
|
|
|
});
|
|
|
|
});
|
2020-05-29 18:50:12 +00:00
|
|
|
|
2021-05-21 22:09:03 +00:00
|
|
|
// The next three tests must run in order -- first using `test`, then `testWidgets`, then `test` again.
|
|
|
|
|
|
|
|
int order = 0;
|
|
|
|
|
2020-05-29 18:50:12 +00:00
|
|
|
test('Initializes httpOverrides and testTextInput', () async {
|
2021-05-21 22:09:03 +00:00
|
|
|
assert(order == 0);
|
|
|
|
expect(binding.testTextInput, isNotNull);
|
|
|
|
expect(binding.testTextInput.isRegistered, isFalse);
|
2020-05-29 18:50:12 +00:00
|
|
|
expect(HttpOverrides.current, isNotNull);
|
2021-05-21 22:09:03 +00:00
|
|
|
order += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('Registers testTextInput', (WidgetTester tester) async {
|
|
|
|
assert(order == 1);
|
|
|
|
expect(tester.testTextInput.isRegistered, isTrue);
|
|
|
|
order += 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Unregisters testTextInput', () async {
|
|
|
|
assert(order == 2);
|
|
|
|
expect(binding.testTextInput.isRegistered, isFalse);
|
|
|
|
order += 1;
|
2020-05-29 18:50:12 +00:00
|
|
|
});
|
2022-10-05 16:35:58 +00:00
|
|
|
|
2023-08-14 23:24:47 +00:00
|
|
|
testWidgets('timeStamp should be accurate to microsecond precision', (WidgetTester tester) async {
|
|
|
|
final WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
|
|
|
await tester.pumpWidget(const CircularProgressIndicator());
|
|
|
|
|
|
|
|
final Duration timeStampBefore = widgetsBinding.currentSystemFrameTimeStamp;
|
|
|
|
await tester.pump(const Duration(microseconds: 12345));
|
|
|
|
final Duration timeStampAfter = widgetsBinding.currentSystemFrameTimeStamp;
|
|
|
|
|
|
|
|
expect(timeStampAfter - timeStampBefore, const Duration(microseconds: 12345));
|
|
|
|
});
|
|
|
|
|
2022-10-05 16:35:58 +00:00
|
|
|
group('elapseBlocking', () {
|
|
|
|
testWidgets('timer is not called', (WidgetTester tester) async {
|
|
|
|
bool timerCalled = false;
|
|
|
|
Timer.run(() => timerCalled = true);
|
|
|
|
|
|
|
|
binding.elapseBlocking(const Duration(seconds: 1));
|
|
|
|
|
|
|
|
expect(timerCalled, false);
|
|
|
|
binding.idle();
|
|
|
|
});
|
|
|
|
|
|
|
|
testWidgets('can use to simulate slow build', (WidgetTester tester) async {
|
|
|
|
final DateTime beforeTime = binding.clock.now();
|
|
|
|
|
|
|
|
await tester.pumpWidget(Builder(builder: (_) {
|
|
|
|
bool timerCalled = false;
|
|
|
|
Timer.run(() => timerCalled = true);
|
|
|
|
|
|
|
|
binding.elapseBlocking(const Duration(seconds: 1));
|
|
|
|
|
|
|
|
// if we use `delayed` instead of `elapseBlocking`, such as
|
|
|
|
// binding.delayed(const Duration(seconds: 1));
|
|
|
|
// the timer will be called here. Surely, that violates how
|
|
|
|
// a flutter widget build works
|
|
|
|
expect(timerCalled, false);
|
|
|
|
|
|
|
|
return Container();
|
|
|
|
}));
|
|
|
|
|
|
|
|
expect(binding.clock.now(), beforeTime.add(const Duration(seconds: 1)));
|
|
|
|
binding.idle();
|
|
|
|
});
|
|
|
|
});
|
2022-11-12 01:36:05 +00:00
|
|
|
|
|
|
|
testWidgets('Assets in the tester can be loaded without turning event loop', (WidgetTester tester) async {
|
|
|
|
bool responded = false;
|
|
|
|
// The particular asset does not matter, as long as it exists.
|
|
|
|
rootBundle.load('AssetManifest.json').then((ByteData data) {
|
|
|
|
responded = true;
|
|
|
|
});
|
|
|
|
expect(responded, true);
|
|
|
|
});
|
2019-02-15 06:49:49 +00:00
|
|
|
}
|