OLD | NEW |
(Empty) | |
| 1 # Copyright 2014 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 import logging |
| 5 import os |
| 6 |
| 7 from page_sets.login_helpers import dropbox_login |
| 8 from page_sets.login_helpers import google_login |
| 9 |
| 10 from telemetry.page import page as page_module |
| 11 from telemetry.page import shared_page_state |
| 12 from telemetry import story |
| 13 |
| 14 DUMP_WAIT_TIME = 10 |
| 15 DUMP_COUNT = 10 |
| 16 |
| 17 class MemoryTestPage(page_module.Page): |
| 18 def __init__(self, story_set, group, url, page_spec): |
| 19 name = 'load:%s:%s' % (group, page_spec.name) |
| 20 super(MemoryTestPage, self).__init__( |
| 21 page_set=story_set, |
| 22 name=name, |
| 23 url=url, |
| 24 shared_page_state_class=shared_page_state.SharedPageState, |
| 25 credentials_path='data/credentials.json') |
| 26 self._page_spec = page_spec |
| 27 |
| 28 @property |
| 29 def platform(self): |
| 30 return self.story_set.PLATFORM |
| 31 |
| 32 def _dumpWithInteraction(self, action_runner, text, do_gc=False): |
| 33 with action_runner.CreateInteraction(text): |
| 34 action_runner.Wait(3) |
| 35 if do_gc: |
| 36 action_runner.ForceGarbageCollection() |
| 37 action_runner.SimulateMemoryPressureNotification('critical') |
| 38 action_runner.Wait(3) |
| 39 if not action_runner.tab.browser.DumpMemory(): |
| 40 logging.error('Unable to get a memory dump for %s.', self.name) |
| 41 |
| 42 def _RunPageInteractions(self, action_runner): |
| 43 action_runner.Wait(60) |
| 44 if not action_runner.tab.browser.DumpMemory(): |
| 45 logging.error('Unable to get a memory dump for %s.', self.name) |
| 46 |
| 47 def _RunPageAndMoveToBackground(self, action_runner): |
| 48 action_runner.Wait(60) |
| 49 # Force V8 GC. |
| 50 action_runner.ForceGarbageCollection() |
| 51 action_runner.Wait(10) |
| 52 # Dump before moving the page to background. |
| 53 if not action_runner.tab.browser.DumpMemory(): |
| 54 logging.error('Unable to get a memory dump for %s.', self.name) |
| 55 action_runner.Wait(3) |
| 56 # Open blank tab (Move the page to background). |
| 57 action_runner.tab.browser.tabs.New() |
| 58 # Wait until purge-and-suspend |
| 59 # Needs "--purge-and-suspend-time=X and X < 20" |
| 60 action_runner.Wait(120) |
| 61 if not action_runner.tab.browser.DumpMemory(): |
| 62 logging.error('Unable to get a memory dump for %s.', self.name) |
| 63 |
| 64 def _RunPageAndMoveToBackgroundWithNoDump(self, action_runner): |
| 65 action_runner.Wait(60) |
| 66 action_runner.ForceGarbageCollection() |
| 67 action_runner.Wait(10) |
| 68 action_runner.tab.browser.tabs.New() |
| 69 action_runner.Wait(540) |
| 70 |
| 71 |
| 72 def RunPageInteractions(self, action_runner): |
| 73 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 74 if self._page_spec.post_load_hook: |
| 75 self._page_spec.post_load_hook(self.platform, action_runner) |
| 76 self._RunPageAndMoveToBackground(action_runner) |
| 77 #self._RunPageAndMoveToBackgroundWithNoDump(action_runner) |
| 78 |
| 79 def RunNavigateSteps(self, action_runner): |
| 80 if self._page_spec.login_hook: |
| 81 self._page_spec.login_hook(action_runner, self.credentials_path) |
| 82 super(MemoryTestPage, self).RunNavigateSteps(action_runner) |
| 83 |
| 84 |
| 85 def _LogIntoGoogleAccount(action_runner, credentials_path): |
| 86 google_login.LoginGoogleAccount(action_runner, 'googletest', credentials_path) |
| 87 |
| 88 |
| 89 def _LogIntoGoogleAccountAndSetUpGmailSession(action_runner, credentials_path): |
| 90 _LogIntoGoogleAccount(action_runner, credentials_path) |
| 91 |
| 92 # Navigating to https://mail.google.com immediately leads to an infinite |
| 93 # redirection loop due to a bug in WPR (see |
| 94 # https://github.com/chromium/web-page-replay/issues/70). We therefore first |
| 95 # navigate to a sub-URL to set up the session and hit the resulting |
| 96 # redirection loop. Afterwards, we can safely navigate to |
| 97 # https://mail.google.com. |
| 98 action_runner.Navigate( |
| 99 'https://mail.google.com/mail/mu/mp/872/trigger_redirection_loop') |
| 100 action_runner.tab.WaitForDocumentReadyStateToBeComplete() |
| 101 |
| 102 |
| 103 def _LogIntoDropboxAccount(action_runner, credentials_path): |
| 104 dropbox_login.LoginAccount(action_runner, 'dropbox', credentials_path) |
| 105 |
| 106 |
| 107 def _CloseInboxInterstitialAndWaitUntilGmailReady(platform, action_runner): |
| 108 if platform == 'desktop': |
| 109 # Wait until the UI loads. |
| 110 action_runner.WaitForJavaScriptCondition( |
| 111 'document.getElementById("loading").style.display === "none"') |
| 112 elif platform == 'mobile': |
| 113 # Close the "Get Inbox by Gmail" interstitial. |
| 114 action_runner.WaitForJavaScriptCondition( |
| 115 'document.querySelector("#isppromo a") !== null') |
| 116 action_runner.ExecuteJavaScript( |
| 117 'document.querySelector("#isppromo a").click()') |
| 118 # Wait until the UI loads. |
| 119 action_runner.WaitForJavaScriptCondition( |
| 120 'document.getElementById("apploadingdiv").style.height === "0px"') |
| 121 |
| 122 |
| 123 def _WaitUntilBubblesReady(_, action_runner): |
| 124 # The #logo element is removed right before the main menu is displayed. |
| 125 action_runner.WaitForJavaScriptCondition( |
| 126 'document.getElementById("logo") === null') |
| 127 |
| 128 |
| 129 def _WaitUntilSpyChaseReady(_, action_runner): |
| 130 # The background of the game canvas is set when the "Tap screen to play" |
| 131 # caption is displayed. |
| 132 action_runner.WaitForJavaScriptCondition( |
| 133 'document.querySelector("#game canvas").style.background !== ""') |
| 134 |
| 135 |
| 136 def _WaitUntilFlickrReady(_, action_runner): |
| 137 # Wait until the 'Recently tagged' view loads. |
| 138 action_runner.WaitForJavaScriptCondition(''' |
| 139 document.querySelector( |
| 140 '.search-photos-everyone-trending-view .photo-list-view') !== null''') |
| 141 |
| 142 |
| 143 class _PageSpec(object): |
| 144 |
| 145 def __init__(self, name, url, login_hook=None, post_load_hook=None): |
| 146 assert isinstance(url, (dict, str)) |
| 147 self._name = name |
| 148 self._url = url |
| 149 self._login_hook = login_hook |
| 150 self._post_load_hook = post_load_hook |
| 151 |
| 152 @property |
| 153 def name(self): |
| 154 return self._name |
| 155 |
| 156 @property |
| 157 def url(self): |
| 158 return self._url |
| 159 |
| 160 @property |
| 161 def login_hook(self): |
| 162 return self._login_hook |
| 163 |
| 164 @property |
| 165 def post_load_hook(self): |
| 166 return self._post_load_hook |
| 167 |
| 168 |
| 169 _SINGLE_PAGE_SPECS = { |
| 170 # Search and e-commerce. |
| 171 'search': [ |
| 172 _PageSpec( |
| 173 name='google', |
| 174 url='https://www.google.com/#hl=en&q=science'), |
| 175 _PageSpec( |
| 176 name='baidu', |
| 177 url='https://www.baidu.com/s?word=google'), |
| 178 _PageSpec( |
| 179 name='yahoo', |
| 180 url='https://search.yahoo.com/search;_ylt=?p=google'), |
| 181 _PageSpec( |
| 182 name='amazon', |
| 183 url='https://www.amazon.com/s/?field-keywords=nexus'), |
| 184 # "ali_trackid" in the URL suppresses "Download app" interstitial. |
| 185 _PageSpec( |
| 186 name='taobao', |
| 187 url={'desktop': 'https://world.taobao.com/', |
| 188 'mobile': 'http://m.intl.taobao.com/?ali_trackid'}), |
| 189 _PageSpec( |
| 190 name='yandex', |
| 191 url='https://yandex.ru/touchsearch?text=science'), |
| 192 # Redirects to the "http://" version. |
| 193 _PageSpec( |
| 194 name='ebay', |
| 195 url='https://www.ebay.com/sch/i.html?_nkw=headphones'), |
| 196 ], |
| 197 |
| 198 # Social networks. |
| 199 'social': [ |
| 200 # Using Facebook login often causes "404 Not Found" with WPR. |
| 201 _PageSpec( |
| 202 name='facebook', |
| 203 url='https://www.facebook.com/rihanna'), |
| 204 _PageSpec( |
| 205 name='twitter', |
| 206 url='https://www.twitter.com/justinbieber?skip_interstitial=true'), |
| 207 # Due to the deterministic date injected by WPR (February 2008), the |
| 208 # cookie set by https://vk.com immediately expires, so the page keeps |
| 209 # refreshing indefinitely on mobile |
| 210 # (see https://github.com/chromium/web-page-replay/issues/71). |
| 211 _PageSpec( |
| 212 name='vk', |
| 213 url={'desktop': 'https://vk.com/sbeatles'}), |
| 214 _PageSpec( |
| 215 name='instagram', |
| 216 url='https://www.instagram.com/selenagomez/'), |
| 217 _PageSpec( |
| 218 name='pinterest', |
| 219 url='https://uk.pinterest.com/categories/popular/'), |
| 220 # Redirects to the "http://" version. |
| 221 _PageSpec( |
| 222 name='tumblr', |
| 223 url='https://50thousand.tumblr.com/'), |
| 224 ], |
| 225 |
| 226 # News, discussion and knowledge portals and blogs. |
| 227 'news': [ |
| 228 # Redirects to the "http://" version. |
| 229 _PageSpec( |
| 230 name='bbc', |
| 231 url='https://www.bbc.co.uk/news/world-asia-china-36189636'), |
| 232 # Using "https://" shows "Your connection is not private". |
| 233 _PageSpec( |
| 234 name='cnn', |
| 235 url=( |
| 236 'http://edition.cnn.com/2016/05/02/health/three-habitable-planet
s-earth-dwarf-star/index.html')), |
| 237 _PageSpec( |
| 238 name='reddit', |
| 239 url={'desktop': ( |
| 240 'https://www.reddit.com/r/AskReddit/comments/4hi90e/whats_y
our_best_wedding_horror_story/'), |
| 241 'mobile': ( |
| 242 'https://m.reddit.com/r/AskReddit/comments/4hi90e/whats_you
r_best_wedding_horror_story/')}), |
| 243 # Using "https://" hangs and shows "This site can't be reached". |
| 244 _PageSpec( |
| 245 name='qq', |
| 246 url='http://news.qq.com/a/20160503/003186.htm'), |
| 247 # Using "https://" leads to missing images and scripts on mobile (due |
| 248 # to mixed content). The desktop page |
| 249 # (http://news.sohu.com/20160503/n447433356.shtml) almost always fails |
| 250 # to completely load due to |
| 251 # https://github.com/chromium/web-page-replay/issues/74. |
| 252 _PageSpec( |
| 253 name='sohu', |
| 254 url={'mobile': 'http://m.sohu.com/n/447433356/'}), |
| 255 _PageSpec( |
| 256 name='wikipedia', |
| 257 url='https://en.wikipedia.org/wiki/Science'), |
| 258 ], |
| 259 |
| 260 # Audio and video. |
| 261 'media': [ |
| 262 # No way to disable autoplay on desktop. |
| 263 _PageSpec( |
| 264 name='youtube', |
| 265 url='https://www.youtube.com/watch?v=QGfhS1hfTWw&autoplay=false'), |
| 266 # The side panel with related videos doesn't show on desktop due to |
| 267 # https://github.com/chromium/web-page-replay/issues/74. |
| 268 _PageSpec( |
| 269 name='dailymotion', |
| 270 url=( |
| 271 'https://www.dailymotion.com/video/x489k7d_street-performer-show
s-off-slinky-skills_fun?autoplay=false')), |
| 272 _PageSpec( |
| 273 name='google_images', |
| 274 url='https://www.google.co.uk/search?tbm=isch&q=love'), |
| 275 # No way to disable autoplay on desktop. Album artwork doesn't load due |
| 276 # to https://github.com/chromium/web-page-replay/issues/73. |
| 277 _PageSpec( |
| 278 name='soundcloud', |
| 279 url='https://soundcloud.com/lifeofdesiigner/desiigner-panda'), |
| 280 _PageSpec( |
| 281 name='9gag', |
| 282 url='https://www.9gag.com/'), |
| 283 _PageSpec( |
| 284 name='flickr', |
| 285 url='https://www.flickr.com/photos/tags/farm', |
| 286 post_load_hook=_WaitUntilFlickrReady), |
| 287 ], |
| 288 |
| 289 # Online tools (documents, emails, storage, ...). |
| 290 'tools': [ |
| 291 _PageSpec( |
| 292 name='docs', |
| 293 url=( |
| 294 'https://docs.google.com/document/d/1GvzDP-tTLmJ0myRhUAfTYWs3ZUF
ilUICg8psNHyccwQ/edit?usp=sharing')), |
| 295 _PageSpec( |
| 296 name='gmail', |
| 297 url='https://mail.google.com/mail/', |
| 298 login_hook=_LogIntoGoogleAccountAndSetUpGmailSession, |
| 299 post_load_hook=_CloseInboxInterstitialAndWaitUntilGmailReady), |
| 300 _PageSpec( |
| 301 name='maps', |
| 302 url='https://www.google.com/maps/place/London,+UK/'), |
| 303 _PageSpec( |
| 304 name='stackoverflow', |
| 305 url=( |
| 306 'https://stackoverflow.com/questions/36827659/compiling-an-appli
cation-for-use-in-highly-radioactive-environments')), |
| 307 _PageSpec( |
| 308 name='dropbox', |
| 309 url='https://www.dropbox.com', |
| 310 login_hook=_LogIntoDropboxAccount), |
| 311 _PageSpec( |
| 312 name='weather', |
| 313 url='https://weather.com/en-GB/weather/today/l/USCA0286:1:US'), |
| 314 _PageSpec( |
| 315 name='drive', |
| 316 url='https://drive.google.com/drive/my-drive', |
| 317 login_hook=_LogIntoGoogleAccount), |
| 318 ], |
| 319 |
| 320 # In-browser games (HTML5 and Flash). |
| 321 'games': [ |
| 322 _PageSpec( |
| 323 name='bubbles', |
| 324 url=( |
| 325 'https://games.cdn.famobi.com/html5games/s/smarty-bubbles/v010/?
fg_domain=play.famobi.com&fg_uid=d8f24956-dc91-4902-9096-a46cb1353b6f&fg_pid=463
8e320-4444-4514-81c4-d80a8c662371&fg_beat=620'), |
| 326 post_load_hook=_WaitUntilBubblesReady), |
| 327 # Using "https://" hangs and shows "This site can't be reached". |
| 328 _PageSpec( |
| 329 name='lazors', |
| 330 url='http://www8.games.mobi/games/html5/lazors/lazors.html'), |
| 331 # Using "https://" shows "Your connection is not private". |
| 332 _PageSpec( |
| 333 name='spychase', |
| 334 url='http://playstar.mobi/games/spychase/index.php', |
| 335 post_load_hook=_WaitUntilSpyChaseReady), |
| 336 # Desktop only (requires Flash). Using "https://" causes |
| 337 # "404 Not Found" during WPR recording. |
| 338 _PageSpec( |
| 339 name='miniclip', |
| 340 url={'desktop': 'http://www.miniclip.com/games/en/'}), |
| 341 # Desktop only (requires Flash). |
| 342 _PageSpec( |
| 343 name='alphabetty', |
| 344 url={'desktop': 'https://king.com/play/alphabetty'}), |
| 345 ], |
| 346 } |
| 347 |
| 348 class MemoryTestPageSet(story.StorySet): |
| 349 |
| 350 PLATFORM = NotImplemented |
| 351 |
| 352 def __init__(self): |
| 353 super(MemoryTestPageSet, self).__init__() |
| 354 |
| 355 param = os.getenv("MEMORY_TEST_PARAM") |
| 356 name = os.getenv("MEMORY_TEST_NAME") |
| 357 |
| 358 for group_name, page_specs in iter(_SINGLE_PAGE_SPECS.items()): |
| 359 if param is not None and group_name != param: |
| 360 continue |
| 361 for page_spec in page_specs: |
| 362 if name is not None and page_spec.name != name: |
| 363 continue |
| 364 url = page_spec.url |
| 365 if isinstance(url, dict): |
| 366 url = url.get(self.PLATFORM) |
| 367 if url is None: |
| 368 continue # URL not supported on the platform. |
| 369 self.AddStory(MemoryTestPage(self, group_name, url, page_spec)) |
OLD | NEW |