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
677b7c15
Unverified
Commit
677b7c15
authored
Jul 19, 2019
by
Lau Ching Jun
Committed by
GitHub
Jul 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Load assets during test from file system instead of manifest. (#36553)
parent
76cbbeb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
39 deletions
+19
-39
binding.dart
packages/flutter_test/lib/src/binding.dart
+19
-39
No files found.
packages/flutter_test/lib/src/binding.dart
View file @
677b7c15
...
...
@@ -798,9 +798,6 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
int
get
microtaskCount
=>
_currentFakeAsync
.
microtaskCount
;
/// A whitelist [Set] that is used in mocking the asset message channel.
static
Set
<
String
>
_allowedAssetKeys
;
void
_mockFlutterAssets
()
{
if
(
isBrowser
)
{
return
;
...
...
@@ -809,46 +806,29 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
return
;
}
final
String
assetFolderPath
=
Platform
.
environment
[
'UNIT_TEST_ASSETS'
];
_ensureInitialized
(
assetFolderPath
);
final
String
prefix
=
'packages/
${Platform.environment['APP_NAME']}
/'
;
if
(
_allowedAssetKeys
.
isNotEmpty
)
{
defaultBinaryMessenger
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
{
String
key
=
utf8
.
decode
(
message
.
buffer
.
asUint8List
());
if
(!
_allowedAssetKeys
.
contains
(
key
))
{
// For tests in package, it will load assets with its own package prefix.
// In this case, we do a best-effort look up.
if
(!
key
.
startsWith
(
prefix
))
return
null
;
key
=
key
.
replaceFirst
(
prefix
,
''
);
if
(!
_allowedAssetKeys
.
contains
(
key
))
return
null
;
defaultBinaryMessenger
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
{
String
key
=
utf8
.
decode
(
message
.
buffer
.
asUint8List
());
File
asset
=
File
(
path
.
join
(
assetFolderPath
,
key
));
if
(!
asset
.
existsSync
())
{
// For tests in package, it will load assets with its own package prefix.
// In this case, we do a best-effort look up.
if
(!
key
.
startsWith
(
prefix
))
{
return
null
;
}
final
File
asset
=
File
(
path
.
join
(
assetFolderPath
,
key
));
final
Uint8List
encoded
=
Uint8List
.
fromList
(
asset
.
readAsBytesSync
());
return
Future
<
ByteData
>.
value
(
encoded
.
buffer
.
asByteData
());
});
}
}
void
_ensureInitialized
(
String
assetFolderPath
)
{
if
(
_allowedAssetKeys
!=
null
)
{
return
;
}
final
File
manifestFile
=
File
(
path
.
join
(
assetFolderPath
,
'AssetManifest.json'
));
// If the file does not exist, it means there is no asset declared in
// the project.
if
(!
manifestFile
.
existsSync
())
{
_allowedAssetKeys
=
<
String
>{};
return
;
}
final
Map
<
String
,
dynamic
>
manifest
=
json
.
decode
(
manifestFile
.
readAsStringSync
());
_allowedAssetKeys
=
<
String
>{
'AssetManifest.json'
,
...
manifest
.
values
.
cast
<
List
<
dynamic
>>().
expand
<
dynamic
>((
List
<
dynamic
>
e
)
=>
e
).
cast
<
String
>(),
};
key
=
key
.
replaceFirst
(
prefix
,
''
);
asset
=
File
(
path
.
join
(
assetFolderPath
,
key
));
if
(!
asset
.
existsSync
())
{
return
null
;
}
}
final
Uint8List
encoded
=
Uint8List
.
fromList
(
asset
.
readAsBytesSync
());
return
Future
<
ByteData
>.
value
(
encoded
.
buffer
.
asByteData
());
});
}
@override
...
...
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