1# Copyright 2016 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 5from page_sets.login_helpers import google_login 6from page_sets.system_health import platforms 7from page_sets.system_health import story_tags 8from page_sets.system_health import system_health_story 9 10 11IDLE_TIME_IN_SECONDS = 100 12SAMPLING_INTERVAL_IN_SECONDS = 1 13STEPS = IDLE_TIME_IN_SECONDS / SAMPLING_INTERVAL_IN_SECONDS 14 15 16class _LongRunningStory(system_health_story.SystemHealthStory): 17 """Abstract base class for long running stories.""" 18 ABSTRACT_STORY = True 19 BACKGROUND = False 20 21 def RunPageInteractions(self, action_runner): 22 super(_LongRunningStory, self).RunPageInteractions(action_runner) 23 if self.BACKGROUND: 24 action_runner.tab.browser.tabs.New() 25 if self._take_memory_measurement: 26 action_runner.MeasureMemory() 27 for _ in xrange(STEPS): 28 action_runner.Wait(SAMPLING_INTERVAL_IN_SECONDS) 29 if self._take_memory_measurement: 30 action_runner.MeasureMemory() 31 32 @classmethod 33 def GenerateStoryDescription(cls): 34 if cls.BACKGROUND: 35 return ('Load %s then open a new blank tab and let the loaded page stay ' 36 'in background for %s seconds.' % (cls.URL, IDLE_TIME_IN_SECONDS)) 37 else: 38 return ('Load %s then let it stay in foreground for %s seconds.' % 39 (cls.URL, IDLE_TIME_IN_SECONDS)) 40 41 42############################################################################## 43# Long running Gmail stories. 44############################################################################## 45 46# TODO(rnephew): Merge _Login() and _DidLoadDocument() with methods in 47# loading_stories. 48class _LongRunningGmailBase(_LongRunningStory): 49 URL = 'https://mail.google.com/mail/' 50 ABSTRACT_STORY = True 51 52 def _Login(self, action_runner): 53 google_login.LoginGoogleAccount(action_runner, 'googletest') 54 55 # Navigating to https://mail.google.com immediately leads to an infinite 56 # redirection loop due to a bug in WPR (see 57 # https://github.com/chromium/web-page-replay/issues/70). We therefore first 58 # navigate to a sub-URL to set up the session and hit the resulting 59 # redirection loop. Afterwards, we can safely navigate to 60 # https://mail.google.com. 61 action_runner.Navigate( 62 'https://mail.google.com/mail/mu/mp/872/trigger_redirection_loop') 63 action_runner.tab.WaitForDocumentReadyStateToBeComplete() 64 65class _LongRunningGmailMobileBase(_LongRunningGmailBase): 66 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY 67 # TODO(crbug.com/862077): Story breaks if login is skipped during replay. 68 SKIP_LOGIN = False 69 70 def _DidLoadDocument(self, action_runner): 71 # Close the "Get Inbox by Gmail" interstitial. 72 action_runner.WaitForJavaScriptCondition( 73 'document.querySelector("#isppromo a") !== null') 74 action_runner.ExecuteJavaScript( 75 'document.querySelector("#isppromo a").click()') 76 # Wait until the UI loads. 77 action_runner.WaitForJavaScriptCondition( 78 'document.getElementById("apploadingdiv").style.height === "0px"') 79 80 81class _LongRunningGmailDesktopBase(_LongRunningGmailBase): 82 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY 83 84 def _DidLoadDocument(self, action_runner): 85 # Wait until the UI loads. 86 action_runner.WaitForJavaScriptCondition( 87 'document.getElementById("loading").style.display === "none"') 88 89 90class LongRunningGmailMobileForegroundStory(_LongRunningGmailMobileBase): 91 NAME = 'long_running:tools:gmail-foreground' 92 TAGS = [story_tags.YEAR_2016] 93 94 95class LongRunningGmailDesktopForegroundStory(_LongRunningGmailDesktopBase): 96 NAME = 'long_running:tools:gmail-foreground' 97 TAGS = [story_tags.HEALTH_CHECK, story_tags.YEAR_2016] 98 99 100class LongRunningGmailMobileBackgroundStory(_LongRunningGmailMobileBase): 101 BACKGROUND = True 102 NAME = 'long_running:tools:gmail-background' 103 TAGS = [story_tags.YEAR_2016] 104 # This runs a gmail story in a background tab, and tabs aren't supported 105 # on WebView. 106 WEBVIEW_NOT_SUPPORTED = True 107 108 109class LongRunningGmailDesktopBackgroundStory(_LongRunningGmailDesktopBase): 110 BACKGROUND = True 111 NAME = 'long_running:tools:gmail-background' 112 TAGS = [story_tags.YEAR_2016] 113