1 # Copyright 2015 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.
4 from page_sets
import android_screen_restoration_shared_state
6 from telemetry
.page
import page
as page_module
7 from telemetry
.page
import shared_page_state
8 from telemetry
import story
11 class KeyIdlePowerPage(page_module
.Page
):
13 def __init__(self
, url
, page_set
, turn_screen_off
,
14 shared_page_state_class
=shared_page_state
.SharedMobilePageState
):
15 super(KeyIdlePowerPage
, self
).__init
__(
18 shared_page_state_class
=(android_screen_restoration_shared_state
19 .AndroidScreenRestorationSharedState
))
20 self
._turn
_screen
_off
= turn_screen_off
22 def RunNavigateSteps(self
, action_runner
):
23 super(KeyIdlePowerPage
, self
).RunNavigateSteps(action_runner
)
25 if self
._turn
_screen
_off
:
26 # TODO(jdduke): Remove this API violation after the shared page state is
27 # exposed here, crbug.com/470147.
28 # pylint: disable=protected-access
29 action_runner
._tab
.browser
.platform
.android_action_runner
.TurnScreenOff()
30 # We're not interested in tracking activity that occurs immediately after
31 # the screen is turned off. Several seconds should be enough time for the
32 # browser to "settle down" into an idle state.
35 def RunPageInteractions(self
, action_runner
):
36 # The page interaction is simply waiting in an idle state.
37 with action_runner
.CreateInteraction('IdleWaiting'):
38 action_runner
.Wait(20)
41 class KeyIdlePowerCasesPageSet(story
.StorySet
):
43 """ Key idle power cases """
46 super(KeyIdlePowerCasesPageSet
, self
).__init
__()
48 foreground_urls_list
= [
49 # Why: Ensure minimal activity for static, empty pages in the foreground.
50 'file://key_idle_power_cases/blank.html',
51 # Why: An infinite rAF loop which does not modify the page should use
53 'file://key_idle_power_cases/no_op_raf.html',
56 for url
in foreground_urls_list
:
57 self
.AddStory(KeyIdlePowerPage(url
, self
, False))
59 background_urls_list
= [
60 # Why: Ensure animated GIFs aren't processed when Chrome is backgrounded.
61 'file://key_idle_power_cases/animated-gif.html',
62 # Why: Ensure CSS animations aren't processed when Chrome is backgrounded.
63 'file://key_idle_power_cases/css-animation.html',
64 # Why: Ensure rAF is suppressed when Chrome is backgrounded.
65 'file://key_idle_power_cases/request-animation-frame.html',
66 # Why: Ensure setTimeout is throttled when Chrome is backgrounded.
67 'file://key_idle_power_cases/set-timeout.html',
70 for url
in background_urls_list
:
71 self
.AddStory(KeyIdlePowerPage(url
, self
, True))