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.
5 from telemetry
.core
import util
6 from telemetry
.page
import page
as page_module
7 from telemetry
.page
import shared_page_state
8 from telemetry
import story
10 util
.AddDirToPythonPath(util
.GetChromiumSrcDir(), 'build', 'android')
11 from pylib
.constants
import keyevent
# pylint: disable=import-error
12 from pylib
.device
import intent
# pylint: disable=import-error
29 class ForegroundPage(page_module
.Page
):
30 """Take a measurement after loading a regular webpage."""
32 def __init__(self
, story_set
, url
):
33 super(ForegroundPage
, self
).__init
__(
34 url
=url
, page_set
=story_set
, name
=url
,
35 shared_page_state_class
=shared_page_state
.SharedMobilePageState
)
36 self
.archive_data_file
= story_set
.archive_data_file
38 def RunPageInteractions(self
, action_runner
):
39 action_runner
.tab
.WaitForDocumentReadyStateToBeComplete()
40 with action_runner
.CreateInteraction('foreground'):
41 # TODO(perezju): This should catch a few memory dumps. When available,
42 # use the dump API to request dumps on demand crbug.com/505826
46 class BackgroundPage(page_module
.Page
):
47 """Take a measurement while Chrome is in the background."""
49 def __init__(self
, story_set
, number
):
50 super(BackgroundPage
, self
).__init
__(
51 url
='about:blank', page_set
=story_set
,
52 name
='chrome_background_%d' % number
,
53 shared_page_state_class
=shared_page_state
.SharedMobilePageState
)
54 self
.archive_data_file
= story_set
.archive_data_file
56 def RunPageInteractions(self
, action_runner
):
57 action_runner
.tab
.WaitForDocumentReadyStateToBeComplete()
59 # launch clock app, pushing Chrome to the background
60 android_platform
= action_runner
.tab
.browser
.platform
61 android_platform
.LaunchAndroidApplication(
62 intent
.Intent(package
='com.google.android.deskclock',
63 activity
='com.android.deskclock.DeskClock'),
64 app_has_webviews
=False)
67 with action_runner
.CreateInteraction('background'):
68 # TODO(perezju): This should catch a few memory dumps. When available,
69 # use the dump API to request dumps on demand crbug.com/505826
73 android_platform
.android_action_runner
.InputKeyEvent(keyevent
.KEYCODE_BACK
)
76 class MemoryHealthStory(story
.StorySet
):
77 """User story for the Memory Health Plan."""
80 super(MemoryHealthStory
, self
).__init
__(
81 archive_data_file
='data/memory_health_plan.json',
82 cloud_storage_bucket
=story
.PARTNER_BUCKET
)
84 for number
, url
in enumerate(URL_LIST
, 1):
85 self
.AddStory(ForegroundPage(self
, url
))
86 self
.AddStory(BackgroundPage(self
, number
))