Index: chrome/test/functional/perf_endure.py |
diff --git a/chrome/test/functional/perf_endure.py b/chrome/test/functional/perf_endure.py |
index 134c9dfdd13c3b82b20b82cdbd9a1453acb11c41..b62ddbb42d97080f469fa25d6022d95511e03f29 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 |
slamm_google
2012/07/25 17:20:48
This is unused in this module.
fdeng1
2012/07/25 22:53:28
Done.
|
class NotSupportedEnvironmentError(RuntimeError): |
@@ -62,6 +63,10 @@ class ChromeEndureBaseTest(perf.BasePerfTest): |
_CHROME_BIN_PATH = os.path.join(perf.BasePerfTest.BrowserPath(), 'chrome') |
def setUp(self): |
+ # The environment variable for the usage of Web Page Replay. |
+ # It must be parsed before perf.BasePerfTest.setUp() |
+ self._not_use_wpr = 'DO_NOT_USE_WPR_FOR_ENDURE' in os.environ |
dennis_jeffrey
2012/07/24 21:03:19
I think it might be easier to reason about this if
slamm_google
2012/07/25 17:20:48
How about a shorter environment variable name too.
fdeng1
2012/07/25 22:53:28
Done.
fdeng1
2012/07/25 22:53:28
Done.
|
+ |
# The environment variables for the Deep Memory Profiler must be set |
# before perf.BasePerfTest.setUp() to inherit them to Chrome. |
self._deep_memory_profile = self._GetDeepMemoryProfileEnv( |
@@ -180,6 +185,11 @@ class ChromeEndureBaseTest(perf.BasePerfTest): |
extra_flags = ['--remote-debugging-port=9222'] |
if deep_memory_profile: |
extra_flags.append('--no-sandbox') |
+ |
+ # Add flags for the Web Page Replay server if necessary. |
+ if not self._not_use_wpr: |
+ extra_flags.extend(ChromeEndureWebPageReplay().chrome_flags) |
+ |
return (perf.BasePerfTest.ExtraChromeFlags(self) + extra_flags) |
def _OnTimelineEvent(self, event_info): |
@@ -540,6 +550,36 @@ class ChromeEndureBaseTest(perf.BasePerfTest): |
return True |
+ def _StartReplayServerIfNecessary(self, test_name): |
+ """Start the Web Page Replay server if DO_NOT_USE_WPR_FOR_ENDURE is not set. |
+ |
+ This method needs to be called BEFORE any connection (which are supposed |
+ to go through the Web Page Replay server) occurs. |
+ |
+ Args: |
+ test_name: name of the test. |
+ """ |
+ if not self._not_use_wpr: |
+ mode = 'Record' if '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.') |
+ |
+ def _StopReplayServerIfNecessary(self): |
+ """Stop the Web Page Replay server if DO_NOT_USE_WPR_FOR_ENDURE is not set. |
+ |
+ This method has to be called AFTER all network connections which go |
+ through Web Page Replay server have shut down. Otherwise the |
+ Web Page Replay server will hang to wait for them. A good |
+ place is to call it at the end of the teardown process. |
+ """ |
+ if not self._not_use_wpr: |
+ logging.info('Stopping The Web Page Replay server.') |
+ self.wpr_server.StopServer() |
+ logging.info('The Web Page Replay server stopped.') |
+ |
class ChromeEndureControlTest(ChromeEndureBaseTest): |
"""Control tests for Chrome Endure.""" |
@@ -597,8 +637,11 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
_TAB_TITLE_SUBSTRING = 'Gmail' |
_FRAME_XPATH = 'id("canvas_frame")' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _GmailSetUp(self, test_name): |
+ """Set up before each test runs.""" |
+ |
+ # Start the Web Page Replay server. |
+ self._StartReplayServerIfNecessary(test_name) |
# Log into a test Google account and open up Gmail. |
self._LoginToGoogleAccount(account_key='test_google_account_gmail') |
@@ -623,6 +666,11 @@ 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 after all connections to WPR closed. |
+ self._StopReplayServerIfNecessary() |
+ |
def _SwitchToCanvasFrame(self, driver): |
"""Switch the WebDriver to Gmail's 'canvas_frame', if it's available. |
@@ -702,6 +750,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. |
@@ -753,6 +802,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. |
@@ -808,6 +858,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 |
@@ -851,6 +902,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, |
@@ -893,6 +945,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
bloat. |
""" |
test_description = 'ExpandCollapse' |
+ self._GmailSetUp(test_description) |
# Enter conversation view for a particular thread. |
thread_xpath = '//span[@email]' |
@@ -943,8 +996,11 @@ class ChromeEndureDocsTest(ChromeEndureBaseTest): |
_WEBAPP_NAME = 'Docs' |
_TAB_TITLE_SUBSTRING = 'Google Drive' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _DocsSetUp(self, test_name): |
+ """Set up before each test runs.""" |
+ |
+ # Start the Web Page Replay server. |
+ self._StartReplayServerIfNecessary(test_name) |
# Log into a test Google account and open up Google Docs. |
self._LoginToGoogleAccount() |
@@ -958,6 +1014,11 @@ class ChromeEndureDocsTest(ChromeEndureBaseTest): |
self._driver = self.NewWebDriver() |
+ def tearDown(self): |
+ super(ChromeEndureDocsTest, self).tearDown() |
+ # Stop the Web Page Replay server after all connections to it closed. |
+ self._StopReplayServerIfNecessary() |
+ |
def testDocsAlternatelyClickLists(self): |
"""Alternates between two different document lists. |
@@ -966,6 +1027,7 @@ class ChromeEndureDocsTest(ChromeEndureBaseTest): |
memory bloat. |
""" |
test_description = 'AlternateLists' |
+ self._DocsSetUp(test_description) |
def scenario(): |
# Click the "Shared with me" button, wait for 1 second, click the |
@@ -1004,8 +1066,11 @@ class ChromeEndurePlusTest(ChromeEndureBaseTest): |
_WEBAPP_NAME = 'Plus' |
_TAB_TITLE_SUBSTRING = 'Google+' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _PlusSetUp(self, test_name): |
+ """Set up before each test runs.""" |
+ |
+ # Start the Web Page Replay server. |
+ self._StartReplayServerIfNecessary(test_name) |
# Log into a test Google account and open up Google Plus. |
self._LoginToGoogleAccount() |
@@ -1017,6 +1082,11 @@ class ChromeEndurePlusTest(ChromeEndureBaseTest): |
self._driver = self.NewWebDriver() |
+ def tearDown(self): |
+ super(ChromeEndurePlusTest, self).tearDown() |
+ # Stop the Web Page Replay server after all connections to it closed. |
+ self._StopReplayServerIfNecessary() |
+ |
def testPlusAlternatelyClickStreams(self): |
"""Alternates between two different streams. |
@@ -1025,6 +1095,7 @@ class ChromeEndurePlusTest(ChromeEndureBaseTest): |
memory bloat. |
""" |
test_description = 'AlternateStreams' |
+ self._PlusSetUp(test_description) |
# TODO(dennisjeffrey): Remove following line once crosbug.com/32357 is |
# fixed. |
@@ -1124,5 +1195,30 @@ class IndexedDBOfflineTest(ChromeEndureBaseTest): |
test_description, scenario) |
+class ChromeEndureWebPageReplay(perf.BaseWebPageReplay): |
+ """Set up Web Page Replay server for Endure tests. |
+ |
+ This class inherits from perf.BaseWebPageReplay to allow different settings |
+ for the Web Page Replay server. |
+ """ |
+ |
+ def __init__(self): |
+ super(ChromeEndureWebPageReplay, self).__init__() |
+ |
+ # Extra paths for Web Page Replay. |
+ extra_paths = { |
+ 'archive': |
+ 'src/chrome/test/data/chrome_endure/webpagereplay/{test_name}.wpr', |
+ 'scripts': 'src/chrome/test/data/chrome_endure/wpr_deterministic.js', |
+ } |
+ self._paths.update(extra_paths) |
+ |
+ # Add customized injected_scripts for Endure tests. |
+ assert os.path.exists(self.Path('scripts')), ( |
+ 'The scripts to be injected do not exist: %s' % |
+ self.Path('scripts')) |
+ self._replay_flags.append('--inject_scripts=%s' % self.Path('scripts')) |
+ |
+ |
if __name__ == '__main__': |
pyauto_functional.Main() |