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

Side by Side Diff: content/test/gpu/gpu_tests/context_lost_integration_test.py

Issue 2672803002: [Telemetry refactor] Migrate clients to new JavaScript API (batch 3) (Closed)
Patch Set: add comment on tools/android Created 3 years, 10 months 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 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 import os 5 import os
6 import sys 6 import sys
7 import time 7 import time
8 8
9 from gpu_tests import gpu_integration_test 9 from gpu_tests import gpu_integration_test
10 from gpu_tests import context_lost_expectations 10 from gpu_tests import context_lost_expectations
11 from gpu_tests import path_util 11 from gpu_tests import path_util
12 12
13 import py_utils
14 from telemetry.core import exceptions 13 from telemetry.core import exceptions
15 14
16 data_path = os.path.join( 15 data_path = os.path.join(
17 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') 16 path_util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu')
18 17
19 wait_timeout = 60 # seconds 18 wait_timeout = 60 # seconds
20 19
21 harness_script = r""" 20 harness_script = r"""
22 var domAutomationController = {}; 21 var domAutomationController = {};
23 22
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 @classmethod 99 @classmethod
101 def setUpClass(cls): 100 def setUpClass(cls):
102 super(cls, ContextLostIntegrationTest).setUpClass() 101 super(cls, ContextLostIntegrationTest).setUpClass()
103 cls.CustomizeOptions() 102 cls.CustomizeOptions()
104 cls.SetBrowserOptions(cls._finder_options) 103 cls.SetBrowserOptions(cls._finder_options)
105 cls.StartBrowser() 104 cls.StartBrowser()
106 cls.SetStaticServerDirs([data_path]) 105 cls.SetStaticServerDirs([data_path])
107 106
108 def _WaitForPageToFinish(self, tab): 107 def _WaitForPageToFinish(self, tab):
109 try: 108 try:
110 py_utils.WaitFor(lambda: tab.EvaluateJavaScript( 109 tab.WaitForJavaScriptCondition2(
111 'window.domAutomationController._finished'), wait_timeout) 110 'window.domAutomationController._finished', timeout=wait_timeout)
112 return True 111 return True
113 except exceptions.TimeoutException: 112 except exceptions.TimeoutException:
114 return False 113 return False
115 114
116 def _KillGPUProcess(self, number_of_gpu_process_kills, 115 def _KillGPUProcess(self, number_of_gpu_process_kills,
117 check_crash_count): 116 check_crash_count):
118 tab = self.tab 117 tab = self.tab
119 # Doing the GPU process kill operation cooperatively -- in the 118 # Doing the GPU process kill operation cooperatively -- in the
120 # same page's context -- is much more stressful than restarting 119 # same page's context -- is much more stressful than restarting
121 # the browser every time. 120 # the browser every time.
122 for x in range(number_of_gpu_process_kills): 121 for x in range(number_of_gpu_process_kills):
123 expected_kills = x + 1 122 expected_kills = x + 1
124 123
125 # Reset the test's state. 124 # Reset the test's state.
126 tab.EvaluateJavaScript( 125 tab.EvaluateJavaScript2(
127 'window.domAutomationController.reset()') 126 'window.domAutomationController.reset()')
128 127
129 # If we're running the GPU process crash test, we need the test 128 # If we're running the GPU process crash test, we need the test
130 # to have fully reset before crashing the GPU process. 129 # to have fully reset before crashing the GPU process.
131 if check_crash_count: 130 if check_crash_count:
132 py_utils.WaitFor(lambda: tab.EvaluateJavaScript( 131 tab.WaitForJavaScriptCondition2(
133 'window.domAutomationController._finished'), wait_timeout) 132 'window.domAutomationController._finished', timeout=wait_timeout)
134 133
135 # Crash the GPU process. 134 # Crash the GPU process.
136 gpucrash_tab = tab.browser.tabs.New() 135 gpucrash_tab = tab.browser.tabs.New()
137 # To access these debug URLs from Telemetry, they have to be 136 # To access these debug URLs from Telemetry, they have to be
138 # written using the chrome:// scheme. 137 # written using the chrome:// scheme.
139 # The try/except is a workaround for crbug.com/368107. 138 # The try/except is a workaround for crbug.com/368107.
140 try: 139 try:
141 gpucrash_tab.Navigate('chrome://gpucrash') 140 gpucrash_tab.Navigate('chrome://gpucrash')
142 except Exception: 141 except Exception:
143 print 'Tab crashed while navigating to chrome://gpucrash' 142 print 'Tab crashed while navigating to chrome://gpucrash'
144 # Activate the original tab and wait for completion. 143 # Activate the original tab and wait for completion.
145 tab.Activate() 144 tab.Activate()
146 completed = self._WaitForPageToFinish(tab) 145 completed = self._WaitForPageToFinish(tab)
147 146
148 if check_crash_count: 147 if check_crash_count:
149 self._CheckCrashCount(tab, expected_kills) 148 self._CheckCrashCount(tab, expected_kills)
150 149
151 # The try/except is a workaround for crbug.com/368107. 150 # The try/except is a workaround for crbug.com/368107.
152 try: 151 try:
153 gpucrash_tab.Close() 152 gpucrash_tab.Close()
154 except Exception: 153 except Exception:
155 print 'Tab crashed while closing chrome://gpucrash' 154 print 'Tab crashed while closing chrome://gpucrash'
156 if not completed: 155 if not completed:
157 self.fail('Test didn\'t complete (no context lost event?)') 156 self.fail('Test didn\'t complete (no context lost event?)')
158 if not tab.EvaluateJavaScript( 157 if not tab.EvaluateJavaScript2(
159 'window.domAutomationController._succeeded'): 158 'window.domAutomationController._succeeded'):
160 self.fail('Test failed (context not restored properly?)') 159 self.fail('Test failed (context not restored properly?)')
161 160
162 def _CheckCrashCount(self, tab, expected_kills): 161 def _CheckCrashCount(self, tab, expected_kills):
163 if not tab.browser.supports_system_info: 162 if not tab.browser.supports_system_info:
164 self.fail('Browser must support system info') 163 self.fail('Browser must support system info')
165 164
166 if not tab.EvaluateJavaScript( 165 if not tab.EvaluateJavaScript2(
167 'window.domAutomationController._succeeded'): 166 'window.domAutomationController._succeeded'):
168 self.fail('Test failed (didn\'t render content properly?)') 167 self.fail('Test failed (didn\'t render content properly?)')
169 168
170 number_of_crashes = -1 169 number_of_crashes = -1
171 # To allow time for a gpucrash to complete, wait up to 20s, 170 # To allow time for a gpucrash to complete, wait up to 20s,
172 # polling repeatedly. 171 # polling repeatedly.
173 start_time = time.time() 172 start_time = time.time()
174 current_time = time.time() 173 current_time = time.time()
175 while current_time - start_time < 20: 174 while current_time - start_time < 20:
176 system_info = tab.browser.GetSystemInfo() 175 system_info = tab.browser.GetSystemInfo()
(...skipping 14 matching lines...) Expand all
191 if number_of_crashes < expected_kills: 190 if number_of_crashes < expected_kills:
192 self.fail('Timed out waiting for a gpu process crash') 191 self.fail('Timed out waiting for a gpu process crash')
193 elif number_of_crashes != expected_kills: 192 elif number_of_crashes != expected_kills:
194 self.fail('Expected %d gpu process crashes; got: %d' % 193 self.fail('Expected %d gpu process crashes; got: %d' %
195 (expected_kills, number_of_crashes)) 194 (expected_kills, number_of_crashes))
196 195
197 def _NavigateAndWaitForLoad(self, test_path): 196 def _NavigateAndWaitForLoad(self, test_path):
198 url = self.UrlOfStaticFilePath(test_path) 197 url = self.UrlOfStaticFilePath(test_path)
199 tab = self.tab 198 tab = self.tab
200 tab.Navigate(url, script_to_evaluate_on_commit=harness_script) 199 tab.Navigate(url, script_to_evaluate_on_commit=harness_script)
201 tab.action_runner.WaitForJavaScriptCondition( 200 tab.action_runner.WaitForJavaScriptCondition2(
202 'window.domAutomationController._loaded') 201 'window.domAutomationController._loaded')
203 202
204 def _WaitForTabAndCheckCompletion(self): 203 def _WaitForTabAndCheckCompletion(self):
205 tab = self.tab 204 tab = self.tab
206 completed = self._WaitForPageToFinish(tab) 205 completed = self._WaitForPageToFinish(tab)
207 if not completed: 206 if not completed:
208 self.fail('Test didn\'t complete (no context restored event?)') 207 self.fail('Test didn\'t complete (no context restored event?)')
209 if not tab.EvaluateJavaScript('window.domAutomationController._succeeded'): 208 if not tab.EvaluateJavaScript2('window.domAutomationController._succeeded'):
210 self.fail('Test failed (context not restored properly?)') 209 self.fail('Test failed (context not restored properly?)')
211 210
212 # The browser test runner synthesizes methods with the exact name 211 # The browser test runner synthesizes methods with the exact name
213 # given in GenerateGpuTests, so in order to hand-write our tests but 212 # given in GenerateGpuTests, so in order to hand-write our tests but
214 # also go through the _RunGpuTest trampoline, the test needs to be 213 # also go through the _RunGpuTest trampoline, the test needs to be
215 # slightly differently named. 214 # slightly differently named.
216 def _GpuCrash_GPUProcessCrashesExactlyOncePerVisitToAboutGpuCrash( 215 def _GpuCrash_GPUProcessCrashesExactlyOncePerVisitToAboutGpuCrash(
217 self, test_path): 216 self, test_path):
218 self._NavigateAndWaitForLoad(test_path) 217 self._NavigateAndWaitForLoad(test_path)
219 self._KillGPUProcess(2, True) 218 self._KillGPUProcess(2, True)
220 self._RestartBrowser('must restart after tests that kill the GPU process') 219 self._RestartBrowser('must restart after tests that kill the GPU process')
221 220
222 def _ContextLost_WebGLContextLostFromGPUProcessExit(self, test_path): 221 def _ContextLost_WebGLContextLostFromGPUProcessExit(self, test_path):
223 self._NavigateAndWaitForLoad(test_path) 222 self._NavigateAndWaitForLoad(test_path)
224 self._KillGPUProcess(1, False) 223 self._KillGPUProcess(1, False)
225 self._RestartBrowser('must restart after tests that kill the GPU process') 224 self._RestartBrowser('must restart after tests that kill the GPU process')
226 225
227 def _ContextLost_WebGLContextLostFromLoseContextExtension(self, test_path): 226 def _ContextLost_WebGLContextLostFromLoseContextExtension(self, test_path):
228 url = self.UrlOfStaticFilePath(test_path) 227 url = self.UrlOfStaticFilePath(test_path)
229 tab = self.tab 228 tab = self.tab
230 tab.Navigate(url, script_to_evaluate_on_commit=harness_script) 229 tab.Navigate(url, script_to_evaluate_on_commit=harness_script)
231 tab.action_runner.WaitForJavaScriptCondition( 230 tab.action_runner.WaitForJavaScriptCondition2(
232 'window.domAutomationController._finished') 231 'window.domAutomationController._finished')
233 232
234 def _ContextLost_WebGLContextLostFromQuantity(self, test_path): 233 def _ContextLost_WebGLContextLostFromQuantity(self, test_path):
235 self._NavigateAndWaitForLoad(test_path) 234 self._NavigateAndWaitForLoad(test_path)
236 # Try to coerce GC to clean up any contexts not attached to the page. 235 # Try to coerce GC to clean up any contexts not attached to the page.
237 # This method seems unreliable, so the page will also attempt to 236 # This method seems unreliable, so the page will also attempt to
238 # force GC through excessive allocations. 237 # force GC through excessive allocations.
239 self.tab.CollectGarbage() 238 self.tab.CollectGarbage()
240 self._WaitForTabAndCheckCompletion() 239 self._WaitForTabAndCheckCompletion()
241 240
242 def _ContextLost_WebGLContextLostFromSelectElement(self, test_path): 241 def _ContextLost_WebGLContextLostFromSelectElement(self, test_path):
243 self._NavigateAndWaitForLoad(test_path) 242 self._NavigateAndWaitForLoad(test_path)
244 self._WaitForTabAndCheckCompletion() 243 self._WaitForTabAndCheckCompletion()
245 244
246 def _ContextLost_WebGLContextLostInHiddenTab(self, test_path): 245 def _ContextLost_WebGLContextLostInHiddenTab(self, test_path):
247 self._NavigateAndWaitForLoad(test_path) 246 self._NavigateAndWaitForLoad(test_path)
248 # Test losing a context in a hidden tab. This test passes if the tab 247 # Test losing a context in a hidden tab. This test passes if the tab
249 # doesn't crash. 248 # doesn't crash.
250 tab = self.tab 249 tab = self.tab
251 dummy_tab = tab.browser.tabs.New() 250 dummy_tab = tab.browser.tabs.New()
252 tab.EvaluateJavaScript('loseContextUsingExtension()') 251 tab.EvaluateJavaScript2('loseContextUsingExtension()')
253 tab.Activate() 252 tab.Activate()
254 self._WaitForTabAndCheckCompletion() 253 self._WaitForTabAndCheckCompletion()
255 254
256 def load_tests(loader, tests, pattern): 255 def load_tests(loader, tests, pattern):
257 del loader, tests, pattern # Unused. 256 del loader, tests, pattern # Unused.
258 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__]) 257 return gpu_integration_test.LoadAllTestsInModule(sys.modules[__name__])
OLDNEW
« no previous file with comments | « components/proximity_auth/e2e_test/cros.py ('k') | content/test/gpu/gpu_tests/depth_capture_integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698