Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-establish breakpoints on hot-restart #7205

Merged
merged 14 commits into from Feb 14, 2024
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/screens/debugger/breakpoints.dart';
import 'package:devtools_app/src/screens/debugger/call_stack.dart';
import 'package:devtools_app/src/screens/debugger/codeview.dart';
import 'package:devtools_test/helpers.dart';
Expand Down Expand Up @@ -59,27 +60,44 @@ void main() {
isTrue,
);

logStatus('opening the "more" menu');
logStatus('Navigating to line 57...');

final moreMenuFinder = find.byType(PopupMenuButton<ScriptPopupMenuOption>);
expect(moreMenuFinder, findsOneWidget);
await tester.tap(moreMenuFinder);
await tester.pumpAndSettle(safePumpDuration);
await goToLine(tester, lineNumber: 57);

logStatus('selecting the go-to-line menu option');
logStatus('looking for line 57');

final goToLineOptionFinder = find.textContaining('Go to line number');
expect(goToLineOptionFinder, findsOneWidget);
await tester.tap(goToLineOptionFinder);
await tester.pumpAndSettle(safePumpDuration);
// Look for the line 57 gutter item:
final gutter57Finder = findGutterItemWithText('57');
expect(gutter57Finder, findsOneWidget);

logStatus('entering line number in the go-to-line dialog');
// Look for the line 57 line item:
final line57Finder = findLineItemWithText("print('Hello!');");
expect(line57Finder, findsOneWidget);

final goToLineInputFinder = find.widgetWithText(TextField, 'Line Number');
expect(goToLineInputFinder, findsOneWidget);
await tester.enterText(goToLineInputFinder, '30');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle(safePumpDuration);
// Verify that the gutter item and line item are aligned:
expect(
areHorizontallyAligned(
gutter57Finder,
line57Finder,
tester: tester,
),
isTrue,
);

logStatus('setting a breakpoint');

// Tap on the gutter for the line to set a breakpoint:
await tester.tap(gutter57Finder);
await tester.pumpAndSettle(longPumpDuration);

logStatus('performing a hot restart');

await tester.tap(find.byKey(const Key('Hot Restart Button')));
elliette marked this conversation as resolved.
Show resolved Hide resolved
await tester.pumpAndSettle(longPumpDuration);

logStatus('Navigating to line 30...');

await goToLine(tester, lineNumber: 30);

logStatus('looking for line 30');

Expand Down Expand Up @@ -107,6 +125,11 @@ void main() {
await tester.tap(gutter30Finder);
await tester.pumpAndSettle(longPumpDuration);

logStatus('verifying breakpoints');

final bpSetBeforeRestart = findBreakpointWithText('main.dart:57');
expect(bpSetBeforeRestart, findsOneWidget);

logStatus('pausing at breakpoint');

final topFrameFinder = findStackFrameWithText('incrementCounter');
Expand Down Expand Up @@ -170,6 +193,30 @@ bool areHorizontallyAligned(
return widgetACenter.dy == widgetBCenter.dy;
}

Future<void> goToLine(WidgetTester tester, {required int lineNumber}) async {
logStatus('opening the "more" menu');

final moreMenuFinder = find.byType(PopupMenuButton<ScriptPopupMenuOption>);
expect(moreMenuFinder, findsOneWidget);
await tester.tap(moreMenuFinder);
await tester.pumpAndSettle(safePumpDuration);

logStatus('selecting the go-to-line menu option');

final goToLineOptionFinder = find.textContaining('Go to line number');
expect(goToLineOptionFinder, findsOneWidget);
await tester.tap(goToLineOptionFinder);
await tester.pumpAndSettle(safePumpDuration);

logStatus('entering line number $lineNumber in the go-to-line dialog');

final goToLineInputFinder = find.widgetWithText(TextField, 'Line Number');
expect(goToLineInputFinder, findsOneWidget);
await tester.enterText(goToLineInputFinder, '$lineNumber');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle(safePumpDuration);
}

T getWidgetFromFinder<T>(Finder finder) =>
finder.first.evaluate().first.widget as T;

Expand All @@ -192,3 +239,8 @@ Finder findStackFrameWithText(String text) => find.descendant(
of: find.byType(CallStack),
matching: find.richTextContaining(text),
);

Finder findBreakpointWithText(String text) => find.descendant(
of: find.byType(Breakpoints),
matching: find.richTextContaining(text),
);
2 changes: 1 addition & 1 deletion packages/devtools_app/lib/src/app.dart
Expand Up @@ -294,7 +294,7 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin {
),
// This button will hide itself based on whether the
// hot restart service is available for the connected app.
const HotRestartButton(),
const HotRestartButton(key: Key('Hot Restart Button')),
],
...DevToolsScaffold.defaultActions(),
],
Expand Down
Expand Up @@ -103,7 +103,7 @@ class FrameworkCore {
service,
onClosed: finishedCompleter.future,
);
breakpointManager.initialize();
await breakpointManager.initialize();
return true;
} catch (e, st) {
if (logException) {
Expand Down