aboutsummaryrefslogtreecommitdiff
path: root/chrome/unittest/run.html
blob: 1c056d5b2f035df7d4169a4b757841f5df1231fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!-- $Id$ -->
<html>
	<head>
		<title>Redirector Unit Tests</title>
		<style type="text/css">
			body { font-family: Verdana, Arial; color:black; background-color:white; font-size:0.8em; width:800px; margin:auto; text-align:center;}
			a { color:blue; }
			h1 { text-align:center; margin:10px 0px; }
			table { margin:10px auto; border:solid 1px black; width:700px; border-collapse:collapse;}
			td { border:solid 1px black; padding:3px; }
			td.result { width:20px; height:20px; padding:0;}
			td.result div { width:70%; height:70%; margin:auto;  }
			button { margin:20px auto; }
		</style>
		<script type="text/javascript">

		//Global variables
		Components.utils.import("chrome://redirector/content/js/redirect.js");
		Components.utils.import("chrome://redirector/content/js/redirector.js");
		var redirector = Redirector;
		
		function setupTest(name, testcase) {
			var table = document.createElement('table');
			var row = document.createElement('tr');
			var cell = document.createElement('th');
			var testdata;
			cell.setAttribute('colspan', 2);
			row.appendChild(cell);
			table.appendChild(row);
			cell.innerHTML = name;
			document.getElementById('tests').appendChild(table);
			for (var i = 0; i < testcase.tests.length; i++) {
				var testdata = testcase.tests[i];
				row = document.createElement('tr');
				cell = document.createElement('td');
				cell.setAttribute('class', 'result');
				var dot = document.createElement('div');
				dot.setAttribute('id', name + '_' + i);
				cell.appendChild(dot);
				
				row.appendChild(cell);
				cell = document.createElement('td');
				cell.innerHTML = testcase.describe(testdata);
				row.appendChild(cell);
				table.appendChild(row);
			}
		}
		
		function setup() {
			//quick and dirty cleanup
			document.getElementById('tests').innerHTML = '';
			
			var sorted = [];
			for (var name in tests) {
				sorted.push(name);
			}	
			
			sorted.sort();			
			for each(var name in sorted) {
				setupTest(name, tests[name]);
			}
		}
		
		function runTests() {
			for (var testcaseName in tests) {
				var testcase = tests[testcaseName];
				for (var i = 0; i < testcase.tests.length; i++) {
					try {
						var dot = document.getElementById(testcaseName + '_' + i);
						var result = testcase.run(testcase.tests[i]);
						if (result && result.passed) {
							dot.style.backgroundColor = '#17f816';
						} else {
							dot.style.backgroundColor = '#ff0000';
							if (result && result.message) {
								dot.parentNode.nextSibling.innerHTML += '<br/><span style="color:red;">' + result.message + '</span>';
							}
						}
					} catch(e) {
						dot.style.backgroundColor = '#ff0000';
						dot.parentNode.nextSibling.innerHTML += '<br/><span style="color:red;">' + e + '</span>';
						;
					}
				}
			}	
		}
		
		</script>
		<script type="text/javascript" src="testcases.js"></script>
	</head>
	<body onload="setup();">
		<h1>Redirector Unit Tests</h1>
		<button onclick="runTests();">Run tests</button>
		<button onclick="setup();">Reload tests</button>
		<div id="tests">
		</div>
	</body>
</html>