OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.runner.browser.safari; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:convert'; |
| 9 import 'dart:io'; |
| 10 |
| 11 import 'package:path/path.dart' as p; |
| 12 |
| 13 import '../../util/io.dart'; |
| 14 import 'browser.dart'; |
| 15 |
| 16 /// A class for running an instance of Safari. |
| 17 /// |
| 18 /// Any errors starting or running the process are reported through [onExit]. |
| 19 class Safari extends Browser { |
| 20 final name = "Safari"; |
| 21 |
| 22 Safari(url, {String executable}) |
| 23 : super(() => _startBrowser(url, executable)); |
| 24 |
| 25 /// Starts a new instance of Safari open to the given [url], which may be a |
| 26 /// [Uri] or a [String]. |
| 27 /// |
| 28 /// If [executable] is passed, it's used as the content shell executable. |
| 29 /// Otherwise the default executable name for the current OS will be used. |
| 30 static Future<Process> _startBrowser(url, [String executable]) async { |
| 31 if (executable == null) { |
| 32 executable = '/Applications/Safari.app/Contents/MacOS/Safari'; |
| 33 } |
| 34 |
| 35 var dir = createTempDir(); |
| 36 |
| 37 // Safari will only open files (not general URLs) via the command-line |
| 38 // API, so we create a dummy file to redirect it to the page we actually |
| 39 // want it to load. |
| 40 var redirect = p.join(dir, 'redirect.html'); |
| 41 new File(redirect).writeAsStringSync( |
| 42 "<script>location = " + JSON.encode(url.toString()) + "</script>"); |
| 43 |
| 44 var process = await Process.start(executable, [redirect]); |
| 45 |
| 46 process.exitCode |
| 47 .then((_) => new Directory(dir).deleteSync(recursive: true)); |
| 48 |
| 49 return process; |
| 50 } |
| 51 } |
OLD | NEW |