mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 759989 - Add test to ensure device sensors are shutdown when listeners are removed. r=smaug
This commit is contained in:
parent
82d4333178
commit
2c1901f5ab
@ -85,6 +85,7 @@ _TEST_FILES = \
|
|||||||
test_bug741666.html \
|
test_bug741666.html \
|
||||||
test_dom_keyboard_event.html \
|
test_dom_keyboard_event.html \
|
||||||
test_dom_mouse_event.html \
|
test_dom_mouse_event.html \
|
||||||
|
test_bug742376.html \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
#bug 585630
|
#bug 585630
|
||||||
|
58
content/events/test/test_bug742376.html
Normal file
58
content/events/test/test_bug742376.html
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=402089
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 742376</title>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=742376">Mozilla Bug 742376</a>
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
|
||||||
|
/** Test for Bug 742376 **/
|
||||||
|
|
||||||
|
function getListenerCount() {
|
||||||
|
|
||||||
|
var Cc = SpecialPowers.wrap(Components).classes;
|
||||||
|
var Ci = SpecialPowers.wrap(Components).interfaces;
|
||||||
|
var dss = Cc["@mozilla.org/devicesensors;1"].getService(Ci.nsIDeviceSensors);
|
||||||
|
|
||||||
|
return dss.listenerCount(Ci.nsIDeviceSensorData.TYPE_ORIENTATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
function dumbListener(event) {}
|
||||||
|
function dumbListener2(event) {}
|
||||||
|
|
||||||
|
window.addEventListener("deviceorientation", dumbListener, false);
|
||||||
|
window.addEventListener("deviceorientation", dumbListener2, false);
|
||||||
|
|
||||||
|
window.setTimeout(function() {
|
||||||
|
|
||||||
|
ok (getListenerCount() >= 1, "Must have at least one listeners at this point");
|
||||||
|
|
||||||
|
window.removeEventListener("deviceorientation", dumbListener, false);
|
||||||
|
window.setTimeout(function() {
|
||||||
|
|
||||||
|
is (getListenerCount(), 1, "Must have one listeners at this point");
|
||||||
|
|
||||||
|
window.removeEventListener("deviceorientation", dumbListener2, false);
|
||||||
|
|
||||||
|
window.setTimeout(function() {
|
||||||
|
is (getListenerCount(), 0, "Must have zero listeners at this point");
|
||||||
|
SimpleTest.finish();
|
||||||
|
}, 0);
|
||||||
|
}, 0);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -10040,35 +10040,44 @@ nsGlobalWindow::EnableDeviceSensor(PRUint32 aType)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alreadyEnabled)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mEnabledSensors.AppendElement(aType);
|
mEnabledSensors.AppendElement(aType);
|
||||||
|
|
||||||
|
if (alreadyEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
|
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
|
||||||
if (ac)
|
if (ac) {
|
||||||
ac->AddWindowListener(aType, this);
|
ac->AddWindowListener(aType, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsGlobalWindow::DisableDeviceSensor(PRUint32 aType)
|
nsGlobalWindow::DisableDeviceSensor(PRUint32 aType)
|
||||||
{
|
{
|
||||||
PRInt32 doomedElement = -1;
|
PRInt32 doomedElement = -1;
|
||||||
|
PRInt32 listenerCount = 0;
|
||||||
for (PRUint32 i = 0; i < mEnabledSensors.Length(); i++) {
|
for (PRUint32 i = 0; i < mEnabledSensors.Length(); i++) {
|
||||||
if (mEnabledSensors[i] == aType) {
|
if (mEnabledSensors[i] == aType) {
|
||||||
doomedElement = i;
|
doomedElement = i;
|
||||||
break;
|
listenerCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doomedElement == -1)
|
if (doomedElement == -1) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mEnabledSensors.RemoveElementAt(doomedElement);
|
mEnabledSensors.RemoveElementAt(doomedElement);
|
||||||
|
|
||||||
|
if (listenerCount > 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
|
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
|
||||||
if (ac)
|
if (ac) {
|
||||||
ac->RemoveWindowListener(aType, this);
|
ac->RemoveWindowListener(aType, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -118,6 +118,17 @@ nsDeviceSensors::~nsDeviceSensors()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsDeviceSensors::ListenerCount(PRUint32 aType, PRInt32 *aRetVal)
|
||||||
|
{
|
||||||
|
if (!mEnabled) {
|
||||||
|
*aRetVal = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aRetVal = mWindowListeners[aType]->Length();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsDeviceSensors::AddWindowListener(PRUint32 aType, nsIDOMWindow *aWindow)
|
NS_IMETHODIMP nsDeviceSensors::AddWindowListener(PRUint32 aType, nsIDOMWindow *aWindow)
|
||||||
{
|
{
|
||||||
if (!mEnabled)
|
if (!mEnabled)
|
||||||
|
@ -24,11 +24,14 @@ interface nsIDeviceSensorData : nsISupports
|
|||||||
readonly attribute double z;
|
readonly attribute double z;
|
||||||
};
|
};
|
||||||
|
|
||||||
[scriptable, uuid(b672bfe0-4479-4094-a9ef-1b6847720d07)]
|
[scriptable, uuid(83306c9f-1c8f-43c4-900a-245d7f219511)]
|
||||||
interface nsIDeviceSensors : nsISupports
|
interface nsIDeviceSensors : nsISupports
|
||||||
{
|
{
|
||||||
|
long listenerCount(in unsigned long aType);
|
||||||
|
|
||||||
// Holds pointers, not AddRef objects -- it is up to the caller
|
// Holds pointers, not AddRef objects -- it is up to the caller
|
||||||
// to call RemoveWindowListener before the window is deleted.
|
// to call RemoveWindowListener before the window is deleted.
|
||||||
|
|
||||||
[noscript] void addWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
|
[noscript] void addWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
|
||||||
[noscript] void removeWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
|
[noscript] void removeWindowListener(in unsigned long aType, in nsIDOMWindow aWindow);
|
||||||
[noscript] void removeWindowAsListener(in nsIDOMWindow aWindow);
|
[noscript] void removeWindowAsListener(in nsIDOMWindow aWindow);
|
||||||
|
Loading…
Reference in New Issue
Block a user