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..89e81fb59c9bc69401d588059e0aef77ee08a7d8 |
--- /dev/null |
+++ b/tools/perf/contrib/cros_benchmarks/tab_switching_stories.py |
@@ -0,0 +1,120 @@ |
+# 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 |
+ |
+ |
+# 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): |
+ """Base class for multi-tab stories.""" |
+ |
+ def __init__(self, story_set, cros_remote, tabset_repeat=1): |
+ super(CrosMultiTabStory, self).__init__( |
+ shared_page_state_class=shared_page_state.SharedPageState, |
+ page_set=story_set, name=self.NAME, url=self.URL) |
+ self._cros_remote = cros_remote |
+ self._tabset_repeat = tabset_repeat |
+ |
+ def RunNavigateSteps(self, action_runner): |
+ """Opening tabs and waiting for them to load.""" |
+ if not self._cros_remote: |
+ raise ValueError('Must specify --remote=DUT_IP to run this test.') |
+ |
+ # As this story may run for a long time, adjusting screen off time to |
+ # avoid screen off. |
+ cros_utils.NoScreenOff(self._cros_remote) |
+ |
+ 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) |
+ |
+ with cros_utils.KeyboardEmulator(self._cros_remote) as keyboard: |
+ for i in range(total_tab_count): |
+ prev_histogram = cros_utils.GetTabSwitchHistogramRetry(browser) |
+ keyboard.SwitchTab() |
+ cros_utils.WaitTabSwitching(browser, prev_histogram) |
+ |
+ if i % 10 == 0: |
+ print 'switching tab:', i |
+ |
+ |
+class CrosMultiTabTypical24Story(CrosMultiTabStory): |
+ """Multi-tab stories to test 24 typical webpages.""" |
+ 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] |