Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / tools / perf / page_sets / memory_health_story.py
bloba2de9ce5904bac12449e14c716e581547e53bba3
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 import logging
6 import re
8 from telemetry.page import page as page_module
9 from telemetry.page import shared_page_state
10 from telemetry import story
12 from pylib.constants import keyevent # pylint: disable=import-error
13 from pylib.device import intent # pylint: disable=import-error
16 DUMP_WAIT_TIME = 3
18 URL_LIST = [
19 'http://google.com',
20 'http://vimeo.com',
21 'http://yahoo.com',
22 'http://baidu.com',
23 'http://cnn.com',
24 'http://yandex.ru',
25 'http://yahoo.co.jp',
26 'http://amazon.com',
27 'http://ebay.com',
28 'http://bing.com',
32 class ForegroundPage(page_module.Page):
33 """Take a measurement after loading a regular webpage."""
35 def __init__(self, story_set, name, url):
36 super(ForegroundPage, self).__init__(
37 url=url, page_set=story_set, name=name,
38 shared_page_state_class=shared_page_state.SharedMobilePageState)
39 self.archive_data_file = story_set.archive_data_file
41 def _TakeMemoryMeasurement(self, action_runner, phase):
42 android_platform = action_runner.tab.browser.platform
43 with action_runner.CreateInteraction(phase):
44 action_runner.Wait(DUMP_WAIT_TIME)
45 action_runner.ForceGarbageCollection()
46 android_platform.RelaxMemory()
47 action_runner.Wait(DUMP_WAIT_TIME)
48 if not action_runner.tab.browser.DumpMemory():
49 logging.error('Unable to get a memory dump for %s.', self.name)
51 def RunPageInteractions(self, action_runner):
52 action_runner.tab.WaitForDocumentReadyStateToBeComplete()
53 self._TakeMemoryMeasurement(action_runner, 'foreground')
56 class BackgroundPage(ForegroundPage):
57 """Take a measurement while Chrome is in the background."""
59 def __init__(self, story_set, name):
60 super(BackgroundPage, self).__init__(story_set, name, 'about:blank')
62 def RunPageInteractions(self, action_runner):
63 action_runner.tab.WaitForDocumentReadyStateToBeComplete()
65 # Launch clock app, pushing Chrome to the background.
66 android_platform = action_runner.tab.browser.platform
67 android_platform.LaunchAndroidApplication(
68 intent.Intent(package='com.google.android.deskclock',
69 activity='com.android.deskclock.DeskClock'),
70 app_has_webviews=False)
72 # Take measurement.
73 self._TakeMemoryMeasurement(action_runner, 'background')
75 # Go back to Chrome.
76 android_platform.android_action_runner.InputKeyEvent(keyevent.KEYCODE_BACK)
79 class MemoryHealthStory(story.StorySet):
80 """User story for the Memory Health Plan."""
82 def __init__(self):
83 super(MemoryHealthStory, self).__init__(
84 archive_data_file='data/memory_health_plan.json',
85 cloud_storage_bucket=story.PARTNER_BUCKET)
87 for url in URL_LIST:
88 # We name pages so their foreground/background counterparts are easy
89 # to identify. For example 'http://google.com' becomes
90 # 'http_google_com' and 'after_http_google_com' respectively.
91 name = re.sub('\W+', '_', url)
92 self.AddStory(ForegroundPage(self, name, url))
93 self.AddStory(BackgroundPage(self, 'after_' + name))