Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / test / gpu / gpu_tests / webgl_robustness.py
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 *
10
11 from webgl_conformance import WebglConformanceValidator
12 from webgl_conformance import conformance_harness_script
13 from webgl_conformance import conformance_path
14
15
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;
23     });
24   }
25   robustnessTestHarness.runTestLoop = function() {
26     // Run the test in a loop until the context is lost.
27     main();
28     if (!robustnessTestHarness._contextLost)
29       window.requestAnimationFrame(robustnessTestHarness.runTestLoop);
30     else
31       robustnessTestHarness.notifyFinished();
32   }
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
36     // crash.
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);
41   }
42
43   window.confirm = function() {
44     robustnessTestHarness.initialize();
45     robustnessTestHarness.runTestLoop();
46     return false;
47   }
48   window.webglRobustnessTestHarness = robustnessTestHarness;
49 """
50
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',
55       page_set=page_set,
56       base_dir=base_dir)
57     self.script_to_evaluate_on_commit = robustness_harness_script
58
59   def RunNavigateSteps(self, action_runner):
60     action_runner.RunAction(NavigateAction())
61     action_runner.RunAction(
62       WaitAction({'javascript': 'webglTestHarness._finished'}))
63
64 class WebglRobustness(test.Test):
65   test = WebglConformanceValidator
66
67   def CreatePageSet(self, options):
68     ps = page_set.PageSet(
69       file_path=conformance_path,
70       description='Test cases for WebGL robustness',
71       user_agent_type='desktop',
72       serving_dirs=[''])
73     ps.AddPage(WebglRobustnessPage(ps, ps.base_dir))
74     return ps