Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
632e21b4
Unverified
Commit
632e21b4
authored
Dec 17, 2018
by
Devon Carew
Committed by
GitHub
Dec 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix the daemon device.getDevices call (#25443)
parent
a039b2ca
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
23 deletions
+144
-23
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+10
-4
daemon_test.dart
packages/flutter_tools/test/commands/daemon_test.dart
+21
-0
daemon_mode_test.dart
...ages/flutter_tools/test/integration/daemon_mode_test.dart
+94
-0
flutter_run_test.dart
...ages/flutter_tools/test/integration/flutter_run_test.dart
+1
-1
test_driver.dart
packages/flutter_tools/test/integration/test_driver.dart
+18
-18
No files found.
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
632e21b4
...
...
@@ -612,12 +612,18 @@ class DeviceDomain extends Domain {
final
List
<
PollingDeviceDiscovery
>
_discoverers
=
<
PollingDeviceDiscovery
>[];
Future
<
List
<
Device
>>
getDevices
([
Map
<
String
,
dynamic
>
args
])
async
{
final
List
<
Device
>
devices
=
<
Device
>[];
/// Return a list of the current devices, with each device represented as a map
/// of properties (id, name, platform, ...).
Future
<
List
<
Map
<
String
,
dynamic
>>>
getDevices
([
Map
<
String
,
dynamic
>
args
])
async
{
final
List
<
Map
<
String
,
dynamic
>>
devicesInfo
=
<
Map
<
String
,
dynamic
>>[];
for
(
PollingDeviceDiscovery
discoverer
in
_discoverers
)
{
devices
.
addAll
(
await
discoverer
.
devices
);
for
(
Device
device
in
await
discoverer
.
devices
)
{
devicesInfo
.
add
(
await
_deviceToMap
(
device
));
}
}
return
devices
;
return
devicesInfo
;
}
/// Enable device events.
...
...
packages/flutter_tools/test/commands/daemon_test.dart
View file @
632e21b4
...
...
@@ -217,6 +217,27 @@ void main() {
await
commands
.
close
();
});
testUsingContext
(
'device.getDevices reports avaiable devices'
,
()
async
{
final
StreamController
<
Map
<
String
,
dynamic
>>
commands
=
StreamController
<
Map
<
String
,
dynamic
>>();
final
StreamController
<
Map
<
String
,
dynamic
>>
responses
=
StreamController
<
Map
<
String
,
dynamic
>>();
daemon
=
Daemon
(
commands
.
stream
,
responses
.
add
,
notifyingLogger:
notifyingLogger
,
);
final
MockPollingDeviceDiscovery
discoverer
=
MockPollingDeviceDiscovery
();
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
discoverer
.
addDevice
(
MockAndroidDevice
());
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'device.getDevices'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
(
_notEvent
);
expect
(
response
[
'id'
],
0
);
final
dynamic
result
=
response
[
'result'
];
expect
(
result
,
isList
);
expect
(
result
,
isNotEmpty
);
await
responses
.
close
();
await
commands
.
close
();
});
testUsingContext
(
'should send device.added event when device is discovered'
,
()
async
{
final
StreamController
<
Map
<
String
,
dynamic
>>
commands
=
StreamController
<
Map
<
String
,
dynamic
>>();
final
StreamController
<
Map
<
String
,
dynamic
>>
responses
=
StreamController
<
Map
<
String
,
dynamic
>>();
...
...
packages/flutter_tools/test/integration/daemon_mode_test.dart
0 → 100644
View file @
632e21b4
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:convert'
;
import
'package:file/file.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:process/process.dart'
;
import
'../src/common.dart'
;
import
'test_data/basic_project.dart'
;
import
'test_driver.dart'
;
import
'test_utils.dart'
;
void
main
(
)
{
group
(
'daemon_mode'
,
()
{
Directory
tempDir
;
final
BasicProject
_project
=
BasicProject
();
Process
process
;
setUp
(()
async
{
tempDir
=
createResolvedTempDirectorySync
();
await
_project
.
setUpIn
(
tempDir
);
});
tearDown
(()
async
{
tryToDelete
(
tempDir
);
process
?.
kill
();
});
test
(
'device.getDevices'
,
()
async
{
final
String
flutterBin
=
fs
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
'flutter'
);
const
ProcessManager
processManager
=
LocalProcessManager
();
process
=
await
processManager
.
start
(
<
String
>[
flutterBin
,
'--show-test-device'
,
'daemon'
],
workingDirectory:
tempDir
.
path
);
final
StreamController
<
String
>
stdout
=
StreamController
<
String
>.
broadcast
();
transformToLines
(
process
.
stdout
)
.
listen
((
String
line
)
=>
stdout
.
add
(
line
));
final
Stream
<
Map
<
String
,
dynamic
>>
stream
=
stdout
.
stream
.
where
((
String
line
)
{
final
Map
<
String
,
dynamic
>
response
=
parseFlutterResponse
(
line
);
// ignore 'Starting device daemon...'
if
(
response
==
null
)
{
return
false
;
}
// TODO(devoncarew): Remove this after #25440 lands.
if
(
response
[
'event'
]
==
'daemon.showMessage'
)
{
return
false
;
}
return
true
;
}).
map
(
parseFlutterResponse
);
Map
<
String
,
dynamic
>
response
=
await
stream
.
first
;
expect
(
response
[
'event'
],
'daemon.connected'
);
// start listening for devices
process
.
stdin
.
writeln
(
'[
${jsonEncode(<String, dynamic>{
'id': 1,
'method': 'device.enable',
}
)}]'
);
response
=
await
stream
.
first
;
expect
(
response
[
'id'
],
1
);
expect
(
response
[
'error'
],
isNull
);
// [{"event":"device.added","params":{"id":"flutter-tester","name":
// "Flutter test device","platform":"flutter-tester","emulator":false}}]
response
=
await
stream
.
first
;
expect
(
response
[
'event'
],
'device.added'
);
// get the list of all devices
process
.
stdin
.
writeln
(
'[
${jsonEncode(<String, dynamic>{
'id': 2,
'method': 'device.getDevices',
}
)}]'
);
response
=
await
stream
.
first
;
expect
(
response
[
'id'
],
2
);
expect
(
response
[
'error'
],
isNull
);
final
dynamic
result
=
response
[
'result'
];
expect
(
result
,
isList
);
expect
(
result
,
isNotEmpty
);
});
},
timeout:
const
Timeout
.
factor
(
2
));
}
packages/flutter_tools/test/integration/flutter_run_test.dart
View file @
632e21b4
...
...
@@ -32,7 +32,7 @@ void main() {
test
(
'reports an error if an invalid device is supplied'
,
()
async
{
// This test forces flutter to check for all possible devices to catch issues
// like https://github.com/flutter/flutter/issues/21418 which were skipped
// over because other integration tes
st
run using flutter-tester which short-cuts
// over because other integration tes
ts
run using flutter-tester which short-cuts
// some of the checks for devices.
final
String
flutterBin
=
fs
.
path
.
join
(
getFlutterRoot
(),
'bin'
,
'flutter'
);
...
...
packages/flutter_tools/test/integration/test_driver.dart
View file @
632e21b4
...
...
@@ -82,8 +82,8 @@ abstract class FlutterTestDriver {
_debugPrint
(
'Process exited (
$code
)'
);
_hasExited
=
true
;
});
_
transformToLines
(
_proc
.
stdout
).
listen
((
String
line
)
=>
_stdout
.
add
(
line
));
_
transformToLines
(
_proc
.
stderr
).
listen
((
String
line
)
=>
_stderr
.
add
(
line
));
transformToLines
(
_proc
.
stdout
).
listen
((
String
line
)
=>
_stdout
.
add
(
line
));
transformToLines
(
_proc
.
stderr
).
listen
((
String
line
)
=>
_stderr
.
add
(
line
));
// Capture stderr to a buffer so we can show it all if any requests fail.
_stderr
.
stream
.
listen
(
_errorBuffer
.
writeln
);
...
...
@@ -236,7 +236,8 @@ abstract class FlutterTestDriver {
final
Completer
<
Map
<
String
,
dynamic
>>
response
=
Completer
<
Map
<
String
,
dynamic
>>();
StreamSubscription
<
String
>
sub
;
sub
=
_stdout
.
stream
.
listen
((
String
line
)
async
{
final
dynamic
json
=
_parseFlutterResponse
(
line
);
final
dynamic
json
=
parseFlutterResponse
(
line
);
_lastResponse
=
line
;
if
(
json
==
null
)
{
return
;
}
else
if
(
...
...
@@ -285,20 +286,6 @@ abstract class FlutterTestDriver {
throw
'
$error
\n
Received:
\n
${messages.toString()}
'
;
}).
whenComplete
(()
=>
sub
.
cancel
());
}
Map
<
String
,
dynamic
>
_parseFlutterResponse
(
String
line
)
{
if
(
line
.
startsWith
(
'['
)
&&
line
.
endsWith
(
']'
))
{
try
{
final
Map
<
String
,
dynamic
>
resp
=
json
.
decode
(
line
)[
0
];
_lastResponse
=
line
;
return
resp
;
}
catch
(
e
)
{
// Not valid JSON, so likely some other output that was surrounded by [brackets]
return
null
;
}
}
return
null
;
}
}
class
FlutterRunTestDriver
extends
FlutterTestDriver
{
...
...
@@ -509,10 +496,23 @@ class FlutterRunTestDriver extends FlutterTestDriver {
}
}
Stream
<
String
>
_
transformToLines
(
Stream
<
List
<
int
>>
byteStream
)
{
Stream
<
String
>
transformToLines
(
Stream
<
List
<
int
>>
byteStream
)
{
return
byteStream
.
transform
<
String
>(
utf8
.
decoder
).
transform
<
String
>(
const
LineSplitter
());
}
Map
<
String
,
dynamic
>
parseFlutterResponse
(
String
line
)
{
if
(
line
.
startsWith
(
'['
)
&&
line
.
endsWith
(
']'
))
{
try
{
final
Map
<
String
,
dynamic
>
resp
=
json
.
decode
(
line
)[
0
];
return
resp
;
}
catch
(
e
)
{
// Not valid JSON, so likely some other output that was surrounded by [brackets]
return
null
;
}
}
return
null
;
}
class
SourcePosition
{
SourcePosition
(
this
.
line
,
this
.
column
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment