diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 00:05:20 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-04 00:05:20 +0000 |
commit | c6ba2ce4faac672e685ee3ac3765c818cbe4dc90 (patch) | |
tree | ec9e7809c1816d0d558df905edd617a9b0887b94 /net/data | |
parent | eed9b070b545c0ae905cc8e5d32ff7c3a58b477c (diff) | |
download | chromium_src-c6ba2ce4faac672e685ee3ac3765c818cbe4dc90.zip chromium_src-c6ba2ce4faac672e685ee3ac3765c818cbe4dc90.tar.gz chromium_src-c6ba2ce4faac672e685ee3ac3765c818cbe4dc90.tar.bz2 |
Fix error being thrown in isInNet() PAC js.
Mozilla is using notation which treats regexp like a function:
var regex = /foo/;
var result = regex("str");
However v8 does not allow this (nor does IE), so we rewrite it in standard form:
var regex = /foo/;
var result = regex.exec("str")
Also finishes off the tests in pac_library_unittest.js. I didn't test every single permutation of dateRange() and timeRange() as there are way too many; but did hit most common flavors.
BUG=2764
Review URL: http://codereview.chromium.org/40006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/data')
-rw-r--r-- | net/data/proxy_resolver_v8_unittest/pac_library_unittest.js | 192 |
1 files changed, 173 insertions, 19 deletions
diff --git a/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js b/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js index d460b99..6141f51 100644 --- a/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js +++ b/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js @@ -45,15 +45,16 @@ Tests.testDnsDomainLevels = function(t) { }; Tests.testIsInNet = function(t) { - // TODO(eroman): + t.expectTrue( + isInNet("192.89.132.25", "192.89.132.25", "255.255.255.255")); + t.expectFalse( + isInNet("193.89.132.25", "192.89.132.25", "255.255.255.255")); + + t.expectTrue(isInNet("192.89.132.25", "192.89.0.0", "255.255.0.0")); + t.expectFalse(isInNet("193.89.132.25", "192.89.0.0", "255.255.0.0")); - // t.expectTrue( - // isInNet("192.89.132.25", "192.89.132.25", "255.255.255.255")); - // t.expectFalse( - // isInNet("193.89.132.25", "192.89.132.25", "255.255.255.255")); - // - // t.expectTrue(isInNet("192.89.132.25", "192.89.0.0", "255.255.0.0")); - // t.expectFalse(isInNet("193.89.132.25", "192.89.0.0", "255.255.0.0")); + t.expectFalse( + isInNet("192.89.132.a", "192.89.0.0", "255.255.0.0")); }; Tests.testIsPlainHostName = function(t) { @@ -68,29 +69,129 @@ Tests.testLocalHostOrDomainIs = function(t) { }; Tests.testShExpMatch = function(t) { - // TODO(eroman): - - //t.expectTrue(shExpMatch("http://maps.google.com/blah/foo/moreblah.jpg", - // ".*/foo/.*jpg")); - - //t.expectFalse(shExpMatch("http://maps.google.com/blah/foo/moreblah.jpg", - // ".*/foo/.*.html")); + t.expectTrue(shExpMatch("foo.jpg", "*.jpg")); + t.expectTrue(shExpMatch("foo5.jpg", "*o?.jpg")); + t.expectFalse(shExpMatch("foo.jpg", ".jpg")); + t.expectFalse(shExpMatch("foo.jpg", "foo")); }; Tests.testWeekdayRange = function(t) { - // TODO(eroman) + // Test with local time. + MockDate.setCurrent("Tue Mar 03 2009"); + t.expectEquals(true, weekdayRange("MON", "FRI")); + t.expectEquals(true, weekdayRange("TUE", "FRI")); + t.expectEquals(true, weekdayRange("TUE", "TUE")); + t.expectEquals(true, weekdayRange("TUE")); + t.expectEquals(false, weekdayRange("WED", "FRI")); + t.expectEquals(false, weekdayRange("SUN", "MON")); + t.expectEquals(false, weekdayRange("SAT")); + t.expectEquals(false, weekdayRange("FRI", "MON")); + + // Test with GMT time. + MockDate.setCurrent("Tue Mar 03 2009 GMT"); + t.expectEquals(true, weekdayRange("MON", "FRI", "GMT")); + t.expectEquals(true, weekdayRange("TUE", "FRI", "GMT")); + t.expectEquals(true, weekdayRange("TUE", "TUE", "GMT")); + t.expectEquals(true, weekdayRange("TUE", "GMT")); + t.expectEquals(false, weekdayRange("WED", "FRI", "GMT")); + t.expectEquals(false, weekdayRange("SUN", "MON", "GMT")); + t.expectEquals(false, weekdayRange("SAT", "GMT")); }; Tests.testDateRange = function(t) { - // TODO(eroman) + // dateRange(day) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(3)); + t.expectEquals(false, dateRange(1)); + + // dateRange(day, "GMT") + MockDate.setCurrent("Mar 03 2009 GMT"); + t.expectEquals(true, dateRange(3, "GMT")); + t.expectEquals(false, dateRange(1, "GMT")); + + // dateRange(day1, day2) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(1, 4)); + t.expectEquals(false, dateRange(4, 20)); + + // dateRange(day, month) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(3, "MAR")); + MockDate.setCurrent("Mar 03 2014"); + t.expectEquals(true, dateRange(3, "MAR")); + // TODO(eroman): + //t.expectEquals(false, dateRange(2, "MAR")); + //t.expectEquals(false, dateRange(3, "JAN")); + + // dateRange(day, month, year) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(3, "MAR", 2009)); + t.expectEquals(false, dateRange(4, "MAR", 2009)); + t.expectEquals(false, dateRange(3, "FEB", 2009)); + MockDate.setCurrent("Mar 03 2014"); + t.expectEquals(false, dateRange(3, "MAR", 2009)); + + // dateRange(month1, month2) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange("JAN", "MAR")); + t.expectEquals(true, dateRange("MAR", "APR")); + t.expectEquals(false, dateRange("MAY", "SEP")); + + // dateRange(day1, month1, day2, month2) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(1, "JAN", 3, "MAR")); + t.expectEquals(true, dateRange(3, "MAR", 4, "SEP")); + t.expectEquals(false, dateRange(4, "MAR", 4, "SEP")); + + // dateRange(month1, year1, month2, year2) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange("FEB", 2009, "MAR", 2009)); + MockDate.setCurrent("Apr 03 2009"); + t.expectEquals(true, dateRange("FEB", 2009, "MAR", 2010)); + t.expectEquals(false, dateRange("FEB", 2009, "MAR", 2009)); + + // dateRange(day1, month1, year1, day2, month2, year2) + MockDate.setCurrent("Mar 03 2009"); + t.expectEquals(true, dateRange(1, "JAN", 2009, 3, "MAR", 2009)); + t.expectEquals(true, dateRange(3, "MAR", 2009, 4, "SEP", 2009)); + t.expectEquals(true, dateRange(3, "JAN", 2009, 4, "FEB", 2010)); + t.expectEquals(false, dateRange(4, "MAR", 2009, 4, "SEP", 2009)); }; Tests.testTimeRange = function(t) { - // TODO(eroman) + // timeRange(hour) + MockDate.setCurrent("Mar 03, 2009 03:34:01"); + t.expectEquals(true, timeRange(3)); + t.expectEquals(false, timeRange(2)); + + // timeRange(hour1, hour2) + MockDate.setCurrent("Mar 03, 2009 03:34:01"); + t.expectEquals(true, timeRange(2, 3)); + t.expectEquals(true, timeRange(2, 4)); + t.expectEquals(true, timeRange(3, 5)); + t.expectEquals(false, timeRange(1, 2)); + t.expectEquals(false, timeRange(11, 12)); + + // timeRange(hour1, min1, hour2, min2) + MockDate.setCurrent("Mar 03, 2009 03:34:01"); + t.expectEquals(true, timeRange(1, 0, 3, 34)); + t.expectEquals(true, timeRange(1, 0, 3, 35)); + t.expectEquals(true, timeRange(3, 34, 5, 0)); + t.expectEquals(false, timeRange(1, 0, 3, 0)); + t.expectEquals(false, timeRange(11, 0, 16, 0)); + + // timeRange(hour1, min1, sec1, hour2, min2, sec2) + MockDate.setCurrent("Mar 03, 2009 03:34:14"); + t.expectEquals(true, timeRange(1, 0, 0, 3, 34, 14)); + t.expectEquals(false, timeRange(1, 0, 0, 3, 34, 0)); + t.expectEquals(true, timeRange(1, 0, 0, 3, 35, 0)); + t.expectEquals(true, timeRange(3, 34, 0, 5, 0, 0)); + t.expectEquals(false, timeRange(1, 0, 0, 3, 0, 0)); + t.expectEquals(false, timeRange(11, 0, 0, 16, 0, 0)); }; // -------------------------- -// Helpers +// TestContext // -------------------------- // |name| is the name of the test being executed, it will be used when logging @@ -128,3 +229,56 @@ TestContext.prototype.log = function(x) { } }; +// -------------------------- +// MockDate +// -------------------------- + +function MockDate() { + this.wrappedDate_ = new MockDate.super_(MockDate.currentDateString_); +}; + +// Setup the MockDate so it forwards methods to "this.wrappedDate_" (which is a +// real Date object). We can't simply chain the prototypes since Date() doesn't +// allow it. +MockDate.init = function() { + MockDate.super_ = Date; + + function createProxyMethod(methodName) { + return function() { + return this.wrappedDate_[methodName] + .apply(this.wrappedDate_, arguments); + } + }; + + for (i in MockDate.methodNames_) { + var methodName = MockDate.methodNames_[i]; + // Don't define the closure directly in the loop body, since Javascript's + // crazy scoping rules mean |methodName| actually bleeds out of the loop! + MockDate.prototype[methodName] = createProxyMethod(methodName); + } + + // Replace the native Date() with our mock. + Date = MockDate; +}; + +// Unfortunately Date()'s methods are non-enumerable, therefore list manually. +MockDate.methodNames_ = [ + "toString", "toDateString", "toTimeString", "toLocaleString", + "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime", + "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", + "getDate", "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", + "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds", + "getMilliseconds", "getUTCMilliseconds", "getTimezoneOffset", "setTime", + "setMilliseconds", "setUTCMilliseconds", "setSeconds", "setUTCSeconds", + "setMinutes", "setUTCMinutes", "setHours", "setUTCHours", "setDate", + "setUTCDate", "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", + "toGMTString", "toUTCString", "getYear", "setYear" +]; + +MockDate.setCurrent = function(currentDateString) { + MockDate.currentDateString_ = currentDateString; +} + +// Bind the methods to proxy requests to the wrapped Date(). +MockDate.init(); + |