blob: 39e012684713e173ec09cb9b96c180bfd900645c [file] [log] [blame]
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from telemetry.core import android_platform
from telemetry.core import platform
from telemetry.internal.platform import android_device
from telemetry import story as story_module
from telemetry.web_perf import timeline_based_measurement
class SharedAndroidState(story_module.SharedState):
"""Manage test state/transitions across multiple android.AndroidStory's.
WARNING: the class is not ready for public consumption.
Email if you feel like you must use it.
def __init__(self, test, finder_options, story_set, possible_browser):
"""This method is styled on unittest.TestCase.setUpClass.
test: a web_perf.TimelineBasedMeasurement instance.
options: a BrowserFinderOptions instance with command line options.
story_set: a story.StorySet instance.
super(SharedAndroidState, self).__init__(
test, finder_options, story_set, possible_browser)
if not isinstance(
test, timeline_based_measurement.TimelineBasedMeasurement):
raise ValueError(
'SharedAndroidState only accepts TimelineBasedMeasurement tests'
' (not %s).' % test.__class__)
self._test = test
self._finder_options = finder_options
self._android_app = None
self._current_story = None
device = android_device.GetDevice(finder_options)
assert device, 'Android device required.'
self._android_platform = platform.GetPlatformForDevice(
device, finder_options)
assert self._android_platform, 'Unable to create android platform.'
assert isinstance(
self._android_platform, android_platform.AndroidPlatform)
def app(self):
return self._android_app
def platform(self):
return self._android_platform
def WillRunStory(self, story):
assert not self._android_app
self._current_story = story
self._android_app = self._android_platform.LaunchAndroidApplication(
story.start_intent, story.is_app_ready_predicate)
def CanRunStory(self, story):
"""This does not apply to android app stories."""
return True
def RunStory(self, results):
self._test.Measure(self._android_platform.tracing_controller, results)
def DidRunStory(self, results):
self._test.DidRunStory(self._android_platform.tracing_controller, results)
if self._android_app:
self._android_app = None
def TearDownState(self):
"""Tear down anything created in the __init__ method that is not needed.
Currently, there is no clean-up needed from SharedAndroidState.__init__.
def DumpStateUponStoryRunFailure(self, results):
# TODO: Dump the state of the Android app.
del results # Unused.