Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 44 additions & 23 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,9 @@ int? get latestAppBeingDebugged =>

Future<void> attachDebugger(int dartAppTabId,
{required Trigger trigger}) async {
// Check if a debugger is already attached:
final existingDebuggerLocation = _debuggerLocation(dartAppTabId);
if (existingDebuggerLocation != null) {
return _showWarningNotification(
'Already debugging in ${existingDebuggerLocation.displayName}.',
);
}
// Determine if there are multiple apps in the tab:
final multipleApps = await fetchStorageObject<String>(
type: StorageObject.multipleAppsDetected,
tabId: dartAppTabId,
);
if (multipleApps != null) {
return _showWarningNotification(
'Dart debugging is not supported in a multi-app environment.',
);
}
// Verify that the user is authenticated:
final isAuthenticated = await _authenticateUser(dartAppTabId);
if (!isAuthenticated) return;
// Validate that the tab can be debugged:
final tabIsDebuggable = await _validateTabIsDebuggable(dartAppTabId);
if (!tabIsDebuggable) return;

_tabIdToTrigger[dartAppTabId] = trigger;
_registerDebugEventListeners();
Expand Down Expand Up @@ -177,6 +160,40 @@ Future<void> clearStaleDebugSession(int tabId) async {
}
}

Future<bool> _validateTabIsDebuggable(int dartAppTabId) async {
// Check if a debugger is already attached:
final existingDebuggerLocation = _debuggerLocation(dartAppTabId);
if (existingDebuggerLocation != null) {
await _showWarningNotification(
'Already debugging in ${existingDebuggerLocation.displayName}.',
);
return false;
}
// Determine if this is a Dart app:
final debugInfo = await fetchStorageObject<DebugInfo>(
type: StorageObject.debugInfo,
tabId: dartAppTabId,
);
if (debugInfo == null) {
await _showWarningNotification('Not a Dart app.');
return false;
}
// Determine if there are multiple apps in the tab:
final multipleApps = await fetchStorageObject<String>(
type: StorageObject.multipleAppsDetected,
tabId: dartAppTabId,
);
if (multipleApps != null) {
await _showWarningNotification(
'Dart debugging is not supported in a multi-app environment.',
);
return false;
}
// Verify that the user is authenticated:
final isAuthenticated = await _authenticateUser(dartAppTabId);
return isAuthenticated;
}

void _registerDebugEventListeners() {
chrome.debugger.onEvent.addListener(allowInterop(_onDebuggerEvent));
chrome.debugger.onDetach.addListener(allowInterop((source, _) async {
Expand Down Expand Up @@ -548,7 +565,7 @@ Future<bool> _authenticateUser(int tabId) async {
);
final authUrl = debugInfo?.authUrl;
if (authUrl == null) {
_showWarningNotification('Cannot authenticate user.');
await _showWarningNotification('Cannot authenticate user.');
return false;
}
final isAuthenticated = await _sendAuthRequest(authUrl);
Expand Down Expand Up @@ -582,7 +599,8 @@ Future<bool> _sendAuthRequest(String authUrl) async {
return responseBody.contains('Dart Debug Authentication Success!');
}

void _showWarningNotification(String message) {
Future<bool> _showWarningNotification(String message) {
final completer = Completer<bool>();
chrome.notifications.create(
/*notificationId*/ null,
NotificationOptions(
Expand All @@ -591,8 +609,11 @@ void _showWarningNotification(String message) {
iconUrl: 'static_assets/dart.png',
type: 'basic',
),
/*callback*/ null,
allowInterop((_) {
completer.complete(true);
}),
);
return completer.future;
}

DebuggerLocation? _debuggerLocation(int dartAppTabId) {
Expand Down
23 changes: 23 additions & 0 deletions dwds/test/puppeteer/extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,29 @@ void main() async {
await devToolsTabTarget.onClose;
});

test('Clicking extension icon for a non Dart app shows warning',
() async {
// Navigate to a page that doesn't contain a Dart app:
final tab = await navigateToPage(browser,
url: 'https://dart.dev', isNew: true);
// Click on the Dart Debug Extension icon:
await workerEvalDelay();
await clickOnExtensionIcon(
worker: worker,
backgroundPage: backgroundPage,
);
// There should now be a warning notificiation:
final chromeNotifications = await evaluate(
_getNotifications(),
worker: worker,
backgroundPage: backgroundPage,
);
await workerEvalDelay();
expect(chromeNotifications, isNotEmpty);
// Close the tab:
await tab.close();
});

test('Refreshing the Dart app does not open a new Dart DevTools',
() async {
final appUrl = context.appUrl;
Expand Down
Binary file modified dwds/test/puppeteer/test_images/chromeDevTools_externalBuild.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.