Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 | 4 |
| 5 from page_sets.system_health import platforms | 5 from page_sets.system_health import platforms |
| 6 | 6 |
| 7 from telemetry import decorators | 7 from telemetry import decorators |
| 8 from telemetry.page import page | 8 from telemetry.page import page |
| 9 from telemetry.page import shared_page_state | 9 from telemetry.page import shared_page_state |
| 10 | 10 |
| 11 from devil.android.sdk import intent # pylint: disable=import-error | |
| 12 from devil.android.sdk import keyevent # pylint: disable=import-error | |
| 11 | 13 |
| 12 # Extra wait time after the page has loaded required by the loading metric. We | 14 # Extra wait time after the page has loaded required by the loading metric. We |
| 13 # use it in all benchmarks to avoid divergence between benchmarks. | 15 # use it in all benchmarks to avoid divergence between benchmarks. |
| 14 # TODO(petrcermak): Switch the memory benchmarks to use it as well. | 16 # TODO(petrcermak): Switch the memory benchmarks to use it as well. |
| 15 _WAIT_TIME_AFTER_LOAD = 10 | 17 _WAIT_TIME_AFTER_LOAD = 10 |
| 16 | 18 |
| 17 | 19 |
| 18 class _SystemHealthSharedState(shared_page_state.SharedPageState): | 20 class _SystemHealthSharedState(shared_page_state.SharedPageState): |
| 19 """Shared state which enables disabling stories on individual platforms. | 21 """Shared state which enables disabling stories on individual platforms. |
| 20 | 22 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 """Abstract base class for System Health user stories.""" | 61 """Abstract base class for System Health user stories.""" |
| 60 __metaclass__ = _MetaSystemHealthStory | 62 __metaclass__ = _MetaSystemHealthStory |
| 61 | 63 |
| 62 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g. | 64 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g. |
| 63 # 'load:search:google'). | 65 # 'load:search:google'). |
| 64 NAME = NotImplemented | 66 NAME = NotImplemented |
| 65 URL = NotImplemented | 67 URL = NotImplemented |
| 66 ABSTRACT_STORY = True | 68 ABSTRACT_STORY = True |
| 67 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS | 69 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS |
| 68 | 70 |
| 69 def __init__(self, story_set, take_memory_measurement): | 71 def __init__( |
| 72 self, story_set, take_memory_measurement, measure_in_background): | |
| 70 case, group, _ = self.NAME.split(':') | 73 case, group, _ = self.NAME.split(':') |
| 71 super(SystemHealthStory, self).__init__( | 74 super(SystemHealthStory, self).__init__( |
| 72 shared_page_state_class=_SystemHealthSharedState, page_set=story_set, | 75 shared_page_state_class=_SystemHealthSharedState, page_set=story_set, |
| 73 name=self.NAME, url=self.URL, | 76 name=self.NAME, url=self.URL, |
| 74 credentials_path='../data/credentials.json', | 77 credentials_path='../data/credentials.json', |
| 75 grouping_keys={'case': case, 'group': group}) | 78 grouping_keys={'case': case, 'group': group}) |
| 76 self._take_memory_measurement = take_memory_measurement | 79 self._take_memory_measurement = take_memory_measurement |
| 80 self._measure_in_background = measure_in_background | |
| 77 | 81 |
| 78 @classmethod | 82 @classmethod |
| 79 def CanRun(cls, possible_browser): | 83 def CanRun(cls, possible_browser): |
| 80 if (decorators.ShouldSkip(cls, possible_browser)[0] or | 84 if (decorators.ShouldSkip(cls, possible_browser)[0] or |
| 81 cls.ShouldDisable(possible_browser)): | 85 cls.ShouldDisable(possible_browser)): |
| 82 return False | 86 return False |
| 83 return True | 87 return True |
| 84 | 88 |
| 85 @classmethod | 89 @classmethod |
| 86 def ShouldDisable(cls, possible_browser): | 90 def ShouldDisable(cls, possible_browser): |
| 87 """Override this method to disable a story under specific conditions. | 91 """Override this method to disable a story under specific conditions. |
| 88 | 92 |
| 89 This method is modelled after telemetry.benchmark.Benchmark.ShouldDisable(). | 93 This method is modelled after telemetry.benchmark.Benchmark.ShouldDisable(). |
| 90 """ | 94 """ |
| 91 del possible_browser | 95 del possible_browser |
| 92 return False | 96 return False |
| 93 | 97 |
| 94 def _Measure(self, action_runner): | 98 def _Measure(self, action_runner): |
| 95 if self._take_memory_measurement: | 99 if self._take_memory_measurement: |
| 96 action_runner.MeasureMemory(deterministic_mode=True) | 100 action_runner.MeasureMemory(deterministic_mode=True) |
| 97 else: | 101 else: |
| 98 action_runner.Wait(_WAIT_TIME_AFTER_LOAD) | 102 action_runner.Wait(_WAIT_TIME_AFTER_LOAD) |
| 99 | 103 |
| 100 def _Login(self, action_runner): | 104 def _Login(self, action_runner): |
| 101 pass | 105 pass |
| 102 | 106 |
| 103 def _DidLoadDocument(self, action_runner): | 107 def _DidLoadDocument(self, action_runner): |
| 104 pass | 108 pass |
| 105 | 109 |
| 110 def _BackgroundChromeIfNecessary(self, action_runner): | |
| 111 if self._measure_in_background: | |
| 112 self._BackgroundChrome(action_runner) | |
| 113 | |
| 114 def _ForegroundChromeIfNecessary(self, action_runner): | |
| 115 if self._measure_in_background: | |
| 116 self._ForegroundChrome(action_runner) | |
| 117 | |
| 118 def _BackgroundChrome(self, action_runner): | |
| 119 platform = action_runner.tab.browser.platform | |
| 120 platform.LaunchAndroidApplication( | |
| 121 intent.Intent( | |
| 122 package='com.google.android.deskclock', | |
| 123 activity='com.android.deskclock.DeskClock'), | |
| 124 app_has_webviews=False) | |
|
hjd
2016/10/03 11:23:27
The block above seems kind of ugly, it seems like
| |
| 125 | |
| 126 def _ForegroundChrome(self, action_runner): | |
| 127 platform = action_runner.tab.browser.platform | |
| 128 platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK) | |
| 129 | |
| 106 def RunNavigateSteps(self, action_runner): | 130 def RunNavigateSteps(self, action_runner): |
| 107 self._Login(action_runner) | 131 self._Login(action_runner) |
| 108 super(SystemHealthStory, self).RunNavigateSteps(action_runner) | 132 super(SystemHealthStory, self).RunNavigateSteps(action_runner) |
| 109 | 133 |
| 110 def RunPageInteractions(self, action_runner): | 134 def RunPageInteractions(self, action_runner): |
| 111 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 135 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 112 self._DidLoadDocument(action_runner) | 136 self._DidLoadDocument(action_runner) |
| 137 self._BackgroundChromeIfNecessary(action_runner) | |
| 113 self._Measure(action_runner) | 138 self._Measure(action_runner) |
| 139 self._ForegroundChromeIfNecessary(action_runner) | |
| 140 | |
| OLD | NEW |