Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2017 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. | |
| 4 | |
| 5 import json | |
| 6 import py_utils | |
| 7 import logging | |
| 8 | |
| 9 from telemetry.value import histogram_util | |
| 10 from page_sets.system_health import system_health_story | |
| 11 from page_sets.system_health import platforms | |
| 12 | |
| 13 | |
| 14 class _MultiTabStory(system_health_story.SystemHealthStory): | |
| 15 ABSTRACT_STORY = True | |
| 16 def __init__(self, story_set, take_memory_measurement): | |
| 17 self.URL = self.URL_LIST[0] | |
| 18 super(_MultiTabStory, self).__init__(story_set, take_memory_measurement) | |
| 19 self._tabs = None | |
| 20 self._prev_histogram = None | |
| 21 | |
| 22 @classmethod | |
| 23 def _GetTabSwitchHistogram(cls, tab_to_switch): | |
| 24 histogram_name = 'MPArch.RWH_TabSwitchPaintDuration' | |
| 25 histogram_type = histogram_util.BROWSER_HISTOGRAM | |
| 26 return histogram_util.GetHistogram( | |
| 27 histogram_type, histogram_name, tab_to_switch) | |
| 28 | |
| 29 def _WaitTabSwitchComplete(self, tab_to_switch): | |
| 30 def _IsDone(): | |
| 31 # pylint: disable=W0640 | |
|
eakuefner
2017/03/01 16:52:13
nit: please write out the name of the rule you're
vovoy
2017/03/02 09:30:27
Removed this function in the next patch.
| |
| 32 cur_histogram = self._GetTabSwitchHistogram(tab_to_switch) | |
| 33 diff_histogram = histogram_util.SubtractHistogram( | |
| 34 cur_histogram, self._prev_histogram) | |
| 35 # TODO(deanliao): Add SubtractHistogramRawValue to process histogram | |
| 36 # object instead of JSON string. | |
| 37 diff_histogram_count = json.loads(diff_histogram).get('count', 0) | |
| 38 return diff_histogram_count > 0 | |
| 39 py_utils.WaitFor(_IsDone, 30) | |
| 40 | |
| 41 # We need to get histogram again instead of getting cur_histogram as | |
| 42 # variables modified inside inner function cannot be retrieved. However, | |
| 43 # inner function can see external scope's variables. | |
| 44 self._prev_histogram = self._GetTabSwitchHistogram(tab_to_switch) | |
| 45 | |
| 46 def RunNavigateSteps(self, action_runner): | |
| 47 super(_MultiTabStory, self).RunNavigateSteps(action_runner) | |
| 48 | |
| 49 # create tabs | |
|
eakuefner
2017/03/01 16:52:13
nit: this comment seems unnecessary because it rep
vovoy
2017/03/02 09:30:27
Done.
| |
| 50 browser = action_runner.tab.browser | |
| 51 self._tabs = [action_runner.tab] | |
| 52 | |
| 53 for i in range(1, len(self.URL_LIST)): | |
| 54 new_tab = browser.tabs.New() | |
| 55 self._tabs.append(new_tab) | |
| 56 new_tab.action_runner.Navigate(self.URL_LIST[i]) | |
| 57 | |
| 58 for i in range(len(self.URL_LIST)): | |
| 59 try: | |
| 60 py_utils.WaitFor(self._tabs[i].HasReachedQuiescence, 15) | |
| 61 except py_utils.TimeoutException: | |
| 62 logging.warning('HasReachedQuiescence timeout, url[%d]: %s' | |
| 63 % (i, self.URL_LIST[i])) | |
| 64 | |
| 65 def RunPageInteractions(self, action_runner): | |
| 66 # get initial histogram | |
| 67 self._prev_histogram = self._GetTabSwitchHistogram(self._tabs[-1]) | |
| 68 | |
| 69 # tab switching | |
| 70 for i in range(len(self._tabs)): | |
| 71 self._tabs[i].Activate() | |
| 72 self._WaitTabSwitchComplete(self._tabs[i]) | |
| 73 | |
| 74 | |
| 75 class MultiTabTypical24Story(_MultiTabStory): | |
| 76 NAME = 'multitab:typical24:typical24' | |
| 77 URL_LIST = [ | |
| 78 # Why: Alexa games #48 | |
| 79 'http://www.nick.com/games', | |
| 80 # Why: Alexa sports #45 | |
| 81 'http://www.rei.com/', | |
| 82 # Why: Alexa sports #50 | |
| 83 'http://www.fifa.com/', | |
| 84 # Why: Alexa shopping #41 | |
| 85 'http://www.gamestop.com/ps3', | |
| 86 # Why: Alexa news #55 | |
| 87 ('http://www.economist.com/news/science-and-technology/21573529-small-' | |
| 88 'models-cosmic-phenomena-are-shedding-light-real-thing-how-build'), | |
| 89 # Why: Alexa news #67 | |
| 90 'http://www.theonion.com', | |
| 91 'http://arstechnica.com/', | |
| 92 # Why: Alexa home #10 | |
| 93 'http://allrecipes.com/Recipe/Pull-Apart-Hot-Cross-Buns/Detail.aspx', | |
| 94 'http://www.html5rocks.com/en/', | |
| 95 'http://www.mlb.com/', | |
| 96 'http://gawker.com/5939683/based-on-a-true-story-is-a-rotten-lie-i-hope-you- never-believe', | |
| 97 'http://www.imdb.com/title/tt0910970/', | |
| 98 'http://www.flickr.com/search/?q=monkeys&f=hp', | |
| 99 'http://money.cnn.com/', | |
| 100 'http://www.nationalgeographic.com/', | |
| 101 'http://premierleague.com', | |
| 102 'http://www.osubeavers.com/', | |
| 103 'http://walgreens.com', | |
| 104 'http://colorado.edu', | |
| 105 ('http://www.ticketmaster.com/JAY-Z-and-Justin-Timberlake-tickets/artist/' | |
| 106 '1837448?brand=none&tm_link=tm_homeA_rc_name2'), | |
| 107 # pylint: disable=line-too-long | |
| 108 'http://www.theverge.com/2013/3/5/4061684/inside-ted-the-smartest-bubble-in- the-world', | |
| 109 'http://www.airbnb.com/', | |
| 110 'http://www.ign.com/', | |
| 111 # Why: Alexa health #25 | |
| 112 'http://www.fda.gov', | |
| 113 ] | |
| 114 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 115 | |
| 116 class MultiTabFiveBlankPagesStory(_MultiTabStory): | |
| 117 NAME = 'multitab:blanks:blanks' | |
| 118 URL_LIST = [ | |
| 119 'about:blank', | |
| 120 'about:blank', | |
| 121 'about:blank', | |
| 122 'about:blank', | |
| 123 'about:blank', | |
| 124 ] | |
| 125 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 126 | |
| 127 | |
| 128 class MultiTabTop9Story(_MultiTabStory): | |
| 129 NAME = 'multitab:top9:top9' | |
| 130 URL_LIST = [ | |
| 131 'https://www.google.com/#hl=en&q=barack+obama', | |
| 132 'https://www.google.com/calendar/', | |
| 133 'http://www.youtube.com', | |
| 134 'https://www.facebook.com/barackobama', | |
| 135 'http://en.wikipedia.org/wiki/Wikipedia', | |
| 136 'http://www.amazon.com', | |
| 137 'http://www.yahoo.com/', | |
| 138 'http://www.bing.com/', | |
| 139 'http://www.ask.com/' | |
| 140 ] | |
| 141 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 142 | |
| 143 | |
| 144 class MultiTabToughImageCasesStory(_MultiTabStory): | |
| 145 NAME = 'multitab:toughimage:toughimage' | |
| 146 URL_LIST = [ | |
| 147 ('https://upload.wikimedia.org/wikipedia/commons/b/b3/' | |
| 148 'KC-130_performs_mid-air_refueling_over_Beaufort_150319-' | |
| 149 'M-ZZ999-306.jpg'), | |
| 150 ('http://upload.wikimedia.org/wikipedia/commons/c/cb/' | |
| 151 'General_history%2C_Alaska_Yukon_Pacific_Exposition%' | |
| 152 '2C_fully_illustrated_-_meet_me_in_Seattle_1909_-_Page_78.jpg') | |
| 153 ] | |
| 154 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 155 | |
| 156 | |
| 157 class MultiTabToughEnergyCasesStory(_MultiTabStory): | |
| 158 NAME = 'multitab:toughenergy:toughenergy' | |
| 159 URL_LIST = [ | |
| 160 'http://codepen.io/testificate364/full/nrbDc', | |
| 161 'http://codepen.io/testificate364/full/fhKCg', | |
| 162 'http://codepen.io/testificate364/full/paJhg', | |
| 163 'http://codepen.io/testificate364/full/yaosK', | |
| 164 'http://codepen.io/testificate364/full/DLbxg', | |
| 165 'http://codepen.io/testificate364/full/kFvpd', | |
| 166 'http://codepen.io/testificate364/full/lEhyw', | |
| 167 'http://codepen.io/testificate364/full/zhgBD', | |
| 168 'http://codepen.io/testificate364/full/jetyn', | |
| 169 'http://codepen.io/testificate364/full/Kvdxs', | |
| 170 'http://codepen.io/testificate364/full/lJAiH', | |
| 171 'http://codepen.io/testificate364/full/EFceH', | |
| 172 'http://codepen.io/testificate364/full/slBue', | |
| 173 'http://codepen.io/testificate364/full/HdIgr', | |
| 174 ] | |
| 175 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| OLD | NEW |