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 import logging | 5 import logging |
| 6 | 6 |
| 7 from page_sets.system_health import platforms | 7 from page_sets.system_health import platforms |
| 8 | 8 |
| 9 from telemetry.core import discover | |
| 10 from telemetry.page import page | 9 from telemetry.page import page |
| 11 | 10 |
| 12 | 11 |
| 13 _DUMP_WAIT_TIME = 3 | 12 _DUMP_WAIT_TIME = 3 |
| 14 | 13 |
| 15 | 14 |
| 15 class _MetaSystemHealthStory(type): | |
| 16 """Metaclass for SystemHealthStory.""" | |
| 17 | |
| 18 @property | |
| 19 def ABSTRACT_STORY(cls): | |
| 20 """Class field marking whether the class is abstract. | |
| 21 | |
| 22 If true, the story will NOT be instantiated and added to a System Health | |
| 23 story set. This field is NOT inherited by subclasses (that's why it's | |
| 24 defined on the metaclass). | |
| 25 """ | |
| 26 return cls.__dict__.get('__ABSTRACT_STORY__', False) | |
|
nednguyen
2016/07/14 20:01:49
nice trick!
petrcermak
2016/07/15 09:01:43
:-)
| |
| 27 | |
| 28 @ABSTRACT_STORY.setter | |
| 29 def ABSTRACT_STORY(cls, ABSTRACT_STORY): | |
| 30 cls.__dict__['__ABSTRACT_STORY__'] = ABSTRACT_STORY | |
| 31 | |
| 32 | |
| 16 class SystemHealthStory(page.Page): | 33 class SystemHealthStory(page.Page): |
| 17 """Abstract base class for System Health user stories.""" | 34 """Abstract base class for System Health user stories.""" |
| 35 __metaclass__ = _MetaSystemHealthStory | |
| 18 | 36 |
| 19 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g. | 37 # The full name of a single page story has the form CASE:GROUP:PAGE (e.g. |
| 20 # 'load:search:google'). | 38 # 'load:search:google'). |
| 21 NAME = NotImplemented | 39 NAME = NotImplemented |
| 22 URL = NotImplemented | 40 URL = NotImplemented |
| 41 ABSTRACT_STORY = True | |
| 23 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS | 42 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS |
| 24 | 43 |
| 25 def __init__(self, story_set, take_memory_measurement): | 44 def __init__(self, story_set, take_memory_measurement): |
| 26 case, group, _ = self.NAME.split(':') | 45 case, group, _ = self.NAME.split(':') |
| 27 super(SystemHealthStory, self).__init__( | 46 super(SystemHealthStory, self).__init__( |
| 28 page_set=story_set, name=self.NAME, url=self.URL, | 47 page_set=story_set, name=self.NAME, url=self.URL, |
| 29 credentials_path='../data/credentials.json', | 48 credentials_path='../data/credentials.json', |
| 30 grouping_keys={'case': case, 'group': group}) | 49 grouping_keys={'case': case, 'group': group}) |
| 31 self._take_memory_measurement = take_memory_measurement | 50 self._take_memory_measurement = take_memory_measurement |
| 32 | 51 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 52 pass | 71 pass |
| 53 | 72 |
| 54 def RunNavigateSteps(self, action_runner): | 73 def RunNavigateSteps(self, action_runner): |
| 55 self._Login(action_runner) | 74 self._Login(action_runner) |
| 56 super(SystemHealthStory, self).RunNavigateSteps(action_runner) | 75 super(SystemHealthStory, self).RunNavigateSteps(action_runner) |
| 57 | 76 |
| 58 def RunPageInteractions(self, action_runner): | 77 def RunPageInteractions(self, action_runner): |
| 59 action_runner.tab.WaitForDocumentReadyStateToBeComplete() | 78 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 60 self._DidLoadDocument(action_runner) | 79 self._DidLoadDocument(action_runner) |
| 61 self._Measure(action_runner) | 80 self._Measure(action_runner) |
| 62 | |
| 63 | |
| 64 def IterAllStoryClasses(module, base_class): | |
| 65 # Sort the classes by their names so that their order is stable and | |
| 66 # deterministic. | |
| 67 for unused_cls_name, cls in sorted(discover.DiscoverClassesInModule( | |
| 68 module=module, | |
| 69 base_class=base_class, | |
| 70 index_by_class_name=True).iteritems()): | |
| 71 yield cls | |
| OLD | NEW |