Commit cb1b5855 authored by maruel@chromium.org's avatar maruel@chromium.org

Fix python scripts src/chrome_frame/tools/test/page_cycler/cf_cycler.py

Make sure that:
- shebang is only present for executable files
- __main__ is only present for executable files
- file's executable bit is coherent

Also fix EOF LF to be only one.

* Doing it separately since the CQ cannot process it.

TBR=robertshield@chromium.org
BUG=105108
TEST=

Review URL: http://codereview.chromium.org/8662025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111399 0039d316-1c4b-4281-b951-d872f2087c98
parent 92c2d905
# Copyright (c) 2009 The Chromium Authors. All rights reserved. #!/usr/bin/env python
# Use of this source code is governed by a BSD-style license that can be # Copyright (c) 2011 The Chromium Authors. All rights reserved.
# found in the LICENSE file. # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Automates IE to visit a list of web sites while running CF in full tab mode.
"""Automates IE to visit a list of web sites while running CF in full tab mode.
The page cycler automates IE and navigates it to a series of URLs. It is
designed to be run with Chrome Frame configured to load every URL inside The page cycler automates IE and navigates it to a series of URLs. It is
CF full tab mode. designed to be run with Chrome Frame configured to load every URL inside
CF full tab mode.
TODO(robertshield): Make use of the python unittest module as per
review comments. TODO(robertshield): Make use of the python unittest module as per
""" review comments.
"""
import optparse
import sys import optparse
import time import sys
import win32com.client import time
import win32gui import win32com.client
import win32gui
def LoadSiteList(path):
"""Loads a list of URLs from |path|. def LoadSiteList(path):
"""Loads a list of URLs from |path|.
Expects the URLs to be separated by newlines, with no leading or trailing
whitespace. Expects the URLs to be separated by newlines, with no leading or trailing
whitespace.
Args:
path: The path to a file containing a list of new-line separated URLs. Args:
path: The path to a file containing a list of new-line separated URLs.
Returns:
A list of strings, each one a URL. Returns:
""" A list of strings, each one a URL.
f = open(path) """
urls = f.readlines() f = open(path)
f.close() urls = f.readlines()
return urls f.close()
return urls
def LaunchIE():
"""Starts up IE, makes it visible and returns the automation object. def LaunchIE():
"""Starts up IE, makes it visible and returns the automation object.
Returns:
The IE automation object. Returns:
""" The IE automation object.
ie = win32com.client.Dispatch("InternetExplorer.Application") """
ie.visible = 1 ie = win32com.client.Dispatch("InternetExplorer.Application")
win32gui.SetForegroundWindow(ie.HWND) ie.visible = 1
return ie win32gui.SetForegroundWindow(ie.HWND)
return ie
def RunTest(url, ie):
"""Loads |url| into the InternetExplorer.Application instance in |ie|. def RunTest(url, ie):
"""Loads |url| into the InternetExplorer.Application instance in |ie|.
Waits for the Document object to be created and then waits for
the document ready state to reach READYSTATE_COMPLETE. Waits for the Document object to be created and then waits for
Args: the document ready state to reach READYSTATE_COMPLETE.
url: A string containing the url to navigate to. Args:
ie: The IE automation object to navigate. url: A string containing the url to navigate to.
""" ie: The IE automation object to navigate.
"""
print "Navigating to " + url
ie.Navigate(url) print "Navigating to " + url
timer = 0 ie.Navigate(url)
timer = 0
READYSTATE_COMPLETE = 4
READYSTATE_COMPLETE = 4
last_ready_state = -1
for retry in xrange(60): last_ready_state = -1
try: for retry in xrange(60):
# TODO(robertshield): Become an event sink instead of polling for try:
# changes to the ready state. # TODO(robertshield): Become an event sink instead of polling for
last_ready_state = ie.Document.ReadyState # changes to the ready state.
if last_ready_state == READYSTATE_COMPLETE: last_ready_state = ie.Document.ReadyState
break if last_ready_state == READYSTATE_COMPLETE:
except: break
# TODO(robertshield): Find the precise exception related to ie.Document except:
# being not accessible and handle it here. # TODO(robertshield): Find the precise exception related to ie.Document
print "Unexpected error:", sys.exc_info()[0] # being not accessible and handle it here.
raise print "Unexpected error:", sys.exc_info()[0]
time.sleep(1) raise
time.sleep(1)
if last_ready_state != READYSTATE_COMPLETE:
print "Timeout waiting for " + url if last_ready_state != READYSTATE_COMPLETE:
print "Timeout waiting for " + url
def main():
parser = optparse.OptionParser() def main():
parser.add_option('-u', '--url_list', default='urllist', parser = optparse.OptionParser()
help='The path to the list of URLs') parser.add_option('-u', '--url_list', default='urllist',
(opts, args) = parser.parse_args() help='The path to the list of URLs')
(opts, args) = parser.parse_args()
urls = LoadSiteList(opts.url_list)
ie = LaunchIE() urls = LoadSiteList(opts.url_list)
for url in urls: ie = LaunchIE()
RunTest(url, ie) for url in urls:
time.sleep(1) RunTest(url, ie)
ie.visible = 0 time.sleep(1)
ie.Quit() ie.visible = 0
ie.Quit()
if __name__ == '__main__':
main() if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment