diff --git a/dwds/test/inspector_test.dart b/dwds/test/inspector_test.dart index 3999296d1..f71d1e226 100644 --- a/dwds/test/inspector_test.dart +++ b/dwds/test/inspector_test.dart @@ -15,8 +15,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext( - directory: '../example', path: 'scopes.html', pathToServe: 'web'); +final context = TestContext(path: 'scopes/scopes.html'); WipConnection get tabConnection => context.tabConnection; @@ -35,11 +34,11 @@ void main() { await context.tearDown(); }); - final url = 'org-dartlang-app:///web/scopes_main.dart'; + final url = 'org-dartlang-app:///example/scopes/scopes_main.dart'; /// A convenient way to get a library variable without boilerplate. String libraryVariableExpression(String variable) => - '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("web/scopes_main")["$url"]["$variable"];'; + '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")["$url"]["$variable"];'; Future libraryPublicFinal() => inspector.jsEvaluate(libraryVariableExpression('libraryPublicFinal')); @@ -225,27 +224,27 @@ void main() { } final jsMultiLineExceptionWithStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" - at Object.assertFailed (org-dartlang-app:///web/scopes_main.dart.js:5297:15) + at Object.assertFailed (org-dartlang-app:///example/scopes/scopes_main.dart.js:5297:15) '''; final formattedMultiLineExceptionWithStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" -org-dartlang-app:///web/scopes_main.dart.js 5297:15 assertFailed +org-dartlang-app:///example/scopes/scopes_main.dart.js 5297:15 assertFailed '''; final jsMultiLineExceptionNoStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; final formattedMultiLineExceptionNoStackTrace = ''' -Error: Assertion failed: org-dartlang-app:///web/scopes_main.dart:4:11 +Error: Assertion failed: org-dartlang-app:///example/scopes/scopes_main.dart:4:11 false "THIS IS THE ASSERT MESSAGE" '''; diff --git a/dwds/test/instance_test.dart b/dwds/test/instance_test.dart index a5c64c74c..d642b9a89 100644 --- a/dwds/test/instance_test.dart +++ b/dwds/test/instance_test.dart @@ -14,8 +14,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext( - directory: '../example', path: 'scopes.html', pathToServe: 'web'); +final context = TestContext(path: 'scopes/scopes.html'); WipConnection get tabConnection => context.tabConnection; @@ -34,10 +33,10 @@ void main() { await context.tearDown(); }); - final url = 'org-dartlang-app:///web/scopes_main.dart'; + final url = 'org-dartlang-app:///example/scopes/scopes_main.dart'; String libraryVariableExpression(String variable) => - '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("web/scopes_main")' + '${globalLoadStrategy.loadModuleSnippet}("dart_sdk").dart.getModuleLibraries("example/scopes/scopes_main")' '["$url"]["$variable"];'; /// A reference to the the variable `libraryPublicFinal`, an instance of @@ -81,7 +80,7 @@ void main() { expect(classRef.name, 'MyTestClass'); expect( classRef.id, - 'classes|org-dartlang-app:///web/scopes_main.dart' + 'classes|org-dartlang-app:///example/scopes/scopes_main.dart' '|MyTestClass'); }); diff --git a/dwds/test/variable_scope_test.dart b/dwds/test/variable_scope_test.dart index 9a592ec6d..ec5f8239f 100644 --- a/dwds/test/variable_scope_test.dart +++ b/dwds/test/variable_scope_test.dart @@ -12,8 +12,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; import 'fixtures/context.dart'; -final context = TestContext( - directory: '../example', path: 'scopes.html', pathToServe: 'web'); +final context = TestContext(path: 'scopes/scopes.html'); ChromeProxyService get service => fetchChromeProxyService(context.debugConnection); WipConnection get tabConnection => context.tabConnection; diff --git a/example/web/scopes.html b/fixtures/_test/example/scopes/scopes.html similarity index 100% rename from example/web/scopes.html rename to fixtures/_test/example/scopes/scopes.html diff --git a/example/web/scopes_main.dart b/fixtures/_test/example/scopes/scopes_main.dart similarity index 100% rename from example/web/scopes_main.dart rename to fixtures/_test/example/scopes/scopes_main.dart diff --git a/fixtures/_testSound/example/scopes/scopes.html b/fixtures/_testSound/example/scopes/scopes.html new file mode 100644 index 000000000..6c3307394 --- /dev/null +++ b/fixtures/_testSound/example/scopes/scopes.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/fixtures/_testSound/example/scopes/scopes_main.dart b/fixtures/_testSound/example/scopes/scopes_main.dart new file mode 100644 index 000000000..ea7338a16 --- /dev/null +++ b/fixtures/_testSound/example/scopes/scopes_main.dart @@ -0,0 +1,165 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// An example with more complicated scope +import 'dart:async'; +import 'dart:collection'; + +final libraryPublicFinal = MyTestClass(); + +final _libraryPrivateFinal = 1; +Object? libraryNull; +var libraryPublic = ['library', 'public', 'variable']; +var notAList = NotReallyAList(); + +var _libraryPrivate = ['library', 'private', 'variable']; + +var identityMap = {}; + +var map = {}; + +void staticFunction(int formal) { + print(formal); // Breakpoint: staticFunction +} + +void main() async { + print('Initial print from scopes app'); + var local = 'local in main'; + var intLocalInMain = 42; + var testClass = MyTestClass(); + Object? localThatsNull; + identityMap['a'] = 1; + identityMap['b'] = 2; + map['a'] = [1, 2, 3]; + map['b'] = 'something'; + notAList.add(7); + + String nestedFunction(T parameter, Object aClass) { + var another = int.tryParse('$parameter'); + return '$local: parameter, $another'; // Breakpoint: nestedFunction + } + + dynamic nestedWithClosure(String banana) { + return () => '$local + $banana'; + } + + Timer.periodic(const Duration(seconds: 1), (Timer t) { + var ticks = t.tick; + // ignore: unused_local_variable, prefer_typing_uninitialized_variables + var closureLocal; + libraryPublicFinal.printCount(); + staticFunction(1); + print('ticking... $ticks (the answer is $intLocalInMain)'); + print(nestedFunction('$ticks ${testClass.message}', Timer)); + print(localThatsNull); + print(libraryNull); + var localList = libraryPublic; + print(localList); + localList.add('abc'); + var f = testClass.methodWithVariables(); + print(f('parameter')); + var num = '1234'.someExtensionMethod(); + print('$num'); + }); + + print(_libraryPrivateFinal); + print(_libraryPrivate); + print(nestedFunction(_libraryPrivate.first, Object)); + print(nestedWithClosure(_libraryPrivate.first)()); +} + +String libraryFunction(String arg) { + print('calling a library function with $arg'); + var concat = 'some constant plus $arg plus whatever'; + print(concat); + return concat; +} + +abstract class MyAbstractClass { + String abstractField = 'abstract-field-value'; +} + +class MyTestClass extends MyAbstractClass { + final String message; + + String? notFinal; + + MyTestClass({this.message = 'world'}) { + myselfField = this; + tornOff = toString; + } + + String hello() => message; + + String Function(String) methodWithVariables() { + var local = '$message + something'; + print(local); + return (String parameter) { + // Be sure to use a field from this, so it isn't entirely optimized away. + var closureLocalInsideMethod = '$message/$local/$parameter'; + print(closureLocalInsideMethod); + return closureLocalInsideMethod; // Breakpoint: nestedClosure + }; + } + + //ignore: avoid_returning_this + MyTestClass get myselfGetter => this; + + late final MyTestClass myselfField; + + var count = 0; + + // An easy location to add a breakpoint. + void printCount() { + print('The count is ${++count}'); + libraryFunction('abc'); // Breakpoint: printMethod + } + + final _privateField = 'a private field'; + + // ignore: unused_element + String privateMethod(String s) => '$s : $_privateField'; + + @override + String toString() => 'A test class with message $message'; + + bool equals(Object other) { + if (other is MyTestClass) return message == other.hello(); + return false; + } + + Function closure = someFunction; + + late final String Function() tornOff; +} + +Function? someFunction() => null; + +// ignore: unused_element +int _libraryPrivateFunction(int a, int b) => a + b; + +class NotReallyAList extends ListBase { + final List _internal; + + NotReallyAList() : _internal = []; + + @override + Object? operator [](x) => _internal[x]; + + @override + operator []=(int x, Object? y) => _internal[x] = y; + + @override + int get length => _internal.length; + + @override + set length(x) => _internal.length = x; +} + +extension NumberParsing on String { + int someExtensionMethod() { + var ret = int.parse(this); + return ret; // Breakpoint: extension + } +}