1# Copyright 2024 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from __future__ import annotations 6 7import datetime as dt 8from typing import TYPE_CHECKING, Dict, Tuple 9 10from crossbench.action_runner.action.get import GetAction 11from crossbench.benchmarks.loading.config.blocks import ActionBlock 12from crossbench.benchmarks.loading.page.base import DEFAULT_DURATION, PAGE_LIST 13from crossbench.benchmarks.loading.page.interactive import InteractivePage 14from crossbench.benchmarks.loading.playback_controller import \ 15 PlaybackController 16from crossbench.benchmarks.loading.tab_controller import TabController 17 18if TYPE_CHECKING: 19 from crossbench.types import JsonDict 20 21 22class LivePage(InteractivePage): 23 24 @classmethod 25 def all_story_names(cls) -> Tuple[str, ...]: 26 return tuple(page.name for page in PAGE_LIST) 27 28 def __init__( 29 self, 30 name: str, 31 url: str, 32 duration: dt.timedelta = DEFAULT_DURATION, 33 playback: PlaybackController = PlaybackController.default(), 34 tabs: TabController = TabController.default(), 35 about_blank_duration: dt.timedelta = dt.timedelta() 36 ) -> None: 37 assert url, "Invalid page url" 38 self.url: str = url 39 blocks = (ActionBlock(actions=(GetAction(self.url, duration),)),) 40 super().__init__( 41 name, 42 blocks=blocks, 43 playback=playback, 44 tabs=tabs, 45 about_blank_duration=about_blank_duration) 46 47 def details_json(self) -> JsonDict: 48 result = super().details_json() 49 result["url"] = str(self.url) 50 return result 51 52 @property 53 def first_url(self) -> str: 54 return self.url 55 56 def __str__(self) -> str: 57 return f"Page(name={self.name}, url={self.url})" 58 59 60LIVE_PAGES = ((LivePage("blank", "about:blank", dt.timedelta(seconds=1)), 61 LivePage("amazon", "https://www.amazon.de/s?k=heizkissen", 62 dt.timedelta(seconds=5)), 63 LivePage("bing", 64 "https://www.bing.com/images/search?q=not+a+squirrel", 65 dt.timedelta(seconds=5)), 66 LivePage("caf", "http://www.caf.fr", dt.timedelta(seconds=6)), 67 LivePage("cnn", "https://cnn.com/", dt.timedelta(seconds=7)), 68 LivePage("ecma262", 69 "https://tc39.es/ecma262/#sec-numbers-and-dates", 70 dt.timedelta(seconds=10)), 71 LivePage("expedia", "https://www.expedia.com/", 72 dt.timedelta(seconds=7)), 73 LivePage("facebook", "https://facebook.com/shakira", 74 dt.timedelta(seconds=8)), 75 LivePage("maps", "https://goo.gl/maps/TEZde4y4Hc6r2oNN8", 76 dt.timedelta(seconds=10)), 77 LivePage("microsoft", "https://microsoft.com/", 78 dt.timedelta(seconds=6)), 79 LivePage("provincial", "http://www.provincial.com", 80 dt.timedelta(seconds=6)), 81 LivePage("sueddeutsche", 82 "https://www.sueddeutsche.de/wirtschaft", 83 dt.timedelta(seconds=8)), 84 LivePage("theverge", "https://www.theverge.com/", 85 dt.timedelta(seconds=10)), 86 LivePage("timesofindia", "https://timesofindia.indiatimes.com/", 87 dt.timedelta(seconds=8)), 88 LivePage("twitter", "https://twitter.com/wernertwertzog?lang=en", 89 dt.timedelta(seconds=6)))) 90 91assert not PAGE_LIST, "PAGE_LIST was already initialized." 92PAGE_LIST.extend(LIVE_PAGES) 93 94PAGES: Dict[str, LivePage] = {page.name: page for page in LIVE_PAGES} 95PAGE_LIST_SMALL = (PAGES["facebook"], PAGES["maps"], PAGES["timesofindia"], 96 PAGES["cnn"]) 97