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