Skip to content

Commit

Permalink
Init licenses for test bindings (flutter#81961)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahaog committed May 8, 2021
1 parent 099f116 commit b3f7ebe
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
@@ -0,0 +1 @@
[0-9]+:[0-9]+ [+]1: All tests passed!
53 changes: 53 additions & 0 deletions dev/automated_tests/integration_test/license_test.dart
@@ -0,0 +1,53 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('Can show the license page', (WidgetTester tester) async {
await tester.pumpWidget(const TestApp());
await tester.pump();

final Finder button = find.byType(TextButton);

await tester.tap(button);
await tester.pumpAndSettle();

await tester.scrollUntilVisible(
// Dart should very definitely be in the licenses list.
find.text('dart'),
100,
maxScrolls: 200,
);

expect(find.text('dart'), findsOneWidget);
});
}

class TestApp extends StatelessWidget {
const TestApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: ShowLicenseButton(),
);
}
}

class ShowLicenseButton extends StatelessWidget {
const ShowLicenseButton({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return TextButton(
onPressed: () => showLicensePage(context: context),
child: const Text(
'Show licenses',
key: Key('show-licenses'),
),
);
}
}
14 changes: 7 additions & 7 deletions packages/flutter_test/lib/src/binding.dart
Expand Up @@ -324,13 +324,6 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
}
}

@override
// ignore: MUST_CALL_SUPER
void initLicenses() {
// Do not include any licenses, because we're a test, and the LICENSE file
// doesn't get generated for tests.
}

@override
BinaryMessenger createBinaryMessenger() {
return TestDefaultBinaryMessenger(super.createBinaryMessenger());
Expand Down Expand Up @@ -927,6 +920,13 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
binding.mockFlutterAssets();
}

@override
// ignore: MUST_CALL_SUPER
void initLicenses() {
// Do not include any licenses, because we're a test, and the LICENSE file
// doesn't get generated for tests.
}

FakeAsync? _currentFakeAsync; // set in runTest; cleared in postTest
Completer<void>? _pendingAsyncTasks;

Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/test/integration.shard/test_test.dart
Expand Up @@ -209,6 +209,10 @@ void main() {
}
expect(result.exitCode, 0);
});

testWithoutContext('integration test can show the license page', () async {
return _testFile('license', automatedTestsDirectory, integrationTestDirectory, exitCode: isZero, extraArguments: integrationTestExtraArgs);
});
}

Future<void> _testFile(
Expand Down

0 comments on commit b3f7ebe

Please sign in to comment.