Bug 1251332 - add PAC support for reversed ranges; r=bagder
authorLiang-Heng Chen <xeonchen@mozilla.com>
Mon, 25 Apr 2016 16:26:52 +0800
changeset 295618 cd913073f87c2636bc3647502ab2308b4ee03ffa
parent 295617 63826ac5bd1f943bc4b28552d30211c5b7b9253e
child 295619 df94f24cdf39fbed76f0c88dd3f98af569c1bf20
push id19015
push usercbook@mozilla.com
push dateMon, 02 May 2016 09:39:23 +0000
treeherderfx-team@2080375bc69d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1251332
milestone49.0a1
Bug 1251332 - add PAC support for reversed ranges; r=bagder MozReview-Commit-ID: HsbupdOORI6
netwerk/base/ProxyAutoConfig.cpp
netwerk/test/unit/test_protocolproxyservice.js
--- a/netwerk/base/ProxyAutoConfig.cpp
+++ b/netwerk/base/ProxyAutoConfig.cpp
@@ -104,17 +104,18 @@ static const char *sPacUtils =
   "        argc--;\n"
   "        wday = date.getUTCDay();\n"
   "    } else {\n"
   "        wday = date.getDay();\n"
   "    }\n"
   "    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"
   "    function getMonth(name) {\n"
   "        if (name in months) {\n"
   "            return months[name];\n"
   "        }\n"
   "        return -1;\n"
@@ -179,17 +180,18 @@ static const char *sPacUtils =
   "        tmp.setFullYear(date.getUTCFullYear());\n"
   "        tmp.setMonth(date.getUTCMonth());\n"
   "        tmp.setDate(date.getUTCDate());\n"
   "        tmp.setHours(date.getUTCHours());\n"
   "        tmp.setMinutes(date.getUTCMinutes());\n"
   "        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"
   ""
   "    if (argc < 1) {\n"
@@ -232,17 +234,19 @@ static const char *sPacUtils =
   "    if (isGMT) {\n"
   "        date.setFullYear(date.getUTCFullYear());\n"
   "        date.setMonth(date.getUTCMonth());\n"
   "        date.setDate(date.getUTCDate());\n"
   "        date.setHours(date.getUTCHours());\n"
   "        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"
   "";
 
 // sRunning is defined for the helper functions only while the
 // Javascript engine is running and the PAC object cannot be deleted
 // or reset.
 static uint32_t sRunningIndex = 0xdeadbeef;
 static ProxyAutoConfig *GetRunning()
--- a/netwerk/test/unit/test_protocolproxyservice.js
+++ b/netwerk/test/unit/test_protocolproxyservice.js
@@ -599,16 +599,46 @@ function run_pac4_test() {
   });
   channel.notificationCallbacks =
     AppsUtils.createLoadContext(appId, isInIsolatedMozBrowser);
 
   // Configure PAC
   prefs.setIntPref("network.proxy.type", 2);
   prefs.setCharPref("network.proxy.autoconfig_url", pac);
 
+  var req = pps.asyncResolve(channel, 0, new TestResolveCallback("http", run_pac5_test));
+}
+
+function run_pac5_test() {
+  // Bug 1251332
+  let wRange = [
+    ["SUN", "MON", "SAT", "MON"], // for Sun
+    ["SUN", "TUE", "SAT", "TUE"], // for Mon
+    ["MON", "WED", "SAT", "WED"], // for Tue
+    ["TUE", "THU", "SAT", "THU"], // for Wed
+    ["WED", "FRI", "WED", "SUN"], // for Thu
+    ["THU", "SAT", "THU", "SUN"], // for Fri
+    ["FRI", "SAT", "FRI", "SUN"], // for Sat
+  ];
+  let today = (new Date()).getDay();
+  var pac = 'data:text/plain,' +
+            'function FindProxyForURL(url, host) {' +
+            '  if (weekdayRange("' + wRange[today][0] + '", "' + wRange[today][1] + '") &&' +
+            '      weekdayRange("' + wRange[today][2] + '", "' + wRange[today][3] + '")) {' +
+            '    return "PROXY foopy:8080; DIRECT";' +
+            '  }' +
+            '}';
+  var channel = NetUtil.newChannel({
+    uri: "http://www.mozilla.org/",
+    loadUsingSystemPrincipal: true
+  });
+  // Configure PAC
+
+  prefs.setIntPref("network.proxy.type", 2);
+  prefs.setCharPref("network.proxy.autoconfig_url", pac);
   var req = pps.asyncResolve(channel, 0, new TestResolveCallback("http", finish_pac_test));
 }
 
 function finish_pac_test() {
   prefs.setBoolPref("network.proxy.proxy_over_tls", originalTLSProxy);
   run_pac_cancel_test();
 }