- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / tools / tests / chrome_mock.py
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.
5
6 import optparse
7 import sys
8 import time
9 import urllib2
10
11 def PrintAndFlush(s):
12   print s
13   sys.stdout.flush()
14
15 def main(args):
16   parser = optparse.OptionParser(usage='%prog [options] <URL to load>')
17   parser.add_option('--post', help='POST to URL.', dest='post',
18                     action='store_true')
19   parser.add_option('--get', help='GET to URL.', dest='get',
20                     action='store_true')
21   parser.add_option('--sleep',
22                     help='Number of seconds to sleep after reading URL',
23                     dest='sleep', default=0)
24   parser.add_option('--expect-to-be-killed', help='If set, the script will warn'
25                     ' if it isn\'t killed before it finishes sleeping.',
26                     dest='expect_to_be_killed', action='store_true')
27   options, args = parser.parse_args(args)
28   if len(args) != 1:
29     parser.error('Expected URL to load.')
30
31   PrintAndFlush('Starting %s.' % sys.argv[0])
32
33   if options.post:
34     urllib2.urlopen(args[0], data='').read()
35   elif options.get:
36     urllib2.urlopen(args[0]).read()
37   else:
38     # Do nothing but wait to be killed.
39     pass
40
41   time.sleep(float(options.sleep))
42
43   if options.expect_to_be_killed:
44     PrintAndFlush('Done sleeping. Expected to be killed.')
45   sys.exit(0)
46
47 if __name__ == '__main__':
48   sys.exit(main(sys.argv[1:]))