1// Copyright 2019 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'enum_util.dart'; 6import 'find.dart'; 7import 'message.dart'; 8 9/// [DiagnosticsNode] tree types that can be requested by [GetDiagnosticsTree]. 10enum DiagnosticsType { 11 /// The [DiagnosticsNode] tree formed by [RenderObject]s. 12 renderObject, 13 14 /// The [DiagnosticsNode] tree formed by [Widget]s. 15 widget, 16} 17 18EnumIndex<DiagnosticsType> _diagnosticsTypeIndex = EnumIndex<DiagnosticsType>(DiagnosticsType.values); 19 20/// A Flutter Driver command to retrieve the json-serialized [DiagnosticsNode] 21/// tree of the object identified by [finder]. 22/// 23/// The [DiagnosticsType] of the [DiagnosticsNode] tree returned is specified by 24/// [diagnosticsType]. 25class GetDiagnosticsTree extends CommandWithTarget { 26 /// Creates a [GetDiagnosticsTree] Flutter Driver command. 27 GetDiagnosticsTree(SerializableFinder finder, this.diagnosticsType, { 28 this.subtreeDepth = 0, 29 this.includeProperties = true, 30 Duration timeout, 31 }) : assert(subtreeDepth != null), 32 assert(includeProperties != null), 33 super(finder, timeout: timeout); 34 35 /// Deserializes this command from the value generated by [serialize]. 36 GetDiagnosticsTree.deserialize(Map<String, dynamic> json) 37 : subtreeDepth = int.parse(json['subtreeDepth']), 38 includeProperties = json['includeProperties'] == 'true', 39 diagnosticsType = _diagnosticsTypeIndex.lookupBySimpleName(json['diagnosticsType']), 40 super.deserialize(json); 41 42 /// How many levels of children to include in the JSON result. 43 /// 44 /// Defaults to zero, which will only return the [DiagnosticsNode] information 45 /// of the object identified by [finder]. 46 final int subtreeDepth; 47 48 /// Whether the properties of a [DiagnosticsNode] should be included. 49 final bool includeProperties; 50 51 /// The type of [DiagnosticsNode] tree that is requested. 52 final DiagnosticsType diagnosticsType; 53 54 @override 55 Map<String, String> serialize() => super.serialize()..addAll(<String, String>{ 56 'subtreeDepth': subtreeDepth.toString(), 57 'includeProperties': includeProperties.toString(), 58 'diagnosticsType': _diagnosticsTypeIndex.toSimpleName(diagnosticsType), 59 }); 60 61 @override 62 String get kind => 'get_diagnostics_tree'; 63} 64 65/// The result of a [GetDiagnosticsTree] command. 66class DiagnosticsTreeResult extends Result { 67 /// Creates a [DiagnosticsTreeResult]. 68 const DiagnosticsTreeResult(this.json); 69 70 /// The json encoded [DiagnosticsNode] tree requested by the 71 /// [GetDiagnosticsTree] command. 72 final Map<String, Object> json; 73 74 @override 75 Map<String, dynamic> toJson() => json; 76} 77