Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3996)

Unified Diff: chrome/test/functional/perf_endure.py

Issue 10803002: Run Chrome Endure tests with network simulation via Web Page Replay. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests by default do not have WPR support. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..252efcf5b6d1319de089e7bcc983c709669dd8f0 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,14 @@ 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 = self._NeedReplayServer()
dennis_jeffrey 2012/08/03 19:39:54 As discussed offline, let's follow this behavior:
fdeng1 2012/08/06 20:58:24 Done.
+ # Do NOT mannually set WPR_RECORD for the purpose of
dennis_jeffrey 2012/08/03 19:39:54 mannually --> manually
fdeng1 2012/08/06 20:58:24 Done.
+ # making recording archive for endure tests. Run record_endure.py instead.
+ if self._use_wpr:
+ self._is_replay_mode = 'WPR_RECORD' 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(
@@ -117,6 +127,7 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
self._deep_memory_profile_json_file = None
self._deep_memory_profile_last_json_filename = ''
self._deep_memory_profile_proc = None
+ self._StartReplayServerIfNecessary()
def tearDown(self):
logging.info('Terminating connection to remote inspector...')
@@ -139,6 +150,30 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
not self._deep_memory_profile_save and
self._deep_tempdir):
pyauto_utils.RemovePath(self._deep_tempdir)
+ # Must be done after perf.BasePerfTest.tearDown()
+ self._StopReplayServerIfNecessary()
+
+ def _NeedReplayServer(self):
+ """Check whether the test needs to run against Web Page Replay server.
+
+ Override this function to turn on Web Page Replay for a test.
+
+ Returns:
+ True if need replay server otherwise False.
+ """
+ return False
fdeng1 2012/08/03 16:47:06 Change this function so that by default, tests wil
dennis_jeffrey 2012/08/03 19:39:54 Let's get rid of this function completely. If a t
fdeng1 2012/08/06 20:58:24 Done.
+
+ def _GenArchiveName(self):
+ """Returns the Web Page Replay archive name that corresponds to a test.
+
+ Use test class name as archive name, e.g. ChromeEndureGmailTest.wpr
+ Override this function to allow other names.
+
dennis_jeffrey 2012/08/03 19:39:54 make a note that this assumes that we only have 1
fdeng1 2012/08/06 20:58:24 Added a note to doc string On 2012/08/03 19:39:54,
+ Returns:
+ An archive name generated using test class name.
+ """
+ # Use class name as archive name.
+ return self.id().split('.')[1] + '.wpr'
def _GetDeepMemoryProfileEnv(self, env_name, converter, default):
"""Returns a converted environment variable for the Deep Memory Profiler.
@@ -180,7 +215,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 +577,30 @@ class ChromeEndureBaseTest(perf.BasePerfTest):
return True
+ def _StartReplayServerIfNecessary(self):
+ """Start replay server if necessary.
+
+ This method needs to be called BEFORE any connection (which is supposed
+ to go through the Web Page Replay server) occurs.
+ """
+ if self._use_wpr and self._is_replay_mode:
+ archive_name = self._GenArchiveName()
+ self._wpr_server = ChromeEndureReplay.ReplayServer(archive_name)
+ self._wpr_server.StartServer()
+ logging.info('Web Page Replay server has started in Replay mode.')
+
+ def _StopReplayServerIfNecessary(self):
+ """Stop the Web Page Replay server if necessary.
+
+ 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 and self._is_replay_mode:
+ self._wpr_server.StopServer()
+ logging.info('The Web Page Replay server stopped.')
+
class ChromeEndureControlTest(ChromeEndureBaseTest):
"""Control tests for Chrome Endure."""
@@ -623,6 +684,20 @@ class ChromeEndureGmailTest(ChromeEndureBaseTest):
self.WaitForDomNode('//a[starts-with(@title, "Inbox")]',
frame_xpath=self._FRAME_XPATH)
+ def _NeedReplayServer(self):
+ """Check whether the test needs to run against Web Page Replay server.
+
+ Returns:
+ True if need replay server otherwise False.
+
+ Environment variable:
+ ENDURE_NO_WPR: if set, do not need replay server
+ """
+ if 'ENDURE_NO_WPR' in os.environ:
+ return False
+ else:
+ return True
+
def _SwitchToCanvasFrame(self, driver):
"""Switch the WebDriver to Gmail's 'canvas_frame', if it's available.
@@ -958,6 +1033,20 @@ class ChromeEndureDocsTest(ChromeEndureBaseTest):
self._driver = self.NewWebDriver()
+ def _NeedReplayServer(self):
+ """Check whether the test needs to run against Web Page Replay server.
+
+ Returns:
+ True if need replay server otherwise False.
+
+ Environment variable:
+ ENDURE_NO_WPR: if set, do not need replay server
+ """
+ if 'ENDURE_NO_WPR' in os.environ:
+ return False
+ else:
+ return True
+
def testDocsAlternatelyClickLists(self):
"""Alternates between two different document lists.
@@ -1017,6 +1106,20 @@ class ChromeEndurePlusTest(ChromeEndureBaseTest):
self._driver = self.NewWebDriver()
+ def _NeedReplayServer(self):
+ """Check whether the test needs to run against Web Page Replay server.
+
+ Returns:
+ True if need replay server otherwise False.
+
+ Environment variable:
+ ENDURE_NO_WPR: if set, do not need replay server
+ """
+ if 'ENDURE_NO_WPR' in os.environ:
+ return False
+ else:
+ return True
+
def testPlusAlternatelyClickStreams(self):
"""Alternates between two different streams.
@@ -1124,5 +1227,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}',
+ '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()

Powered by Google App Engine
This is Rietveld 408576698