Index: tools/perf/page_sets/tab_switching_cases.py |
diff --git a/tools/perf/page_sets/tab_switching_cases.py b/tools/perf/page_sets/tab_switching_cases.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ae85ef09b640132f0278c17702b5bf1553356d98 |
--- /dev/null |
+++ b/tools/perf/page_sets/tab_switching_cases.py |
@@ -0,0 +1,194 @@ |
+# Copyright 2014 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 json |
+import py_utils |
+ |
+from telemetry.page import page as page_module |
+from telemetry.page import shared_page_state |
+from telemetry import story |
+from telemetry.value import histogram_util |
+ |
+ |
+class MultiTabStory(page_module.Page): |
+ def __init__(self, page_set, urls_list): |
+ super(MultiTabStory, self).__init__(url=urls_list[0], page_set=page_set, |
+ credentials_path='data/credentials.json', |
+ shared_page_state_class=shared_page_state.SharedDesktopPageState) |
+ self._urls = urls_list |
+ self._tabs = None |
+ self._prev_histogram = None |
+ |
+ @classmethod |
+ def _GetTabSwitchHistogram(cls, tab_to_switch): |
+ histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' |
+ histogram_type = histogram_util.BROWSER_HISTOGRAM |
+ return histogram_util.GetHistogram( |
+ histogram_type, histogram_name, tab_to_switch) |
+ |
+ def _WaitTabSwitchComplete(self, tab_to_switch): |
+ def _IsDone(): |
+ # pylint: disable=W0640 |
+ cur_histogram = self._GetTabSwitchHistogram(tab_to_switch) |
+ diff_histogram = histogram_util.SubtractHistogram( |
+ cur_histogram, self._prev_histogram) |
+ # TODO(deanliao): Add SubtractHistogramRawValue to process histogram |
+ # object instead of JSON string. |
+ diff_histogram_count = json.loads(diff_histogram).get('count', 0) |
+ return diff_histogram_count > 0 |
+ py_utils.WaitFor(_IsDone, 30) |
+ |
+ # We need to get histogram again instead of getting cur_histogram as |
+ # variables modified inside inner function cannot be retrieved. However, |
+ # inner function can see external scope's variables. |
+ self._prev_histogram = self._GetTabSwitchHistogram(tab_to_switch) |
+ |
+ def RunNavigateSteps(self, action_runner): |
+ super(MultiTabStory, self).RunNavigateSteps(action_runner) |
+ |
+ # create all tabs |
+ |
+ browser = action_runner.tab.browser |
+ # create tabs |
+ self._tabs = [action_runner.tab] |
+ |
+ for i in range(1, len(self._urls)): |
+ new_tab = browser.tabs.New() |
+ self._tabs.append(new_tab) |
+ new_tab.action_runner.Navigate(self._urls[i]) |
+ |
+ for i in range(len(self._urls)): |
+ py_utils.WaitFor(self._tabs[i].HasReachedQuiescence, 30) |
+ |
+ def RunPageInteractions(self, action_runner): |
+ # get initial histogram |
+ self._prev_histogram = self._GetTabSwitchHistogram(self._tabs[-1]) |
+ |
+ # tab switching |
+ for i in range(len(self._tabs)): |
+ self._tabs[i].Activate() |
+ self._WaitTabSwitchComplete(self._tabs[i]) |
+ |
+ |
+class MultiTabTypical24StorySet(story.StorySet): |
+ """ Pages designed to represent the median, not highly optimized web """ |
+ def __init__(self): |
+ super(MultiTabTypical24StorySet, self).__init__( |
+ archive_data_file='data/typical_25.json', |
+ cloud_storage_bucket=story.PARTNER_BUCKET) |
+ |
+ urls_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', |
+ ] |
+ self.AddStory(MultiTabStory(self, urls_list)) |
+ |
+ |
+class MultiTabFiveBlankPagesStorySet(story.StorySet): |
+ def __init__(self): |
+ super(MultiTabFiveBlankPagesStorySet, self).__init__() |
+ # archive_data_file='data/typical_25.json', |
+ # cloud_storage_bucket=story.PARTNER_BUCKET) |
+ |
+ urls_list = [ |
+ 'file://blank_page/blank_page.html', |
+ 'file://blank_page/blank_page.html', |
+ 'file://blank_page/blank_page.html', |
+ 'file://blank_page/blank_page.html', |
+ 'file://blank_page/blank_page.html', |
+ #'about:blank', |
+ ] |
+ self.AddStory(MultiTabStory(self, urls_list)) |
+ |
+ |
+class MultiTabTop10StorySet(story.StorySet): |
+ def __init__(self): |
+ super(MultiTabTop10StorySet, self).__init__( |
+ archive_data_file='data/top_10.json', |
+ cloud_storage_bucket=story.PARTNER_BUCKET) |
+ |
+ urls_list = [ |
+ 'https://www.google.com/#hl=en&q=barack+obama', |
+ #'https://mail.google.com/mail/', |
+ 'https://www.google.com/calendar/', |
+ 'http://www.youtube.com', |
+ 'https://www.facebook.com/barackobama', |
+ 'http://en.wikipedia.org/wiki/Wikipedia', |
+ 'http://www.amazon.com', |
+ 'http://www.yahoo.com/', |
+ 'http://www.bing.com/', |
+ 'http://www.ask.com/' |
+ ] |
+ self.AddStory(MultiTabStory(self, urls_list)) |
+ |
+ |
+class MultiTabToughImageCasesStorySet(story.StorySet): |
+ def __init__(self): |
+ super(MultiTabToughImageCasesStorySet, self).__init__() |
+ |
+ urls_list = [ |
+ 'http://www.free-pictures-photos.com/aviation/airplane-306.jpg', |
+ ('http://upload.wikimedia.org/wikipedia/commons/c/cb/' |
+ 'General_history%2C_Alaska_Yukon_Pacific_Exposition%' |
+ '2C_fully_illustrated_-_meet_me_in_Seattle_1909_-_Page_78.jpg') |
+ ] |
+ self.AddStory(MultiTabStory(self, urls_list)) |
+ |
+ |
+class MultiTabToughEnergyCasesStorySet(story.StorySet): |
+ def __init__(self): |
+ super(MultiTabToughEnergyCasesStorySet, self).__init__( |
+ archive_data_file='data/tough_energy_cases.json', |
+ cloud_storage_bucket=story.PARTNER_BUCKET) |
+ |
+ urls_list = [ |
+ 'http://codepen.io/testificate364/debug/nrbDc', |
+ 'http://codepen.io/testificate364/debug/fhKCg', |
+ 'http://codepen.io/testificate364/debug/paJhg', |
+ 'http://codepen.io/testificate364/debug/yaosK', |
+ 'http://codepen.io/testificate364/debug/DLbxg', |
+ 'http://codepen.io/testificate364/debug/kFvpd', |
+ 'http://codepen.io/testificate364/debug/lEhyw', |
+ 'http://codepen.io/testificate364/debug/zhgBD', |
+ 'http://codepen.io/testificate364/debug/jetyn', |
+ 'http://codepen.io/testificate364/debug/Kvdxs', |
+ 'http://codepen.io/testificate364/debug/lJAiH', |
+ 'http://codepen.io/testificate364/debug/EFceH', |
+ 'http://codepen.io/testificate364/debug/slBue', |
+ 'http://codepen.io/testificate364/debug/HdIgr', |
+ ] |
+ self.AddStory(MultiTabStory(self, urls_list)) |