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