Commit 9513f52b authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Update the PAC JavaScript library to match latest Firefox code.

This brings it up to revision 6aa3b57955fed5e137d0306478e1a4b424a6d392, which includes the following two changes:

* Support for reversed dates in timeRange() and dateRange():
  https://hg.mozilla.org/mozilla-central/rev/cd913073f87c
* Additional validation of IP(v4) literals in isInNet:
  https://hg.mozilla.org/mozilla-central/rev/dd66d01e757c

Bug: 827292
Change-Id: I3d6670c7ceed0fc1bc453d6892922ffb047ab2bc
Reviewed-on: https://chromium-review.googlesource.com/986949
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarHelen Li <xunjieli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548253}
parent 1df2f270
......@@ -220,6 +220,7 @@ Tests.testWeekdayRange = function(t) {
t.expectEquals(true, weekdayRange("MON", "FRI"));
t.expectEquals(true, weekdayRange("TUE", "FRI"));
t.expectEquals(true, weekdayRange("TUE", "TUE"));
t.expectEquals(true, weekdayRange("SAT", "WED"));
t.expectEquals(true, weekdayRange("TUE"));
t.expectEquals(false, weekdayRange("WED", "FRI"));
t.expectEquals(false, weekdayRange("SUN", "MON"));
......@@ -270,20 +271,40 @@ Tests.testDateRange = function(t) {
// 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));
// Unclear what this is supposed to mean. Behavior changed with
// https://hg.mozilla.org/mozilla-central/rev/cd913073f87c.
// See also https://crbug.com/827292
t.expectEquals(true, dateRange(4, "MAR", 2009));
t.expectEquals(true, dateRange(3, "FEB", 2009));
MockDate.setCurrent("Mar 03 2014");
t.expectEquals(false, dateRange(3, "MAR", 2009));
// Unclear what this is supposed to mean. Behavior changed with
// https://hg.mozilla.org/mozilla-central/rev/cd913073f87c.
// See also https://crbug.com/827292
t.expectEquals(true, dateRange(3, "MAR", 2009));
// dateRange(month1, month2)
MockDate.setCurrent("Mar 03 2009");
t.expectEquals(true, dateRange("JAN", "MAR"));
// The reverse should also work.
t.expectEquals(true, dateRange("MAR", "JAN"));
t.expectEquals(true, dateRange("SEP", "APR"));
t.expectEquals(true, dateRange("FEB", "JAN"));
t.expectEquals(false, dateRange("SEP", "FEB"));
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"));
// The reverse should also work.
t.expectEquals(true, dateRange(3, "MAR", 1, "JAN"));
t.expectEquals(true, dateRange(4, "SEP", 3, "APR"));
t.expectEquals(true, dateRange(4, "FEB", 3, "JAN"));
t.expectEquals(false, dateRange(4, "SEP", 3, "FEB"));
t.expectEquals(true, dateRange(3, "MAR", 4, "SEP"));
t.expectEquals(false, dateRange(4, "MAR", 4, "SEP"));
......@@ -319,6 +340,8 @@ Tests.testTimeRange = function(t) {
// timeRange(hour1, min1, hour2, min2)
MockDate.setCurrent("Mar 03, 2009 03:34:01");
t.expectEquals(true, timeRange(1, 0, 3, 34));
// The reverse should also work.
t.expectEquals(true, timeRange(3, 34, 1, 0));
t.expectEquals(true, timeRange(1, 0, 3, 35));
t.expectEquals(true, timeRange(3, 34, 5, 0));
t.expectEquals(false, timeRange(1, 0, 3, 0));
......@@ -351,8 +374,10 @@ TestContext.prototype.failed = function() {
TestContext.prototype.expectEquals = function(expectation, actual) {
if (!(expectation === actual)) {
var callstack = new Error().stack;
this.numFailures_++;
this.log("FAIL: expected: " + expectation + ", actual: " + actual);
this.log("FAIL: expected: " + expectation +
", actual: " + actual + "\n" + callstack);
}
};
......
......@@ -44,19 +44,17 @@
*
* ***** END LICENSE BLOCK ***** */
// The following code was formatted from:
// 'mozilla/netwerk/base/src/nsProxyAutoConfig.js' (1.55)
// The following code was last extracted from netwerk/base/ProxyAutoConfig.cpp
// on 2018-03-29 using this command:
//
// Using the command:
// $ cat nsProxyAutoConfig.js |
// awk '/var pacUtils/,/EOF/' |
// sed -e 's/^\s*$/""/g' |
// sed -e 's/"\s*[+]\s*$/"/g' |
// sed -e 's/"$/" \\/g' |
// sed -e 's/\/(ipaddr);/\/.exec(ipaddr);/g' |
// grep -v '^var pacUtils ='
// REV="6aa3b57955fed5e137d0306478e1a4b424a6d392"
// FILE_PATH="netwerk/base/ProxyAutoConfig.cpp"
// URL="https://hg.mozilla.org/mozilla-central/raw-file/$REV/$FILE_PATH"
//
// isPlainHost() was removed.
// curl "$URL" | awk '/sPacUtils =/,/ "";/' | sed -e 's/"$/" \\/g'
//
// Additionally, the definition for isPlainHostName() was removed, as it is
// implemented by the C++ side already.
#define PAC_JS_LIBRARY \
"function dnsDomainIs(host, domain) {\n" \
" return (host.length >= domain.length &&\n" \
......@@ -64,7 +62,19 @@
"}\n" \
"" \
"function dnsDomainLevels(host) {\n" \
" return host.split('.').length-1;\n" \
" return host.split('.').length - 1;\n" \
"}\n" \
"" \
"function isValidIpAddress(ipchars) {\n" \
" var matches = " \
"/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipchars);\n" \
" if (matches == null) {\n" \
" return false;\n" \
" } else if (matches[1] > 255 || matches[2] > 255 || \n" \
" matches[3] > 255 || matches[4] > 255) {\n" \
" return false;\n" \
" }\n" \
" return true;\n" \
"}\n" \
"" \
"function convert_addr(ipchars) {\n" \
......@@ -77,15 +87,14 @@
"}\n" \
"" \
"function isInNet(ipaddr, pattern, maskstr) {\n" \
" var test = " \
"/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/.exec(ipaddr);\n" \
" if (test == null) {\n" \
" if (!isValidIpAddress(pattern) || !isValidIpAddress(maskstr)) {\n" \
" return false;\n" \
" }\n" \
" if (!isValidIpAddress(ipaddr)) {\n" \
" ipaddr = dnsResolve(ipaddr);\n" \
" if (ipaddr == null)\n" \
" if (ipaddr == null) {\n" \
" return false;\n" \
" } else if (test[1] > 255 || test[2] > 255 || \n" \
" test[3] > 255 || test[4] > 255) {\n" \
" return false; // not an IP address\n" \
" }\n" \
" }\n" \
" var host = convert_addr(ipaddr);\n" \
" var pat = convert_addr(pattern);\n" \
......@@ -113,7 +122,6 @@
"}\n" \
"" \
"var wdays = {SUN: 0, MON: 1, TUE: 2, WED: 3, THU: 4, FRI: 5, SAT: 6};\n" \
"" \
"var months = {JAN: 0, FEB: 1, MAR: 2, APR: 3, MAY: 4, JUN: 5, JUL: 6, " \
"AUG: 7, SEP: 8, OCT: 9, NOV: 10, DEC: 11};\n" \
"" \
......@@ -138,7 +146,10 @@
" var wd1 = getDay(arguments[0]);\n" \
" var wd2 = (argc == 2) ? getDay(arguments[1]) : wd1;\n" \
" return (wd1 == -1 || wd2 == -1) ? false\n" \
" : (wd1 <= wday && wday <= wd2);\n" \
" : (wd1 <= wd2) ? (wd1 <= wday && wday " \
"<= wd2)\n" \
" : (wd2 >= wday || wday " \
">= wd1);\n" \
"}\n" \
"" \
"function dateRange() {\n" \
......@@ -163,14 +174,14 @@
" var tmp = parseInt(arguments[0]);\n" \
" if (isNaN(tmp)) {\n" \
" return ((isGMT ? date.getUTCMonth() : date.getMonth()) ==\n" \
"getMonth(arguments[0]));\n" \
" getMonth(arguments[0]));\n" \
" } else if (tmp < 32) {\n" \
" return ((isGMT ? date.getUTCDate() : date.getDate()) == " \
"tmp);\n" \
" } else { \n" \
" return ((isGMT ? date.getUTCFullYear() : date.getFullYear()) " \
"==\n" \
"tmp);\n" \
" tmp);\n" \
" }\n" \
" }\n" \
" var year = date.getFullYear();\n" \
......@@ -215,14 +226,15 @@
" tmp.setSeconds(date.getUTCSeconds());\n" \
" date = tmp;\n" \
" }\n" \
" return ((date1 <= date) && (date <= date2));\n" \
" return (date1 <= date2) ? (date1 <= date) && (date <= date2)\n" \
" : (date2 >= date) || (date >= date1);\n" \
"}\n" \
"" \
"function timeRange() {\n" \
" var argc = arguments.length;\n" \
" var date = new Date();\n" \
" var isGMT= false;\n" \
"\n" \
"" \
" if (argc < 1) {\n" \
" return false;\n" \
" }\n" \
......@@ -268,7 +280,9 @@
" date.setMinutes(date.getUTCMinutes());\n" \
" date.setSeconds(date.getUTCSeconds());\n" \
" }\n" \
" return ((date1 <= date) && (date <= date2));\n" \
" return (date1 <= date2) ? (date1 <= date) && (date <= date2)\n" \
" : (date2 >= date) || (date >= date1);\n" \
"\n" \
"}\n"
// This is a Microsoft extension to PAC for IPv6, see:
......
......@@ -20,6 +20,7 @@
using net::test::IsError;
using net::test::IsOk;
using ::testing::IsEmpty;
namespace net {
namespace {
......@@ -347,11 +348,11 @@ TEST_F(ProxyResolverV8Test, JavascriptLibrary) {
// If the javascript side of this unit-test fails, it will throw a javascript
// exception. Otherwise it will return "PROXY success:80".
EXPECT_THAT(result, IsOk());
EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI());
EXPECT_THAT(bindings()->alerts, IsEmpty());
EXPECT_THAT(bindings()->errors, IsEmpty());
EXPECT_EQ(0U, bindings()->alerts.size());
EXPECT_EQ(0U, bindings()->errors.size());
ASSERT_THAT(result, IsOk());
EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI());
}
// Test marshalling/un-marshalling of values between C++/V8.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment