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.
7 This script launches Chrome and waits until its window shows up.
18 def WaitForWindow(process_id
, class_pattern
):
19 """Waits until a window specified by |process_id| and class name shows up.
22 process_id: The ID of the process that owns the window.
23 class_pattern: The regular expression pattern of the window class name.
26 A boolean value indicating whether the specified window shows up within
29 start_time
= time
.time()
30 while time
.time() - start_time
< 30:
31 if chrome_helper
.WindowExists([process_id
], class_pattern
):
38 usage
= 'usage: %prog chrome_path'
39 parser
= optparse
.OptionParser(usage
, description
='Launch Chrome.')
40 _
, args
= parser
.parse_args()
42 parser
.error('Incorrect number of arguments.')
45 # Use CreateProcess rather than subprocess.Popen to avoid side effects such as
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.')
55 if __name__
== '__main__':