Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / mochi-to-testcase.py
blobbff3b675b04d144deeab5e03789918fece8e0fae
1 #! /usr/bin/env python3
2 import pathlib
3 import re
4 import sys
6 assert len(sys.argv) == 2
7 MOCHI_PATH = pathlib.Path(sys.argv[1])
8 assert MOCHI_PATH.suffix == ".html"
10 TEST_PATH = MOCHI_PATH.with_suffix(".solo.html")
13 def read_local_file(include):
14 inc_path = MOCHI_PATH.parent
15 file_path = inc_path / include
17 try:
18 return file_path.read_bytes()
19 except IOError:
20 return b""
23 SIMPLETEST_REPLACEMENT = b"""
25 <script>
26 // SimpleTest.js replacement
28 function debug(text) {
29 var elem = document.getElementById('mochi-to-testcase-output');
30 elem.innerHTML += '\\n<br/>\\n' + text;
33 function ok(val, text) {
34 var status = val ? 'Test <font color=\\'green\\'>passed</font>: '
35 : 'Test <font color=\\'red\\' >FAILED</font>: ';
36 debug(status + text);
39 function todo(val, text) {
40 var status = val ? 'Test <font color=\\'orange\\'>UNEXPECTED PASS</font>: '
41 : 'Test <font color=\\'blue\\' >todo</font>: ';
42 debug(status + text);
45 function addLoadEvent(func) {
46 window.addEventListener('load', func);
49 SimpleTest = {
50 waitForExplicitFinish: () => {},
51 finish: () => {},
52 requestFlakyTimeout: () => {},
55 SpecialPowers = {
56 pushPrefEnv: async (env, callback = null) => {
57 console.log(`SpecialPowers.pushPrefEnv(${JSON.stringify(env)})`);
58 await new Promise(res => {
59 setTimeout(res, 0);
60 });
61 if (callback) {
62 await callback();
65 popPrefEnv: async (callback = null) => {
66 console.log('SpecialPowers.popPrefEnv()');
67 await new Promise(res => {
68 setTimeout(res, 0);
69 });
70 if (callback) {
71 await callback();
75 </script>
76 <div id='mochi-to-testcase-output'></div>
78 """
80 INCLUDE_PATTERN = re.compile(b"<script\\s*src=['\"](.*)\\.js['\"]>\\s*</script>")
81 CSS_PATTERN = re.compile(
82 b"<link\\s*rel=['\"]stylesheet['\"]\\s*href=['\"]([^=>]*)['\"]>"
85 with open(TEST_PATH, "wb") as fout:
86 with open(MOCHI_PATH, "rb") as fin:
87 for line in fin:
88 skip_line = False
89 for css in CSS_PATTERN.findall(line):
90 skip_line = True
91 print("Ignoring stylesheet: " + css.decode())
93 for inc in INCLUDE_PATTERN.findall(line):
94 skip_line = True
95 if inc == b"/MochiKit/MochiKit":
96 continue
98 if inc == b"/tests/SimpleTest/SimpleTest":
99 print("Injecting SimpleTest replacement")
100 fout.write(SIMPLETEST_REPLACEMENT)
101 continue
103 inc_js = inc.decode() + ".js"
104 inc_data = read_local_file(inc_js)
105 if not inc_data:
106 print("Warning: Unknown JS file ignored: " + inc_js)
107 continue
109 print("Injecting include: " + inc_js)
110 fout.write(b"\n<script>\n// Imported from: " + inc_js.encode() + b"\n")
111 fout.write(inc_data)
112 fout.write(b"\n</script>\n")
113 continue
115 if skip_line:
116 continue
118 fout.write(line)
119 continue