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 test
5 from telemetry
.page
import page
6 from telemetry
.page
import page_set
7 from telemetry
.page
import page_test
8 # pylint: disable=W0401,W0614
9 from telemetry
.page
.actions
.all_page_actions
import *
11 from webgl_conformance
import WebglConformanceValidator
12 from webgl_conformance
import conformance_harness_script
13 from webgl_conformance
import conformance_path
16 robustness_harness_script
= conformance_harness_script
+ r
"""
17 var robustnessTestHarness = {};
18 robustnessTestHarness._contextLost = false;
19 robustnessTestHarness.initialize = function() {
20 var canvas = document.getElementById('example');
21 canvas.addEventListener('webglcontextlost', function() {
22 robustnessTestHarness._contextLost = true;
25 robustnessTestHarness.runTestLoop = function() {
26 // Run the test in a loop until the context is lost.
28 if (!robustnessTestHarness._contextLost)
29 window.requestAnimationFrame(robustnessTestHarness.runTestLoop);
31 robustnessTestHarness.notifyFinished();
33 robustnessTestHarness.notifyFinished = function() {
34 // The test may fail in unpredictable ways depending on when the context is
35 // lost. We ignore such errors and only require that the browser doesn't
37 webglTestHarness._allTestSucceeded = true;
38 // Notify test completion after a delay to make sure the browser is able to
39 // recover from the lost context.
40 setTimeout(webglTestHarness.notifyFinished, 3000);
43 window.confirm = function() {
44 robustnessTestHarness.initialize();
45 robustnessTestHarness.runTestLoop();
48 window.webglRobustnessTestHarness = robustnessTestHarness;
51 class WebglRobustnessPage(page
.Page
):
52 def __init__(self
, page_set
, base_dir
):
53 super(WebglRobustnessPage
, self
).__init
__(
54 url
='file://extra/lots-of-polys-example.html',
57 self
.script_to_evaluate_on_commit
= robustness_harness_script
59 def RunNavigateSteps(self
, action_runner
):
60 action_runner
.NavigateToPage(self
)
61 action_runner
.RunAction(
62 WaitAction({'javascript': 'webglTestHarness._finished'}))
64 class WebglRobustness(test
.Test
):
65 test
= WebglConformanceValidator
67 def CreatePageSet(self
, options
):
68 ps
= page_set
.PageSet(
69 file_path
=conformance_path
,
70 user_agent_type
='desktop',
72 ps
.AddPage(WebglRobustnessPage(ps
, ps
.base_dir
))