1// Copyright 2017 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'package:flutter/material.dart'; 6import 'package:flutter/scheduler.dart'; 7import 'package:flutter_test/flutter_test.dart'; 8import 'package:flutter_gallery/gallery/app.dart'; 9 10void main() { 11 final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); 12 if (binding is LiveTestWidgetsFlutterBinding) 13 binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive; 14 15 testWidgets('Flutter Gallery drawer item test', (WidgetTester tester) async { 16 bool hasFeedback = false; 17 18 await tester.pumpWidget( 19 GalleryApp( 20 testMode: true, 21 onSendFeedback: () { 22 hasFeedback = true; 23 }, 24 ), 25 ); 26 await tester.pump(); // see https://github.com/flutter/flutter/issues/1865 27 await tester.pump(); // triggers a frame 28 29 // Show the options page 30 await tester.tap(find.byTooltip('Toggle options page')); 31 await tester.pumpAndSettle(); 32 33 // Verify theme settings 34 MaterialApp app = find.byType(MaterialApp).evaluate().first.widget; 35 expect(app.theme.brightness, equals(Brightness.light)); 36 expect(app.darkTheme.brightness, equals(Brightness.dark)); 37 38 // Switch to the dark theme: first menu button, choose 'Dark' 39 await tester.tap(find.byIcon(Icons.arrow_drop_down).first); 40 await tester.pumpAndSettle(); 41 await tester.tap(find.text('Dark')); 42 await tester.pumpAndSettle(); 43 app = find.byType(MaterialApp).evaluate().first.widget; 44 expect(app.themeMode, ThemeMode.dark); 45 46 // Switch to the light theme: first menu button, choose 'Light' 47 await tester.tap(find.byIcon(Icons.arrow_drop_down).first); 48 await tester.pumpAndSettle(); 49 await tester.tap(find.text('Light')); 50 await tester.pumpAndSettle(); 51 app = find.byType(MaterialApp).evaluate().first.widget; 52 expect(app.themeMode, ThemeMode.light); 53 54 // Switch back to system theme setting: first menu button, choose 'System Default' 55 await tester.tap(find.byIcon(Icons.arrow_drop_down).first); 56 await tester.pumpAndSettle(); 57 await tester.tap(find.text('System Default').at(1)); 58 await tester.pumpAndSettle(); 59 app = find.byType(MaterialApp).evaluate().first.widget; 60 expect(app.themeMode, ThemeMode.system); 61 62 // Verify platform settings 63 expect(app.theme.platform, equals(TargetPlatform.android)); 64 65 // Popup the platform menu: third menu button, choose 'Cupertino' 66 await tester.tap(find.byIcon(Icons.arrow_drop_down).at(2)); 67 await tester.pumpAndSettle(); 68 await tester.tap(find.text('Cupertino').at(1)); 69 await tester.pumpAndSettle(); 70 app = find.byType(MaterialApp).evaluate().first.widget; 71 expect(app.theme.platform, equals(TargetPlatform.iOS)); 72 73 // Verify the font scale. 74 final Size origTextSize = tester.getSize(find.text('Text size')); 75 expect(origTextSize, equals(const Size(144.0, 16.0))); 76 77 // Popup the text size menu: second menu button, choose 'Small' 78 await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1)); 79 await tester.pumpAndSettle(); 80 await tester.tap(find.text('Small')); 81 await tester.pumpAndSettle(); 82 Size textSize = tester.getSize(find.text('Text size')); 83 expect(textSize, equals(const Size(116.0, 13.0))); 84 85 // Set font scale back to the default. 86 await tester.tap(find.byIcon(Icons.arrow_drop_down).at(1)); 87 await tester.pumpAndSettle(); 88 await tester.tap(find.text('System Default').at(1)); 89 await tester.pumpAndSettle(); 90 textSize = tester.getSize(find.text('Text size')); 91 expect(textSize, origTextSize); 92 93 // Switch to slow animation: second switch control 94 expect(timeDilation, 1.0); 95 await tester.tap(find.byType(Switch).at(1)); 96 await tester.pumpAndSettle(); 97 expect(timeDilation, greaterThan(1.0)); 98 99 // Restore normal animation: second switch control 100 await tester.tap(find.byType(Switch).at(1)); 101 await tester.pumpAndSettle(); 102 expect(timeDilation, 1.0); 103 104 // Send feedback. 105 expect(hasFeedback, false); 106 107 // Scroll to the end 108 await tester.drag(find.text('Text size'), const Offset(0.0, -1000.0)); 109 await tester.pumpAndSettle(); 110 await tester.tap(find.text('Send feedback')); 111 await tester.pumpAndSettle(); 112 expect(hasFeedback, true); 113 114 // Hide the options page 115 await tester.tap(find.byTooltip('Toggle options page')); 116 await tester.pumpAndSettle(); 117 }); 118} 119