From a703799580a208beac24c827fcd54b799f46a3d7 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Wed, 7 Oct 2009 11:24:44 +0000 Subject: Finally working normally again after massive refactoring. Disabling single redirects works but needs more GUI work. Added Redirector log file since the Error Console keeps deleting our messages. git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@253 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/unittest/run.html | 18 +++++++++----- chrome/content/unittest/testcases.js | 46 +++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 9 deletions(-) (limited to 'chrome/content/unittest') diff --git a/chrome/content/unittest/run.html b/chrome/content/unittest/run.html index 2c4f968..5658137 100644 --- a/chrome/content/unittest/run.html +++ b/chrome/content/unittest/run.html @@ -6,7 +6,7 @@ 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;} + 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; } @@ -50,7 +50,7 @@ for (var i = 0; i < tables.length; i++) { tables[i].parentNode.removeChild(tables[i]); } - + subscriptLoader.loadSubScript('chrome://redirector/content/code/redirect.js'); subscriptLoader.loadSubScript('chrome://redirector/content/unittest/testcases.js'); redirector.reload(); @@ -64,14 +64,20 @@ 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) { - document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#17f816'; + if (result && result.passed) { + dot.style.backgroundColor = '#17f816'; } else { - document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#ff0000'; + dot.style.backgroundColor = '#ff0000'; + if (result && result.message) { + dot.parentNode.nextSibling.innerHTML += '
' + result.message + ''; + } } } catch(e) { - document.getElementById(testcaseName + '_' + i).style.backgroundColor = '#ff0000'; + dot.style.backgroundColor = '#ff0000'; + dot.parentNode.nextSibling.innerHTML += '
' + e + ''; + ; } } } diff --git a/chrome/content/unittest/testcases.js b/chrome/content/unittest/testcases.js index ea6e26b..ac9539f 100644 --- a/chrome/content/unittest/testcases.js +++ b/chrome/content/unittest/testcases.js @@ -1,7 +1,7 @@ //// $Id$ var tests = { "Wildcard matches" : { - run : function(data) { + run : function(data,log) { var pattern = data[0], url = data[1], expected = data[2]; @@ -13,8 +13,9 @@ var tests = { } redirectUrl = redirectUrl.substr(0, redirectUrl.length-1); } - var result = redirector.wildcardMatch(pattern, url, redirectUrl, false); - return result == expected; + var redirect = new Redirect(null, pattern, null, redirectUrl, Redirect.WILDCARD, null); + var result = redirect.getMatch(url); + return { passed: result.isMatch && (result.redirectTo == expected), message : "Expected '" + expected + "', actual was '" + result.redirectTo + "'"}; }, describe : function(data) { return data[0] + ' == ' + data[1] + ', matches=' + data[2]; }, @@ -35,5 +36,44 @@ var tests = { ['*://*oo*bar*', 'http://foo.is/bar/baz', 'http,f,.is/,/baz'], ['*://**oo*bar*', 'http://foo.is/bar/baz', 'http,,f,.is/,/baz'], ] + }, + + "Regex matches" : { + run : function(data,log) { + 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 redirect = new Redirect(null, pattern, null, redirectUrl, Redirect.REGEX, null); + var result = redirect.getMatch(url); + return { passed: result.isMatch && result.redirectTo == expected, message : "Expected '" + expected + "', actual was '" + result.redirectTo + "'"}; + }, + + 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'], + ] } + }; -- cgit v1.2.3-70-g09d2