content/canvas/test/webgl-mochitest/mochi-to-testcase.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial