1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-mochitest/mochi-to-testcase.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +import sys 1.5 +import os.path 1.6 +import re 1.7 + 1.8 +assert len(sys.argv) == 2 1.9 +mochiPath = sys.argv[1] 1.10 + 1.11 +extDotPos = mochiPath.find('.html') 1.12 +assert extDotPos != -1, 'mochitest target must be an html doc.' 1.13 + 1.14 +testPath = mochiPath[:extDotPos] + '.solo.html' 1.15 + 1.16 +def ReadLocalFile(include): 1.17 + incPath = os.path.dirname(mochiPath) 1.18 + filePath = os.path.join(incPath, include) 1.19 + 1.20 + data = None 1.21 + try: 1.22 + f = open(filePath, 'r') 1.23 + data = f.read() 1.24 + except: 1.25 + pass 1.26 + 1.27 + try: 1.28 + f.close() 1.29 + except: 1.30 + pass 1.31 + 1.32 + return data 1.33 + 1.34 +kSimpleTestReplacement = '''\n 1.35 +<script> 1.36 +// SimpleTest.js replacement 1.37 +function ok(val, text) { 1.38 + var elem = document.getElementById('mochi-to-testcase-output'); 1.39 + var status = val ? 'Test <font color=\\'green\\'>passed</font>: ' 1.40 + : 'Test <font color=\\'red\\' >FAILED</font>: '; 1.41 + elem.innerHTML += '\\n<br/>\\n' + status + text; 1.42 +} 1.43 + 1.44 +function todo(val, text) { 1.45 + ok(!val, 'Todo: ' + text); 1.46 +} 1.47 +</script> 1.48 +<div id='mochi-to-testcase-output'></div> 1.49 +\n''' 1.50 + 1.51 +fin = open(mochiPath, 'r') 1.52 +fout = open(testPath, 'w') 1.53 +includePattern = re.compile('<script\\s*src=[\'"](.*)\\.js[\'"]>\\s*</script>') 1.54 +cssPattern = re.compile('<link\\s*rel=[\'"]stylesheet[\'"]\\s*href=[\'"]([^=>]*)[\'"]>') 1.55 +for line in fin: 1.56 + skipLine = False 1.57 + for css in cssPattern.findall(line): 1.58 + skipLine = True 1.59 + print('Ignoring stylesheet: ' + css) 1.60 + 1.61 + for inc in includePattern.findall(line): 1.62 + skipLine = True 1.63 + if inc == '/MochiKit/MochiKit': 1.64 + continue 1.65 + 1.66 + if inc == '/tests/SimpleTest/SimpleTest': 1.67 + print('Injecting SimpleTest replacement') 1.68 + fout.write(kSimpleTestReplacement); 1.69 + continue 1.70 + 1.71 + incData = ReadLocalFile(inc + '.js') 1.72 + if not incData: 1.73 + print('Warning: Unknown JS file ignored: ' + inc + '.js') 1.74 + continue 1.75 + 1.76 + print('Injecting include: ' + inc + '.js') 1.77 + fout.write('\n<script>\n// Imported from: ' + inc + '.js\n'); 1.78 + fout.write(incData); 1.79 + fout.write('\n</script>\n'); 1.80 + continue 1.81 + 1.82 + if skipLine: 1.83 + continue 1.84 + 1.85 + fout.write(line) 1.86 + continue 1.87 + 1.88 +fin.close() 1.89 +fout.close()