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 py_utils |
| 6 import logging |
| 7 |
| 8 from telemetry.core import exceptions |
| 9 from telemetry.page import page as page_module |
| 10 from telemetry.page import shared_page_state |
| 11 from contrib.cros_benchmarks import cros_utils |
| 12 |
| 13 |
| 14 # NOTE: When tab count is high, some tabs may be discarded, and the tab |
| 15 # context would be invalidated. Avoid storing tab object for later use. |
| 16 class CrosMultiTabStory(page_module.Page): |
| 17 """Base class for multi-tab stories.""" |
| 18 |
| 19 def __init__(self, story_set, cros_remote, tabset_repeat=1): |
| 20 super(CrosMultiTabStory, self).__init__( |
| 21 shared_page_state_class=shared_page_state.SharedPageState, |
| 22 page_set=story_set, name=self.NAME, url=self.URL) |
| 23 self._cros_remote = cros_remote |
| 24 self._tabset_repeat = tabset_repeat |
| 25 |
| 26 def RunNavigateSteps(self, action_runner): |
| 27 """Opening tabs and waiting for them to load.""" |
| 28 if not self._cros_remote: |
| 29 raise ValueError('Must specify --remote=DUT_IP to run this test.') |
| 30 |
| 31 # As this story may run for a long time, adjusting screen off time to |
| 32 # avoid screen off. |
| 33 cros_utils.NoScreenOff(self._cros_remote) |
| 34 |
| 35 tabs = action_runner.tab.browser.tabs |
| 36 |
| 37 # No need to create the first tab as there is already one |
| 38 # when the browser is ready. |
| 39 url_list = self.URL_LIST * self._tabset_repeat |
| 40 if url_list: |
| 41 action_runner.Navigate(url_list[0]) |
| 42 for i, url in enumerate(url_list[1:]): |
| 43 new_tab = tabs.New() |
| 44 new_tab.action_runner.Navigate(url) |
| 45 if i % 10 == 0: |
| 46 print 'opening tab:', i |
| 47 |
| 48 # Waiting for every tabs to be stable. |
| 49 for i, url in enumerate(url_list): |
| 50 try: |
| 51 tabs[i].action_runner.WaitForNetworkQuiescence() |
| 52 except py_utils.TimeoutException: |
| 53 logging.info('WaitForNetworkQuiescence() timeout, url[%d]: %s', |
| 54 i, url) |
| 55 except exceptions.DevtoolsTargetCrashException: |
| 56 logging.info('RunNavigateSteps: devtools context lost') |
| 57 |
| 58 def RunPageInteractions(self, action_runner): |
| 59 """Tab switching to each tabs.""" |
| 60 url_list = self.URL_LIST * self._tabset_repeat |
| 61 browser = action_runner.tab.browser |
| 62 |
| 63 total_tab_count = len(url_list) |
| 64 live_tab_count = len(browser.tabs) |
| 65 if live_tab_count != total_tab_count: |
| 66 logging.warning('live tab: %d, tab discarded: %d', |
| 67 live_tab_count, total_tab_count - live_tab_count) |
| 68 |
| 69 with cros_utils.KeyboardEmulator(self._cros_remote) as keyboard: |
| 70 for i in range(total_tab_count): |
| 71 prev_histogram = cros_utils.GetTabSwitchHistogramRetry(browser) |
| 72 keyboard.SwitchTab() |
| 73 cros_utils.WaitTabSwitching(browser, prev_histogram) |
| 74 |
| 75 if i % 10 == 0: |
| 76 print 'switching tab:', i |
| 77 |
| 78 |
| 79 class CrosMultiTabTypical24Story(CrosMultiTabStory): |
| 80 """Multi-tab stories to test 24 typical webpages.""" |
| 81 NAME = 'cros_tab_switching_typical24' |
| 82 URL_LIST = [ |
| 83 # Why: Alexa games #48 |
| 84 'http://www.nick.com/games', |
| 85 # Why: Alexa sports #45 |
| 86 'http://www.rei.com/', |
| 87 # Why: Alexa sports #50 |
| 88 'http://www.fifa.com/', |
| 89 # Why: Alexa shopping #41 |
| 90 'http://www.gamestop.com/ps3', |
| 91 # Why: Alexa news #55 |
| 92 ('http://www.economist.com/news/science-and-technology/21573529-small-' |
| 93 'models-cosmic-phenomena-are-shedding-light-real-thing-how-build'), |
| 94 # Why: Alexa news #67 |
| 95 'http://www.theonion.com', |
| 96 'http://arstechnica.com/', |
| 97 # Why: Alexa home #10 |
| 98 'http://allrecipes.com/Recipe/Pull-Apart-Hot-Cross-Buns/Detail.aspx', |
| 99 'http://www.html5rocks.com/en/', |
| 100 'http://www.mlb.com/', |
| 101 ('http://gawker.com/5939683/based-on-a-true-story-is-a-rotten-lie-i-' |
| 102 'hope-you-never-believe'), |
| 103 'http://www.imdb.com/title/tt0910970/', |
| 104 'http://www.flickr.com/search/?q=monkeys&f=hp', |
| 105 'http://money.cnn.com/', |
| 106 'http://www.nationalgeographic.com/', |
| 107 'http://premierleague.com', |
| 108 'http://www.osubeavers.com/', |
| 109 'http://walgreens.com', |
| 110 'http://colorado.edu', |
| 111 ('http://www.ticketmaster.com/JAY-Z-and-Justin-Timberlake-tickets/artist/' |
| 112 '1837448?brand=none&tm_link=tm_homeA_rc_name2'), |
| 113 # pylint: disable=line-too-long |
| 114 'http://www.theverge.com/2013/3/5/4061684/inside-ted-the-smartest-bubble-i
n-the-world', |
| 115 'http://www.airbnb.com/', |
| 116 'http://www.ign.com/', |
| 117 # Why: Alexa health #25 |
| 118 'http://www.fda.gov', |
| 119 ] |
| 120 URL = URL_LIST[0] |
OLD | NEW |