Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(610)

Side by Side Diff: tools/telemetry/telemetry/core/tab.py

Issue 668753002: [Telemetry] Migrate bitmap.py from bitmaptools.cc to numpy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make GetBoundingBox just, like, WAY too fast Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from telemetry.core import bitmap
5 from telemetry.core import video 6 from telemetry.core import video
6 from telemetry.core import web_contents 7 from telemetry.core import web_contents
7 8
8 DEFAULT_TAB_TIMEOUT = 60 9 DEFAULT_TAB_TIMEOUT = 60
9 10
10 11
11 class Tab(web_contents.WebContents): 12 class Tab(web_contents.WebContents):
12 """Represents a tab in the browser 13 """Represents a tab in the browser
13 14
14 The important parts of the Tab object are in the runtime and page objects. 15 The important parts of the Tab object are in the runtime and page objects.
15 E.g.: 16 E.g.:
16 # Navigates the tab to a given url. 17 # Navigates the tab to a given url.
17 tab.Navigate('http://www.google.com/') 18 tab.Navigate('http://www.google.com/')
18 19
19 # Evaluates 1+1 in the tab's JavaScript context. 20 # Evaluates 1+1 in the tab's JavaScript context.
20 tab.Evaluate('1+1') 21 tab.Evaluate('1+1')
21 """ 22 """
23
22 def __init__(self, inspector_backend, backend_list): 24 def __init__(self, inspector_backend, backend_list):
23 super(Tab, self).__init__(inspector_backend, backend_list) 25 super(Tab, self).__init__(inspector_backend, backend_list)
24 26
25 @property 27 @property
26 def browser(self): 28 def browser(self):
27 """The browser in which this tab resides.""" 29 """The browser in which this tab resides."""
28 return self._inspector_backend.browser 30 return self._inspector_backend.browser
29 31
30 @property 32 @property
31 def url(self): 33 def url(self):
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 A telemetry.core.Bitmap. 82 A telemetry.core.Bitmap.
81 """ 83 """
82 return self._inspector_backend.Screenshot(timeout) 84 return self._inspector_backend.Screenshot(timeout)
83 85
84 @property 86 @property
85 def video_capture_supported(self): 87 def video_capture_supported(self):
86 """True if the browser instance is capable of capturing video.""" 88 """True if the browser instance is capable of capturing video."""
87 return self.browser.platform.CanCaptureVideo() 89 return self.browser.platform.CanCaptureVideo()
88 90
89 def Highlight(self, color): 91 def Highlight(self, color):
90 """Synchronously highlights entire tab contents with the given RgbaColor. 92 """Synchronously highlights entire tab contents with the given color.
91 93
92 TODO(tonyg): It is possible that the z-index hack here might not work for 94 TODO(tonyg): It is possible that the z-index hack here might not work for
93 all pages. If this happens, DevTools also provides a method for this. 95 all pages. If this happens, DevTools also provides a method for this.
94 """ 96 """
95 self.ExecuteJavaScript(""" 97 self.ExecuteJavaScript("""
96 (function() { 98 (function() {
97 var screen = document.createElement('div'); 99 var screen = document.createElement('div');
98 screen.style.background = 'rgba(%d, %d, %d, %d)'; 100 screen.style.background = 'rgba(%d, %d, %d, %d)';
99 screen.style.position = 'fixed'; 101 screen.style.position = 'fixed';
100 screen.style.top = '0'; 102 screen.style.top = '0';
101 screen.style.left = '0'; 103 screen.style.left = '0';
102 screen.style.width = '100%%'; 104 screen.style.width = '100%%';
103 screen.style.height = '100%%'; 105 screen.style.height = '100%%';
104 screen.style.zIndex = '2147483638'; 106 screen.style.zIndex = '2147483638';
105 document.body.appendChild(screen); 107 document.body.appendChild(screen);
106 requestAnimationFrame(function() { 108 requestAnimationFrame(function() {
107 requestAnimationFrame(function() { 109 requestAnimationFrame(function() {
108 window.__telemetry_screen_%d = screen; 110 window.__telemetry_screen_%d = screen;
109 }); 111 });
110 }); 112 });
111 })(); 113 })();
112 """ % (color.r, color.g, color.b, color.a, int(color))) 114 """ % (color[2], color[1], color[0], 255, bitmap.BGRAColorAsInt(color)))
113 self.WaitForJavaScriptExpression( 115 self.WaitForJavaScriptExpression(
114 '!!window.__telemetry_screen_%d' % int(color), 5) 116 '!!window.__telemetry_screen_%d' % bitmap.BGRAColorAsInt(color), 5)
115 117
116 def ClearHighlight(self, color): 118 def ClearHighlight(self, color):
117 """Clears a highlight of the given bitmap.RgbaColor.""" 119 """Clears a highlight of the given color."""
118 self.ExecuteJavaScript(""" 120 self.ExecuteJavaScript("""
119 (function() { 121 (function() {
120 document.body.removeChild(window.__telemetry_screen_%d); 122 document.body.removeChild(window.__telemetry_screen_%d);
121 requestAnimationFrame(function() { 123 requestAnimationFrame(function() {
122 requestAnimationFrame(function() { 124 requestAnimationFrame(function() {
123 window.__telemetry_screen_%d = null; 125 window.__telemetry_screen_%d = null;
124 console.time('__ClearHighlight.video_capture_start'); 126 console.time('__ClearHighlight.video_capture_start');
125 console.timeEnd('__ClearHighlight.video_capture_start'); 127 console.timeEnd('__ClearHighlight.video_capture_start');
126 }); 128 });
127 }); 129 });
128 })(); 130 })();
129 """ % (int(color), int(color))) 131 """ % (bitmap.BGRAColorAsInt(color), bitmap.BGRAColorAsInt(color)))
130 self.WaitForJavaScriptExpression( 132 self.WaitForJavaScriptExpression(
131 '!window.__telemetry_screen_%d' % int(color), 5) 133 '!window.__telemetry_screen_%d' % int(color), 5)
132 134
133 def StartVideoCapture(self, min_bitrate_mbps, 135 def StartVideoCapture(self, min_bitrate_mbps,
134 highlight_bitmap=video.HIGHLIGHT_ORANGE_FRAME): 136 highlight_bitmap=video.HIGHLIGHT_ORANGE_FRAME):
135 """Starts capturing video of the tab's contents. 137 """Starts capturing video of the tab's contents.
136 138
137 This works by flashing the entire tab contents to a arbitrary color and then 139 This works by flashing the entire tab contents to a arbitrary color and then
138 starting video recording. When the frames are processed, we can look for 140 starting video recording. When the frames are processed, we can look for
139 that flash as the content bounds. 141 that flash as the content bounds.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 self.ExecuteJavaScript(""" 202 self.ExecuteJavaScript("""
201 if (window.chrome && chrome.benchmarking && 203 if (window.chrome && chrome.benchmarking &&
202 chrome.benchmarking.clearCache) { 204 chrome.benchmarking.clearCache) {
203 chrome.benchmarking.clearCache(); 205 chrome.benchmarking.clearCache();
204 chrome.benchmarking.clearPredictorCache(); 206 chrome.benchmarking.clearPredictorCache();
205 chrome.benchmarking.clearHostResolverCache(); 207 chrome.benchmarking.clearHostResolverCache();
206 } 208 }
207 """) 209 """)
208 if force: 210 if force:
209 self.Navigate('about:blank') 211 self.Navigate('about:blank')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698