From c6ecd7be04207be2b4e892d00a3bf64a6cef37f4 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Thu, 12 Nov 2015 19:01:00 +0100 Subject: [PATCH] Bug 1209654 - Modify the type of the threshold of addAlarm() and getAllAlarms() to long long from long, and add test cases. r=ettseng, r=bz --- .../interfaces/nsIDOMNetworkStatsManager.idl | 4 +- .../tests/test_networkstats_alarms.html | 45 +++++++++++++++++++ dom/system/gonk/NetworkUtils.cpp | 2 +- dom/system/gonk/nsINetworkService.idl | 4 +- dom/webidl/MozNetworkStatsAlarm.webidl | 2 +- dom/webidl/NetworkOptions.webidl | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/dom/network/interfaces/nsIDOMNetworkStatsManager.idl b/dom/network/interfaces/nsIDOMNetworkStatsManager.idl index fd663e9a908c..9db848af1022 100644 --- a/dom/network/interfaces/nsIDOMNetworkStatsManager.idl +++ b/dom/network/interfaces/nsIDOMNetworkStatsManager.idl @@ -6,7 +6,7 @@ interface nsIDOMDOMRequest; -[scriptable, uuid(ceb874cd-cc1a-4e65-b404-cc2d3e42425f)] +[scriptable, uuid(72c4e583-389d-4d1b-9424-702feabb6055)] interface nsIDOMMozNetworkStatsManager : nsISupports { /** @@ -40,7 +40,7 @@ interface nsIDOMMozNetworkStatsManager : nsISupports * If success, the |result| field of the DOMRequest keeps the alarm Id. */ nsIDOMDOMRequest addAlarm(in nsISupports network, - in long threshold, + in long long threshold, [optional] in jsval options /* NetworkStatsAlarmOptions */); /** diff --git a/dom/network/tests/test_networkstats_alarms.html b/dom/network/tests/test_networkstats_alarms.html index f74081eefe4b..5fcaef568ed5 100644 --- a/dom/network/tests/test_networkstats_alarms.html +++ b/dom/network/tests/test_networkstats_alarms.html @@ -147,6 +147,51 @@ var steps = [ ok(false, "getAllAlarms() shouldn't fail."); } }, + // Bug 1209654 - Test threshold value will overflow or not for 2^32. + function () { + ok(true, "Calling addAlarm() with threshold greater than 4GiB"); + + req = navigator.mozNetworkStats + .addAlarm(new window.MozNetworkStatsInterface(wifi), 5000000000); + + req.onsuccess = function () { + ok(true, "Succeeded to add alarm. AlarmId: " + req.result); + next(); + }; + req.onerror = function () { + ok(false, "addAlarm() shouldn't fail."); + }; + }, + function () { + ok(true, "Calling getAllAlarms() and check threshold."); + + req = navigator.mozNetworkStats.getAllAlarms(); + + req.onsuccess = function () { + ok(Array.isArray(req.result) && req.result[0].threshold == 5000000000, + "Succeeded to check threshold."); + next(); + }; + + req.onerror = function () { + ok(false, "getAllAlarms() shouldn't fail."); + } + }, + // Bug 1209654 - Test threshold value will overflow or not for signed long. + function () { + ok(true, "Calling addAlarm() with threshold 3 Gib"); + + req = navigator.mozNetworkStats + .addAlarm(new window.MozNetworkStatsInterface(wifi), 3000000000); + + req.onsuccess = function () { + ok(true, "Succeeded to add alarm. AlarmId: " + req.result); + next(); + }; + req.onerror = function () { + ok(false, "addAlarm() shouldn't fail."); + }; + }, function () { ok(true, "all done!\n"); SimpleTest.finish(); diff --git a/dom/system/gonk/NetworkUtils.cpp b/dom/system/gonk/NetworkUtils.cpp index f057556e2448..5dd4710c68f7 100644 --- a/dom/system/gonk/NetworkUtils.cpp +++ b/dom/system/gonk/NetworkUtils.cpp @@ -734,7 +734,7 @@ void NetworkUtils::setAlarm(CommandChain* aChain, NetworkResultOptions& aResult) { char command[MAX_COMMAND_SIZE]; - PR_snprintf(command, MAX_COMMAND_SIZE - 1, "bandwidth setinterfacealert %s %ld", GET_CHAR(mIfname), GET_FIELD(mThreshold)); + PR_snprintf(command, MAX_COMMAND_SIZE - 1, "bandwidth setinterfacealert %s %lld", GET_CHAR(mIfname), GET_FIELD(mThreshold)); doCommand(command, aChain, aCallback); } diff --git a/dom/system/gonk/nsINetworkService.idl b/dom/system/gonk/nsINetworkService.idl index 974fbd797a22..200ea5b9f30b 100644 --- a/dom/system/gonk/nsINetworkService.idl +++ b/dom/system/gonk/nsINetworkService.idl @@ -157,7 +157,7 @@ interface nsIDhcpRequestCallback : nsISupports /** * Provide network services. */ -[scriptable, uuid(8f689d9f-30c0-4809-8bf6-87120e71f3ee)] +[scriptable, uuid(bb929ae3-4a42-4a63-8388-97c4de69200e)] interface nsINetworkService : nsISupports { const long MODIFY_ROUTE_ADD = 0; @@ -228,7 +228,7 @@ interface nsINetworkService : nsISupports * @return false if there is no interface registered for the networkType param. */ boolean setNetworkInterfaceAlarm(in DOMString networkName, - in long threshold, + in long long threshold, in nsINetworkUsageAlarmCallback callback); /** diff --git a/dom/webidl/MozNetworkStatsAlarm.webidl b/dom/webidl/MozNetworkStatsAlarm.webidl index 840cc4e2c3c7..0d8b781ef260 100644 --- a/dom/webidl/MozNetworkStatsAlarm.webidl +++ b/dom/webidl/MozNetworkStatsAlarm.webidl @@ -9,6 +9,6 @@ interface MozNetworkStatsAlarm { readonly attribute unsigned long alarmId; readonly attribute MozNetworkStatsInterface network; - readonly attribute long threshold; + readonly attribute long long threshold; readonly attribute any data; }; diff --git a/dom/webidl/NetworkOptions.webidl b/dom/webidl/NetworkOptions.webidl index ab5e67983081..2af039da0db7 100644 --- a/dom/webidl/NetworkOptions.webidl +++ b/dom/webidl/NetworkOptions.webidl @@ -38,7 +38,7 @@ dictionary NetworkCommandOptions DOMString usbEndIp; // for "setWifiTethering". DOMString dns1; // for "setWifiTethering". DOMString dns2; // for "setWifiTethering". - long threshold; // for "setNetworkInterfaceAlarm", + long long threshold; // for "setNetworkInterfaceAlarm", // "enableNetworkInterfaceAlarm". DOMString startIp; // for "setDhcpServer". DOMString endIp; // for "setDhcpServer".