Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 import sys
2 import os.path
3 import re
5 assert len(sys.argv) == 2
6 mochiPath = sys.argv[1]
8 extDotPos = mochiPath.find('.html')
9 assert extDotPos != -1, 'mochitest target must be an html doc.'
11 testPath = mochiPath[:extDotPos] + '.solo.html'
13 def ReadLocalFile(include):
14 incPath = os.path.dirname(mochiPath)
15 filePath = os.path.join(incPath, include)
17 data = None
18 try:
19 f = open(filePath, 'r')
20 data = f.read()
21 except:
22 pass
24 try:
25 f.close()
26 except:
27 pass
29 return data
31 kSimpleTestReplacement = '''\n
32 <script>
33 // SimpleTest.js replacement
34 function ok(val, text) {
35 var elem = document.getElementById('mochi-to-testcase-output');
36 var status = val ? 'Test <font color=\\'green\\'>passed</font>: '
37 : 'Test <font color=\\'red\\' >FAILED</font>: ';
38 elem.innerHTML += '\\n<br/>\\n' + status + text;
39 }
41 function todo(val, text) {
42 ok(!val, 'Todo: ' + text);
43 }
44 </script>
45 <div id='mochi-to-testcase-output'></div>
46 \n'''
48 fin = open(mochiPath, 'r')
49 fout = open(testPath, 'w')
50 includePattern = re.compile('<script\\s*src=[\'"](.*)\\.js[\'"]>\\s*</script>')
51 cssPattern = re.compile('<link\\s*rel=[\'"]stylesheet[\'"]\\s*href=[\'"]([^=>]*)[\'"]>')
52 for line in fin:
53 skipLine = False
54 for css in cssPattern.findall(line):
55 skipLine = True
56 print('Ignoring stylesheet: ' + css)
58 for inc in includePattern.findall(line):
59 skipLine = True
60 if inc == '/MochiKit/MochiKit':
61 continue
63 if inc == '/tests/SimpleTest/SimpleTest':
64 print('Injecting SimpleTest replacement')
65 fout.write(kSimpleTestReplacement);
66 continue
68 incData = ReadLocalFile(inc + '.js')
69 if not incData:
70 print('Warning: Unknown JS file ignored: ' + inc + '.js')
71 continue
73 print('Injecting include: ' + inc + '.js')
74 fout.write('\n<script>\n// Imported from: ' + inc + '.js\n');
75 fout.write(incData);
76 fout.write('\n</script>\n');
77 continue
79 if skipLine:
80 continue
82 fout.write(line)
83 continue
85 fin.close()
86 fout.close()