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