From c6c9728ba23ff88a40edc48c998e960f0bc88aff Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 2 Aug 2024 15:12:05 -0700 Subject: [PATCH] Update min SDK and a number of lints Update dev dependencies --- .github/workflows/build.yaml | 58 +++++++++++++++++++++-------- CHANGELOG.md | 4 ++ analysis_options.yaml | 6 +-- example/multiplex.dart | 4 +- example/multiplex_impl.dart | 2 - lib/dom_model.dart | 10 ++--- lib/forwarder.dart | 8 ++-- lib/src/console.dart | 6 +-- lib/src/debugger.dart | 50 +++++++++++++------------ lib/src/dom.dart | 24 ++++++------ lib/src/log.dart | 4 +- lib/src/page.dart | 2 +- lib/src/runtime.dart | 57 ++++++++++++++-------------- lib/src/target.dart | 8 ++-- lib/webkit_inspection_protocol.dart | 24 ++++++------ pubspec.yaml | 14 +++---- test/console_test.dart | 10 ++--- test/debugger_test.dart | 6 +-- test/dom_model_test.dart | 28 +++++++------- test/runtime_test.dart | 20 +++++----- test/test_setup.dart | 6 +-- 21 files changed, 186 insertions(+), 165 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 97a17b1..bffa66c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,7 @@ name: Dart on: + # Run on PRs and pushes to the default branch. push: branches: [ main ] pull_request: @@ -8,32 +9,59 @@ on: schedule: - cron: "0 0 * * 0" +env: + PUB_ENVIRONMENT: bot.github + permissions: read-all jobs: - build: + analyze: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sdk: [ dev ] + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + with: + sdk: ${{ matrix.sdk }} + - id: install + name: Install dependencies + run: dart pub get + - name: Check formatting + run: dart format --output=none --set-exit-if-changed . + if: always() && steps.install.outcome == 'success' + - name: Analyze code + run: dart analyze --fatal-infos + if: always() && steps.install.outcome == 'success' + + test: + needs: analyze runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Add macos-latest and/or windows-latest if relevant for this package. + os: [ubuntu-latest] + sdk: [3.4, dev] steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 - uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672 + with: + sdk: ${{ matrix.sdk }} - uses: nanasess/setup-chromedriver@42cc2998329f041de87dc3cfa33a930eacd57eaa - name: Install dependencies run: dart pub get - - name: Validate formatting - run: dart format --output=none --set-exit-if-changed . - - - name: Analyze source code - run: dart analyze - # Disabled; tracked via #75. - # - name: Run tests - # run: | - # export DISPLAY=:99 - # chromedriver --port=4444 --url-base=/wd/hub & - # sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & - # dart test - # env: - # CHROMEDRIVER_ARGS: '--no-sandbox --headless' + - name: Run tests + run: | + export DISPLAY=:99 + chromedriver --port=4444 --url-base=/wd/hub & + sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & + dart test + env: + CHROMEDRIVER_ARGS: '--no-sandbox --headless' diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e1a570..84ad84f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.2.2-wip + +- Require SDK `sdk: ^3.4.0`. + ## 1.2.1 - Make the return type of `runtime`'s `ExceptionDetails.url` field nullable. diff --git a/analysis_options.yaml b/analysis_options.yaml index 8051c3b..fbb7ad1 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,9 +1,5 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: errors: deprecated_member_use_from_same_package: ignore - -linter: - rules: - - avoid_dynamic_calls diff --git a/example/multiplex.dart b/example/multiplex.dart index 8fc6e97..fa4b1bb 100644 --- a/example/multiplex.dart +++ b/example/multiplex.dart @@ -1,13 +1,11 @@ // Copyright 2015 Google. All rights reserved. Use of this source code is // governed by a BSD-style license that can be found in the LICENSE file. -library wip.multiplex; - import 'dart:io' show stderr; import 'package:args/args.dart' show ArgParser; import 'package:logging/logging.dart' - show hierarchicalLoggingEnabled, Level, Logger, LogRecord; + show Level, LogRecord, Logger, hierarchicalLoggingEnabled; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' show ChromeConnection; diff --git a/example/multiplex_impl.dart b/example/multiplex_impl.dart index c8eeb34..3558996 100644 --- a/example/multiplex_impl.dart +++ b/example/multiplex_impl.dart @@ -1,8 +1,6 @@ // Copyright 2015 Google. All rights reserved. Use of this source code is // governed by a BSD-style license that can be found in the LICENSE file. -library wip.multiplex_impl; - import 'dart:async' show Future; import 'dart:convert' show jsonEncode; import 'dart:io' show HttpServer, InternetAddress; diff --git a/lib/dom_model.dart b/lib/dom_model.dart index 9bb5f05..37d9036 100644 --- a/lib/dom_model.dart +++ b/lib/dom_model.dart @@ -1,8 +1,6 @@ // Copyright 2015 Google. All rights reserved. Use of this source code is // governed by a BSD-style license that can be found in the LICENSE file. -library wip.dom_model; - import 'dart:async' show EventSink, Future, Stream, StreamTransformer; import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView; import 'dart:mirrors' show reflect; @@ -112,7 +110,7 @@ class WipDomModel implements WipDom { void _onChildNodeInserted( ChildNodeInsertedEvent event, EventSink sink) { var parent = _getOrCreateNode(event.parentNodeId); - int index = + var index = parent._children!.indexOf(_getOrCreateNode(event.previousNodeId)) + 1; var node = _getOrCreateNodeFromNode(event.node); parent._children!.insert(index, node); @@ -147,7 +145,7 @@ class WipDomModel implements WipDom { @override Future> getAttributes(int nodeId) async { - Map attributes = await _dom.getAttributes(nodeId); + var attributes = await _dom.getAttributes(nodeId); var node = _getOrCreateNode(nodeId); node._attributes = Map.from(attributes); return attributes; @@ -158,7 +156,7 @@ class WipDomModel implements WipDom { /// multiple times on the same page. @override Future getDocument() { - _root ??= _dom.getDocument().then((n) => _getOrCreateNodeFromNode(n)); + _root ??= _dom.getDocument().then(_getOrCreateNodeFromNode); return _root!; } @@ -303,7 +301,7 @@ class _Node implements Node { map['childNodeCount'] = childNodeCount!; } if (_children != null && _children!.isNotEmpty) { - var newChildren = []; + var newChildren = >[]; for (var child in _children!) { newChildren.add(child._toJsonInternal(visited)); } diff --git a/lib/forwarder.dart b/lib/forwarder.dart index 16a1ac0..06863c0 100644 --- a/lib/forwarder.dart +++ b/lib/forwarder.dart @@ -1,8 +1,6 @@ // Copyright 2015 Google. All rights reserved. Use of this source code is // governed by a BSD-style license that can be found in the LICENSE file. -library crmux.forwarder; - import 'dart:async' show Future, Stream, StreamController, StreamSink, StreamSubscription; import 'dart:convert' show jsonDecode, jsonEncode; @@ -11,7 +9,7 @@ import 'package:logging/logging.dart' show Logger; import 'dom_model.dart' show flattenAttributesMap; import 'webkit_inspection_protocol.dart' - show WipConnection, WipDom, WipError, WipEvent, WipResponse; + show WipConnection, WipDom, WipError, WipEvent; /// Forwards a [Stream] to a [WipConnection] and events /// from a [WipConnection] to a [StreamSink]. @@ -51,7 +49,7 @@ class WipForwarder { try { var method = json['method'] as String; var params = json['params'] as Map; - bool processed = false; + var processed = false; if (method.contains('reakpoint')) { forwardPausedEvents = true; @@ -72,7 +70,7 @@ class WipForwarder { } } if (!processed) { - WipResponse resp = await _debugger.sendCommand(method, params); + var resp = await _debugger.sendCommand(method, params); if (resp.result != null) { response['result'] = resp.result; } diff --git a/lib/src/console.dart b/lib/src/console.dart index 4864a9f..5a14913 100644 --- a/lib/src/console.dart +++ b/lib/src/console.dart @@ -7,7 +7,7 @@ import '../webkit_inspection_protocol.dart'; @Deprecated('This domain is deprecated - use Runtime or Log instead') class WipConsole extends WipDomain { - WipConsole(WipConnection connection) : super(connection); + WipConsole(super.connection); Future enable() => sendCommand('Console.enable'); @@ -25,7 +25,7 @@ class WipConsole extends WipDomain { } class ConsoleMessageEvent extends WipEvent { - ConsoleMessageEvent(Map json) : super(json); + ConsoleMessageEvent(super.json); Map get _message => params!['message'] as Map; @@ -49,7 +49,7 @@ class ConsoleMessageEvent extends WipEvent { } class ConsoleClearedEvent extends WipEvent { - ConsoleClearedEvent(Map json) : super(json); + ConsoleClearedEvent(super.json); } class WipConsoleCallFrame { diff --git a/lib/src/debugger.dart b/lib/src/debugger.dart index 73bf2ca..847c3e4 100644 --- a/lib/src/debugger.dart +++ b/lib/src/debugger.dart @@ -9,7 +9,7 @@ import '../webkit_inspection_protocol.dart'; class WipDebugger extends WipDomain { final _scripts = {}; - WipDebugger(WipConnection connection) : super(connection) { + WipDebugger(super.connection) { onScriptParsed.listen((event) { _scripts[event.script.scriptId] = event.script; }); @@ -55,14 +55,14 @@ class WipDebugger extends WipDomain { WipLocation location, { String? condition, }) async { - Map params = { + var params = { 'location': location.toJsonMap(), }; if (condition != null) { params['condition'] = condition; } - final WipResponse response = + final response = await sendCommand('Debugger.setBreakpoint', params: params); if (response.result!.containsKey('exceptionDetails')) { @@ -90,7 +90,7 @@ class WipDebugger extends WipDomain { String expression, { bool? returnByValue, }) async { - Map params = { + var params = { 'callFrameId': callFrameId, 'expression': expression, }; @@ -98,7 +98,7 @@ class WipDebugger extends WipDomain { params['returnByValue'] = returnByValue; } - final WipResponse response = + final response = await sendCommand('Debugger.evaluateOnCallFrame', params: params); if (response.result!.containsKey('exceptionDetails')) { @@ -122,7 +122,7 @@ class WipDebugger extends WipDomain { WipLocation? end, bool? restrictToFunction, }) async { - Map params = { + var params = { 'start': start.toJsonMap(), }; if (end != null) { @@ -132,15 +132,16 @@ class WipDebugger extends WipDomain { params['restrictToFunction'] = restrictToFunction; } - final WipResponse response = + final response = await sendCommand('Debugger.getPossibleBreakpoints', params: params); if (response.result!.containsKey('exceptionDetails')) { throw ExceptionDetails( response.result!['exceptionDetails'] as Map); } else { - List locations = response.result!['locations']; - return List.from(locations.map((map) => WipBreakLocation(map))); + var locations = response.result!['locations'] as List; + return List.from(locations + .map((map) => WipBreakLocation(map as Map))); } } @@ -187,7 +188,7 @@ String _pauseStateToString(PauseState state) { enum PauseState { all, none, uncaught } class ScriptParsedEvent extends WipEvent { - ScriptParsedEvent(Map json) : super(json); + ScriptParsedEvent(super.json); WipScript get script => WipScript(params!); @@ -196,17 +197,17 @@ class ScriptParsedEvent extends WipEvent { } class GlobalObjectClearedEvent extends WipEvent { - GlobalObjectClearedEvent(Map json) : super(json); + GlobalObjectClearedEvent(super.json); } class DebuggerResumedEvent extends WipEvent { - DebuggerResumedEvent(Map json) : super(json); + DebuggerResumedEvent(super.json); } /// Fired when the virtual machine stopped on breakpoint or exception or any /// other stop criteria. class DebuggerPausedEvent extends WipEvent { - DebuggerPausedEvent(Map json) : super(json); + DebuggerPausedEvent(super.json); /// Call stack the virtual machine stopped on. List getCallFrames() => (params!['callFrames'] as List) @@ -231,7 +232,7 @@ class DebuggerPausedEvent extends WipEvent { /// Async stack trace, if any. StackTrace? get asyncStackTrace => params!['asyncStackTrace'] == null ? null - : StackTrace(params!['asyncStackTrace']); + : StackTrace(params!['asyncStackTrace'] as Map); @override String toString() => 'paused: $reason'; @@ -295,11 +296,11 @@ class WipLocation { } } - String get scriptId => json['scriptId']; + String get scriptId => json['scriptId'] as String; - int get lineNumber => json['lineNumber']; + int get lineNumber => json['lineNumber'] as int; - int? get columnNumber => json['columnNumber']; + int? get columnNumber => json['columnNumber'] as int?; Map toJsonMap() { return json; @@ -353,11 +354,11 @@ class WipScope { } class WipBreakLocation extends WipLocation { - WipBreakLocation(Map json) : super(json); + WipBreakLocation(super.json); - WipBreakLocation.fromValues(String scriptId, int lineNumber, - {int? columnNumber, String? type}) - : super.fromValues(scriptId, lineNumber, columnNumber: columnNumber) { + WipBreakLocation.fromValues(super.scriptId, super.lineNumber, + {super.columnNumber, String? type}) + : super.fromValues() { if (type != null) { json['type'] = type; } @@ -369,9 +370,10 @@ class WipBreakLocation extends WipLocation { /// The response from [WipDebugger.setBreakpoint]. class SetBreakpointResponse extends WipResponse { - SetBreakpointResponse(Map json) : super(json); + SetBreakpointResponse(super.json); - String get breakpointId => result!['breakpointId']; + String get breakpointId => result!['breakpointId'] as String; - WipLocation get actualLocation => WipLocation(result!['actualLocation']); + WipLocation get actualLocation => + WipLocation(result!['actualLocation'] as Map); } diff --git a/lib/src/dom.dart b/lib/src/dom.dart index 7c5433f..1b26127 100644 --- a/lib/src/dom.dart +++ b/lib/src/dom.dart @@ -9,10 +9,10 @@ import '../webkit_inspection_protocol.dart'; /// Implementation of the /// https://developer.chrome.com/devtools/docs/protocol/1.1/dom class WipDom extends WipDomain { - WipDom(WipConnection connection) : super(connection); + WipDom(super.connection); Future> getAttributes(int nodeId) async { - WipResponse resp = + var resp = await sendCommand('DOM.getAttributes', params: {'nodeId': nodeId}); return _attributeListToMap((resp.result!['attributes'] as List).cast()); } @@ -178,7 +178,7 @@ class WipDom extends WipDomain { } class AttributeModifiedEvent extends WipEvent { - AttributeModifiedEvent(Map json) : super(json); + AttributeModifiedEvent(super.json); int get nodeId => params!['nodeId'] as int; @@ -188,7 +188,7 @@ class AttributeModifiedEvent extends WipEvent { } class AttributeRemovedEvent extends WipEvent { - AttributeRemovedEvent(Map json) : super(json); + AttributeRemovedEvent(super.json); int get nodeId => params!['nodeId'] as int; @@ -196,7 +196,7 @@ class AttributeRemovedEvent extends WipEvent { } class CharacterDataModifiedEvent extends WipEvent { - CharacterDataModifiedEvent(Map json) : super(json); + CharacterDataModifiedEvent(super.json); int get nodeId => params!['nodeId'] as int; @@ -204,7 +204,7 @@ class CharacterDataModifiedEvent extends WipEvent { } class ChildNodeCountUpdatedEvent extends WipEvent { - ChildNodeCountUpdatedEvent(Map json) : super(json); + ChildNodeCountUpdatedEvent(super.json); int get nodeId => params!['nodeId'] as int; @@ -212,7 +212,7 @@ class ChildNodeCountUpdatedEvent extends WipEvent { } class ChildNodeInsertedEvent extends WipEvent { - ChildNodeInsertedEvent(Map json) : super(json); + ChildNodeInsertedEvent(super.json); int get parentNodeId => params!['parentNodeId'] as int; @@ -222,7 +222,7 @@ class ChildNodeInsertedEvent extends WipEvent { } class ChildNodeRemovedEvent extends WipEvent { - ChildNodeRemovedEvent(Map json) : super(json); + ChildNodeRemovedEvent(super.json); int get parentNodeId => params!['parentNodeId'] as int; @@ -230,16 +230,16 @@ class ChildNodeRemovedEvent extends WipEvent { } class DocumentUpdatedEvent extends WipEvent { - DocumentUpdatedEvent(Map json) : super(json); + DocumentUpdatedEvent(super.json); } class SetChildNodesEvent extends WipEvent { - SetChildNodesEvent(Map json) : super(json); + SetChildNodesEvent(super.json); int get nodeId => params!['parentId'] as int; Iterable get nodes sync* { - for (Map node in params!['nodes']) { + for (var node in (params!['nodes'] as List)) { yield Node(node as Map); } } @@ -321,7 +321,7 @@ class Rgba { Map _attributeListToMap(List attrList) { var attributes = {}; - for (int i = 0; i < attrList.length; i += 2) { + for (var i = 0; i < attrList.length; i += 2) { attributes[attrList[i]] = attrList[i + 1]; } return UnmodifiableMapView(attributes); diff --git a/lib/src/log.dart b/lib/src/log.dart index 9839472..e3d3a26 100644 --- a/lib/src/log.dart +++ b/lib/src/log.dart @@ -6,7 +6,7 @@ import 'dart:async'; import '../webkit_inspection_protocol.dart'; class WipLog extends WipDomain { - WipLog(WipConnection connection) : super(connection); + WipLog(super.connection); Future enable() => sendCommand('Log.enable'); @@ -17,7 +17,7 @@ class WipLog extends WipDomain { } class LogEntry extends WipEvent { - LogEntry(Map json) : super(json); + LogEntry(super.json); Map get _entry => params!['entry'] as Map; diff --git a/lib/src/page.dart b/lib/src/page.dart index 5b125d0..ba872d3 100644 --- a/lib/src/page.dart +++ b/lib/src/page.dart @@ -6,7 +6,7 @@ import 'dart:async'; import '../webkit_inspection_protocol.dart'; class WipPage extends WipDomain { - WipPage(WipConnection connection) : super(connection); + WipPage(super.connection); Future enable() => sendCommand('Page.enable'); diff --git a/lib/src/runtime.dart b/lib/src/runtime.dart index 3be4e44..49d543c 100644 --- a/lib/src/runtime.dart +++ b/lib/src/runtime.dart @@ -7,7 +7,7 @@ import 'dart:math'; import '../webkit_inspection_protocol.dart'; class WipRuntime extends WipDomain { - WipRuntime(WipConnection connection) : super(connection); + WipRuntime(super.connection); /// Enables reporting of execution contexts creation by means of /// executionContextCreated event. When the reporting gets enabled the event @@ -32,7 +32,7 @@ class WipRuntime extends WipDomain { int? contextId, bool? awaitPromise, }) async { - Map params = { + var params = { 'expression': expression, }; if (returnByValue != null) { @@ -45,8 +45,7 @@ class WipRuntime extends WipDomain { params['awaitPromise'] = awaitPromise; } - final WipResponse response = - await sendCommand('Runtime.evaluate', params: params); + final response = await sendCommand('Runtime.evaluate', params: params); if (response.result!.containsKey('exceptionDetails')) { throw ExceptionDetails( @@ -68,7 +67,7 @@ class WipRuntime extends WipDomain { bool? returnByValue, int? executionContextId, }) async { - Map params = { + var params = { 'functionDeclaration': functionDeclaration, }; if (objectId != null) { @@ -91,7 +90,7 @@ class WipRuntime extends WipDomain { }).toList(); } - final WipResponse response = + final response = await sendCommand('Runtime.callFunctionOn', params: params); if (response.result!.containsKey('exceptionDetails')) { @@ -106,7 +105,7 @@ class WipRuntime extends WipDomain { /// corresponding isolate not scoped to a particular Runtime. @experimental Future getHeapUsage() async { - final WipResponse response = await sendCommand('Runtime.getHeapUsage'); + final response = await sendCommand('Runtime.getHeapUsage'); return HeapUsage(response.result!); } @@ -127,22 +126,22 @@ class WipRuntime extends WipDomain { RemoteObject object, { bool? ownProperties, }) async { - Map params = { + var params = { 'objectId': object.objectId, }; if (ownProperties != null) { params['ownProperties'] = ownProperties; } - final WipResponse response = - await sendCommand('Runtime.getProperties', params: params); + final response = await sendCommand('Runtime.getProperties', params: params); if (response.result!.containsKey('exceptionDetails')) { throw ExceptionDetails( response.result!['exceptionDetails'] as Map); } else { - List locations = response.result!['result']; - return List.from(locations.map((map) => PropertyDescriptor(map))); + var locations = response.result!['result'] as List; + return List.from(locations + .map((map) => PropertyDescriptor(map as Map))); } } @@ -158,13 +157,13 @@ class WipRuntime extends WipDomain { Stream get onExecutionContextCreated => eventStream( 'Runtime.executionContextCreated', - (WipEvent event) => - ExecutionContextDescription(event.params!['context'])); + (WipEvent event) => ExecutionContextDescription( + event.params!['context'] as Map)); /// Issued when execution context is destroyed. Stream get onExecutionContextDestroyed => eventStream( 'Runtime.executionContextDestroyed', - (WipEvent event) => event.params!['executionContextId']); + (WipEvent event) => event.params!['executionContextId'] as String); /// Issued when all executionContexts were cleared in browser. Stream get onExecutionContextsCleared => eventStream( @@ -173,7 +172,7 @@ class WipRuntime extends WipDomain { // TODO: stackTrace, StackTrace, Stack trace captured when the call was made. class ConsoleAPIEvent extends WipEvent { - ConsoleAPIEvent(Map json) : super(json); + ConsoleAPIEvent(super.json); /// Type of the call. Allowed values: log, debug, info, error, warning, dir, /// dirxml, table, trace, clear, startGroup, startGroupCollapsed, endGroup, @@ -200,14 +199,14 @@ class ExecutionContextDescription { int get id => json['id'] as int; /// Execution context origin. - String get origin => json['origin']; + String get origin => json['origin'] as String; /// Human readable name describing given context. - String get name => json['name']; + String get name => json['name'] as String; } class ExceptionThrownEvent extends WipEvent { - ExceptionThrownEvent(Map json) : super(json); + ExceptionThrownEvent(super.json); /// Timestamp of the exception. int get timestamp => params!['timestamp'] as int; @@ -277,13 +276,14 @@ class StackTrace { /// Asynchronous JavaScript stack trace that preceded this stack, if /// available. @optional - StackTrace? get parent => - json['parent'] == null ? null : StackTrace(json['parent']); + StackTrace? get parent => json['parent'] == null + ? null + : StackTrace(json['parent'] as Map); List printFrames() { - List frames = callFrames; + var frames = callFrames; - int width = frames.fold(0, (int val, CallFrame frame) { + var width = frames.fold(0, (int val, CallFrame frame) { return max(val, frame.functionName.length); }); @@ -370,10 +370,10 @@ class HeapUsage { HeapUsage(this.json); /// Used heap size in bytes. - int get usedSize => json['usedSize']; + int get usedSize => json['usedSize'] as int; /// Allocated heap size in bytes. - int get totalSize => json['totalSize']; + int get totalSize => json['totalSize'] as int; @override String toString() => '$usedSize of $totalSize'; @@ -386,11 +386,12 @@ class PropertyDescriptor { PropertyDescriptor(this.json); /// Property name or symbol description. - String get name => json['name']; + String get name => json['name'] as String; /// The value associated with the property. - RemoteObject? get value => - json['value'] != null ? RemoteObject(json['value']) : null; + RemoteObject? get value => json['value'] != null + ? RemoteObject(json['value'] as Map) + : null; /// True if the value associated with the property may be changed (data /// descriptors only). diff --git a/lib/src/target.dart b/lib/src/target.dart index 41a04c1..b50b262 100644 --- a/lib/src/target.dart +++ b/lib/src/target.dart @@ -6,7 +6,7 @@ import 'dart:async'; import '../webkit_inspection_protocol.dart'; class WipTarget extends WipDomain { - WipTarget(WipConnection connection) : super(connection); + WipTarget(super.connection); /// Creates a new page. /// @@ -14,7 +14,7 @@ class WipTarget extends WipDomain { /// /// Returns the targetId of the page opened. Future createTarget(String url) async { - WipResponse response = + var response = await sendCommand('Target.createTarget', params: {'url': url}); return response.result!['targetId'] as String; } @@ -27,7 +27,7 @@ class WipTarget extends WipDomain { /// /// Returns `true` on success. Future closeTarget(String targetId) async { - WipResponse response = + var response = await sendCommand('Target.closeTarget', params: {'targetId': targetId}); return response.result!['success'] as bool; } @@ -45,7 +45,7 @@ class WipTarget extends WipDomain { String targetId, { String? bindingName, }) { - final Map params = {'targetId': targetId}; + final params = {'targetId': targetId}; if (bindingName != null) { params['bindingName'] = bindingName; } diff --git a/lib/webkit_inspection_protocol.dart b/lib/webkit_inspection_protocol.dart index 251cd1a..4d8f12a 100644 --- a/lib/webkit_inspection_protocol.dart +++ b/lib/webkit_inspection_protocol.dart @@ -2,7 +2,7 @@ // governed by a BSD-style license that can be found in the LICENSE file. /// A library to connect to a Webkit Inspection Protocol server (like Chrome). -library wip; +library; import 'dart:async'; import 'dart:convert'; @@ -48,7 +48,7 @@ class ChromeConnection { Duration? retryFor, }) async { final start = DateTime.now(); - DateTime? end = retryFor == null ? null : start.add(retryFor); + var end = retryFor == null ? null : start.add(retryFor); var response = await getUrl('/json'); var responseBody = await utf8.decodeStream(response.cast>()); @@ -56,12 +56,12 @@ class ChromeConnection { late List decoded; while (true) { try { - decoded = jsonDecode(responseBody); + decoded = jsonDecode(responseBody) as List; return List.from(decoded.map((m) => ChromeTab(m as Map))); } on FormatException catch (formatException) { if (end != null && end.isBefore(DateTime.now())) { // Delay for retryFor / 4 milliseconds. - await Future.delayed( + await Future.delayed( Duration(milliseconds: retryFor!.inMilliseconds ~/ 4), ); } else { @@ -100,7 +100,7 @@ class ChromeConnection { rethrow; } } - await Future.delayed(const Duration(milliseconds: 25)); + await Future.delayed(const Duration(milliseconds: 25)); } } @@ -179,7 +179,7 @@ class ChromeTab { /// /// On errors from this stream, the [onError] handler is called with the error /// object and possibly a stack trace. The [onError] callback must be of type - /// `void Function(Object error)` or `void Function(Object error, StackTrace)`. + /// `void Function(Object error)` or `void Function(Object error, StackTrace)` Future connect({Function? onError}) { return WipConnection.connect(webSocketDebuggerUrl, onError: onError); } @@ -226,7 +226,7 @@ class WipConnection { /// /// On errors from this stream, the [onError] handler is called with the error /// object and possibly a stack trace. The [onError] callback must be of type - /// `void Function(Object error)` or `void Function(Object error, StackTrace)`. + /// `void Function(Object error)` or `void Function(Object error, StackTrace)` static Future connect(String url, {Function? onError}) { return WebSocket.connect(url).then((socket) { return WipConnection._(url, socket, onError: onError); @@ -235,9 +235,9 @@ class WipConnection { WipConnection._(this.url, this._ws, {Function? onError}) { void onData(dynamic /*String|List*/ data) { - _onReceive.add(data); + _onReceive.add(data as String); - var json = jsonDecode(data as String) as Map; + var json = jsonDecode(data) as Map; if (json.containsKey('id')) { _handleResponse(json); } else { @@ -271,7 +271,7 @@ class WipConnection { json['params'] = params; } _completers[json['id'] as int] = completer; - String message = jsonEncode(json); + var message = jsonEncode(json); _ws.add(message); _onSend.add(message); return completer.future; @@ -328,9 +328,9 @@ class WipError implements Exception { : id = json['id'] as int, error = json['error'] as Map?; - int? get code => error == null ? null : error!['code']; + int? get code => error?['code'] as int?; - String? get message => error == null ? null : error!['message']; + String? get message => error?['message'] as String?; @override String toString() => 'WipError $code $message'; diff --git a/pubspec.yaml b/pubspec.yaml index 29397fd..763096a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,22 +1,22 @@ name: webkit_inspection_protocol -version: 1.2.1 +version: 1.2.2-wip description: > A client for the Chrome DevTools Protocol (previously called the Webkit Inspection Protocol). repository: https://github.com/google/webkit_inspection_protocol.dart environment: - sdk: ^3.0.0 + sdk: ^3.4.0 dependencies: logging: ^1.0.0 dev_dependencies: args: ^2.0.0 - lints: '>=1.0.0 <3.0.0' - shelf_static: ^1.0.0 - shelf_web_socket: ^1.0.0 + dart_flutter_team_lints: ^3.0.0 shelf: ^1.0.0 - test: ^1.16.0 - web_socket_channel: ^2.0.0 # used in example/ + shelf_static: ^1.0.0 + shelf_web_socket: ^2.0.0 + test: ^1.16.6 + web_socket_channel: ^3.0.0 # used in example/ webdriver: ^3.0.0 diff --git a/test/console_test.dart b/test/console_test.dart index e4f68a0..3661c15 100644 --- a/test/console_test.dart +++ b/test/console_test.dart @@ -2,7 +2,7 @@ // governed by a BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library wip.console_test; +library; import 'dart:async'; @@ -14,14 +14,14 @@ import 'test_setup.dart'; void main() { group('WipConsole', () { WipConsole? console; // ignore: deprecated_member_use - List events = []; + var events = []; var subs = []; Future checkMessages(int expectedCount) async { // make sure all messages have been delivered - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); expect(events, hasLength(expectedCount)); - for (int i = 0; i < expectedCount; i++) { + for (var i = 0; i < expectedCount; i++) { if (i == 0) { // Clearing adds this message. expect(events[i].text, 'console.clear'); @@ -43,7 +43,7 @@ void main() { console = null; await closeConnection(); for (var s in subs) { - s.cancel(); + await s.cancel(); } subs.clear(); }); diff --git a/test/debugger_test.dart b/test/debugger_test.dart index b9e691c..e0db3a9 100644 --- a/test/debugger_test.dart +++ b/test/debugger_test.dart @@ -2,7 +2,7 @@ // governed by a BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library wip.debugger_test; +library; import 'dart:async'; @@ -14,7 +14,7 @@ import 'test_setup.dart'; void main() { group('WipDebugger', () { WipDebugger? debugger; - List subs = []; + var subs = []; setUp(() async { debugger = (await wipConnection).debugger; @@ -26,7 +26,7 @@ void main() { await closeConnection(); for (var s in subs) { - s.cancel(); + await s.cancel(); } subs.clear(); }); diff --git a/test/dom_model_test.dart b/test/dom_model_test.dart index 5ac2b53..9c574ca 100644 --- a/test/dom_model_test.dart +++ b/test/dom_model_test.dart @@ -2,7 +2,7 @@ // governed by a BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library wip.console_test; +library; import 'package:test/test.dart'; import 'package:webkit_inspection_protocol/dom_model.dart'; @@ -30,7 +30,7 @@ void main() { }); test('requestChildNodes updates children', () async { - Node htmlNode = (await dom!.getDocument()).children![1]; + var htmlNode = (await dom!.getDocument()).children![1]; for (var child in htmlNode.children!) { expect(child.children, isNull); await dom!.requestChildNodes(child.nodeId); @@ -42,7 +42,7 @@ void main() { }); test('removing a node updates children', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; await dom!.requestChildNodes(bodyNode.nodeId); var childCount = bodyNode.childNodeCount!; await dom!.removeNode(bodyNode.children!.first.nodeId); @@ -52,10 +52,10 @@ void main() { }); test('Moving a node updates children', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; await dom!.requestChildNodes(bodyNode.nodeId); - Node div1 = bodyNode.children![0]; - Node div2 = bodyNode.children![1]; + var div1 = bodyNode.children![0]; + var div2 = bodyNode.children![1]; expect(div1.childNodeCount, 1); expect(div2.childNodeCount, 0); @@ -71,16 +71,16 @@ void main() { }, skip: 'google/webkit_inspection_protocol.dart/issues/52'); test('Setting node value updates value', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; await dom!.requestChildNodes(bodyNode.nodeId); - Node div1 = bodyNode.children![0]; + var div1 = bodyNode.children![0]; await dom!.requestChildNodes(div1.nodeId); - Node h1 = div1.children![0]; + var h1 = div1.children![0]; await dom!.requestChildNodes(h1.nodeId); - Node text = h1.children![0]; + var text = h1.children![0]; expect(text.nodeValue, 'test'); @@ -90,21 +90,21 @@ void main() { }); test('Adding attribute updates attributes', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; expect(bodyNode.attributes!.containsKey('my-attr'), isFalse); await dom!.setAttributeValue(bodyNode.nodeId, 'my-attr', 'my-value'); expect(bodyNode.attributes!['my-attr'], 'my-value'); }); test('Changing attribute updates attributes', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; expect(bodyNode.attributes!['test-attr'], 'test-attr-value'); await dom!.setAttributeValue(bodyNode.nodeId, 'test-attr', 'my-value'); expect(bodyNode.attributes!['test-attr'], 'my-value'); }); test('Removing attribute updates attributes', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; expect(bodyNode.attributes!['test-attr'], 'test-attr-value'); await dom!.removeAttribute(bodyNode.nodeId, 'test-attr'); expect(bodyNode.attributes!.containsKey('test-attr'), isFalse); @@ -118,7 +118,7 @@ void main() { }); test('getting attributes works', () async { - Node bodyNode = (await dom!.getDocument()).children![1].children![1]; + var bodyNode = (await dom!.getDocument()).children![1].children![1]; var attributes = bodyNode.attributes; var getAttributes = await dom!.getAttributes(bodyNode.nodeId); diff --git a/test/runtime_test.dart b/test/runtime_test.dart index 33d61cf..c739c50 100644 --- a/test/runtime_test.dart +++ b/test/runtime_test.dart @@ -2,7 +2,7 @@ // governed by a BSD-style license that can be found in the LICENSE file. @TestOn('vm') -library wip.runtime_test; +library; import 'dart:async'; @@ -14,7 +14,7 @@ import 'test_setup.dart'; void main() { group('WipRuntime', () { WipRuntime? runtime; - List subs = []; + var subs = []; setUp(() async { runtime = (await wipConnection).runtime; @@ -26,7 +26,7 @@ void main() { await closeConnection(); for (var s in subs) { - s.cancel(); + await s.cancel(); } subs.clear(); }); @@ -42,7 +42,7 @@ void main() { await runtime!.enable(); await navigateToPage('runtime_test.html'); - HeapUsage usage = await runtime!.getHeapUsage(); + var usage = await runtime!.getHeapUsage(); expect(usage.usedSize, greaterThan(0)); expect(usage.totalSize, greaterThan(0)); @@ -52,7 +52,7 @@ void main() { await runtime!.enable(); await navigateToPage('runtime_test.html'); - RemoteObject result = await runtime!.evaluate('1+1'); + var result = await runtime!.evaluate('1+1'); expect(result.type, 'number'); expect(result.value, 2); }); @@ -61,8 +61,8 @@ void main() { await runtime!.enable(); await navigateToPage('runtime_test.html'); - RemoteObject console = await runtime!.evaluate('console'); - RemoteObject result = await runtime!.callFunctionOn( + var console = await runtime!.evaluate('console'); + var result = await runtime!.callFunctionOn( ''' function(msg) { console.log(msg); @@ -82,16 +82,16 @@ void main() { await runtime!.enable(); await navigateToPage('runtime_test.html'); - RemoteObject console = await runtime!.evaluate('console'); + var console = await runtime!.evaluate('console'); - List properties = await runtime!.getProperties( + var properties = await runtime!.getProperties( console, ownProperties: true, ); expect(properties, isNotEmpty); - PropertyDescriptor property = properties.first; + var property = properties.first; expect(property.name, isNotEmpty); }); }); diff --git a/test/test_setup.dart b/test/test_setup.dart index 8170d38..5e61036 100644 --- a/test/test_setup.dart +++ b/test/test_setup.dart @@ -1,8 +1,6 @@ // Copyright 2015 Google. All rights reserved. Use of this source code is // governed by a BSD-style license that can be found in the LICENSE file. -library wip.test.setup; - import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -53,7 +51,7 @@ Future _startChromeDriver() async { var chromeDriverPort = await findUnusedPort(); // Delay a small amount to allow us to close the above port. - await Future.delayed(const Duration(milliseconds: 25)); + await Future.delayed(const Duration(milliseconds: 25)); try { var exeExt = Platform.isWindows ? '.exe' : ''; @@ -131,7 +129,7 @@ Future navigateToPage(String page) async { await (await wipConnection) .page .navigate((await _testServerUri)!.resolve(page).toString()); - await Future.delayed(const Duration(seconds: 1)); + await Future.delayed(const Duration(seconds: 1)); return wipConnection; }