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 KeyMobileSitesPage(page_module.Page): 9 10 def __init__(self, url, page_set, name=''): 11 super(KeyMobileSitesPage, self).__init__(url=url, page_set=page_set, 12 name=name) 13 self.credentials_path = 'data/credentials.json' 14 self.user_agent_type = 'mobile' 15 self.archive_data_file = 'data/key_mobile_sites.json' 16 17 def RunSmoothness(self, action_runner): 18 interaction = action_runner.BeginGestureInteraction( 19 'ScrollAction', is_smooth=True) 20 action_runner.ScrollPage() 21 interaction.End() 22 23 def RunRepaint(self, action_runner): 24 action_runner.RepaintContinuously(seconds=5) 25 26 27class Page1(KeyMobileSitesPage): 28 29 """ Why: Top news site """ 30 31 def __init__(self, page_set): 32 super(Page1, self).__init__( 33 url='http://nytimes.com/', 34 page_set=page_set) 35 36 self.fastpath = True 37 38 39class Page2(KeyMobileSitesPage): 40 41 """ Why: Typical mobile business site """ 42 43 def __init__(self, page_set): 44 super(Page2, self).__init__( 45 url=('http://iphone.capitolvolkswagen.com/index.htm' 46 '#new-inventory_p_2Fsb-new_p_2Ehtm_p_3Freset_p_3DInventoryListing'), 47 page_set=page_set) 48 49 def RunNavigateSteps(self, action_runner): 50 action_runner.NavigateToPage(self) 51 action_runner.WaitForElement(text='Next 35') 52 action_runner.WaitForJavaScriptCondition( 53 'document.body.scrollHeight > 2560') 54 55 56class Page3(KeyMobileSitesPage): 57 58 """ Why: Image-heavy site """ 59 60 def __init__(self, page_set): 61 super(Page3, self).__init__( 62 url='http://cuteoverload.com', 63 page_set=page_set) 64 65 self.fastpath = True 66 67 68class Page4(KeyMobileSitesPage): 69 70 """ Why: Top tech blog """ 71 72 def __init__(self, page_set): 73 super(Page4, self).__init__( 74 # pylint: disable=C0301 75 url='http://www.theverge.com/2012/10/28/3568746/amazon-7-inch-fire-hd-ipad-mini-ad-ballsy', 76 page_set=page_set) 77 78 def RunNavigateSteps(self, action_runner): 79 action_runner.NavigateToPage(self) 80 action_runner.WaitForJavaScriptCondition( 81 'window.Chorus !== undefined &&' 82 'window.Chorus.Comments !== undefined &&' 83 'window.Chorus.Comments.Json !== undefined &&' 84 '(window.Chorus.Comments.loaded ||' 85 ' window.Chorus.Comments.Json.load_comments())') 86 87 88class Page5(KeyMobileSitesPage): 89 90 """ Why: Top news site """ 91 92 def __init__(self, page_set): 93 super(Page5, self).__init__( 94 # pylint: disable=C0301 95 url='http://www.cnn.com/2012/10/03/politics/michelle-obama-debate/index.html', 96 page_set=page_set) 97 98 def RunNavigateSteps(self, action_runner): 99 action_runner.NavigateToPage(self) 100 action_runner.Wait(8) 101 102 103class Page6(KeyMobileSitesPage): 104 105 """ Why: Social; top Google property; Public profile; infinite scrolls """ 106 107 def __init__(self, page_set): 108 super(Page6, self).__init__( 109 # pylint: disable=C0301 110 url='https://plus.google.com/app/basic/110031535020051778989/posts?source=apppromo', 111 page_set=page_set) 112 113 def RunSmoothness(self, action_runner): 114 interaction = action_runner.BeginGestureInteraction( 115 'ScrollAction', is_smooth=True) 116 action_runner.ScrollPage() 117 interaction.End() 118 119 120class Page7(KeyMobileSitesPage): 121 122 """ Why: #1 (Alexa global) """ 123 124 def __init__(self, page_set): 125 super(Page7, self).__init__( 126 url='https://facebook.com/barackobama', 127 page_set=page_set) 128 129 def RunNavigateSteps(self, action_runner): 130 action_runner.NavigateToPage(self) 131 action_runner.WaitForJavaScriptCondition( 132 'document.getElementById("u_0_c") !== null &&' 133 'document.body.scrollHeight > window.innerHeight') 134 135 136class Page8(KeyMobileSitesPage): 137 138 """ Why: #3 (Alexa global) """ 139 140 def __init__(self, page_set): 141 super(Page8, self).__init__( 142 url='http://m.youtube.com/watch?v=9hBpF_Zj4OA', 143 page_set=page_set) 144 145 def RunNavigateSteps(self, action_runner): 146 action_runner.NavigateToPage(self) 147 action_runner.WaitForJavaScriptCondition( 148 'document.getElementById("paginatortarget") !== null') 149 150 151class Page9(KeyMobileSitesPage): 152 153 """ 154 Why: #11 (Alexa global), google property; some blogger layouts have infinite 155 scroll but more interesting 156 """ 157 158 def __init__(self, page_set): 159 super(Page9, self).__init__( 160 url='http://googlewebmastercentral.blogspot.com/', 161 page_set=page_set, 162 name='Blogger') 163 164 165class Page10(KeyMobileSitesPage): 166 167 """ Why: #18 (Alexa global), Picked an interesting post """ 168 169 def __init__(self, page_set): 170 super(Page10, self).__init__( 171 # pylint: disable=C0301 172 url='http://en.blog.wordpress.com/2012/09/04/freshly-pressed-editors-picks-for-august-2012/', 173 page_set=page_set, 174 name='Wordpress') 175 176 177class Page11(KeyMobileSitesPage): 178 179 """ Why: #12 (Alexa global),Public profile """ 180 181 def __init__(self, page_set): 182 super(Page11, self).__init__( 183 url='https://www.linkedin.com/in/linustorvalds', 184 page_set=page_set, 185 name='LinkedIn') 186 187 def RunNavigateSteps(self, action_runner): 188 action_runner.NavigateToPage(self) 189 action_runner.WaitForJavaScriptCondition( 190 'document.getElementById("profile-view-scroller") !== null') 191 192 193class Page12(KeyMobileSitesPage): 194 195 """ Why: #6 (Alexa) most visited worldwide, picked an interesting page """ 196 197 def __init__(self, page_set): 198 super(Page12, self).__init__( 199 url='http://en.wikipedia.org/wiki/Wikipedia', 200 page_set=page_set, 201 name='Wikipedia (1 tab)') 202 203 204class Page13(KeyMobileSitesPage): 205 206 """ Why: #8 (Alexa global), picked an interesting page """ 207 208 def __init__(self, page_set): 209 super(Page13, self).__init__( 210 url='http://twitter.com/katyperry', 211 page_set=page_set, 212 name='Twitter') 213 self.disabled = 'Forbidden (Rate Limit Exceeded)' 214 215 216class Page14(KeyMobileSitesPage): 217 218 """ Why: #37 (Alexa global) """ 219 220 def __init__(self, page_set): 221 super(Page14, self).__init__( 222 url='http://pinterest.com', 223 page_set=page_set, 224 name='Pinterest') 225 226 227class Page15(KeyMobileSitesPage): 228 229 """ Why: #1 sports """ 230 231 def __init__(self, page_set): 232 super(Page15, self).__init__( 233 url='http://espn.go.com', 234 page_set=page_set, 235 name='ESPN') 236 self.disabled = 'Fails often; crbug.com/249722' 237 238 239class Page16(KeyMobileSitesPage): 240 241 """ Why: #1 Alexa reference """ 242 243 def __init__(self, page_set): 244 super(Page16, self).__init__( 245 # pylint: disable=C0301 246 url='http://answers.yahoo.com/question/index?qid=20110117024343AAopj8f', 247 page_set=page_set) 248 249 def RunNavigateSteps(self, action_runner): 250 action_runner.NavigateToPage(self) 251 action_runner.WaitForElement(text='Other Answers (1 - 20 of 149)') 252 action_runner.ClickElement(text='Other Answers (1 - 20 of 149)') 253 254 255class Page17(KeyMobileSitesPage): 256 257 """ Why: productivity, top google properties """ 258 259 def __init__(self, page_set): 260 super(Page17, self).__init__( 261 url='https://mail.google.com/mail/', 262 page_set=page_set) 263 264 self.credentials = 'google' 265 266 def RunNavigateSteps(self, action_runner): 267 action_runner.NavigateToPage(self) 268 action_runner.WaitForJavaScriptCondition( 269 'document.getElementById("og_user_warning") !== null') 270 action_runner.WaitForJavaScriptCondition( 271 'document.getElementById("og_user_warning") === null') 272 273 def RunSmoothness(self, action_runner): 274 interaction = action_runner.BeginGestureInteraction( 275 'ScrollAction', is_smooth=True) 276 action_runner.ScrollElement(element_function=( 277 'document.getElementById("views").childNodes[1].firstChild')) 278 interaction.End() 279 interaction = action_runner.BeginGestureInteraction( 280 'ScrollAction', is_smooth=True) 281 action_runner.ScrollElement(element_function=( 282 'document.getElementById("views").childNodes[1].firstChild')) 283 interaction.End() 284 285 286class Page18(KeyMobileSitesPage): 287 288 """ Why: crbug.com/169827 """ 289 290 def __init__(self, page_set): 291 super(Page18, self).__init__( 292 url='http://slashdot.org/', 293 page_set=page_set) 294 295 self.fastpath = True 296 297 298class Page19(KeyMobileSitesPage): 299 300 """ Why: #5 Alexa news """ 301 302 def __init__(self, page_set): 303 super(Page19, self).__init__( 304 url='http://www.reddit.com/r/programming/comments/1g96ve', 305 page_set=page_set) 306 307 self.fastpath = True 308 309 310class Page20(KeyMobileSitesPage): 311 312 """ Why: Problematic use of fixed position elements """ 313 314 def __init__(self, page_set): 315 super(Page20, self).__init__( 316 url='http://www.boingboing.net', 317 page_set=page_set) 318 319 self.fastpath = True 320 321 322class Page21(KeyMobileSitesPage): 323 324 """ Why: crbug.com/172906 """ 325 326 def __init__(self, page_set): 327 super(Page21, self).__init__( 328 url='http://groupcloned.com', 329 page_set=page_set) 330 331 self.disabled = ('Page behaves non-deterministically, replaced with test' 332 'version for now') 333 334 def RunNavigateSteps(self, action_runner): 335 action_runner.NavigateToPage(self) 336 action_runner.Wait(5) 337 action_runner.WaitForJavaScriptCondition(''' 338 document.getElementById("element-19") !== null && 339 document.getElementById("element-19").contentDocument 340 .getElementById("element-22") !== null && 341 document.getElementById("element-19").contentDocument 342 .getElementsByClassName( 343 "container list-item gc-list-item stretched").length !== 0''') 344 345 def RunSmoothness(self, action_runner): 346 interaction = action_runner.BeginGestureInteraction( 347 'ScrollAction', is_smooth=True) 348 action_runner.ScrollPage( 349 distance_expr=''' 350 Math.max(0, 1250 + document.getElementById("element-19") 351 .contentDocument 352 .getElementById("element-22") 353 .getBoundingClientRect().top);''', 354 use_touch=True) 355 interaction.End() 356 357 358class Page22(KeyMobileSitesPage): 359 360 """ Why: crbug.com/172906 """ 361 362 def __init__(self, page_set): 363 super(Page22, self).__init__( 364 url='http://groupcloned.com/test/list-images-variable/index.html', 365 page_set=page_set) 366 367 def RunNavigateSteps(self, action_runner): 368 action_runner.NavigateToPage(self) 369 action_runner.WaitForJavaScriptCondition( 370 'document.getElementById("element-5") !== null') 371 372 def RunSmoothness(self, action_runner): 373 interaction = action_runner.BeginGestureInteraction( 374 'ScrollAction', is_smooth=True) 375 action_runner.ScrollPage( 376 distance_expr=''' 377 Math.max(0, 1250 + 378 document.getElementById("element-5") 379 .getBoundingClientRect().top);''', 380 use_touch=True) 381 interaction.End() 382 383 384class Page23(KeyMobileSitesPage): 385 386 """ Why: crbug.com/231413 """ 387 388 def __init__(self, page_set): 389 super(Page23, self).__init__( 390 url='http://forecast.io', 391 page_set=page_set) 392 393 self.disabled = u"Doesn't scroll; crbug.com/249736" 394 395 396class Page24(KeyMobileSitesPage): 397 398 """ Why: Google News: accelerated scrolling version """ 399 400 def __init__(self, page_set): 401 super(Page24, self).__init__( 402 url='http://mobile-news.sandbox.google.com/news/pt1', 403 page_set=page_set) 404 405 def RunNavigateSteps(self, action_runner): 406 action_runner.NavigateToPage(self) 407 action_runner.WaitForJavaScriptCondition( 408 'typeof NEWS_telemetryReady !== "undefined" && ' 409 'NEWS_telemetryReady == true') 410 411 412class Page25(KeyMobileSitesPage): 413 414 """ 415 Why: Google News: this iOS version is slower than accelerated scrolling 416 """ 417 418 def __init__(self, page_set): 419 super(Page25, self).__init__( 420 url='http://mobile-news.sandbox.google.com/news/pt0', 421 page_set=page_set) 422 423 def RunNavigateSteps(self, action_runner): 424 action_runner.NavigateToPage(self) 425 action_runner.WaitForJavaScriptCondition( 426 'document.getElementById(":h") != null') 427 action_runner.Wait(1) 428 429 def RunSmoothness(self, action_runner): 430 interaction = action_runner.BeginGestureInteraction( 431 'ScrollAction', is_smooth=True) 432 action_runner.ScrollElement( 433 element_function='document.getElementById(":5")', 434 distance_expr=''' 435 Math.max(0, 2500 + 436 document.getElementById(':h').getBoundingClientRect().top)''', 437 use_touch=True) 438 interaction.End() 439 440 441class Page26(KeyMobileSitesPage): 442 443 """ 444 Why: #1 world commerce website by visits; #3 commerce in the US by time spent 445 """ 446 447 def __init__(self, page_set): 448 super(Page26, self).__init__( 449 url='http://www.amazon.com/gp/aw/s/ref=is_box_?k=nicolas+cage', 450 page_set=page_set) 451 452 def RunSmoothness(self, action_runner): 453 interaction = action_runner.BeginGestureInteraction( 454 'ScrollAction', is_smooth=True) 455 action_runner.ScrollElement( 456 selector='#search', 457 distance_expr='document.body.scrollHeight - window.innerHeight') 458 interaction.End() 459 460 461class KeyMobileSitesPageSet(page_set_module.PageSet): 462 463 """ Key mobile sites """ 464 465 def __init__(self): 466 super(KeyMobileSitesPageSet, self).__init__( 467 credentials_path='data/credentials.json', 468 user_agent_type='mobile', 469 archive_data_file='data/key_mobile_sites.json', 470 bucket=page_set_module.PARTNER_BUCKET) 471 472 self.AddPage(Page1(self)) 473 self.AddPage(Page2(self)) 474 self.AddPage(Page3(self)) 475 self.AddPage(Page4(self)) 476 self.AddPage(Page5(self)) 477 self.AddPage(Page6(self)) 478 self.AddPage(Page7(self)) 479 self.AddPage(Page8(self)) 480 self.AddPage(Page9(self)) 481 self.AddPage(Page10(self)) 482 self.AddPage(Page11(self)) 483 self.AddPage(Page12(self)) 484# self.AddPage(Page13(self)) 485 self.AddPage(Page14(self)) 486# self.AddPage(Page15(self)) 487 self.AddPage(Page16(self)) 488 self.AddPage(Page17(self)) 489 self.AddPage(Page18(self)) 490 self.AddPage(Page19(self)) 491 self.AddPage(Page20(self)) 492 self.AddPage(Page21(self)) 493 self.AddPage(Page22(self)) 494# self.AddPage(Page23(self)) 495 self.AddPage(Page24(self)) 496 self.AddPage(Page25(self)) 497 self.AddPage(Page26(self)) 498 499 urls_list = [ 500 # Why: crbug.com/242544 501 ('http://www.androidpolice.com/2012/10/03/rumor-evidence-mounts-that-an-' 502 'lg-optimus-g-nexus-is-coming-along-with-a-nexus-phone-certification-' 503 'program/'), 504 # Why: crbug.com/149958 505 'http://gsp.ro', 506 # Why: Top tech blog 507 'http://theverge.com', 508 # Why: Top tech site 509 'http://digg.com', 510 # Why: Top Google property; a Google tab is often open 511 'https://www.google.com/#hl=en&q=barack+obama', 512 # Why: #1 news worldwide (Alexa global) 513 'http://news.yahoo.com', 514 # Why: #2 news worldwide 515 'http://www.cnn.com', 516 # Why: #1 commerce website by time spent by users in US 517 'http://shop.mobileweb.ebay.com/searchresults?kw=viking+helmet', 518 # Why: #1 Alexa recreation 519 # pylint: disable=C0301 520 'http://www.booking.com/searchresults.html?src=searchresults&latitude=65.0500&longitude=25.4667', 521 # Why: #1 Alexa sports 522 'http://sports.yahoo.com/', 523 # Why: Top tech blog 524 'http://techcrunch.com', 525 # Why: #6 Alexa sports 526 'http://mlb.com/', 527 # Why: #14 Alexa California 528 'http://www.sfgate.com/', 529 # Why: Non-latin character set 530 'http://worldjournal.com/', 531 # Why: Mobile wiki 532 'http://www.wowwiki.com/World_of_Warcraft:_Mists_of_Pandaria', 533 # Why: #15 Alexa news 534 'http://online.wsj.com/home-page', 535 # Why: Image-heavy mobile site 536 'http://www.deviantart.com/', 537 # Why: Top search engine 538 ('http://www.baidu.com/s?wd=barack+obama&rsv_bp=0&rsv_spt=3&rsv_sug3=9&' 539 'rsv_sug=0&rsv_sug4=3824&rsv_sug1=3&inputT=4920'), 540 # Why: Top search engine 541 'http://www.bing.com/search?q=sloths', 542 # Why: Good example of poor initial scrolling 543 'http://ftw.usatoday.com/2014/05/spelling-bee-rules-shenanigans' 544 ] 545 546 for url in urls_list: 547 self.AddPage(KeyMobileSitesPage(url, self)) 548