Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / mini_installer / launch_chrome.py
blob9f8cd6e1de04c668d8dd106b112faf5eeb3690dd
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Launches Chrome.
7 This script launches Chrome and waits until its window shows up.
8 """
10 import optparse
11 import sys
12 import time
13 import win32process
15 import chrome_helper
18 def WaitForWindow(process_id, class_pattern):
19 """Waits until a window specified by |process_id| and class name shows up.
21 Args:
22 process_id: The ID of the process that owns the window.
23 class_pattern: The regular expression pattern of the window class name.
25 Returns:
26 A boolean value indicating whether the specified window shows up within
27 30 seconds.
28 """
29 start_time = time.time()
30 while time.time() - start_time < 30:
31 if chrome_helper.WindowExists([process_id], class_pattern):
32 return True
33 time.sleep(0.1)
34 return False
37 def main():
38 usage = 'usage: %prog chrome_path'
39 parser = optparse.OptionParser(usage, description='Launch Chrome.')
40 _, args = parser.parse_args()
41 if len(args) != 1:
42 parser.error('Incorrect number of arguments.')
43 chrome_path = args[0]
45 # Use CreateProcess rather than subprocess.Popen to avoid side effects such as
46 # handle interitance.
47 _, _, process_id, _ = win32process.CreateProcess(None, chrome_path, None,
48 None, 0, 0, None, None,
49 win32process.STARTUPINFO())
50 if not WaitForWindow(process_id, 'Chrome_WidgetWin_'):
51 raise Exception('Could not launch Chrome.')
52 return 0
55 if __name__ == '__main__':
56 sys.exit(main())