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. 4from telemetry.page import page as page_module 5from telemetry.page import page_set as page_set_module 6 7 8class ToughPinchZoomCasesPage(page_module.Page): 9 10 def __init__(self, url, page_set, name=''): 11 super(ToughPinchZoomCasesPage, self).__init__(url=url, page_set=page_set, 12 name=name) 13 self.credentials_path = 'data/credentials.json' 14 self.user_agent_type = 'desktop' 15 self.archive_data_file = 'data/tough_pinch_zoom_cases.json' 16 17 def RunSmoothness(self, action_runner): 18 interaction = action_runner.BeginGestureInteraction( 19 'PinchAction', is_smooth=True) 20 action_runner.PinchPage() 21 interaction.End() 22 23 24class GoogleSearchPage(ToughPinchZoomCasesPage): 25 26 """ Why: top google property; a google tab is often open. """ 27 28 def __init__(self, page_set): 29 super(GoogleSearchPage, self).__init__( 30 url='https://www.google.com/#hl=en&q=barack+obama', 31 page_set=page_set) 32 33 def RunNavigateSteps(self, action_runner): 34 action_runner.NavigateToPage(self) 35 action_runner.WaitForElement(text='Next') 36 37 38class GmailPage(ToughPinchZoomCasesPage): 39 40 """ Why: productivity, top google properties """ 41 42 def __init__(self, page_set): 43 super(GmailPage, self).__init__( 44 url='https://mail.google.com/mail/', 45 page_set=page_set) 46 47 self.credentials = 'google' 48 49 def RunNavigateSteps(self, action_runner): 50 action_runner.NavigateToPage(self) 51 action_runner.WaitForJavaScriptCondition( 52 'window.gmonkey !== undefined &&' 53 'document.getElementById("gb") !== null') 54 55 56class GoogleCalendarPage(ToughPinchZoomCasesPage): 57 58 """ Why: productivity, top google properties """ 59 60 def __init__(self, page_set): 61 super(GoogleCalendarPage, self).__init__( 62 url='https://www.google.com/calendar/', 63 page_set=page_set) 64 65 self.credentials = 'google' 66 67 def RunNavigateSteps(self, action_runner): 68 action_runner.NavigateToPage(self) 69 action_runner.Wait(2) 70 71 def RunSmoothness(self, action_runner): 72 interaction = action_runner.BeginGestureInteraction( 73 'PinchAction', is_smooth=True) 74 action_runner.PinchPage(left_anchor_ratio=0.1, top_anchor_ratio=0.3) 75 interaction.End() 76 77 78class GoogleImageSearchPage(ToughPinchZoomCasesPage): 79 80 """ Why: tough image case; top google properties """ 81 82 def __init__(self, page_set): 83 super(GoogleImageSearchPage, self).__init__( 84 url='https://www.google.com/search?q=cats&tbm=isch', 85 page_set=page_set) 86 87 self.credentials = 'google' 88 89 90class GooglePlusPage(ToughPinchZoomCasesPage): 91 92 """ Why: social; top google property; Public profile; infinite scrolls """ 93 94 def __init__(self, page_set): 95 super(GooglePlusPage, self).__init__( 96 url='https://plus.google.com/+BarackObama/posts', 97 page_set=page_set) 98 99 self.credentials = 'google' 100 101 def RunNavigateSteps(self, action_runner): 102 action_runner.NavigateToPage(self) 103 action_runner.WaitForElement(text='Home') 104 105 def RunSmoothness(self, action_runner): 106 interaction = action_runner.BeginGestureInteraction( 107 'PinchAction', is_smooth=True) 108 action_runner.PinchElement(selector='[id="110031535020051778989-tab-bar"]') 109 interaction.End() 110 111 112class YoutubePage(ToughPinchZoomCasesPage): 113 114 """ Why: #3 (Alexa global) """ 115 116 def __init__(self, page_set): 117 super(YoutubePage, self).__init__( 118 url='http://www.youtube.com', 119 page_set=page_set) 120 121 self.credentials = 'google' 122 123 def RunNavigateSteps(self, action_runner): 124 action_runner.NavigateToPage(self) 125 action_runner.Wait(2) 126 127class BlogSpotPage(ToughPinchZoomCasesPage): 128 129 """ 130 Why: #11 (Alexa global), google property; some blogger layouts have infinite 131 scroll but more interesting 132 """ 133 134 def __init__(self, page_set): 135 super(BlogSpotPage, self).__init__( 136 url='http://googlewebmastercentral.blogspot.com/', 137 page_set=page_set, name='Blogger') 138 139 def RunNavigateSteps(self, action_runner): 140 action_runner.NavigateToPage(self) 141 action_runner.WaitForElement(text='accessibility') 142 143 144class FacebookPage(ToughPinchZoomCasesPage): 145 146 """ Why: top social,Public profile """ 147 148 def __init__(self, page_set): 149 super(FacebookPage, self).__init__( 150 url='http://www.facebook.com/barackobama', 151 page_set=page_set, name='Facebook') 152 self.credentials = 'facebook' 153 154 def RunNavigateSteps(self, action_runner): 155 action_runner.NavigateToPage(self) 156 action_runner.WaitForElement(text='About') 157 158 159class LinkedinPage(ToughPinchZoomCasesPage): 160 161 """ Why: #12 (Alexa global),Public profile """ 162 163 def __init__(self, page_set): 164 super(LinkedinPage, self).__init__( 165 url='http://www.linkedin.com/in/linustorvalds', 166 page_set=page_set, name='LinkedIn') 167 168 169class WikipediaPage(ToughPinchZoomCasesPage): 170 171 """ Why: #6 (Alexa) most visited worldwide,Picked an interesting page """ 172 173 def __init__(self, page_set): 174 super(WikipediaPage, self).__init__( 175 url='http://en.wikipedia.org/wiki/Wikipedia', 176 page_set=page_set, name='Wikipedia (1 tab)') 177 178 179class TwitterPage(ToughPinchZoomCasesPage): 180 181 """ Why: #8 (Alexa global),Picked an interesting page """ 182 183 def __init__(self, page_set): 184 super(TwitterPage, self).__init__( 185 url='https://twitter.com/katyperry', 186 page_set=page_set, name='Twitter') 187 188 def RunNavigateSteps(self, action_runner): 189 action_runner.NavigateToPage(self) 190 action_runner.Wait(2) 191 192class ESPNPage(ToughPinchZoomCasesPage): 193 194 """ Why: #1 sports """ 195 196 def __init__(self, page_set): 197 super(ESPNPage, self).__init__( 198 url='http://espn.go.com/nba', 199 page_set=page_set, name='ESPN') 200 201 202class WeatherDotComPage(ToughPinchZoomCasesPage): 203 204 """ Why: #7 (Alexa news); #27 total time spent,Picked interesting page """ 205 206 def __init__(self, page_set): 207 super(WeatherDotComPage, self).__init__( 208 # pylint: disable=C0301 209 url='http://www.weather.com/weather/right-now/Mountain+View+CA+94043', 210 page_set=page_set, name='Weather.com') 211 212 213class YahooGamePage(ToughPinchZoomCasesPage): 214 215 """ Why: #1 games according to Alexa (with actual games in it) """ 216 217 def __init__(self, page_set): 218 super(YahooGamePage, self).__init__( 219 url='http://games.yahoo.com', 220 page_set=page_set) 221 222 def RunNavigateSteps(self, action_runner): 223 action_runner.NavigateToPage(self) 224 action_runner.Wait(2) 225 226 227class YahooAnswersPage(ToughPinchZoomCasesPage): 228 229 """ Why: #1 Alexa reference """ 230 231 def __init__(self, page_set): 232 super(YahooAnswersPage, self).__init__( 233 url='http://answers.yahoo.com', 234 page_set=page_set) 235 236 def RunSmoothness(self, action_runner): 237 interaction = action_runner.BeginGestureInteraction( 238 'PinchAction', is_smooth=True) 239 action_runner.PinchElement(selector='#ya-content-apps') 240 interaction.End() 241 242 243class ToughPinchZoomCasesPageSet(page_set_module.PageSet): 244 245 """ Set of pages that are tricky to pinch-zoom """ 246 247 def __init__(self): 248 super(ToughPinchZoomCasesPageSet, self).__init__( 249 credentials_path='data/credentials.json', 250 user_agent_type='desktop', 251 archive_data_file='data/tough_pinch_zoom_cases.json', 252 bucket=page_set_module.PARTNER_BUCKET) 253 254 self.AddPage(GoogleSearchPage(self)) 255 self.AddPage(GmailPage(self)) 256 self.AddPage(GoogleCalendarPage(self)) 257 self.AddPage(GoogleImageSearchPage(self)) 258 self.AddPage(GooglePlusPage(self)) 259 self.AddPage(YoutubePage(self)) 260 self.AddPage(BlogSpotPage(self)) 261 self.AddPage(FacebookPage(self)) 262 self.AddPage(LinkedinPage(self)) 263 self.AddPage(WikipediaPage(self)) 264 self.AddPage(TwitterPage(self)) 265 self.AddPage(ESPNPage(self)) 266 267 # Why: #1 news worldwide (Alexa global) 268 self.AddPage(ToughPinchZoomCasesPage('http://news.yahoo.com', self)) 269 270 # Why: #2 news worldwide 271 self.AddPage(ToughPinchZoomCasesPage('http://www.cnn.com', self)) 272 273 self.AddPage(WeatherDotComPage(self)) 274 275 # Why: #1 world commerce website by visits; #3 commerce in the US by time 276 # spent 277 self.AddPage(ToughPinchZoomCasesPage('http://www.amazon.com', self)) 278 279 # Why: #1 commerce website by time spent by users in US 280 self.AddPage(ToughPinchZoomCasesPage('http://www.ebay.com', self)) 281 282 self.AddPage(YahooGamePage(self)) 283 284 # Why: #1 Alexa recreation 285 self.AddPage(ToughPinchZoomCasesPage('http://booking.com', self)) 286 287 self.AddPage(YahooAnswersPage(self)) 288 289 # Why: #1 Alexa sports 290 self.AddPage(ToughPinchZoomCasesPage('http://sports.yahoo.com/', self)) 291