Commit 833d322d authored by aberent@chromium.org's avatar aberent@chromium.org

[Android] Don't wait for background tabs

The session restore tests were timing out on Android. This was because
they were waiting for the background tabs to be loaded, which they
would not be in normal startup.

The only reason the test worked at all is that when devtools accessed
the background tabs this forced them to be loaded.

This changes the test to only wait for, and to only measure, the
foreground tab.

NOTRY=true
BUG=343168,343900

Review URL: https://codereview.chromium.org/161473002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251364 0039d316-1c4b-4281-b951-d872f2087c98
parent 6cfd2a10
...@@ -50,11 +50,8 @@ class SessionRestore(startup.Startup): ...@@ -50,11 +50,8 @@ class SessionRestore(startup.Startup):
self._cpu_metric.Start(None, None) self._cpu_metric.Start(None, None)
def MeasurePage(self, page, tab, results): def MeasurePage(self, page, tab, results):
# Wait for all tabs to finish loading.
for i in xrange(len(tab.browser.tabs)):
t = tab.browser.tabs[i]
t.WaitForDocumentReadyStateToBeComplete()
tab.browser.foreground_tab.WaitForDocumentReadyStateToBeComplete()
# Record CPU usage from browser start to when all pages have loaded. # Record CPU usage from browser start to when all pages have loaded.
self._cpu_metric.Stop(None, None) self._cpu_metric.Stop(None, None)
self._cpu_metric.AddResults(tab, results, 'cpu_utilization') self._cpu_metric.AddResults(tab, results, 'cpu_utilization')
......
...@@ -41,17 +41,15 @@ class StartupMetric(Metric): ...@@ -41,17 +41,15 @@ class StartupMetric(Metric):
return None return None
return (int(high_bytes) << 32) | (int(low_bytes) << 1) return (int(high_bytes) << 32) | (int(low_bytes) << 1)
# pylint: disable=W0101
def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results): def _RecordTabLoadTimes(self, tab, browser_main_entry_time_ms, results):
"""Records the tab load times for the browser. """ """Records the tab load times for the browser. """
tab_load_times = [] tab_load_times = []
TabLoadTime = collections.namedtuple( TabLoadTime = collections.namedtuple(
'TabLoadTime', 'TabLoadTime',
['load_start_ms', 'load_duration_ms', 'is_foreground_tab']) ['load_start_ms', 'load_duration_ms'])
num_open_tabs = len(tab.browser.tabs)
for i in xrange(num_open_tabs): def RecordTabLoadTime(t):
try: try:
t = tab.browser.tabs[i]
t.WaitForDocumentReadyStateToBeComplete() t.WaitForDocumentReadyStateToBeComplete()
result = t.EvaluateJavaScript( result = t.EvaluateJavaScript(
...@@ -61,51 +59,34 @@ class StartupMetric(Metric): ...@@ -61,51 +59,34 @@ class StartupMetric(Metric):
if 'load_start_ms' not in result or 'load_duration_ms' not in result: if 'load_start_ms' not in result or 'load_duration_ms' not in result:
raise Exception("Outdated Chrome version, " raise Exception("Outdated Chrome version, "
"statsCollectionController.tabLoadTiming() not present") "statsCollectionController.tabLoadTiming() not present")
return
if result['load_duration_ms'] is None: if result['load_duration_ms'] is None:
tab_title = t.EvaluateJavaScript('document.title') tab_title = t.EvaluateJavaScript('document.title')
print "Page: ", tab_title, " didn't finish loading." print "Page: ", tab_title, " didn't finish loading."
continue return
is_foreground_tab = t.EvaluateJavaScript('!document.hidden')
tab_load_times.append(TabLoadTime( tab_load_times.append(TabLoadTime(
int(result['load_start_ms']), int(result['load_start_ms']),
int(result['load_duration_ms']), int(result['load_duration_ms'])))
is_foreground_tab))
except util.TimeoutException: except util.TimeoutException:
# Low memory Android devices may not be able to load more than # Low memory Android devices may not be able to load more than
# one tab at a time, so may timeout when the test attempts to # one tab at a time, so may timeout when the test attempts to
# access a background tab. Ignore these tabs. # access a background tab. Ignore these tabs.
logging.error("Tab number: %d timed out on JavaScript access" % i) logging.error("Tab timed out on JavaScript access")
continue
# Only measure the foreground tab. We can't measure all tabs on Android
# Postprocess results # because on Android the data of the background tabs is loaded on demand,
load_complete_times = ( # when the user switches to them, rather than during startup. In view of
[t.load_start_ms + t.load_duration_ms for t in tab_load_times]) # this, to get the same measures on all platform, we only measure the
load_complete_times.sort() # foreground tab on all platforms.
if 'android' in tab.browser.browser_type: RecordTabLoadTime(tab.browser.foreground_tab)
# document.hidden is broken on Android - crbug.com/322544.
foreground_tab_stats = [tab_load_times[0]] foreground_tab_stats = tab_load_times[0]
else:
foreground_tab_stats = (
[t for t in tab_load_times if t.is_foreground_tab == True])
if (len(foreground_tab_stats) != 1):
raise Exception ("More than one foreground tab? ", foreground_tab_stats)
foreground_tab_stats = foreground_tab_stats[0]
# Report load stats.
foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms + foreground_tab_load_complete = ((foreground_tab_stats.load_start_ms +
foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms) foreground_tab_stats.load_duration_ms) - browser_main_entry_time_ms)
results.Add( results.Add(
'foreground_tab_load_complete', 'ms', foreground_tab_load_complete) 'foreground_tab_load_complete', 'ms', foreground_tab_load_complete)
if num_open_tabs > 1:
last_tab_load_complete = (
load_complete_times[-1] - browser_main_entry_time_ms)
results.Add('last_tab_load_complete', 'ms', last_tab_load_complete)
def AddResults(self, tab, results): def AddResults(self, tab, results):
get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")' get_histogram_js = 'statsCollectionController.getBrowserHistogram("%s")'
......
...@@ -84,6 +84,18 @@ class Browser(object): ...@@ -84,6 +84,18 @@ class Browser(object):
def tabs(self): def tabs(self):
return self._tabs return self._tabs
@property
def foreground_tab(self):
for i in xrange(len(self._tabs)):
# The foreground tab is the first (only) one that isn't hidden.
# This only works through luck on Android, due to crbug.com/322544
# which means that tabs that have never been in the foreground return
# document.hidden as false; however in current code the Android foreground
# tab is always tab 0, which will be the first one that isn't hidden
if self._tabs[i].EvaluateJavaScript('!document.hidden'):
return self._tabs[i]
raise Exception("No foreground tab found")
@property @property
def extensions(self): def extensions(self):
"""Returns the extension dictionary if it exists.""" """Returns the extension dictionary if it exists."""
...@@ -392,3 +404,4 @@ class Browser(object): ...@@ -392,3 +404,4 @@ class Browser(object):
See the documentation of the SystemInfo class for more details.""" See the documentation of the SystemInfo class for more details."""
return self._browser_backend.GetSystemInfo() return self._browser_backend.GetSystemInfo()
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