This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Run engine tests on Safari locally by launching safari installed on MacOS #14555
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # For more information on test and runner configurations: | ||
| # | ||
| # * https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md#platforms | ||
|
|
||
| platforms: | ||
| - safari | ||
| - vm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright 2013 The Flutter 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 'dart:io'; | ||
|
|
||
| import 'environment.dart'; | ||
|
|
||
| import 'package:path/path.dart' as path; | ||
| import 'package:pedantic/pedantic.dart'; | ||
|
|
||
| import 'package:test_core/src/util/io.dart'; // ignore: implementation_imports | ||
|
|
||
| import 'browser.dart'; | ||
| import 'safari_installation.dart'; | ||
| import 'common.dart'; | ||
|
|
||
| /// A class for running an instance of Safari. | ||
| /// | ||
| /// Most of the communication with the browser is expected to happen via HTTP, | ||
| /// so this exposes a bare-bones API. The browser starts as soon as the class is | ||
| /// constructed, and is killed when [close] is called. | ||
| /// | ||
| /// Any errors starting or running the process are reported through [onExit]. | ||
| class Safari extends Browser { | ||
| @override | ||
| final name = 'Safari'; | ||
|
|
||
| static String version; | ||
|
|
||
| /// Starts a new instance of Safari open to the given [url], which may be a | ||
| /// [Uri] or a [String]. | ||
| factory Safari(Uri url, {bool debug = false}) { | ||
| version = SafariArgParser.instance.version; | ||
|
|
||
| assert(version != null); | ||
| return Safari._(() async { | ||
| // TODO(nurhan): Configure info log for LUCI. | ||
| final BrowserInstallation installation = await getOrInstallSafari( | ||
| version, | ||
| infoLog: DevNull(), | ||
| ); | ||
|
|
||
| // Safari will only open files (not general URLs) via the command-line | ||
| // API, so we create a dummy file to redirect it to the page we actually | ||
| // want it to load. | ||
| final Directory redirectDir = Directory( | ||
| path.join(environment.webUiDartToolDir.path), | ||
| ); | ||
| final redirect = path.join(redirectDir.path, 'redirect.html'); | ||
| File(redirect).writeAsStringSync( | ||
| '<script>location = ' + jsonEncode(url.toString()) + '</script>'); | ||
|
|
||
| var process = | ||
| await Process.start(installation.executable, [redirect] /* args */); | ||
|
|
||
| unawaited(process.exitCode | ||
| .then((_) => File(redirect).deleteSync(recursive: true))); | ||
|
|
||
| return process; | ||
| }); | ||
| } | ||
|
|
||
| Safari._(Future<Process> startBrowser()) : super(startBrowser); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright 2013 The Flutter 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:io' as io; | ||
|
|
||
| import 'package:args/args.dart'; | ||
|
|
||
| import 'common.dart'; | ||
|
|
||
| class SafariArgParser extends BrowserArgParser { | ||
| static final SafariArgParser _singletonInstance = SafariArgParser._(); | ||
|
|
||
| /// The [SafariArgParser] singleton. | ||
| static SafariArgParser get instance => _singletonInstance; | ||
|
|
||
| String _version; | ||
|
|
||
| SafariArgParser._(); | ||
|
|
||
| @override | ||
| void populateOptions(ArgParser argParser) { | ||
| argParser | ||
| ..addOption( | ||
| 'safari-version', | ||
| defaultsTo: 'system', | ||
| help: 'The Safari version to use while running tests. The Safari ' | ||
| 'browswer installed on the system is used as the only option now.' | ||
| 'Soon we will add support for using different versions using the ' | ||
| 'tech previews.', | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| void parseOptions(ArgResults argResults) { | ||
| _version = argResults['safari-version']; | ||
| assert(_version == 'system'); | ||
| } | ||
|
|
||
| @override | ||
| String get version => _version; | ||
| } | ||
|
|
||
| /// Returns the installation of Safari. | ||
| /// | ||
| /// Currently uses the Safari version installed on the operating system. | ||
| /// | ||
| /// Latest Safari version for Catalina, Mojave, High Siera is 13. | ||
| /// | ||
| /// Latest Safari version for Sierra is 12. | ||
| // TODO(nurhan): user latest version to download and install the latest | ||
| // technology preview. | ||
| Future<BrowserInstallation> getOrInstallSafari( | ||
| String requestedVersion, { | ||
| StringSink infoLog, | ||
| }) async { | ||
|
|
||
| // These tests are aimed to run only on MacOs machines local or on LUCI. | ||
| if (!io.Platform.isMacOS) { | ||
| throw UnimplementedError(); | ||
|
nturgut marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| infoLog ??= io.stdout; | ||
|
|
||
| if (requestedVersion == 'system') { | ||
| // Since Safari is included in MacOS, always assume there will be one on the | ||
| // system. | ||
| infoLog.writeln('Using the system version is already installed.'); | ||
|
nturgut marked this conversation as resolved.
Outdated
|
||
| return BrowserInstallation( | ||
| version: 'system', | ||
| executable: PlatformBinding.instance.getSafariSystemExecutablePath(), | ||
| ); | ||
| } else { | ||
| infoLog.writeln('Unsupported version $requestedVersion.'); | ||
| throw UnimplementedError(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.