Index: chrome/test/functional/perf_endure.py |
diff --git a/chrome/test/functional/perf_endure.py b/chrome/test/functional/perf_endure.py |
index 0b13151a4c125d8f3a2d215d6b918922c3894533..64aae64a5a5f30f802eac70264ce3485985353b7 100755 |
--- a/chrome/test/functional/perf_endure.py |
+++ b/chrome/test/functional/perf_endure.py |
@@ -33,6 +33,7 @@ import pyauto_utils |
import remote_inspector_client |
import selenium.common.exceptions |
from selenium.webdriver.support.ui import WebDriverWait |
+import webpagereplay |
class NotSupportedEnvironmentError(RuntimeError): |
@@ -579,9 +580,22 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
_TAB_TITLE_SUBSTRING = 'Gmail' |
_FRAME_XPATH = 'id("canvas_frame")' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
- |
+ def ExtraChromeFlags(self): |
Nirnimesh
2012/07/18 19:41:18
I wish you add this functionality to ChromeEndureB
fdeng1
2012/07/24 00:05:50
Done.
I also moved the code that starts/shuts do
|
+ flags = super(ChromeEndureGmailTest, self).ExtraChromeFlags() |
+ # Add flags for the Web Page Replay server. |
+ if 'USE_WPR_FOR_ENDURE' in os.environ: |
+ return flags + ChromeEndureWebPageReplay.CHROME_FLAGS |
+ return flags |
+ |
+ def _GmailSetUp(self, test_name): |
+ # Start the Web Page Replay server. |
+ if 'USE_WPR_FOR_ENDURE' in os.environ: |
+ mode = 'Record' if 'ENDURE_WPR_RECORD' in os.environ else 'Replay' |
+ logging.info('Starting the Web Page Replay server: in %s mode', mode) |
+ |
+ self.wpr_server = ChromeEndureWebPageReplay().GetReplayServer(test_name) |
+ self.wpr_server.StartServer() |
+ logging.info('The Web Page Replay server started.') |
# Log into a test Google account and open up Gmail. |
self._LoginToGoogleAccount(account_key='test_google_account_gmail') |
self.NavigateToURL('http://www.gmail.com') |
@@ -605,6 +619,16 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
self.WaitForDomNode('//a[starts-with(@title, "Inbox")]', |
frame_xpath=self._FRAME_XPATH) |
+ def tearDown(self): |
+ super(ChromeEndureGmailTest, self).tearDown() |
+ # Stop the Web Page Replay server. This has to be done AFTER |
+ # the parent's tearDown has run. Otherwise the Web Page Replay server |
+ # will hang to wait for all connection to close. |
+ if 'USE_WPR_FOR_ENDURE' in os.environ: |
+ logging.info('Stopping The Web Page Replay server.') |
+ self.wpr_server.StopServer() |
+ logging.info('The Web Page Replay server stopped.') |
+ |
def _SwitchToCanvasFrame(self, driver): |
"""Switch the WebDriver to Gmail's 'canvas_frame', if it's available. |
@@ -684,6 +708,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
periodically gathers performance stats that may reveal memory bloat. |
""" |
test_description = 'ComposeDiscard' |
+ self._GmailSetUp(test_description) |
# TODO(dennisjeffrey): Remove following line once crosbug.com/32357 is |
# fixed. |
@@ -734,6 +759,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
results from testGmailComposeDiscard above. |
""" |
test_description = 'ComposeDiscardSleep' |
+ self._GmailSetUp(test_description) |
# TODO(dennisjeffrey): Remove following line once crosbug.com/32357 is |
# fixed. |
@@ -788,6 +814,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
performance stats that may reveal memory bloat. |
""" |
test_description = 'ThreadConversation' |
+ self._GmailSetUp(test_description) |
def scenario(): |
# Click an e-mail to see the conversation view, wait 1 second, click the |
@@ -830,6 +857,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
and periodically gathers performance stats that may reveal memory bloat. |
""" |
test_description = 'AlternateLabels' |
+ self._GmailSetUp(test_description) |
def scenario(): |
# Click the "Sent Mail" label, wait for 1 second, click the "Inbox" label, |
@@ -871,6 +899,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
bloat. |
""" |
test_description = 'ExpandCollapse' |
+ self._GmailSetUp(test_description) |
# Enter conversation view for a particular thread. |
thread_xpath = '//span[@email]' |
@@ -1101,5 +1130,77 @@ class IndexedDBOfflineTest(ChromeEndureBaseTest): |
test_description, scenario) |
+class ChromeEndureWebPageReplay(perf.WebPageReplay): |
+ """Set up Web Page Replay server. |
+ |
+ This class inherits from perf.WebPageReplay to allow different settings |
+ for the Web Page Replay server. |
+ |
+ Environment Variables: |
+ ENDURE_WPR_RECORD: If set, puts Web Page Replay in record mode |
+ instead of replay. |
+ ENDURE_WPR_REPLAY_DIR: Path to alternate Web Page Replay source |
+ (for development). |
+ ENDUER_ WPR_ARCHIVE_PATH: Path to alternate archive file. |
+ E.g. '/tmp/foo.wpr'. |
+ """ |
+ _PATHS = { |
+ 'archive': 'src/data/endure/webpagereplay/{test_name}.wpr', |
+ 'replay': 'src/third_party/webpagereplay', |
+ 'logs': 'src/chrome_endure_webpagereplay_logs', |
+ 'scripts': 'src/chrome/test/data/chrome_endure/deterministic.js' |
+ } |
+ |
+ CHROME_FLAGS = [ |
+ '--host-resolver-rules=MAP * %s' % webpagereplay.REPLAY_HOST, |
Nirnimesh
2012/07/18 19:41:18
If it works with it, I think you should retain the
fdeng1
2012/07/24 00:05:50
I restructured perf.WebPageReplay. Now we have per
|
+ '--testing-fixed-http-port=%s' % webpagereplay.HTTP_PORT, |
+ '--testing-fixed-https-port=%s' % webpagereplay.HTTPS_PORT, |
+ '--log-level=0', |
Nirnimesh
2012/07/18 19:41:18
remove this and other flags that are not necessary
fdeng1
2012/07/24 00:05:50
Done.
Please take a look at __init__ in perf.BaseW
|
+ '--disable-background-networking', |
+ '--enable-logging', |
+ '--ignore-certificate-errors', |
+ '--no-first-run', |
+ '--no-proxy-server', |
+ ] |
+ |
+ def __init__(self): |
+ self.archive_path = os.environ.get('ENDURE_WPR_ARCHIVE_PATH') |
+ self.replay_dir = os.environ.get('ENDURE_WPR_REPLAY_DIR', |
+ self.Path('replay')) |
+ self.is_record_mode = 'ENDURE_WPR_RECORD' in os.environ |
+ if self.is_record_mode: |
+ self._num_iterations = 1 |
+ |
+ def GetReplayServer(self, test_name): |
+ """Create the Web Page Replay server. |
+ |
+ This function overrides the one in perf.WebpageReplay to pass a customized |
+ deterministic.js to Web Page Replay server. This one differs from the |
+ default one as it uses a different value for time_seed. See the file |
+ (src/chrome/test/data/chrome_endure/deterministic.js) for |
+ how time_seed works. |
+ |
+ Args: |
+ test_name: the test name, should be identical for each test. |
+ Returns: |
+ An instance of webpagereplay.ReplayServer. |
+ """ |
+ |
+ replay_options = [] |
+ replay_options.append('--no-dns_forwarding') |
+ if self.is_record_mode: |
+ replay_options.append('--record') |
+ |
+ assert os.path.exists(self.Path('scripts')), \ |
+ 'The scripts to be injected do not exist: %s' % self.Path('scripts') |
+ replay_options.append('--inject_scripts=%s' % self.Path('scripts')) |
+ |
+ return webpagereplay.ReplayServer( |
+ self.replay_dir, |
+ self._ArchivePath(test_name), |
+ self.Path('logs'), |
+ replay_options) |
+ |
+ |
if __name__ == '__main__': |
pyauto_functional.Main() |