@@ -22,6 +22,7 @@ import 'package:test/test.dart';
2222import '../../debug_extension_mv3/web/data_serializers.dart' ;
2323import '../../debug_extension_mv3/web/data_types.dart' ;
2424import '../fixtures/context.dart' ;
25+ import '../fixtures/utilities.dart' ;
2526import 'test_utils.dart' ;
2627
2728final context = TestContext .withSoundNullSafety ();
@@ -435,6 +436,74 @@ void main() async {
435436 });
436437 }
437438 });
439+
440+ group ('connected to a fake app' , () {
441+ final fakeAppPath = webCompatiblePath (
442+ p.split (
443+ absolutePath (
444+ pathFromDwds: p.join (
445+ 'test' ,
446+ 'puppeteer' ,
447+ 'fake_app' ,
448+ 'index.html' ,
449+ ),
450+ ),
451+ ),
452+ );
453+ final fakeAppUrl = 'file://$fakeAppPath ' ;
454+ late Browser browser;
455+ late Worker worker;
456+
457+ setUpAll (() async {
458+ browser = await puppeteer.launch (
459+ headless: false ,
460+ timeout: Duration (seconds: 60 ),
461+ args: [
462+ '--load-extension=$extensionPath ' ,
463+ '--disable-extensions-except=$extensionPath ' ,
464+ '--disable-features=DialMediaRouteProvider' ,
465+ ],
466+ );
467+ worker = await getServiceWorker (browser);
468+ // Navigate to the Chrome extension page instead of the blank tab
469+ // opened by Chrome. This is helpful for local debugging.
470+ final blankTab = await navigateToPage (browser, url: 'about:blank' );
471+ await blankTab.goto ('chrome://extensions/' );
472+ });
473+
474+ tearDown (() async {
475+ await workerEvalDelay ();
476+ await worker.evaluate (_clearStorageJs ());
477+ await workerEvalDelay ();
478+ });
479+
480+ tearDownAll (() async {
481+ await browser.close ();
482+ });
483+
484+ // Note: This tests that the debug extension still works for DWDS versions
485+ // <17.0.0. Those versions don't send the debug info with the ready event.
486+ // Therefore the values are read from the Window object.
487+ test ('reads debug info from Window and saves to storage' , () async {
488+ // Navigate to the "Dart" app:
489+ await navigateToPage (browser, url: fakeAppUrl, isNew: true );
490+ // Verify that we have debug info for the fake "Dart" app:
491+ final appTabId = await _getTabId (fakeAppUrl, worker: worker);
492+ final debugInfoKey = '$appTabId -debugInfo' ;
493+ final debugInfo = await _fetchStorageObj <DebugInfo >(
494+ debugInfoKey,
495+ storageArea: 'session' ,
496+ worker: worker,
497+ );
498+ expect (debugInfo.appId, equals ('DART_APP_ID' ));
499+ expect (debugInfo.appEntrypointPath, equals ('DART_ENTRYPOINT_PATH' ));
500+ expect (debugInfo.appInstanceId, equals ('DART_APP_INSTANCE_ID' ));
501+ expect (debugInfo.isInternalBuild, isTrue);
502+ expect (debugInfo.isFlutterApp, isFalse);
503+ expect (debugInfo.appOrigin, isNotNull);
504+ expect (debugInfo.appUrl, isNotNull);
505+ });
506+ });
438507 });
439508}
440509
@@ -521,11 +590,13 @@ Future<T> _fetchStorageObj<T>(
521590 required String storageArea,
522591 required Worker worker,
523592}) async {
524- final storageObj = await worker.evaluate (_fetchStorageObjJs (
525- storageKey,
526- storageArea: storageArea,
527- ));
528- final json = storageObj[storageKey];
593+ final json = await retryFnAsync <String >(() async {
594+ final storageObj = await worker.evaluate (_fetchStorageObjJs (
595+ storageKey,
596+ storageArea: storageArea,
597+ ));
598+ return storageObj[storageKey];
599+ });
529600 return serializers.deserialize (jsonDecode (json)) as T ;
530601}
531602
0 commit comments