Skip to content

Commit a995a59

Browse files
authored
Updating Chrome Proxy Service tests to avoid manually invoking generic Dart constructors. (#2477)
This fixes breakages from an incoming change to update how DDC represents generic types. The old code here was manually invoking Dart constructors from JS; this broke when we changed their APIs to accept an RTI. The new scheme evals a top-level object (initialized with the correct state).
1 parent e1c2b7f commit a995a59

File tree

2 files changed

+115
-66
lines changed

2 files changed

+115
-66
lines changed

dwds/test/chrome_proxy_service_test.dart

Lines changed: 102 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'dart:async';
1111
import 'dart:convert';
1212
import 'dart:io';
1313

14-
import 'package:dwds/src/config/tool_configuration.dart';
1514
import 'package:dwds/src/services/chrome_proxy_service.dart';
1615
import 'package:dwds/src/utilities/dart_uri.dart';
1716
import 'package:dwds/src/utilities/shared.dart';
@@ -22,7 +21,6 @@ import 'package:test_common/logging.dart';
2221
import 'package:test_common/test_sdk_configuration.dart';
2322
import 'package:vm_service/vm_service.dart';
2423
import 'package:vm_service_interface/vm_service_interface.dart';
25-
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
2624

2725
import 'fixtures/context.dart';
2826
import 'fixtures/project.dart';
@@ -670,38 +668,13 @@ void main() {
670668
expect(largeString.length, 5 * 250);
671669
});
672670

673-
/// Helper to create a list of 1001 elements, doing a direct JS eval.
674-
Future<RemoteObject> createList() {
675-
final expr = '''
676-
(function () {
677-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk");
678-
const list = sdk.dart.dsend(sdk.core.List,"filled", [1001, 5]);
679-
list[4] = 100;
680-
return list;
681-
})()''';
682-
return service.inspector.jsEvaluate(expr);
683-
}
684-
685-
/// Helper to create a LinkedHashMap with 1001 entries, doing a direct JS eval.
686-
Future<RemoteObject> createMap() {
687-
final expr = '''
688-
(function () {
689-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk");
690-
const iterable = sdk.dart.dsend(sdk.core.Iterable, "generate", [1001]);
691-
const list1 = sdk.dart.dsend(iterable, "toList", []);
692-
const reversed = sdk.dart.dload(list1, "reversed");
693-
const list2 = sdk.dart.dsend(reversed, "toList", []);
694-
const map = sdk.dart.dsend(list2, "asMap", []);
695-
const linkedMap = sdk.dart.dsend(sdk.collection.LinkedHashMap, "from", [map]);
696-
return linkedMap;
697-
})()''';
698-
return service.inspector.jsEvaluate(expr);
699-
}
700-
701671
test('Lists', () async {
702-
final list = await createList();
703-
final inst =
704-
await service.getObject(isolate.id!, list.objectId!) as Instance;
672+
final list = await service.evaluate(
673+
isolate.id!,
674+
bootstrap!.id!,
675+
'topLevelList',
676+
) as InstanceRef;
677+
final inst = await service.getObject(isolate.id!, list.id!) as Instance;
705678
expect(inst.length, 1001);
706679
expect(inst.offset, null);
707680
expect(inst.count, null);
@@ -713,9 +686,12 @@ void main() {
713686
});
714687

715688
test('Maps', () async {
716-
final map = await createMap();
717-
final inst =
718-
await service.getObject(isolate.id!, map.objectId!) as Instance;
689+
final map = await service.evaluate(
690+
isolate.id!,
691+
bootstrap!.id!,
692+
'topLevelMap',
693+
) as InstanceRef;
694+
final inst = await service.getObject(isolate.id!, map.id!) as Instance;
719695
expect(inst.length, 1001);
720696
expect(inst.offset, null);
721697
expect(inst.count, null);
@@ -769,10 +745,14 @@ void main() {
769745

770746
group('getObject called with offset/count parameters', () {
771747
test('Lists with null offset and count are not truncated', () async {
772-
final list = await createList();
748+
final list = await service.evaluate(
749+
isolate.id!,
750+
bootstrap!.id!,
751+
'topLevelList',
752+
) as InstanceRef;
773753
final inst = await service.getObject(
774754
isolate.id!,
775-
list.objectId!,
755+
list.id!,
776756
count: null,
777757
offset: null,
778758
) as Instance;
@@ -787,10 +767,14 @@ void main() {
787767
});
788768

789769
test('Lists with null count are not truncated', () async {
790-
final list = await createList();
770+
final list = await service.evaluate(
771+
isolate.id!,
772+
bootstrap!.id!,
773+
'topLevelList',
774+
) as InstanceRef;
791775
final inst = await service.getObject(
792776
isolate.id!,
793-
list.objectId!,
777+
list.id!,
794778
count: null,
795779
offset: 0,
796780
) as Instance;
@@ -807,10 +791,14 @@ void main() {
807791
test(
808792
'Lists with null count and offset greater than 0 are '
809793
'truncated from offset to end of list', () async {
810-
final list = await createList();
794+
final list = await service.evaluate(
795+
isolate.id!,
796+
bootstrap!.id!,
797+
'topLevelList',
798+
) as InstanceRef;
811799
final inst = await service.getObject(
812800
isolate.id!,
813-
list.objectId!,
801+
list.id!,
814802
count: null,
815803
offset: 1000,
816804
) as Instance;
@@ -823,10 +811,14 @@ void main() {
823811
});
824812

825813
test('Lists with offset/count are truncated', () async {
826-
final list = await createList();
814+
final list = await service.evaluate(
815+
isolate.id!,
816+
bootstrap!.id!,
817+
'topLevelList',
818+
) as InstanceRef;
827819
final inst = await service.getObject(
828820
isolate.id!,
829-
list.objectId!,
821+
list.id!,
830822
count: 7,
831823
offset: 4,
832824
) as Instance;
@@ -842,10 +834,14 @@ void main() {
842834

843835
test('Lists are truncated to the end if offset/count runs off the end',
844836
() async {
845-
final list = await createList();
837+
final list = await service.evaluate(
838+
isolate.id!,
839+
bootstrap!.id!,
840+
'topLevelList',
841+
) as InstanceRef;
846842
final inst = await service.getObject(
847843
isolate.id!,
848-
list.objectId!,
844+
list.id!,
849845
count: 5,
850846
offset: 1000,
851847
) as Instance;
@@ -859,10 +855,14 @@ void main() {
859855

860856
test('Lists are truncated to empty if offset runs off the end',
861857
() async {
862-
final list = await createList();
858+
final list = await service.evaluate(
859+
isolate.id!,
860+
bootstrap!.id!,
861+
'topLevelList',
862+
) as InstanceRef;
863863
final inst = await service.getObject(
864864
isolate.id!,
865-
list.objectId!,
865+
list.id!,
866866
count: 5,
867867
offset: 1002,
868868
) as Instance;
@@ -875,10 +875,14 @@ void main() {
875875

876876
test('Lists are truncated to empty with 0 count and null offset',
877877
() async {
878-
final list = await createList();
878+
final list = await service.evaluate(
879+
isolate.id!,
880+
bootstrap!.id!,
881+
'topLevelList',
882+
) as InstanceRef;
879883
final inst = await service.getObject(
880884
isolate.id!,
881-
list.objectId!,
885+
list.id!,
882886
count: 0,
883887
offset: null,
884888
) as Instance;
@@ -890,10 +894,14 @@ void main() {
890894
});
891895

892896
test('Maps with null offset/count are not truncated', () async {
893-
final map = await createMap();
897+
final map = await service.evaluate(
898+
isolate.id!,
899+
bootstrap!.id!,
900+
'topLevelMap',
901+
) as InstanceRef;
894902
final inst = await service.getObject(
895903
isolate.id!,
896-
map.objectId!,
904+
map.id!,
897905
count: null,
898906
offset: null,
899907
) as Instance;
@@ -912,10 +920,14 @@ void main() {
912920
test(
913921
'Maps with null count and offset greater than 0 are '
914922
'truncated from offset to end of map', () async {
915-
final list = await createMap();
923+
final map = await service.evaluate(
924+
isolate.id!,
925+
bootstrap!.id!,
926+
'topLevelMap',
927+
) as InstanceRef;
916928
final inst = await service.getObject(
917929
isolate.id!,
918-
list.objectId!,
930+
map.id!,
919931
count: null,
920932
offset: 1000,
921933
) as Instance;
@@ -929,10 +941,14 @@ void main() {
929941
});
930942

931943
test('Maps with null count are not truncated', () async {
932-
final map = await createMap();
944+
final map = await service.evaluate(
945+
isolate.id!,
946+
bootstrap!.id!,
947+
'topLevelMap',
948+
) as InstanceRef;
933949
final inst = await service.getObject(
934950
isolate.id!,
935-
map.objectId!,
951+
map.id!,
936952
count: null,
937953
offset: 0,
938954
) as Instance;
@@ -949,10 +965,14 @@ void main() {
949965
});
950966

951967
test('Maps with offset/count are truncated', () async {
952-
final map = await createMap();
968+
final map = await service.evaluate(
969+
isolate.id!,
970+
bootstrap!.id!,
971+
'topLevelMap',
972+
) as InstanceRef;
953973
final inst = await service.getObject(
954974
isolate.id!,
955-
map.objectId!,
975+
map.id!,
956976
count: 7,
957977
offset: 4,
958978
) as Instance;
@@ -970,10 +990,14 @@ void main() {
970990

971991
test('Maps are truncated to the end if offset/count runs off the end',
972992
() async {
973-
final map = await createMap();
993+
final map = await service.evaluate(
994+
isolate.id!,
995+
bootstrap!.id!,
996+
'topLevelMap',
997+
) as InstanceRef;
974998
final inst = await service.getObject(
975999
isolate.id!,
976-
map.objectId!,
1000+
map.id!,
9771001
count: 5,
9781002
offset: 1000,
9791003
) as Instance;
@@ -988,10 +1012,14 @@ void main() {
9881012

9891013
test('Maps are truncated to empty if offset runs off the end',
9901014
() async {
991-
final list = await createMap();
1015+
final map = await service.evaluate(
1016+
isolate.id!,
1017+
bootstrap!.id!,
1018+
'topLevelMap',
1019+
) as InstanceRef;
9921020
final inst = await service.getObject(
9931021
isolate.id!,
994-
list.objectId!,
1022+
map.id!,
9951023
count: 5,
9961024
offset: 1002,
9971025
) as Instance;
@@ -1022,10 +1050,14 @@ void main() {
10221050

10231051
test('Maps are truncated to empty if offset runs off the end',
10241052
() async {
1025-
final list = await createMap();
1053+
final map = await service.evaluate(
1054+
isolate.id!,
1055+
bootstrap!.id!,
1056+
'topLevelMap',
1057+
) as InstanceRef;
10261058
final inst = await service.getObject(
10271059
isolate.id!,
1028-
list.objectId!,
1060+
map.id!,
10291061
count: 5,
10301062
offset: 1002,
10311063
) as Instance;
@@ -1038,10 +1070,14 @@ void main() {
10381070

10391071
test('Maps are truncated to empty with 0 count and null offset',
10401072
() async {
1041-
final list = await createMap();
1073+
final map = await service.evaluate(
1074+
isolate.id!,
1075+
bootstrap!.id!,
1076+
'topLevelMap',
1077+
) as InstanceRef;
10421078
final inst = await service.getObject(
10431079
isolate.id!,
1044-
list.objectId!,
1080+
map.id!,
10451081
count: 0,
10461082
offset: null,
10471083
) as Instance;

fixtures/_testSound/example/hello_world/main.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6+
import 'dart:collection';
67
import 'dart:convert';
78
import 'dart:developer';
89
import 'dart:html';
@@ -13,6 +14,18 @@ import 'package:path/path.dart' as p;
1314

1415
part 'part.dart';
1516

17+
// Create a series of top level objects for tests in
18+
// dwds/test/chrome_proxy_service_test.dart
19+
20+
final topLevelList = () {
21+
var l = List.filled(1001, 5);
22+
l[4] = 100;
23+
return l;
24+
}();
25+
26+
final topLevelMap = LinkedHashMap.from(
27+
Iterable.generate(1001).toList().reversed.toList().asMap());
28+
1629
final myInstance = MyTestClass();
1730

1831
void main() async {

0 commit comments

Comments
 (0)