| Index: tools/perf/contrib/cros_benchmarks/tab_switching_stories.py
|
| diff --git a/tools/perf/contrib/cros_benchmarks/tab_switching_stories.py b/tools/perf/contrib/cros_benchmarks/tab_switching_stories.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6712381d5da1d31df45700a4fa15ba4c892e7647
|
| --- /dev/null
|
| +++ b/tools/perf/contrib/cros_benchmarks/tab_switching_stories.py
|
| @@ -0,0 +1,116 @@
|
| +# Copyright 2017 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import py_utils
|
| +import logging
|
| +
|
| +from telemetry.core import exceptions
|
| +from telemetry.page import page as page_module
|
| +from telemetry.page import shared_page_state
|
| +from contrib.cros_benchmarks import cros_utils
|
| +
|
| +
|
| +class CrosMultiTabSharedState(shared_page_state.SharedPageState):
|
| + def __init__(self, test, finder_options, story_set):
|
| + super(CrosMultiTabSharedState, self).__init__(test,finder_options,
|
| + story_set)
|
| + cros_utils.SetupKeyDispatch(finder_options.cros_remote)
|
| +
|
| +
|
| +# NOTE: When tab count is high, some tabs may be discarded, and the tab
|
| +# context would be invalidated. Avoid storing tab object for later use.
|
| +class CrosMultiTabStory(page_module.Page):
|
| + def __init__(self, story_set, tabset_repeat=1):
|
| + super(CrosMultiTabStory, self).__init__(
|
| + shared_page_state_class=CrosMultiTabSharedState, page_set=story_set,
|
| + name=self.NAME, url=self.URL)
|
| + self._tabset_repeat = tabset_repeat
|
| +
|
| + def RunNavigateSteps(self, action_runner):
|
| + """Opening tabs and waiting for them to load."""
|
| + # As this story may run for a long time, adjusting screen off time to
|
| + # avoid screen off.
|
| + # pylint: disable=protected-access
|
| + cros_utils.NoScreenOff(action_runner.tab.browser._platform_backend)
|
| +
|
| + tabs = action_runner.tab.browser.tabs
|
| +
|
| + # No need to create the first tab as there is already one
|
| + # when the browser is ready.
|
| + url_list = self.URL_LIST * self._tabset_repeat
|
| + if url_list:
|
| + action_runner.Navigate(url_list[0])
|
| + for i, url in enumerate(url_list[1:]):
|
| + new_tab = tabs.New()
|
| + new_tab.action_runner.Navigate(url)
|
| + if i % 10 == 0:
|
| + print 'opening tab:', i
|
| +
|
| + # Waiting for every tabs to be stable.
|
| + for i, url in enumerate(url_list):
|
| + try:
|
| + tabs[i].action_runner.WaitForNetworkQuiescence()
|
| + except py_utils.TimeoutException:
|
| + logging.info('WaitForNetworkQuiescence() timeout, url[%d]: %s'
|
| + % (i, url))
|
| + except exceptions.DevtoolsTargetCrashException:
|
| + logging.info('RunNavigateSteps: devtools context lost')
|
| +
|
| + def RunPageInteractions(self, action_runner):
|
| + """Tab switching to each tabs."""
|
| + url_list = self.URL_LIST * self._tabset_repeat
|
| + browser = action_runner.tab.browser
|
| +
|
| + total_tab_count = len(url_list)
|
| + live_tab_count = len(browser.tabs)
|
| + if live_tab_count != total_tab_count:
|
| + logging.warning('live tab: %d, tab discarded: %d',
|
| + live_tab_count, total_tab_count - live_tab_count)
|
| +
|
| + for i in range(total_tab_count):
|
| + cros_utils.SwitchTab(browser)
|
| + if i % 10 == 0:
|
| + print 'switching tab:', i
|
| +
|
| +
|
| +class CrosMultiTabTypical24Story(CrosMultiTabStory):
|
| + NAME = 'cros_tab_switching_typical24'
|
| + URL_LIST = [
|
| + # Why: Alexa games #48
|
| + 'http://www.nick.com/games',
|
| + # Why: Alexa sports #45
|
| + 'http://www.rei.com/',
|
| + # Why: Alexa sports #50
|
| + 'http://www.fifa.com/',
|
| + # Why: Alexa shopping #41
|
| + 'http://www.gamestop.com/ps3',
|
| + # Why: Alexa news #55
|
| + ('http://www.economist.com/news/science-and-technology/21573529-small-'
|
| + 'models-cosmic-phenomena-are-shedding-light-real-thing-how-build'),
|
| + # Why: Alexa news #67
|
| + 'http://www.theonion.com',
|
| + 'http://arstechnica.com/',
|
| + # Why: Alexa home #10
|
| + 'http://allrecipes.com/Recipe/Pull-Apart-Hot-Cross-Buns/Detail.aspx',
|
| + 'http://www.html5rocks.com/en/',
|
| + 'http://www.mlb.com/',
|
| + 'http://gawker.com/5939683/based-on-a-true-story-is-a-rotten-lie-i-hope-you-never-believe',
|
| + 'http://www.imdb.com/title/tt0910970/',
|
| + 'http://www.flickr.com/search/?q=monkeys&f=hp',
|
| + 'http://money.cnn.com/',
|
| + 'http://www.nationalgeographic.com/',
|
| + 'http://premierleague.com',
|
| + 'http://www.osubeavers.com/',
|
| + 'http://walgreens.com',
|
| + 'http://colorado.edu',
|
| + ('http://www.ticketmaster.com/JAY-Z-and-Justin-Timberlake-tickets/artist/'
|
| + '1837448?brand=none&tm_link=tm_homeA_rc_name2'),
|
| + # pylint: disable=line-too-long
|
| + 'http://www.theverge.com/2013/3/5/4061684/inside-ted-the-smartest-bubble-in-the-world',
|
| + 'http://www.airbnb.com/',
|
| + 'http://www.ign.com/',
|
| + # Why: Alexa health #25
|
| + 'http://www.fda.gov',
|
| + ]
|
| + URL = URL_LIST[0]
|
|
|