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..531ef5abea794ad9c6e5a98b727eb8e639f0242b 100755 |
--- a/chrome/test/functional/perf_endure.py |
+++ b/chrome/test/functional/perf_endure.py |
@@ -33,12 +33,14 @@ import pyauto_utils |
import remote_inspector_client |
import selenium.common.exceptions |
from selenium.webdriver.support.ui import WebDriverWait |
+import webpagereplay |
class NotSupportedEnvironmentError(RuntimeError): |
"""Represent an error raised since the environment (OS) is not supported.""" |
pass |
+ |
class ChromeEndureBaseTest(perf.BasePerfTest): |
"""Implements common functionality for all Chrome Endure tests. |
@@ -62,6 +64,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._use_wpr = 'ENDURE_NO_WPR' not in os.environ |
+ |
# 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,7 +186,9 @@ class ChromeEndureBaseTest(perf.BasePerfTest): |
extra_flags = ['--remote-debugging-port=9222'] |
if deep_memory_profile: |
extra_flags.append('--no-sandbox') |
- return (perf.BasePerfTest.ExtraChromeFlags(self) + extra_flags) |
+ if self._use_wpr: |
+ extra_flags.extend(ChromeEndureReplay.CHROME_FLAGS) |
+ return perf.BasePerfTest.ExtraChromeFlags(self) + extra_flags |
def _OnTimelineEvent(self, event_info): |
"""Invoked by the Remote Inspector Client when a timeline event occurs. |
@@ -540,6 +548,36 @@ class ChromeEndureBaseTest(perf.BasePerfTest): |
return True |
+ def _StartReplayServerIfNecessary(self, archive_name): |
+ """Start the Web Page Replay server if ENDURE_NO_WPR 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: |
+ archive_name: a string representing the name of the web page replay |
+ archive. |
+ """ |
+ if self._use_wpr: |
+ self._wpr_server = ChromeEndureReplay.ReplayServer(archive_name) |
+ mode = 'Record' if self._wpr_server.is_record_mode else 'Replay' |
+ logging.info('Starting the Web Page Replay server: in %s mode', mode) |
+ self._wpr_server.StartServer() |
+ logging.info('The Web Page Replay server started.') |
Nirnimesh
2012/08/01 01:03:00
Too much logging. Please pick between this line an
fdeng1
2012/08/01 17:14:57
Done.
|
+ |
+ def _StopReplayServerIfNecessary(self): |
+ """Stop the Web Page Replay server if ENDURE_NO_WPR 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 self._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 +635,9 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
_TAB_TITLE_SUBSTRING = 'Gmail' |
_FRAME_XPATH = 'id("canvas_frame")' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _GmailSetUp(self, archive_name): |
+ """Set up before each test runs.""" |
+ self._StartReplayServerIfNecessary(archive_name) |
Nirnimesh
2012/08/01 01:03:00
I thought this was going to be done in ChromeEndur
fdeng1
2012/08/01 17:14:57
When starting a replay server, an "archive_name" n
dennis_jeffrey
2012/08/01 18:35:54
self.id(), as discussed offline
fdeng1
2012/08/01 18:37:31
I just talked to Dennis and we came up a plan to c
|
# Log into a test Google account and open up Gmail. |
self._LoginToGoogleAccount(account_key='test_google_account_gmail') |
@@ -623,6 +662,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 +746,7 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
periodically gathers performance stats that may reveal memory bloat. |
""" |
test_description = 'ComposeDiscard' |
+ self._GmailSetUp(test_description) |
Nirnimesh
2012/08/01 01:03:00
Why not do this it setUp instead of calling before
fdeng1
2012/08/01 17:14:57
Please see the above comment.
On 2012/08/01 01:03
|
# TODO(dennisjeffrey): Remove following line once crosbug.com/32357 is |
# fixed. |
@@ -753,6 +798,8 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest): |
results from testGmailComposeDiscard above. |
""" |
test_description = 'ComposeDiscardSleep' |
+ # Use the same archive_name as testGmailComposeDiscard uses. |
+ self._GmailSetUp('ComposeDiscard') |
# TODO(dennisjeffrey): Remove following line once crosbug.com/32357 is |
# fixed. |
@@ -808,6 +855,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 +899,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 +942,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 +993,9 @@ class ChromeEndureDocsTest(ChromeEndureBaseTest): |
_WEBAPP_NAME = 'Docs' |
_TAB_TITLE_SUBSTRING = 'Google Drive' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _DocsSetUp(self, archive_name): |
+ """Set up before each test runs.""" |
+ self._StartReplayServerIfNecessary(archive_name) |
# Log into a test Google account and open up Google Docs. |
self._LoginToGoogleAccount() |
@@ -958,6 +1009,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 +1022,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 +1061,9 @@ class ChromeEndurePlusTest(ChromeEndureBaseTest): |
_WEBAPP_NAME = 'Plus' |
_TAB_TITLE_SUBSTRING = 'Google+' |
- def setUp(self): |
- ChromeEndureBaseTest.setUp(self) |
+ def _PlusSetUp(self, archive_name): |
+ """Set up before each test runs.""" |
+ self._StartReplayServerIfNecessary(archive_name) |
# Log into a test Google account and open up Google Plus. |
self._LoginToGoogleAccount() |
@@ -1017,6 +1075,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 +1088,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 +1188,33 @@ class IndexedDBOfflineTest(ChromeEndureBaseTest): |
test_description, scenario) |
+class ChromeEndureReplay(object): |
+ """Run Chrome Endure tests with network simulation via Web Page Replay.""" |
+ |
+ _PATHS = { |
+ 'archive': |
+ 'src/chrome/test/data/pyauto_private/webpagereplay/{archive_name}.wpr', |
+ 'scripts': |
+ 'src/chrome/test/data/chrome_endure/webpagereplay/wpr_deterministic.js', |
+ } |
+ CHROME_FLAGS = webpagereplay.CHROME_FLAGS |
+ |
+ @classmethod |
+ def Path(cls, key, **kwargs): |
+ return perf.FormatChromePath(cls._PATHS[key], **kwargs) |
+ |
+ @classmethod |
+ def ReplayServer(cls, archive_name): |
+ """Creat a replay server.""" |
+ # Inject customized scripts for Google webapps. |
+ # See the java script file for details. |
+ scripts = cls.Path('scripts') |
+ if not os.path.exists(scripts): |
+ raise webpagereplay.ReplayNotFoundError('injected scripts', scripts) |
+ replay_options = ['--inject_scripts', scripts] |
+ archive_path = cls.Path('archive', archive_name=archive_name) |
+ return webpagereplay.ReplayServer(archive_path, replay_options) |
+ |
+ |
if __name__ == '__main__': |
pyauto_functional.Main() |