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.firefox; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:io'; |
| 9 |
| 10 import 'package:path/path.dart' as p; |
| 11 |
| 12 import '../../util/io.dart'; |
| 13 import 'browser.dart'; |
| 14 |
| 15 final _preferences = ''' |
| 16 user_pref("browser.shell.checkDefaultBrowser", false); |
| 17 user_pref("dom.disable_open_during_load", false); |
| 18 user_pref("dom.max_script_run_time", 0); |
| 19 '''; |
| 20 |
| 21 /// A class for running an instance of Firefox. |
| 22 /// |
| 23 /// Most of the communication with the browser is expected to happen via HTTP, |
| 24 /// so this exposes a bare-bones API. The browser starts as soon as the class is |
| 25 /// constructed, and is killed when [close] is called. |
| 26 /// |
| 27 /// Any errors starting or running the process are reported through [onExit]. |
| 28 class Firefox extends Browser { |
| 29 final name = "Firefox"; |
| 30 |
| 31 Firefox(url, {String executable}) |
| 32 : super(() => _startBrowser(url, executable)); |
| 33 |
| 34 /// Starts a new instance of Firefox open to the given [url], which may be a |
| 35 /// [Uri] or a [String]. |
| 36 /// |
| 37 /// If [executable] is passed, it's used as the Firefox executable. |
| 38 /// Otherwise the default executable name for the current OS will be used. |
| 39 static Future<Process> _startBrowser(url, [String executable]) async { |
| 40 if (executable == null) executable = _defaultExecutable(); |
| 41 |
| 42 var dir = createTempDir(); |
| 43 new File(p.join(dir, 'prefs.js')).writeAsStringSync(_preferences); |
| 44 |
| 45 var process = await Process.start(executable, [ |
| 46 "--profile", "$dir", |
| 47 url.toString(), |
| 48 "--no-remote" |
| 49 ], environment: { |
| 50 "MOZ_CRASHREPORTER_DISABLE": "1" |
| 51 }); |
| 52 |
| 53 process.exitCode |
| 54 .then((_) => new Directory(dir).deleteSync(recursive: true)); |
| 55 |
| 56 return process; |
| 57 } |
| 58 |
| 59 /// Return the default executable for the current operating system. |
| 60 static String _defaultExecutable() { |
| 61 if (Platform.isMacOS) { |
| 62 return '/Applications/Firefox.app/Contents/MacOS/firefox-bin'; |
| 63 } |
| 64 if (!Platform.isWindows) return 'firefox'; |
| 65 |
| 66 // Firefox could be installed in several places on Windows. The only way to |
| 67 // find it is to check. |
| 68 var prefixes = [ |
| 69 Platform.environment['PROGRAMFILES'], |
| 70 Platform.environment['PROGRAMFILES(X86)'] |
| 71 ]; |
| 72 var suffix = r'Mozilla Firefox\firefox.exe'; |
| 73 |
| 74 for (var prefix in prefixes) { |
| 75 if (prefix == null) continue; |
| 76 |
| 77 var path = p.join(prefix, suffix); |
| 78 if (new File(p.join(prefix, suffix)).existsSync()) return path; |
| 79 } |
| 80 |
| 81 // Fall back on looking it up on the path. This probably won't work, but at |
| 82 // least it will fail with a useful error message. |
| 83 return "firefox.exe"; |
| 84 } |
| 85 } |
OLD | NEW |