blob: b25af546ad7c677209cd9561a4cb25a19406ae09 [file] [log] [blame]
rnephew20017d22017-04-11 18:38:021# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4import time
5
6from telemetry.page import shared_page_state
7from telemetry import story
8
9
10class _IdleSharedState(shared_page_state.SharedPageState):
11 def __init__(self, test, finder_options, story_set):
12 super(_IdleSharedState, self).__init__(test, finder_options, story_set)
13 self._current_story = None
14
15 def WillRunStory(self, current_story):
16 self._current_story = current_story
17 assert self.platform.tracing_controller.is_tracing_running
18
19 def RunStory(self, _):
20 self._current_story.Run(self)
21
22 def DidRunStory(self, _):
23 self._current_story = None
24
25
26class _IdleStory(story.Story):
27 def __init__(self, name, duration):
28 super(_IdleStory, self).__init__(
29 shared_state_class=_IdleSharedState, name=name)
30 self._duration = duration
rnephew1dbbac22017-04-12 19:37:0931 # https://github.com/catapult-project/catapult/issues/3489
32 # Even though there is no actual url being used, it is required for
33 # uploading results using the --upload-results flag. Remove url when
34 # it is no longer needed.
35 self._url = name
rnephew20017d22017-04-11 18:38:0236
37 def Run(self, shared_state):
38 time.sleep(self._duration)
39
rnephew1dbbac22017-04-12 19:37:0940 @property
41 def url(self):
42 return self._url
43
rnephew20017d22017-04-11 18:38:0244
45class IdleStorySet(story.StorySet):
46 def __init__(self):
ashleymariec3c82af2017-06-14 02:21:5447 super(IdleStorySet, self).__init__()
rnephew20017d22017-04-11 18:38:0248 self.AddStory(_IdleStory('IdleStory_10s', 10))
49 self.AddStory(_IdleStory('IdleStory_60s', 60))
50 self.AddStory(_IdleStory('IdleStory_120s', 120))