| OLD | NEW |
| 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 4 | 5 |
| 5 """Automates IE to visit a list of web sites while running CF in full tab mode. | 6 """Automates IE to visit a list of web sites while running CF in full tab mode. |
| 6 | 7 |
| 7 The page cycler automates IE and navigates it to a series of URLs. It is | 8 The page cycler automates IE and navigates it to a series of URLs. It is |
| 8 designed to be run with Chrome Frame configured to load every URL inside | 9 designed to be run with Chrome Frame configured to load every URL inside |
| 9 CF full tab mode. | 10 CF full tab mode. |
| 10 | 11 |
| 11 TODO(robertshield): Make use of the python unittest module as per | 12 TODO(robertshield): Make use of the python unittest module as per |
| 12 review comments. | 13 review comments. |
| 13 """ | 14 """ |
| 14 | 15 |
| 15 import optparse | 16 import optparse |
| 16 import sys | 17 import sys |
| 17 import time | 18 import time |
| 18 import win32com.client | 19 import win32com.client |
| 19 import win32gui | 20 import win32gui |
| 20 | 21 |
| 21 def LoadSiteList(path): | 22 def LoadSiteList(path): |
| 22 """Loads a list of URLs from |path|. | 23 """Loads a list of URLs from |path|. |
| 23 | 24 |
| 24 Expects the URLs to be separated by newlines, with no leading or trailing | 25 Expects the URLs to be separated by newlines, with no leading or trailing |
| 25 whitespace. | 26 whitespace. |
| 26 | 27 |
| 27 Args: | 28 Args: |
| 28 path: The path to a file containing a list of new-line separated URLs. | 29 path: The path to a file containing a list of new-line separated URLs. |
| 29 | 30 |
| 30 Returns: | 31 Returns: |
| 31 A list of strings, each one a URL. | 32 A list of strings, each one a URL. |
| 32 """ | 33 """ |
| 33 f = open(path) | 34 f = open(path) |
| 34 urls = f.readlines() | 35 urls = f.readlines() |
| 35 f.close() | 36 f.close() |
| 36 return urls | 37 return urls |
| 37 | 38 |
| 38 def LaunchIE(): | 39 def LaunchIE(): |
| 39 """Starts up IE, makes it visible and returns the automation object. | 40 """Starts up IE, makes it visible and returns the automation object. |
| 40 | 41 |
| 41 Returns: | 42 Returns: |
| 42 The IE automation object. | 43 The IE automation object. |
| 43 """ | 44 """ |
| 44 ie = win32com.client.Dispatch("InternetExplorer.Application") | 45 ie = win32com.client.Dispatch("InternetExplorer.Application") |
| 45 ie.visible = 1 | 46 ie.visible = 1 |
| 46 win32gui.SetForegroundWindow(ie.HWND) | 47 win32gui.SetForegroundWindow(ie.HWND) |
| 47 return ie | 48 return ie |
| 48 | 49 |
| 49 def RunTest(url, ie): | 50 def RunTest(url, ie): |
| 50 """Loads |url| into the InternetExplorer.Application instance in |ie|. | 51 """Loads |url| into the InternetExplorer.Application instance in |ie|. |
| 51 | 52 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 77 raise | 78 raise |
| 78 time.sleep(1) | 79 time.sleep(1) |
| 79 | 80 |
| 80 if last_ready_state != READYSTATE_COMPLETE: | 81 if last_ready_state != READYSTATE_COMPLETE: |
| 81 print "Timeout waiting for " + url | 82 print "Timeout waiting for " + url |
| 82 | 83 |
| 83 def main(): | 84 def main(): |
| 84 parser = optparse.OptionParser() | 85 parser = optparse.OptionParser() |
| 85 parser.add_option('-u', '--url_list', default='urllist', | 86 parser.add_option('-u', '--url_list', default='urllist', |
| 86 help='The path to the list of URLs') | 87 help='The path to the list of URLs') |
| 87 (opts, args) = parser.parse_args() | 88 (opts, args) = parser.parse_args() |
| 88 | 89 |
| 89 urls = LoadSiteList(opts.url_list) | 90 urls = LoadSiteList(opts.url_list) |
| 90 ie = LaunchIE() | 91 ie = LaunchIE() |
| 91 for url in urls: | 92 for url in urls: |
| 92 RunTest(url, ie) | 93 RunTest(url, ie) |
| 93 time.sleep(1) | 94 time.sleep(1) |
| 94 ie.visible = 0 | 95 ie.visible = 0 |
| 95 ie.Quit() | 96 ie.Quit() |
| 96 | 97 |
| 97 | 98 |
| 98 if __name__ == '__main__': | 99 if __name__ == '__main__': |
| 99 main() | 100 main() |
| OLD | NEW |