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
3422540b
Unverified
Commit
3422540b
authored
Nov 04, 2019
by
Jonah Williams
Committed by
GitHub
Nov 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
copy chrome preferences to seeded data dir (#44032)
parent
df0501c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
30 deletions
+103
-30
chrome.dart
packages/flutter_tools/lib/src/web/chrome.dart
+41
-4
web_device.dart
packages/flutter_tools/lib/src/web/web_device.dart
+4
-1
chrome_test.dart
...ges/flutter_tools/test/general.shard/web/chrome_test.dart
+58
-25
No files found.
packages/flutter_tools/lib/src/web/chrome.dart
View file @
3422540b
...
...
@@ -4,6 +4,7 @@
import
'dart:async'
;
import
'package:meta/meta.dart'
;
import
'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'
;
import
'../base/common.dart'
;
...
...
@@ -65,13 +66,18 @@ String findChromeExecutable() {
return
null
;
}
@visibleForTesting
void
resetChromeForTesting
(
)
{
ChromeLauncher
.
_currentCompleter
=
Completer
<
Chrome
>();
}
/// Responsible for launching chrome with devtools configured.
class
ChromeLauncher
{
const
ChromeLauncher
();
static
bool
get
hasChromeInstance
=>
_currentCompleter
.
isCompleted
;
static
final
Completer
<
Chrome
>
_currentCompleter
=
Completer
<
Chrome
>();
static
Completer
<
Chrome
>
_currentCompleter
=
Completer
<
Chrome
>();
/// Whether we can locate the chrome executable.
bool
canFindChrome
()
{
...
...
@@ -89,15 +95,31 @@ class ChromeLauncher {
/// a `headfull` browser.
///
/// `skipCheck` does not attempt to make a devtools connection before returning.
Future
<
Chrome
>
launch
(
String
url
,
{
bool
headless
=
false
,
bool
skipCheck
=
false
})
async
{
Future
<
Chrome
>
launch
(
String
url
,
{
bool
headless
=
false
,
bool
skipCheck
=
false
,
Directory
dataDir
})
async
{
// This is a JSON file which contains configuration from the
// browser session, such as window position. It is located
// under the Chrome data-dir folder.
final
String
preferencesPath
=
fs
.
path
.
join
(
'Default'
,
'preferences'
);
final
String
chromeExecutable
=
findChromeExecutable
();
final
Directory
dataDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tool.'
);
final
Directory
activeDataDir
=
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tool.'
);
// Seed data dir with previous state.
final
File
savedPreferencesFile
=
fs
.
file
(
fs
.
path
.
join
(
dataDir
?.
path
??
''
,
preferencesPath
));
final
File
destinationFile
=
fs
.
file
(
fs
.
path
.
join
(
activeDataDir
.
path
,
preferencesPath
));
if
(
dataDir
!=
null
)
{
if
(
savedPreferencesFile
.
existsSync
())
{
destinationFile
.
parent
.
createSync
(
recursive:
true
);
savedPreferencesFile
.
copySync
(
destinationFile
.
path
);
}
}
final
int
port
=
await
os
.
findFreePort
();
final
List
<
String
>
args
=
<
String
>[
chromeExecutable
,
// Using a tmp directory ensures that a new instance of chrome launches
// allowing for the remote debug port to be enabled.
'--user-data-dir=
${
d
ataDir.path}
'
,
'--user-data-dir=
${
activeD
ataDir.path}
'
,
'--remote-debugging-port=
$port
'
,
// When the DevTools has focus we don't want to slow down the application.
'--disable-background-timer-throttling'
,
...
...
@@ -117,6 +139,21 @@ class ChromeLauncher {
final
Process
process
=
await
processManager
.
start
(
args
);
// When the process exits, copy the user settings back to the provided
// data-dir.
if
(
dataDir
!=
null
)
{
unawaited
(
process
.
exitCode
.
whenComplete
(()
{
if
(
destinationFile
.
existsSync
())
{
savedPreferencesFile
.
parent
.
createSync
(
recursive:
true
);
// If the file contains a crash string, remove it to hide
// the popup on next run.
final
String
contents
=
destinationFile
.
readAsStringSync
();
savedPreferencesFile
.
writeAsStringSync
(
contents
.
replaceFirst
(
'"exit_type":"Crashed"'
,
'"exit_type":"Normal"'
));
}
}));
}
// Wait until the DevTools are listening before trying to connect.
await
process
.
stderr
.
transform
(
utf8
.
decoder
)
...
...
packages/flutter_tools/lib/src/web/web_device.dart
View file @
3422540b
...
...
@@ -132,7 +132,10 @@ class ChromeDevice extends Device {
// for the web initialization and server logic.
final
String
url
=
platformArgs
[
'uri'
];
if
(
debuggingOptions
.
browserLaunch
)
{
_chrome
=
await
chromeLauncher
.
launch
(
url
);
_chrome
=
await
chromeLauncher
.
launch
(
url
,
dataDir:
fs
.
currentDirectory
.
childDirectory
(
'.dart_tool'
)
.
childDirectory
(
'chrome-device'
));
}
else
{
printStatus
(
'Waiting for connection from Dart debug extension at
$url
'
,
emphasis:
true
);
logger
.
sendNotification
(
url
,
progressId:
'debugExtension'
);
...
...
packages/flutter_tools/test/general.shard/web/chrome_test.dart
View file @
3422540b
...
...
@@ -19,33 +19,43 @@ import '../../src/testbed.dart';
void
main
(
)
{
Testbed
testbed
;
Completer
<
int
>
exitCompleter
;
setUp
(()
{
final
MockPlatform
platform
=
MockPlatform
();
exitCompleter
=
Completer
<
int
>.
sync
();
when
(
platform
.
isWindows
).
thenReturn
(
false
);
final
MockFileSystem
mockFileSystem
=
MockFileSystem
();
testbed
=
Testbed
(
overrides:
<
Type
,
Generator
>{
ProcessManager:
()
=>
MockProcessManager
(),
Platform:
()
=>
platform
,
OperatingSystemUtils:
()
=>
MockOperatingSystemUtils
(),
FileSystem:
()
=>
mockFileSystem
,
},
setup:
()
{
when
(
os
.
findFreePort
()).
thenAnswer
((
Invocation
invocation
)
async
{
return
1234
;
});
when
(
platform
.
environment
).
thenReturn
(<
String
,
String
>{
kChromeEnvironment:
'example_chrome'
,
});
when
(
processManager
.
start
(
any
))
.
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
'
),
]),
);
});
});
});
tearDown
(()
{
resetChromeForTesting
();
});
test
(
'can launch chrome and connect to the devtools'
,
()
=>
testbed
.
run
(()
async
{
when
(
os
.
findFreePort
()).
thenAnswer
((
Invocation
invocation
)
async
{
return
1234
;
});
when
(
platform
.
environment
).
thenReturn
(<
String
,
String
>{
kChromeEnvironment:
'example_chrome'
,
});
final
Directory
mockDirectory
=
MockDirectory
();
when
(
fs
.
systemTempDirectory
).
thenReturn
(
mockDirectory
);
when
(
mockDirectory
.
createTempSync
(
any
)).
thenReturn
(
mockDirectory
);
when
(
mockDirectory
.
path
).
thenReturn
(
'example'
);
when
(
processManager
.
start
(<
String
>[
const
List
<
String
>
expected
=
<
String
>[
'example_chrome'
,
'--user-data-dir=example'
,
'--remote-debugging-port=1234'
,
'--disable-background-timer-throttling'
,
'--disable-extensions'
,
...
...
@@ -56,22 +66,45 @@ void main() {
'--disable-default-apps'
,
'--disable-translate'
,
'example_url'
,
])).
thenAnswer
((
Invocation
invocation
)
async
{
return
FakeProcess
(
exitCode:
Completer
<
int
>().
future
,
stdout:
const
Stream
<
List
<
int
>>.
empty
(),
stderr:
Stream
<
List
<
int
>>.
fromIterable
(<
List
<
int
>>[
utf8
.
encode
(
'
\n\n
DevTools listening
\n\n
'
),
]),
);
});
];
await
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
);
final
VerificationResult
result
=
verify
(
processManager
.
start
(
captureAny
));
expect
(
result
.
captured
.
single
,
containsAll
(
expected
));
}));
test
(
'can seed chrome temp directory with existing preferences'
,
()
=>
testbed
.
run
(()
async
{
final
Directory
dataDir
=
fs
.
directory
(
'chrome-stuff'
);
final
File
preferencesFile
=
dataDir
.
childDirectory
(
'Default'
)
.
childFile
(
'preferences'
);
preferencesFile
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
'example'
);
await
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
dataDir:
dataDir
);
final
VerificationResult
result
=
verify
(
processManager
.
start
(
captureAny
));
final
String
arg
=
result
.
captured
.
single
.
firstWhere
((
String
arg
)
=>
arg
.
startsWith
(
'--user-data-dir='
));
final
Directory
tempDirectory
=
fs
.
directory
(
arg
.
split
(
'='
)[
1
]);
final
File
tempFile
=
tempDirectory
.
childDirectory
(
'Default'
)
.
childFile
(
'preferences'
);
expect
(
tempFile
.
existsSync
(),
true
);
expect
(
tempFile
.
readAsStringSync
(),
'example'
);
// write crash to file:
tempFile
.
writeAsStringSync
(
'"exit_type":"Crashed"'
);
exitCompleter
.
complete
(
0
);
// 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
MockFileSystem
extends
Mock
implements
FileSystem
{}
class
MockDirectory
extends
Mock
implements
Directory
{}
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