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