diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-23 19:10:45 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-23 19:10:45 +0000 |
commit | 943c808476fc4ccea2175a4f76bc05346c53c209 (patch) | |
tree | ae0c1fe78fa44eeb238770a6051fc639885572f8 /net/data | |
parent | 45bdf86341670d95573acbc699f2d2998a25cf1d (diff) | |
download | chromium_src-943c808476fc4ccea2175a4f76bc05346c53c209.zip chromium_src-943c808476fc4ccea2175a4f76bc05346c53c209.tar.gz chromium_src-943c808476fc4ccea2175a4f76bc05346c53c209.tar.bz2 |
Add ProxyResolverV8 class.darin@chromium.org is the original author of 'proxy_resolver_v8.cc' and 'proxy_resolver_script.h'.
Review URL: http://codereview.chromium.org/21391
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10199 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/data')
14 files changed, 230 insertions, 0 deletions
diff --git a/net/data/proxy_resolver_v8_unittest/direct.js b/net/data/proxy_resolver_v8_unittest/direct.js new file mode 100644 index 0000000..43a04da --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/direct.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return "DIRECT"; +} + diff --git a/net/data/proxy_resolver_v8_unittest/missing_close_brace.js b/net/data/proxy_resolver_v8_unittest/missing_close_brace.js new file mode 100644 index 0000000..8018f8f --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/missing_close_brace.js @@ -0,0 +1,6 @@ +// This PAC script is invalid, because there is a missing close brace +// on the function FindProxyForURL(). + +function FindProxyForURL(url, host) { + return "DIRECT"; + diff --git a/net/data/proxy_resolver_v8_unittest/no_entrypoint.js b/net/data/proxy_resolver_v8_unittest/no_entrypoint.js new file mode 100644 index 0000000..8993059 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/no_entrypoint.js @@ -0,0 +1,2 @@ +var x = "This is an invalid PAC script because it lacks a " + + "FindProxyForURL() function"; diff --git a/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js b/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js new file mode 100644 index 0000000..d460b99 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/pac_library_unittest.js @@ -0,0 +1,130 @@ +// This should output "PROXY success:80" if all the tests pass. +// Otherwise it will output "PROXY failure:<num-failures>". +// +// This aims to unit-test the PAC library functions, which are +// exposed in the PAC's execution environment. (Namely, dnsDomainLevels, +// timeRange, etc.) + +function FindProxyForURL(url, host) { + var numTestsFailed = 0; + + // Run all the tests + for (var test in Tests) { + var t = new TestContext(test); + + // Run the test. + Tests[test](t); + + if (t.failed()) { + numTestsFailed++; + } + } + + if (numTestsFailed == 0) { + return "PROXY success:80"; + } + return "PROXY failure:" + numTestsFailed; +} + +// -------------------------- +// Tests +// -------------------------- + +var Tests = {}; + +Tests.testDnsDomainIs = function(t) { + t.expectTrue(dnsDomainIs("google.com", ".com")); + t.expectTrue(dnsDomainIs("google.co.uk", ".co.uk")); + t.expectFalse(dnsDomainIs("google.com", ".co.uk")); +}; + +Tests.testDnsDomainLevels = function(t) { + t.expectEquals(0, dnsDomainLevels("www")); + t.expectEquals(2, dnsDomainLevels("www.google.com")); + t.expectEquals(3, dnsDomainLevels("192.168.1.1")); +}; + +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")); +}; + +Tests.testIsPlainHostName = function(t) { + t.expectTrue(isPlainHostName("google")); + t.expectFalse(isPlainHostName("google.com")); +}; + +Tests.testLocalHostOrDomainIs = function(t) { + t.expectTrue(localHostOrDomainIs("www.google.com", "www.google.com")); + t.expectTrue(localHostOrDomainIs("www", "www.google.com")); + t.expectFalse(localHostOrDomainIs("maps.google.com", "www.google.com")); +}; + +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")); +}; + +Tests.testWeekdayRange = function(t) { + // TODO(eroman) +}; + +Tests.testDateRange = function(t) { + // TODO(eroman) +}; + +Tests.testTimeRange = function(t) { + // TODO(eroman) +}; + +// -------------------------- +// Helpers +// -------------------------- + +// |name| is the name of the test being executed, it will be used when logging +// errors. +function TestContext(name) { + this.numFailures_ = 0; + this.name_ = name; +}; + +TestContext.prototype.failed = function() { + return this.numFailures_ != 0; +}; + +TestContext.prototype.expectEquals = function(expectation, actual) { + if (!(expectation === actual)) { + this.numFailures_++; + this.log("FAIL: expected: " + expectation + ", actual: " + actual); + } +}; + +TestContext.prototype.expectTrue = function(x) { + this.expectEquals(true, x); +}; + +TestContext.prototype.expectFalse = function(x) { + this.expectEquals(false, x); +}; + +TestContext.prototype.log = function(x) { + // Prefix with the test name that generated the log. + try { + alert(this.name_ + ": " + x); + } catch(e) { + // In case alert() is not defined. + } +}; + diff --git a/net/data/proxy_resolver_v8_unittest/passthrough.js b/net/data/proxy_resolver_v8_unittest/passthrough.js new file mode 100644 index 0000000..832ac66 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/passthrough.js @@ -0,0 +1,45 @@ +// Return a single-proxy result, which encodes ALL the arguments that were +// passed to FindProxyForURL(). + +function FindProxyForURL(url, host) { + if (arguments.length != 2) { + throw "Wrong number of arguments passed to FindProxyForURL!"; + return "FAIL"; + } + + return "PROXY " + makePseudoHost(url + "." + host); +} + +// Form a string that kind-of resembles a host. We will replace any +// non-alphanumeric character with a dot, then fix up the oddly placed dots. +function makePseudoHost(str) { + var result = ""; + + for (var i = 0; i < str.length; ++i) { + var c = str.charAt(i); + if (!isValidPseudoHostChar(c)) { + c = '.'; // Replace unsupported characters with a dot. + } + + // Take care not to place multiple adjacent dots, + // a dot at the beginning, or a dot at the end. + if (c == '.' && + (result.length == 0 || + i == str.length - 1 || + result.charAt(result.length - 1) == '.')) { + continue; + } + result += c; + } + return result; +} + +function isValidPseudoHostChar(c) { + if (c >= '0' && c <= '9') + return true; + if (c >= 'a' && c <= 'z') + return true; + if (c >= 'A' && c <= 'Z') + return true; + return false; +} diff --git a/net/data/proxy_resolver_v8_unittest/return_empty_string.js b/net/data/proxy_resolver_v8_unittest/return_empty_string.js new file mode 100644 index 0000000..3342196 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_empty_string.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return ""; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_function.js b/net/data/proxy_resolver_v8_unittest/return_function.js new file mode 100644 index 0000000..9005553 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_function.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return FindProxyForURL; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_integer.js b/net/data/proxy_resolver_v8_unittest/return_integer.js new file mode 100644 index 0000000..d86b299 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_integer.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return 0; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_null.js b/net/data/proxy_resolver_v8_unittest/return_null.js new file mode 100644 index 0000000..6cf90c5 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_null.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return null; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_object.js b/net/data/proxy_resolver_v8_unittest/return_object.js new file mode 100644 index 0000000..3824f8a --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_object.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return {result: "PROXY foo"}; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_undefined.js b/net/data/proxy_resolver_v8_unittest/return_undefined.js new file mode 100644 index 0000000..0f0aa98 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_undefined.js @@ -0,0 +1,4 @@ +function FindProxyForURL(url, host) { + return undefined; +} + diff --git a/net/data/proxy_resolver_v8_unittest/return_unicode.js b/net/data/proxy_resolver_v8_unittest/return_unicode.js new file mode 100644 index 0000000..5ecdd1c --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/return_unicode.js @@ -0,0 +1,4 @@ +// U+200B is the codepoint for zero-width-space. +function FindProxyForURL(url, host) { + return "PROXY foo.com\u200B"; +} diff --git a/net/data/proxy_resolver_v8_unittest/side_effects.js b/net/data/proxy_resolver_v8_unittest/side_effects.js new file mode 100644 index 0000000..39b3b2d --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/side_effects.js @@ -0,0 +1,10 @@ +if (!gCounter) { + // We write it this way so if the script gets loaded twice, + // gCounter remains dirty. + var gCounter = 0; +} + +function FindProxyForURL(url, host) { + return "PROXY sideffect_" + gCounter++; +} + diff --git a/net/data/proxy_resolver_v8_unittest/unhandled_exception.js b/net/data/proxy_resolver_v8_unittest/unhandled_exception.js new file mode 100644 index 0000000..9cc2856 --- /dev/null +++ b/net/data/proxy_resolver_v8_unittest/unhandled_exception.js @@ -0,0 +1,5 @@ +function FindProxyForURL(url, host) { + // This will throw a runtime exception. + return "PROXY x" + undefined_variable; +} + |