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
611e5cb4
Unverified
Commit
611e5cb4
authored
Feb 27, 2020
by
Jonah Williams
Committed by
GitHub
Feb 27, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] update chrome tests to remove globals, mock processmanager, mock process (#51533)
parent
ee4b40a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
80 deletions
+143
-80
chrome_test.dart
...ges/flutter_tools/test/general.shard/web/chrome_test.dart
+116
-80
fake_process_manager.dart
packages/flutter_tools/test/src/fake_process_manager.dart
+27
-0
No files found.
packages/flutter_tools/test/general.shard/web/chrome_test.dart
View file @
611e5cb4
...
...
@@ -4,99 +4,126 @@
import
'dart:async'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/convert.dart'
;
import
'package:flutter_tools/src/web/chrome.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:platform/platform.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/testbed.dart'
;
import
'../../src/context.dart'
;
const
List
<
String
>
_kChromeArgs
=
<
String
>[
'--disable-background-timer-throttling'
,
'--disable-extensions'
,
'--disable-popup-blocking'
,
'--bwsi'
,
'--no-first-run'
,
'--no-default-browser-check'
,
'--disable-default-apps'
,
'--disable-translate'
,
];
const
String
kDevtoolsStderr
=
'
\n\n
DevTools listening
\n\n
'
;
void
main
(
)
{
Testbed
testbed
;
Completer
<
int
>
exitCompleter
;
ChromeLauncher
chromeLauncher
;
FileSystem
fileSystem
;
Platform
platform
;
FakeProcessManager
processManager
;
OperatingSystemUtils
operatingSystemUtils
;
MockLogger
logger
;
setUp
(()
{
final
MockPlatform
platform
=
MockPlatform
();
final
MockOperatingSystemUtils
os
=
MockOperatingSystemUtils
();
exitCompleter
=
Completer
<
int
>.
sync
();
when
(
platform
.
isWindows
).
thenReturn
(
false
);
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
MockProcessManager
(),
Platform:
()
=>
platform
,
OperatingSystemUtils:
()
=>
os
,
},
setup:
()
{
when
(
os
.
findFreePort
()).
thenAnswer
((
Invocation
invocation
)
async
{
return
1234
;
});
when
(
platform
.
environment
).
thenReturn
(<
String
,
String
>{
kChromeEnvironment:
'example_chrome'
,
});
when
(
globals
.
processManager
.
start
(
any
))
logger
=
MockLogger
();
operatingSystemUtils
=
MockOperatingSystemUtils
();
when
(
operatingSystemUtils
.
findFreePort
())
.
thenAnswer
((
Invocation
invocation
)
async
{
return
FakeProcess
(
exitCode:
exitCompleter
.
future
,
stdout:
const
Stream
<
List
<
int
>>.
empty
(),
stderr:
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
'
\n\n
DevTools listening
\n\n
'
),
]),
);
});
return
1234
;
});
platform
=
FakePlatform
(
operatingSystem:
'macos'
,
environment:
<
String
,
String
>{
kChromeEnvironment:
'example_chrome'
,
});
fileSystem
=
MemoryFileSystem
.
test
();
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
chromeLauncher
=
ChromeLauncher
(
fileSystem:
fileSystem
,
platform:
platform
,
processManager:
processManager
,
operatingSystemUtils:
operatingSystemUtils
,
logger:
logger
,
);
});
tearDown
(()
{
resetChromeForTesting
();
});
List
<
String
>
expectChromeArgs
({
int
debugPort
=
1234
})
{
return
<
String
>[
'example_chrome'
,
'--remote-debugging-port=
$debugPort
'
,
'--disable-background-timer-throttling'
,
'--disable-extensions'
,
'--disable-popup-blocking'
,
'--bwsi'
,
'--no-first-run'
,
'--no-default-browser-check'
,
'--disable-default-apps'
,
'--disable-translate'
,
test
(
'can launch chrome and connect to the devtools'
,
()
async
{
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tool.rand0'
,
'--remote-debugging-port=1234'
,
...
_kChromeArgs
,
'example_url'
,
],
stderr:
kDevtoolsStderr
,
));
await
chromeLauncher
.
launch
(
'example_url'
,
];
}
test
(
'can launch chrome and connect to the devtools'
,
()
=>
testbed
.
run
(()
async
{
await
globals
.
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
);
final
VerificationResult
result
=
verify
(
globals
.
processManager
.
start
(
captureAny
));
expect
(
result
.
captured
.
single
,
containsAll
(
expectChromeArgs
()));
expect
(
result
.
captured
.
single
,
isNot
(
contains
(
'--window-size=2400,1800'
)));
}));
test
(
'can launch chrome with a custom debug port'
,
()
=>
testbed
.
run
(()
async
{
await
globals
.
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
debugPort:
10000
);
final
VerificationResult
result
=
verify
(
globals
.
processManager
.
start
(
captureAny
));
expect
(
result
.
captured
.
single
,
containsAll
(
expectChromeArgs
(
debugPort:
10000
)));
expect
(
result
.
captured
.
single
,
isNot
(
contains
(
'--window-size=2400,1800'
)));
}));
test
(
'can launch chrome headless'
,
()
=>
testbed
.
run
(()
async
{
await
globals
.
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
headless:
true
);
final
VerificationResult
result
=
verify
(
globals
.
processManager
.
start
(
captureAny
));
skipCheck:
true
,
);
});
expect
(
result
.
captured
.
single
,
containsAll
(
expectChromeArgs
()));
expect
(
result
.
captured
.
single
,
contains
(
'--window-size=2400,1800'
));
}));
test
(
'can launch chrome with a custom debug port'
,
()
async
{
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tool.rand0'
,
'--remote-debugging-port=10000'
,
...
_kChromeArgs
,
'example_url'
,
],
stderr:
kDevtoolsStderr
,
));
await
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
debugPort:
10000
,
);
});
test
(
'can launch chrome headless'
,
()
async
{
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tool.rand0'
,
'--remote-debugging-port=1234'
,
...
_kChromeArgs
,
'--headless'
,
'--disable-gpu'
,
'--no-sandbox'
,
'--window-size=2400,1800'
,
'example_url'
,
],
stderr:
kDevtoolsStderr
,
));
await
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
headless:
true
,
);
});
test
(
'can seed chrome temp directory with existing preferences'
,
()
=>
testbed
.
run
(()
async
{
final
Directory
dataDir
=
globals
.
fs
.
directory
(
'chrome-stuff'
);
test
(
'can seed chrome temp directory with existing preferences'
,
()
async
{
final
Completer
<
void
>
exitCompleter
=
Completer
<
void
>.
sync
();
final
Directory
dataDir
=
fileSystem
.
directory
(
'chrome-stuff'
);
final
File
preferencesFile
=
dataDir
.
childDirectory
(
'Default'
)
.
childFile
(
'preferences'
);
...
...
@@ -104,12 +131,22 @@ void main() {
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'example'
);
await
globals
.
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
dataDir:
dataDir
);
final
VerificationResult
result
=
verify
(
globals
.
processManager
.
start
(
captureAny
));
final
String
arg
=
(
result
.
captured
.
single
as
List
<
String
>)
.
firstWhere
((
String
arg
)
=>
arg
.
startsWith
(
'--user-data-dir='
));
final
Directory
tempDirectory
=
globals
.
fs
.
directory
(
arg
.
split
(
'='
)[
1
]);
final
File
tempFile
=
tempDirectory
processManager
.
addCommand
(
FakeCommand
(
command:
const
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tool.rand0'
,
'--remote-debugging-port=1234'
,
...
_kChromeArgs
,
'example_url'
,
],
completer:
exitCompleter
));
await
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
dataDir:
dataDir
,
);
final
File
tempFile
=
fileSystem
.
directory
(
'.tmp_rand0/flutter_tool.rand0'
)
.
childDirectory
(
'Default'
)
.
childFile
(
'preferences'
);
...
...
@@ -118,13 +155,12 @@ void main() {
// write crash to file:
tempFile
.
writeAsStringSync
(
'"exit_type":"Crashed"'
);
exitCompleter
.
complete
(
0
);
exitCompleter
.
complete
();
// writes non-crash back to dart_tool
expect
(
preferencesFile
.
readAsStringSync
(),
'"exit_type":"Normal"'
);
})
)
;
});
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
class
MockPlatform
extends
Mock
implements
Platform
{}
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{}
class
MockLogger
extends
Mock
implements
Logger
{}
packages/flutter_tools/test/src/fake_process_manager.dart
View file @
611e5cb4
...
...
@@ -2,6 +2,7 @@
// 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
'dart:io'
as
io
show
ProcessSignal
;
...
...
@@ -26,6 +27,7 @@ class FakeCommand {
this
.
exitCode
=
0
,
this
.
stdout
=
''
,
this
.
stderr
=
''
,
this
.
completer
,
})
:
assert
(
command
!=
null
),
assert
(
duration
!=
null
),
assert
(
exitCode
!=
null
),
...
...
@@ -78,6 +80,10 @@ class FakeCommand {
/// returned in one go.
final
String
stderr
;
/// If provided, allows the command completion to be blocked until the future
/// resolves.
final
Completer
<
void
>
completer
;
static
bool
_listEquals
<
T
>(
List
<
T
>
a
,
List
<
T
>
b
)
{
if
(
a
==
null
)
{
return
b
==
null
;
...
...
@@ -123,10 +129,14 @@ class _FakeProcess implements Process {
this
.
_stderr
,
this
.
stdin
,
this
.
_stdout
,
Completer
<
void
>
completer
,
)
:
exitCode
=
Future
<
void
>.
delayed
(
duration
).
then
((
void
value
)
{
if
(
onRun
!=
null
)
{
onRun
();
}
if
(
completer
!=
null
)
{
return
completer
.
future
.
then
((
void
_
)
=>
_exitCode
);
}
return
_exitCode
;
}),
stderr
=
Stream
<
List
<
int
>>.
value
(
utf8
.
encode
(
_stderr
)),
...
...
@@ -184,6 +194,14 @@ abstract class FakeProcessManager implements ProcessManager {
FakeProcessManager
.
_
();
/// Adds a new [FakeCommand] to the current process manager.
///
/// This can be used to configure test expectations after the [ProcessManager] has been
/// provided to another interface.
///
/// This is a no-op on [FakeProcessManager.any].
void
addCommand
(
FakeCommand
command
);
@protected
FakeCommand
findCommand
(
List
<
String
>
command
,
String
workingDirectory
,
Map
<
String
,
String
>
environment
);
...
...
@@ -200,6 +218,7 @@ abstract class FakeProcessManager implements ProcessManager {
fakeCommand
.
stderr
,
null
,
// stdin
fakeCommand
.
stdout
,
fakeCommand
.
completer
,
);
}
...
...
@@ -277,6 +296,9 @@ class _FakeAnyProcessManager extends FakeProcessManager {
stderr:
''
,
);
}
@override
void
addCommand
(
FakeCommand
command
)
{
}
}
class
_SequenceProcessManager
extends
FakeProcessManager
{
...
...
@@ -298,4 +320,9 @@ class _SequenceProcessManager extends FakeProcessManager {
);
return
_commands
.
removeAt
(
0
);
}
@override
void
addCommand
(
FakeCommand
command
)
{
_commands
.
add
(
command
);
}
}
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