Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: mojo/public/dart/third_party/test/lib/src/runner/browser/chrome.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.chrome;
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 // TODO(nweiz): move this into its own package?
16 /// A class for running an instance of Chrome.
17 ///
18 /// Most of the communication with the browser is expected to happen via HTTP,
19 /// so this exposes a bare-bones API. The browser starts as soon as the class is
20 /// constructed, and is killed when [close] is called.
21 ///
22 /// Any errors starting or running the process are reported through [onExit].
23 class Chrome extends Browser {
24 final name = "Chrome";
25
26 /// Starts a new instance of Chrome open to the given [url], which may be a
27 /// [Uri] or a [String].
28 ///
29 /// If [executable] is passed, it's used as the Chrome executable. Otherwise
30 /// the default executable name for the current OS will be used.
31 Chrome(url, {String executable})
32 : super(() => _startBrowser(url, executable));
33
34 static Future<Process> _startBrowser(url, [String executable]) async {
35 if (executable == null) executable = _defaultExecutable();
36
37 var dir = createTempDir();
38 var process = await Process.start(executable, [
39 "--user-data-dir=$dir",
40 url.toString(),
41 "--disable-extensions",
42 "--disable-popup-blocking",
43 "--bwsi",
44 "--no-first-run",
45 "--no-default-browser-check",
46 "--disable-default-apps",
47 "--disable-translate"
48 ]);
49
50 process.exitCode
51 .then((_) => new Directory(dir).deleteSync(recursive: true));
52
53 return process;
54 }
55
56 /// Return the default executable for the current operating system.
57 static String _defaultExecutable() {
58 if (Platform.isMacOS) {
59 return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
60 }
61 if (!Platform.isWindows) return 'google-chrome';
62
63 // Chrome could be installed in several places on Windows. The only way to
64 // find it is to check.
65 var prefixes = [
66 Platform.environment['LOCALAPPDATA'],
67 Platform.environment['PROGRAMFILES'],
68 Platform.environment['PROGRAMFILES(X86)']
69 ];
70 var suffix = r'Google\Chrome\Application\chrome.exe';
71
72 for (var prefix in prefixes) {
73 if (prefix == null) continue;
74
75 var path = p.join(prefix, suffix);
76 if (new File(p.join(prefix, suffix)).existsSync()) return path;
77 }
78
79 // Fall back on looking it up on the path. This probably won't work, but at
80 // least it will fail with a useful error message.
81 return "chrome.exe";
82 }
83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698