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 import time | |
8 | |
9 from telemetry.core import exceptions | |
10 from telemetry.page import page as page_module | |
11 from telemetry.page import shared_page_state | |
12 from contrib.cros_benchmarks.cros_utils import SetupKeyDispatch, SwitchTab, NoSc reenOff | |
13 | |
14 | |
15 class CrosMultiTabSharedState(shared_page_state.SharedPageState): | |
16 def __init__(self, test, finder_options, story_set): | |
17 super(CrosMultiTabSharedState, self).__init__(test,finder_options, | |
18 story_set) | |
19 self._results = None | |
20 SetupKeyDispatch(finder_options.cros_remote) | |
21 | |
22 | |
23 # note: when tab count is high, some tab may be discarded, and the tab | |
24 # context would be invalidated. avoid store tab object for later use. | |
bccheng
2017/05/19 09:09:14
Capitalize the sentences in comments. For example:
vovoy
2017/05/22 03:54:08
Done.
| |
25 class CrosMultiTabStory(page_module.Page): | |
26 def __init__(self, story_set, tabset_repeat=1): | |
27 super(CrosMultiTabStory, self).__init__( | |
28 shared_page_state_class=CrosMultiTabSharedState, page_set=story_set, | |
29 name=self.NAME, url=self.URL) | |
30 self._tabset_repeat = tabset_repeat | |
31 | |
32 def RunNavigateSteps(self, action_runner): | |
33 # pylint: disable=protected-access | |
34 NoScreenOff(action_runner.tab.browser._platform_backend) | |
35 | |
36 tabs = action_runner.tab.browser.tabs | |
37 | |
38 # No need to create the first tab as there is already one | |
39 # when the browser is ready, | |
40 url_list = self.URL_LIST * self._tabset_repeat | |
41 if url_list: | |
42 action_runner.Navigate(url_list[0]) | |
43 for i, url in enumerate(url_list[1:]): | |
44 new_tab = tabs.New() | |
45 new_tab.action_runner.Navigate(url) | |
46 if i % 10 == 0: | |
47 print 'opening tab:', i | |
48 | |
49 for i, url in enumerate(url_list): | |
50 try: | |
51 tabs[i].action_runner.WaitForNetworkQuiescence() | |
52 except py_utils.TimeoutException: | |
53 logging.warning('WaitForNetworkQuiescence() timeout, url[%d]: %s' | |
54 % (i, url)) | |
55 except exceptions.DevtoolsTargetCrashException: | |
56 logging.warning('got DevtoolsTargetCrashException') | |
57 | |
58 def RunPageInteractions(self, action_runner): | |
59 # pylint: disable=protected-access | |
60 url_list = self.URL_LIST * self._tabset_repeat | |
61 browser = action_runner.tab.browser | |
62 total_tab_count = len(url_list) | |
63 live_tab_count = len(browser.tabs) | |
64 if live_tab_count != total_tab_count: | |
65 logging.warning('live tab: %d, tab discarded: %d', | |
66 live_tab_count, total_tab_count - live_tab_count) | |
67 platform_backend = browser._platform_backend | |
68 for i in range(total_tab_count): | |
69 SwitchTab(platform_backend) | |
70 time.sleep(2.0) | |
71 if i % 10 == 0: | |
72 print 'switching tab:', i | |
73 | |
74 | |
75 class CrosMultiTabTypical24Story(CrosMultiTabStory): | |
76 NAME = 'cros_tab_switching_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 URL = URL_LIST[0] | |
OLD | NEW |