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

Side by Side Diff: tools/telemetry/telemetry/user_story/android/shared_app_state.py

Issue 852623002: Call test methods from shared_app_state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import os 4 import os
5 5
6 from telemetry.core import platform 6 from telemetry.core import platform
7 from telemetry.core.platform import android_platform 7 from telemetry.core.platform import android_platform
8 from telemetry.core import wpr_modes 8 from telemetry.core import wpr_modes
9 from telemetry.core.platform import android_device 9 from telemetry.core.platform import android_device
10 from telemetry.user_story import shared_user_story_state 10 from telemetry.user_story import shared_user_story_state
11 from telemetry.web_perf import timeline_based_measurement 11 from telemetry.web_perf import timeline_based_measurement
12 12
13 13
14 # TODO(slamm): Interact with TimelineBasedMeasurement when it no longer
15 # depends on browser logic.
16 class SharedAppState(shared_user_story_state.SharedUserStoryState): 14 class SharedAppState(shared_user_story_state.SharedUserStoryState):
17 """Manage test state/transitions across multiple android.UserStory's. 15 """Manage test state/transitions across multiple android.UserStory's.
18 16
19 WARNING: the class is not ready for public consumption. 17 WARNING: the class is not ready for public consumption.
20 Email telemetry@chromium.org if you feel like you must use it. 18 Email telemetry@chromium.org if you feel like you must use it.
21 """ 19 """
22 20
23 def __init__(self, test, finder_options, user_story_set): 21 def __init__(self, test, finder_options, user_story_set):
24 """This method is styled on unittest.TestCase.setUpClass. 22 """This method is styled on unittest.TestCase.setUpClass.
25 23
26 Args: 24 Args:
27 test: a web_perf.TimelineBasedMeasurement instance. 25 test: a web_perf.TimelineBasedMeasurement instance.
28 options: a BrowserFinderOptions instance with command line options. 26 options: a BrowserFinderOptions instance with command line options.
29 user_story_set: an android.UserStorySet instance. 27 user_story_set: an android.UserStorySet instance.
30 """ 28 """
31 super(SharedAppState, self).__init__(test, finder_options, user_story_set) 29 super(SharedAppState, self).__init__(test, finder_options, user_story_set)
32 if not isinstance( 30 if not isinstance(
33 test, timeline_based_measurement.TimelineBasedMeasurement): 31 test, timeline_based_measurement.TimelineBasedMeasurement):
34 raise ValueError( 32 raise ValueError(
35 'SharedAppState only accepts TimelineBasedMeasurement tests' 33 'SharedAppState only accepts TimelineBasedMeasurement tests'
36 ' (not %s).' % test.__class__) 34 ' (not %s).' % test.__class__)
35 self._test = test
37 self._finder_options = finder_options 36 self._finder_options = finder_options
38 self._android_app = None 37 self._android_app = None
39 self._current_user_story = None 38 self._current_user_story = None
40 self._android_platform = platform.GetPlatformForDevice( 39 self._android_platform = platform.GetPlatformForDevice(
41 android_device.GetDevice(finder_options)) 40 android_device.GetDevice(finder_options))
42 assert self._android_platform, 'Unable to create android platform.' 41 assert self._android_platform, 'Unable to create android platform.'
43 assert isinstance( 42 assert isinstance(
44 self._android_platform, android_platform.AndroidPlatform) 43 self._android_platform, android_platform.AndroidPlatform)
45 44
46 @property 45 @property
47 def app(self): 46 def app(self):
48 return self._android_app 47 return self._android_app
49 48
50 @property 49 @property
51 def platform(self): 50 def platform(self):
52 return self._android_platform 51 return self._android_platform
53 52
54 def WillRunUserStory(self, user_story): 53 def WillRunUserStory(self, user_story):
55 assert not self._android_app 54 assert not self._android_app
55 tracing_controller = self._android_platform.tracing_controller
56 self._test.WillRunUserStory(tracing_controller)
56 self._current_user_story = user_story 57 self._current_user_story = user_story
57 self._android_app = self._android_platform.LaunchAndroidApplication( 58 self._android_app = self._android_platform.LaunchAndroidApplication(
58 user_story.start_intent, user_story.is_app_ready_predicate) 59 user_story.start_intent, user_story.is_app_ready_predicate)
59 60
60 def RunUserStory(self, results): 61 def RunUserStory(self, results):
61 self._current_user_story.Run(self) 62 self._current_user_story.Run(self)
63 tracing_controller = self._android_platform.tracing_controller
64 self._test.Measure(tracing_controller, results)
62 65
63 def DidRunUserStory(self, results): 66 def DidRunUserStory(self, results):
67 tracing_controller = self._android_platform.tracing_controller
68 self._test.WillDidRunUserStory(tracing_controller)
nednguyen 2015/01/13 21:26:09 self._test.DidRunUserStory(..)
64 if self._android_app: 69 if self._android_app:
65 self._android_app.Close() 70 self._android_app.Close()
66 self._android_app = None 71 self._android_app = None
67 72
68 def GetTestExpectationAndSkipValue(self, expectations): 73 def GetTestExpectationAndSkipValue(self, expectations):
69 # TODO(chrishenry): Implement this properly. 74 """This does not apply to android app user stories."""
70 return 'pass', None 75 return 'pass', None
71 76
72 def TearDownState(self, results): 77 def TearDownState(self, results):
78 """Tear down anything created in the __init__ method that is not needed.
79
80 Currently, there is no clean-up needed from SharedAppState.__init__.
81 """
73 pass 82 pass
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698