Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / native_client_sdk / src / tools / tests / chrome_mock.py
blob966e2310ad70444284b603d25baf3e565f153421
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Mock chrome process used by test code for http server."""
8 import argparse
9 import sys
10 import time
11 import urllib2
13 def PrintAndFlush(s):
14 sys.stdout.write(s + '\n')
15 sys.stdout.flush()
17 def main(args):
18 parser = argparse.ArgumentParser(description=__doc__)
19 parser.add_argument('--post', help='POST to URL.', dest='post',
20 action='store_true')
21 parser.add_argument('--get', help='GET to URL.', dest='get',
22 action='store_true')
23 parser.add_argument('--sleep',
24 help='Number of seconds to sleep after reading URL',
25 dest='sleep', default=0)
26 parser.add_argument('--expect-to-be-killed', help='If set, the script will'
27 ' warn if it isn\'t killed before it finishes sleeping.',
28 dest='expect_to_be_killed', action='store_true')
29 parser.add_argument('url')
31 options = parser.parse_args(args)
33 PrintAndFlush('Starting %s.' % sys.argv[0])
35 if options.post:
36 urllib2.urlopen(options.url, data='').read()
37 elif options.get:
38 urllib2.urlopen(options.url).read()
39 else:
40 # Do nothing but wait to be killed.
41 pass
43 time.sleep(float(options.sleep))
45 if options.expect_to_be_killed:
46 PrintAndFlush('Done sleeping. Expected to be killed.')
47 return 0
49 if __name__ == '__main__':
50 sys.exit(main(sys.argv[1:]))