aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/unittest
diff options
context:
space:
mode:
authorEinar Egilsson2009-09-15 21:41:06 +0000
committerEinar Egilsson2009-09-15 21:41:06 +0000
commit96966ca83f96ed1babcd2bd23aa68feb63fbb7a7 (patch)
treef2483b413192a279753cb02d2d8fcff9f0ad9b03 /chrome/content/unittest
parentd32cd776748e45abeaa6c2284b96210952c79717 (diff)
Total restructuring of files.
Unescape matches fully working Export of redirects working. git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@249 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/unittest')
-rw-r--r--chrome/content/unittest/run.html87
-rw-r--r--chrome/content/unittest/testcases.js39
2 files changed, 126 insertions, 0 deletions
diff --git a/chrome/content/unittest/run.html b/chrome/content/unittest/run.html
new file mode 100644
index 0000000..2c4f968
--- /dev/null
+++ b/chrome/content/unittest/run.html
@@ -0,0 +1,87 @@
+<!-- $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: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
+ var subscriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
+ var redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
+
+ 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.getElementsByTagName('body')[0].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() {
+ var tables = document.getElementsByTagName('table');
+ for (var i = 0; i < tables.length; i++) {
+ tables[i].parentNode.removeChild(tables[i]);
+ }
+
+ subscriptLoader.loadSubScript('chrome://redirector/content/unittest/testcases.js');
+ redirector.reload();
+
+ for (var name in tests) {
+ 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 result = testcase.run(testcase.tests[i]);
+ if (result) {
+ document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#17f816';
+ } else {
+ document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#ff0000';
+ }
+ } catch(e) {
+ document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#ff0000';
+ }
+ }
+ }
+ }
+
+ </script>
+ </head>
+ <body onload="setup();">
+ <h1>Redirector Unit Tests</h1>
+ <button onclick="runTests();">Run tests</button>
+ <button onclick="setup();">Reload tests</button>
+ </body>
+</html> \ No newline at end of file
diff --git a/chrome/content/unittest/testcases.js b/chrome/content/unittest/testcases.js
new file mode 100644
index 0000000..ea6e26b
--- /dev/null
+++ b/chrome/content/unittest/testcases.js
@@ -0,0 +1,39 @@
+//// $Id$
+var tests = {
+ "Wildcard matches" : {
+ run : function(data) {
+ var pattern = data[0],
+ url = data[1],
+ expected = data[2];
+ var parts = expected.split(',');
+ var redirectUrl = '';
+ if (!(parts.length == 1 && parts[0] == '')) {
+ for (var i in parts) {
+ redirectUrl += '$' + (parseFloat(i)+1) + ',';
+ }
+ redirectUrl = redirectUrl.substr(0, redirectUrl.length-1);
+ }
+ var result = redirector.wildcardMatch(pattern, url, redirectUrl, false);
+ return result == expected;
+ },
+
+ describe : function(data) { return data[0] + ' == ' + data[1] + ', matches=' + data[2]; },
+ tests : [
+ ['http://foo*', 'http://foobar.is', 'bar.is'],
+ ['http://foo*', 'http://foo', ''],
+ ['*://foo.is', 'http://foo.is', 'http'],
+ ['*http://foo.is', 'http://foo.is', ''],
+ ['http*foo*', 'http://foobar.is', '://,bar.is'],
+ ['http*foo*', 'http://foo', '://,'],
+ ['*://f*.is', 'http://foo.is', 'http,oo'],
+ ['*http://f*.is', 'http://foo.is', ',oo'],
+ ['*foo*', 'http://foo', 'http://,'],
+ ['*foo*', 'foobar.is', ',bar.is'],
+ ['*foo*', 'http://foobar.is', 'http://,bar.is'],
+ ['http://foo.is', 'http://foo.is', ''],
+ ['*', 'http://foo.is', 'http://foo.is'],
+ ['*://*oo*bar*', 'http://foo.is/bar/baz', 'http,f,.is/,/baz'],
+ ['*://**oo*bar*', 'http://foo.is/bar/baz', 'http,,f,.is/,/baz'],
+ ]
+ }
+};