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
cbf885b7
Unverified
Commit
cbf885b7
authored
Apr 28, 2021
by
Jenn Magder
Committed by
GitHub
Apr 28, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace MockAndroidDevice and MockIOSDevice with fakes (#81352)
parent
41d0e1a9
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
182 additions
and
120 deletions
+182
-120
attach_test.dart
...utter_tools/test/commands.shard/hermetic/attach_test.dart
+19
-1
daemon_test.dart
...utter_tools/test/commands.shard/hermetic/daemon_test.dart
+55
-21
install_test.dart
...tter_tools/test/commands.shard/hermetic/install_test.dart
+40
-15
build_bundle_test.dart
...ools/test/commands.shard/permeable/build_bundle_test.dart
+26
-22
ios_device_start_nonprebuilt_test.dart
.../general.shard/ios/ios_device_start_nonprebuilt_test.dart
+42
-29
mocks.dart
packages/flutter_tools/test/src/mocks.dart
+0
-32
No files found.
packages/flutter_tools/test/commands.shard/hermetic/attach_test.dart
View file @
cbf885b7
...
@@ -8,11 +8,13 @@ import 'dart:async';
...
@@ -8,11 +8,13 @@ import 'dart:async';
import
'dart:io'
;
import
'dart:io'
;
import
'package:file/memory.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/dds.dart'
;
import
'package:flutter_tools/src/base/dds.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/base/terminal.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/attach.dart'
;
import
'package:flutter_tools/src/commands/attach.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/device.dart'
;
...
@@ -31,7 +33,6 @@ import '../../src/common.dart';
...
@@ -31,7 +33,6 @@ import '../../src/common.dart';
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fake_devices.dart'
;
import
'../../src/fake_devices.dart'
;
import
'../../src/fake_vm_services.dart'
;
import
'../../src/fake_vm_services.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
final
vm_service
.
Isolate
fakeUnpausedIsolate
=
vm_service
.
Isolate
(
final
vm_service
.
Isolate
fakeUnpausedIsolate
=
vm_service
.
Isolate
(
...
@@ -929,3 +930,20 @@ class TestHotRunnerFactory extends HotRunnerFactory {
...
@@ -929,3 +930,20 @@ class TestHotRunnerFactory extends HotRunnerFactory {
}
}
class
MockDartDevelopmentService
extends
Mock
implements
DartDevelopmentService
{}
class
MockDartDevelopmentService
extends
Mock
implements
DartDevelopmentService
{}
class
MockAndroidDevice
extends
Mock
implements
AndroidDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
android_arm
;
@override
bool
isSupported
()
=>
true
;
@override
bool
get
supportsHotRestart
=>
true
;
@override
bool
get
supportsFlutterExit
=>
false
;
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
true
;
}
packages/flutter_tools/test/commands.shard/hermetic/daemon_test.dart
View file @
cbf885b7
...
@@ -7,23 +7,25 @@
...
@@ -7,23 +7,25 @@
import
'dart:async'
;
import
'dart:async'
;
import
'package:fake_async/fake_async.dart'
;
import
'package:fake_async/fake_async.dart'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/utils.dart'
;
import
'package:flutter_tools/src/base/utils.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/commands/daemon.dart'
;
import
'package:flutter_tools/src/commands/daemon.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/fuchsia/fuchsia_workflow.dart'
;
import
'package:flutter_tools/src/fuchsia/fuchsia_workflow.dart'
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/ios/ios_workflow.dart'
;
import
'package:flutter_tools/src/ios/ios_workflow.dart'
;
import
'package:flutter_tools/src/resident_runner.dart'
;
import
'package:flutter_tools/src/resident_runner.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fake_devices.dart'
;
import
'../../src/fake_devices.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/mocks.dart'
;
/// Runs a callback using FakeAsync.run while continually pumping the
/// Runs a callback using FakeAsync.run while continually pumping the
/// microtask queue. This avoids a deadlock when tests `await` a Future
/// microtask queue. This avoids a deadlock when tests `await` a Future
...
@@ -44,13 +46,11 @@ void main() {
...
@@ -44,13 +46,11 @@ void main() {
Daemon
daemon
;
Daemon
daemon
;
NotifyingLogger
notifyingLogger
;
NotifyingLogger
notifyingLogger
;
BufferLogger
bufferLogger
;
BufferLogger
bufferLogger
;
DevtoolsLauncher
mockDevToolsLauncher
;
group
(
'daemon'
,
()
{
group
(
'daemon'
,
()
{
setUp
(()
{
setUp
(()
{
bufferLogger
=
BufferLogger
.
test
();
bufferLogger
=
BufferLogger
.
test
();
notifyingLogger
=
NotifyingLogger
(
verbose:
false
,
parent:
bufferLogger
);
notifyingLogger
=
NotifyingLogger
(
verbose:
false
,
parent:
bufferLogger
);
mockDevToolsLauncher
=
MockDevToolsLauncher
();
});
});
tearDown
(()
{
tearDown
(()
{
...
@@ -241,7 +241,7 @@ void main() {
...
@@ -241,7 +241,7 @@ void main() {
);
);
final
FakePollingDeviceDiscovery
discoverer
=
FakePollingDeviceDiscovery
();
final
FakePollingDeviceDiscovery
discoverer
=
FakePollingDeviceDiscovery
();
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
discoverer
.
addDevice
(
Mock
AndroidDevice
());
discoverer
.
addDevice
(
Fake
AndroidDevice
());
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'device.getDevices'
});
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'device.getDevices'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
(
_notEvent
);
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
(
_notEvent
);
expect
(
response
[
'id'
],
0
);
expect
(
response
[
'id'
],
0
);
...
@@ -263,22 +263,22 @@ void main() {
...
@@ -263,22 +263,22 @@ void main() {
final
FakePollingDeviceDiscovery
discoverer
=
FakePollingDeviceDiscovery
();
final
FakePollingDeviceDiscovery
discoverer
=
FakePollingDeviceDiscovery
();
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
daemon
.
deviceDomain
.
addDeviceDiscoverer
(
discoverer
);
discoverer
.
addDevice
(
Mock
AndroidDevice
());
discoverer
.
addDevice
(
Fake
AndroidDevice
());
return
responses
.
stream
.
skipWhile
(
_isConnectedEvent
).
first
.
then
<
void
>((
Map
<
String
,
dynamic
>
response
)
async
{
return
responses
.
stream
.
skipWhile
(
_isConnectedEvent
).
first
.
then
<
void
>((
Map
<
String
,
dynamic
>
response
)
async
{
expect
(
response
[
'event'
],
'device.added'
);
expect
(
response
[
'event'
],
'device.added'
);
expect
(
response
[
'params'
],
isMap
);
expect
(
response
[
'params'
],
isMap
);
final
Map
<
String
,
dynamic
>
params
=
castStringKeyedMap
(
response
[
'params'
]);
final
Map
<
String
,
dynamic
>
params
=
castStringKeyedMap
(
response
[
'params'
]);
expect
(
params
[
'platform'
],
isNotEmpty
);
// the
mock
device has a platform of 'android-arm'
expect
(
params
[
'platform'
],
isNotEmpty
);
// the
fake
device has a platform of 'android-arm'
await
responses
.
close
();
await
responses
.
close
();
await
commands
.
close
();
await
commands
.
close
();
});
});
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
AndroidWorkflow:
()
=>
Mock
AndroidWorkflow
(),
AndroidWorkflow:
()
=>
Fake
AndroidWorkflow
(),
IOSWorkflow:
()
=>
Mock
IOSWorkflow
(),
IOSWorkflow:
()
=>
Fake
IOSWorkflow
(),
FuchsiaWorkflow:
()
=>
Mock
FuchsiaWorkflow
(),
FuchsiaWorkflow:
()
=>
Fake
FuchsiaWorkflow
(),
});
});
testUsingContext
(
'emulator.launch without an emulatorId should report an error'
,
()
async
{
testUsingContext
(
'emulator.launch without an emulatorId should report an error'
,
()
async
{
...
@@ -350,7 +350,6 @@ void main() {
...
@@ -350,7 +350,6 @@ void main() {
responses
.
add
,
responses
.
add
,
notifyingLogger:
notifyingLogger
,
notifyingLogger:
notifyingLogger
,
);
);
when
(
mockDevToolsLauncher
.
serve
()).
thenAnswer
((
_
)
async
=>
DevToolsServerAddress
(
'127.0.0.1'
,
1234
));
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
...
@@ -360,7 +359,7 @@ void main() {
...
@@ -360,7 +359,7 @@ void main() {
await
responses
.
close
();
await
responses
.
close
();
await
commands
.
close
();
await
commands
.
close
();
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
DevtoolsLauncher:
()
=>
mockDevToolsLauncher
,
DevtoolsLauncher:
()
=>
FakeDevtoolsLauncher
(
DevToolsServerAddress
(
'127.0.0.1'
,
1234
))
,
});
});
testUsingContext
(
'devtools.serve command should return null fields if null returned'
,
()
async
{
testUsingContext
(
'devtools.serve command should return null fields if null returned'
,
()
async
{
...
@@ -371,7 +370,6 @@ void main() {
...
@@ -371,7 +370,6 @@ void main() {
responses
.
add
,
responses
.
add
,
notifyingLogger:
notifyingLogger
,
notifyingLogger:
notifyingLogger
,
);
);
when
(
mockDevToolsLauncher
.
serve
()).
thenAnswer
((
_
)
async
=>
null
);
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
commands
.
add
(<
String
,
dynamic
>{
'id'
:
0
,
'method'
:
'devtools.serve'
});
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
final
Map
<
String
,
dynamic
>
response
=
await
responses
.
stream
.
firstWhere
((
Map
<
String
,
dynamic
>
response
)
=>
response
[
'id'
]
==
0
);
...
@@ -381,7 +379,7 @@ void main() {
...
@@ -381,7 +379,7 @@ void main() {
await
responses
.
close
();
await
responses
.
close
();
await
commands
.
close
();
await
commands
.
close
();
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
DevtoolsLauncher:
()
=>
mockDevToolsLauncher
,
DevtoolsLauncher:
()
=>
FakeDevtoolsLauncher
(
null
)
,
});
});
});
});
...
@@ -519,25 +517,61 @@ bool _notEvent(Map<String, dynamic> map) => map['event'] == null;
...
@@ -519,25 +517,61 @@ bool _notEvent(Map<String, dynamic> map) => map['event'] == null;
bool
_isConnectedEvent
(
Map
<
String
,
dynamic
>
map
)
=>
map
[
'event'
]
==
'daemon.connected'
;
bool
_isConnectedEvent
(
Map
<
String
,
dynamic
>
map
)
=>
map
[
'event'
]
==
'daemon.connected'
;
class
MockFuchsiaWorkflow
extend
s
FuchsiaWorkflow
{
class
FakeFuchsiaWorkflow
extends
Fake
implement
s
FuchsiaWorkflow
{
Mock
FuchsiaWorkflow
({
this
.
canListDevices
=
true
});
Fake
FuchsiaWorkflow
({
this
.
canListDevices
=
true
});
@override
@override
final
bool
canListDevices
;
final
bool
canListDevices
;
}
}
class
MockAndroidWorkflow
extend
s
AndroidWorkflow
{
class
FakeAndroidWorkflow
extends
Fake
implement
s
AndroidWorkflow
{
Mock
AndroidWorkflow
({
this
.
canListDevices
=
true
});
Fake
AndroidWorkflow
({
this
.
canListDevices
=
true
});
@override
@override
final
bool
canListDevices
;
final
bool
canListDevices
;
}
}
class
MockIOSWorkflow
extend
s
IOSWorkflow
{
class
FakeIOSWorkflow
extends
Fake
implement
s
IOSWorkflow
{
Mock
IOSWorkflow
({
this
.
canListDevices
=
true
});
Fake
IOSWorkflow
({
this
.
canListDevices
=
true
});
@override
@override
final
bool
canListDevices
;
final
bool
canListDevices
;
}
}
class
MockDevToolsLauncher
extends
Mock
implements
DevtoolsLauncher
{}
class
FakeAndroidDevice
extends
Fake
implements
AndroidDevice
{
@override
final
String
id
=
'device'
;
@override
final
String
name
=
'device'
;
@override
Future
<
String
>
get
emulatorId
async
=>
'device'
;
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
android_arm
;
@override
Future
<
bool
>
get
isLocalEmulator
async
=>
false
;
@override
final
Category
category
=
Category
.
mobile
;
@override
final
PlatformType
platformType
=
PlatformType
.
android
;
@override
final
bool
ephemeral
=
false
;
}
class
FakeDevtoolsLauncher
extends
Fake
implements
DevtoolsLauncher
{
FakeDevtoolsLauncher
(
this
.
_serverAddress
);
final
DevToolsServerAddress
_serverAddress
;
@override
Future
<
DevToolsServerAddress
>
serve
()
async
=>
_serverAddress
;
@override
Future
<
void
>
close
()
async
{}
}
packages/flutter_tools/test/commands.shard/hermetic/install_test.dart
View file @
cbf885b7
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
// @dart = 2.8
// @dart = 2.8
import
'package:file/file.dart'
;
import
'package:file/file.dart'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/android/application_package.dart'
;
import
'package:flutter_tools/src/android/application_package.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
...
@@ -12,11 +13,11 @@ import 'package:flutter_tools/src/build_info.dart';
...
@@ -12,11 +13,11 @@ import 'package:flutter_tools/src/build_info.dart';
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/install.dart'
;
import
'package:flutter_tools/src/commands/install.dart'
;
import
'package:flutter_tools/src/ios/application_package.dart'
;
import
'package:flutter_tools/src/ios/application_package.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
import
'../../src/test_flutter_command_runner.dart'
;
void
main
(
)
{
void
main
(
)
{
...
@@ -29,11 +30,7 @@ void main() {
...
@@ -29,11 +30,7 @@ void main() {
final
InstallCommand
command
=
InstallCommand
();
final
InstallCommand
command
=
InstallCommand
();
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeAndroidApk
());
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeAndroidApk
());
final
MockAndroidDevice
device
=
MockAndroidDevice
();
final
FakeAndroidDevice
device
=
FakeAndroidDevice
();
when
(
device
.
isAppInstalled
(
any
,
userIdentifier:
anyNamed
(
'userIdentifier'
)))
.
thenAnswer
((
_
)
async
=>
false
);
when
(
device
.
installApp
(
any
,
userIdentifier:
anyNamed
(
'userIdentifier'
)))
.
thenAnswer
((
_
)
async
=>
true
);
testDeviceManager
.
addDevice
(
device
);
testDeviceManager
.
addDevice
(
device
);
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
...
@@ -45,11 +42,7 @@ void main() {
...
@@ -45,11 +42,7 @@ void main() {
final
InstallCommand
command
=
InstallCommand
();
final
InstallCommand
command
=
InstallCommand
();
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeAndroidApk
());
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeAndroidApk
());
final
MockIOSDevice
device
=
MockIOSDevice
();
final
FakeIOSDevice
device
=
FakeIOSDevice
();
when
(
device
.
isAppInstalled
(
any
,
userIdentifier:
anyNamed
(
'userIdentifier'
)))
.
thenAnswer
((
_
)
async
=>
false
);
when
(
device
.
installApp
(
any
,
userIdentifier:
anyNamed
(
'userIdentifier'
)))
.
thenAnswer
((
_
)
async
=>
true
);
testDeviceManager
.
addDevice
(
device
);
testDeviceManager
.
addDevice
(
device
);
expect
(()
async
=>
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
,
'--device-user'
,
'10'
]),
expect
(()
async
=>
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
,
'--device-user'
,
'10'
]),
...
@@ -62,9 +55,7 @@ void main() {
...
@@ -62,9 +55,7 @@ void main() {
final
InstallCommand
command
=
InstallCommand
();
final
InstallCommand
command
=
InstallCommand
();
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeIOSApp
());
command
.
applicationPackages
=
FakeApplicationPackageFactory
(
FakeIOSApp
());
final
MockIOSDevice
device
=
MockIOSDevice
();
final
FakeIOSDevice
device
=
FakeIOSDevice
();
when
(
device
.
isAppInstalled
(
any
)).
thenAnswer
((
_
)
async
=>
false
);
when
(
device
.
installApp
(
any
)).
thenAnswer
((
_
)
async
=>
true
);
testDeviceManager
.
addDevice
(
device
);
testDeviceManager
.
addDevice
(
device
);
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'install'
]);
...
@@ -86,3 +77,37 @@ class FakeApplicationPackageFactory extends Fake implements ApplicationPackageFa
...
@@ -86,3 +77,37 @@ class FakeApplicationPackageFactory extends Fake implements ApplicationPackageFa
}
}
class
FakeIOSApp
extends
Fake
implements
IOSApp
{}
class
FakeIOSApp
extends
Fake
implements
IOSApp
{}
class
FakeAndroidApk
extends
Fake
implements
AndroidApk
{}
class
FakeAndroidApk
extends
Fake
implements
AndroidApk
{}
class
FakeIOSDevice
extends
Fake
implements
IOSDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
ios
;
@override
Future
<
bool
>
isAppInstalled
(
IOSApp
app
,
{
String
userIdentifier
,
})
async
=>
false
;
@override
Future
<
bool
>
installApp
(
IOSApp
app
,
{
String
userIdentifier
,
})
async
=>
true
;
}
class
FakeAndroidDevice
extends
Fake
implements
AndroidDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
android_arm
;
@override
Future
<
bool
>
isAppInstalled
(
AndroidApk
app
,
{
String
userIdentifier
,
})
async
=>
false
;
@override
Future
<
bool
>
installApp
(
AndroidApk
app
,
{
String
userIdentifier
,
})
async
=>
true
;
}
packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart
View file @
cbf885b7
...
@@ -16,8 +16,10 @@ import 'package:flutter_tools/src/cache.dart';
...
@@ -16,8 +16,10 @@ import 'package:flutter_tools/src/cache.dart';
import
'package:flutter_tools/src/commands/build_bundle.dart'
;
import
'package:flutter_tools/src/commands/build_bundle.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
;
...
@@ -28,23 +30,12 @@ import '../../src/test_flutter_command_runner.dart';
...
@@ -28,23 +30,12 @@ import '../../src/test_flutter_command_runner.dart';
void
main
(
)
{
void
main
(
)
{
Cache
.
disableLocking
();
Cache
.
disableLocking
();
Directory
tempDir
;
Directory
tempDir
;
MockBundleBuilder
mock
BundleBuilder
;
FakeBundleBuilder
fake
BundleBuilder
;
setUp
(()
{
setUp
(()
{
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tools_packages_test.'
);
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tools_packages_test.'
);
mockBundleBuilder
=
MockBundleBuilder
();
fakeBundleBuilder
=
FakeBundleBuilder
();
when
(
mockBundleBuilder
.
build
(
platform:
anyNamed
(
'platform'
),
buildInfo:
anyNamed
(
'buildInfo'
),
mainPath:
anyNamed
(
'mainPath'
),
manifestPath:
anyNamed
(
'manifestPath'
),
applicationKernelFilePath:
anyNamed
(
'applicationKernelFilePath'
),
depfilePath:
anyNamed
(
'depfilePath'
),
assetDirPath:
anyNamed
(
'assetDirPath'
),
),
).
thenAnswer
((
_
)
=>
Future
<
void
>.
value
());
});
});
tearDown
(()
{
tearDown
(()
{
...
@@ -52,7 +43,7 @@ void main() {
...
@@ -52,7 +43,7 @@ void main() {
});
});
Future
<
BuildBundleCommand
>
runCommandIn
(
String
projectPath
,
{
List
<
String
>
arguments
})
async
{
Future
<
BuildBundleCommand
>
runCommandIn
(
String
projectPath
,
{
List
<
String
>
arguments
})
async
{
final
BuildBundleCommand
command
=
BuildBundleCommand
(
bundleBuilder:
mock
BundleBuilder
);
final
BuildBundleCommand
command
=
BuildBundleCommand
(
bundleBuilder:
fake
BundleBuilder
);
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
await
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -98,7 +89,7 @@ void main() {
...
@@ -98,7 +89,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'.packages'
).
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'.packages'
).
createSync
(
recursive:
true
);
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
expect
(()
=>
runner
.
run
(<
String
>[
expect
(()
=>
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -116,7 +107,7 @@ void main() {
...
@@ -116,7 +107,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
expect
(()
=>
runner
.
run
(<
String
>[
expect
(()
=>
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -134,7 +125,7 @@ void main() {
...
@@ -134,7 +125,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
expect
(()
=>
runner
.
run
(<
String
>[
expect
(()
=>
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -152,7 +143,7 @@ void main() {
...
@@ -152,7 +143,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
await
runner
.
run
(<
String
>[
await
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -170,7 +161,7 @@ void main() {
...
@@ -170,7 +161,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
await
runner
.
run
(<
String
>[
await
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -188,7 +179,7 @@ void main() {
...
@@ -188,7 +179,7 @@ void main() {
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
BuildBundleCommand
()
..
bundleBuilder
=
Mock
BundleBuilder
());
..
bundleBuilder
=
Fake
BundleBuilder
());
await
runner
.
run
(<
String
>[
await
runner
.
run
(<
String
>[
'bundle'
,
'bundle'
,
...
@@ -380,4 +371,17 @@ void main() {
...
@@ -380,4 +371,17 @@ void main() {
});
});
}
}
class
MockBundleBuilder
extends
Mock
implements
BundleBuilder
{}
class
FakeBundleBuilder
extends
Fake
implements
BundleBuilder
{
@override
Future
<
void
>
build
({
@required
TargetPlatform
platform
,
@required
BuildInfo
buildInfo
,
FlutterProject
project
,
String
mainPath
,
String
manifestPath
=
defaultManifestPath
,
String
applicationKernelFilePath
,
String
depfilePath
,
String
assetDirPath
,
@visibleForTesting
BuildSystem
buildSystem
,
})
async
{}
}
packages/flutter_tools/test/general.shard/ios/ios_device_start_nonprebuilt_test.dart
View file @
cbf885b7
...
@@ -23,10 +23,11 @@ import 'package:flutter_tools/src/ios/mac.dart';
...
@@ -23,10 +23,11 @@ import 'package:flutter_tools/src/ios/mac.dart';
import
'package:flutter_tools/src/ios/xcodeproj.dart'
;
import
'package:flutter_tools/src/ios/xcodeproj.dart'
;
import
'package:flutter_tools/src/macos/xcode.dart'
;
import
'package:flutter_tools/src/macos/xcode.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/context.dart'
hide
FakeXcodeProjectInterpreter
;
import
'../../src/fake_process_manager.dart'
;
import
'../../src/fake_process_manager.dart'
;
import
'../../src/fakes.dart'
;
import
'../../src/fakes.dart'
;
...
@@ -84,35 +85,14 @@ void main() {
...
@@ -84,35 +85,14 @@ void main() {
FakeProcessManager
processManager
;
FakeProcessManager
processManager
;
BufferLogger
logger
;
BufferLogger
logger
;
Xcode
xcode
;
Xcode
xcode
;
MockXcodeProjectInterpreter
mock
XcodeProjectInterpreter
;
FakeXcodeProjectInterpreter
fake
XcodeProjectInterpreter
;
setUp
(()
{
setUp
(()
{
logger
=
BufferLogger
.
test
();
logger
=
BufferLogger
.
test
();
fileSystem
=
MemoryFileSystem
.
test
();
fileSystem
=
MemoryFileSystem
.
test
();
processManager
=
FakeProcessManager
.
empty
();
processManager
=
FakeProcessManager
.
empty
();
fakeXcodeProjectInterpreter
=
FakeXcodeProjectInterpreter
();
mockXcodeProjectInterpreter
=
MockXcodeProjectInterpreter
();
xcode
=
Xcode
.
test
(
processManager:
FakeProcessManager
.
any
(),
xcodeProjectInterpreter:
fakeXcodeProjectInterpreter
);
when
(
mockXcodeProjectInterpreter
.
isInstalled
).
thenReturn
(
true
);
when
(
mockXcodeProjectInterpreter
.
version
).
thenReturn
(
Version
(
1000
,
0
,
0
));
when
(
mockXcodeProjectInterpreter
.
xcrunCommand
()).
thenReturn
(<
String
>[
'xcrun'
]);
when
(
mockXcodeProjectInterpreter
.
getInfo
(
any
,
projectFilename:
anyNamed
(
'projectFilename'
))).
thenAnswer
(
(
_
)
{
return
Future
<
XcodeProjectInfo
>.
value
(
XcodeProjectInfo
(
<
String
>[
'Runner'
],
<
String
>[
'Debug'
,
'Release'
],
<
String
>[
'Runner'
],
logger
,
));
}
);
when
(
mockXcodeProjectInterpreter
.
getBuildSettings
(
any
,
buildContext:
anyNamed
(
'buildContext'
)))
.
thenAnswer
((
_
)
async
=>
<
String
,
String
>{
'TARGET_BUILD_DIR'
:
'build/ios/Release-iphoneos'
,
'WRAPPER_NAME'
:
'My Super Awesome App.app'
,
'DEVELOPMENT_TEAM'
:
'3333CCCC33'
,
});
xcode
=
Xcode
.
test
(
processManager:
FakeProcessManager
.
any
(),
xcodeProjectInterpreter:
mockXcodeProjectInterpreter
);
fileSystem
.
file
(
'foo/.packages'
)
fileSystem
.
file
(
'foo/.packages'
)
..
createSync
(
recursive:
true
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'
\n
'
);
..
writeAsStringSync
(
'
\n
'
);
...
@@ -172,7 +152,7 @@ void main() {
...
@@ -172,7 +152,7 @@ void main() {
FileSystem:
()
=>
fileSystem
,
FileSystem:
()
=>
fileSystem
,
Logger:
()
=>
logger
,
Logger:
()
=>
logger
,
Platform:
()
=>
macPlatform
,
Platform:
()
=>
macPlatform
,
XcodeProjectInterpreter:
()
=>
mock
XcodeProjectInterpreter
,
XcodeProjectInterpreter:
()
=>
fake
XcodeProjectInterpreter
,
Xcode:
()
=>
xcode
,
Xcode:
()
=>
xcode
,
});
});
...
@@ -232,7 +212,7 @@ void main() {
...
@@ -232,7 +212,7 @@ void main() {
FileSystem:
()
=>
fileSystem
,
FileSystem:
()
=>
fileSystem
,
Logger:
()
=>
logger
,
Logger:
()
=>
logger
,
Platform:
()
=>
macPlatform
,
Platform:
()
=>
macPlatform
,
XcodeProjectInterpreter:
()
=>
mock
XcodeProjectInterpreter
,
XcodeProjectInterpreter:
()
=>
fake
XcodeProjectInterpreter
,
Xcode:
()
=>
xcode
,
Xcode:
()
=>
xcode
,
},
skip:
true
);
// TODO(jonahwilliams): clean up with https://github.com/flutter/flutter/issues/60675
},
skip:
true
);
// TODO(jonahwilliams): clean up with https://github.com/flutter/flutter/issues/60675
});
});
...
@@ -289,4 +269,37 @@ IOSDevice setUpIOSDevice({
...
@@ -289,4 +269,37 @@ IOSDevice setUpIOSDevice({
);
);
}
}
class
MockXcodeProjectInterpreter
extends
Mock
implements
XcodeProjectInterpreter
{}
class
FakeXcodeProjectInterpreter
extends
Fake
implements
XcodeProjectInterpreter
{
@override
final
bool
isInstalled
=
true
;
@override
final
Version
version
=
Version
(
1000
,
0
,
0
);
@override
List
<
String
>
xcrunCommand
()
=>
<
String
>[
'xcrun'
];
@override
Future
<
XcodeProjectInfo
>
getInfo
(
String
projectPath
,
{
String
projectFilename
,
})
async
=>
XcodeProjectInfo
(
<
String
>[
'Runner'
],
<
String
>[
'Debug'
,
'Release'
],
<
String
>[
'Runner'
],
BufferLogger
.
test
(),
);
@override
Future
<
Map
<
String
,
String
>>
getBuildSettings
(
String
projectPath
,
{
@required
XcodeProjectBuildContext
buildContext
,
Duration
timeout
=
const
Duration
(
minutes:
1
),
})
async
=>
<
String
,
String
>{
'TARGET_BUILD_DIR'
:
'build/ios/Release-iphoneos'
,
'WRAPPER_NAME'
:
'My Super Awesome App.app'
,
'DEVELOPMENT_TEAM'
:
'3333CCCC33'
,
};
}
packages/flutter_tools/test/src/mocks.dart
View file @
cbf885b7
...
@@ -6,14 +6,10 @@
...
@@ -6,14 +6,10 @@
import
'dart:async'
;
import
'dart:async'
;
import
'package:flutter_tools/src/android/android_device.dart'
;
import
'package:flutter_tools/src/android/android_sdk.dart'
show
AndroidSdk
;
import
'package:flutter_tools/src/android/android_sdk.dart'
show
AndroidSdk
;
import
'package:flutter_tools/src/base/file_system.dart'
hide
IOSink
;
import
'package:flutter_tools/src/base/file_system.dart'
hide
IOSink
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/ios/devices.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:process/process.dart'
;
...
@@ -154,31 +150,3 @@ _ProcessFactory flakyProcessFactory({
...
@@ -154,31 +150,3 @@ _ProcessFactory flakyProcessFactory({
);
);
};
};
}
}
class
MockAndroidDevice
extends
Mock
implements
AndroidDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
android_arm
;
@override
bool
isSupported
()
=>
true
;
@override
bool
get
supportsHotRestart
=>
true
;
@override
bool
get
supportsFlutterExit
=>
false
;
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
true
;
}
class
MockIOSDevice
extends
Mock
implements
IOSDevice
{
@override
Future
<
TargetPlatform
>
get
targetPlatform
async
=>
TargetPlatform
.
ios
;
@override
bool
isSupported
()
=>
true
;
@override
bool
isSupportedForProject
(
FlutterProject
flutterProject
)
=>
true
;
}
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