1# Copyright 2013 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. 4from telemetry import test 5from telemetry.page import page_set 6from webgl_conformance import WebglConformanceValidator 7from webgl_conformance import conformance_harness_script 8from webgl_conformance import conformance_path 9 10 11robustness_harness_script = conformance_harness_script + r""" 12 var robustnessTestHarness = {}; 13 robustnessTestHarness._contextLost = false; 14 robustnessTestHarness.initialize = function() { 15 var canvas = document.getElementById('example'); 16 canvas.addEventListener('webglcontextlost', function() { 17 robustnessTestHarness._contextLost = true; 18 }); 19 } 20 robustnessTestHarness.runTestLoop = function() { 21 // Run the test in a loop until the context is lost. 22 main(); 23 if (!robustnessTestHarness._contextLost) 24 window.requestAnimationFrame(robustnessTestHarness.runTestLoop); 25 else 26 robustnessTestHarness.notifyFinished(); 27 } 28 robustnessTestHarness.notifyFinished = function() { 29 // The test may fail in unpredictable ways depending on when the context is 30 // lost. We ignore such errors and only require that the browser doesn't 31 // crash. 32 webglTestHarness._allTestSucceeded = true; 33 // Notify test completion after a delay to make sure the browser is able to 34 // recover from the lost context. 35 setTimeout(webglTestHarness.notifyFinished, 3000); 36 } 37 38 window.confirm = function() { 39 robustnessTestHarness.initialize(); 40 robustnessTestHarness.runTestLoop(); 41 return false; 42 } 43 window.webglRobustnessTestHarness = robustnessTestHarness; 44""" 45 46 47class WebglRobustness(test.Test): 48 test = WebglConformanceValidator 49 50 def CreatePageSet(self, options): 51 page_set_dict = { 52 'description': 'Test cases for WebGL robustness', 53 'user_agent_type': 'desktop', 54 'serving_dirs': [''], 55 'pages': [ 56 { 57 'url': 'file://extra/lots-of-polys-example.html', 58 'script_to_evaluate_on_commit': robustness_harness_script, 59 'navigate_steps': [ 60 { 'action': 'navigate' }, 61 { 'action': 'wait', 'javascript': 'webglTestHarness._finished' } 62 ] 63 } 64 ] 65 } 66 return page_set.PageSet.FromDict(page_set_dict, conformance_path) 67