Closed Bug 759989 Opened 12 years ago Closed 12 years ago

Add test to ensure device sensors are shutdown when listeners are removed

Categories

(Core :: DOM: Device Interfaces, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla16

People

(Reporter: dougt, Assigned: dougt)

References

Details

Attachments

(1 file, 2 obsolete files)

Attached patch patch v.1 (obsolete) — Splinter Review
follow up from 742376 * Adds test to verify that device sensors are being shutdown. * Adds a new method to nsIDeviceSensors that exposes if a window has a listener. * Fixes bug in nsGlobalWindow::DisableDeviceSensor where we call through to RemoveWindowListener while there are still valid listeners
Attachment #628592 - Flags: review?(bugs)
Comment on attachment 628592 [details] [diff] [review] patch v.1 >+++ b/content/events/test/test_bug742376.html >@@ -0,0 +1,59 @@ >+<!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() { >+ >+ netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); >+ var dss = Components.classes["@mozilla.org/devicesensors;1"] >+ .getService(Components.interfaces.nsIDeviceSensors); >+ >+ return dss.getWindowListenerCount(Components.interfaces.nsIDeviceSensorData.TYPE_ORIENTATION, >+ window); Either make this chrome test or expose deviceSensors in SpecialPowers. We really don't want new enablePrivilege() calls. > >+NS_IMETHODIMP nsDeviceSensors::GetWindowListenerCount(PRUint32 aType, nsIDOMWindow *aWindow, PRInt32 *_retval NS_OUTPARAM) drop NS_OUTPARAM and _retval -> aRetVal >+{ >+ *_retval = 0; >+ >+ if (!mEnabled) >+ return NS_OK; >+ >+ if (mWindowListeners[aType]->IndexOf(aWindow) == NoIndex) >+ return NS_OK; Looks like the file doesn't use Mozilla coding style, so perhaps no need to fix these to use if (expr) { stmt; } >+[scriptable, uuid(83306c9f-1c8f-43c4-900a-245d7f219511)] > interface nsIDeviceSensors : nsISupports > { >+ long getWindowListenerCount(in unsigned long aType, in nsIDOMWindow aWindow); This is strange method. It takes aWindow just to check that window has registered aType. Wouldn't it be better to have two separate methods. bool hasRegisteredType(in nsIDOMWindow aWindow); and long listenerCount(in unsigned long aType);
Attachment #628592 - Flags: review?(bugs) → review-
> We really don't want new enablePrivilege() calls. There are 55 other calls in that directory. I do not see the harm in adding more. When enablePrivilege is actually removed, someone is going to have to fix up all of these in the manner that you prescribed. if you insist, where exactly should this test live? > Wouldn't it be better to have two separate methods. every window can have n listeners for every type. > Looks like the file doesn't use Mozilla coding style, so perhaps no need to fix these to use I'll fix it, but I should really just send you a patch which is just ws changes.
Attached patch patch v.2 (obsolete) — Splinter Review
converting test to use SpecialPowers.
Assignee: nobody → doug.turner
Attachment #628592 - Attachment is obsolete: true
Attachment #629811 - Flags: review?(bugs)
Attached patch patch v.3Splinter Review
dropping GetWindowListenerCount() in favor of listenerCount. we do not need hasRegisteredType at this point.
Attachment #629811 - Attachment is obsolete: true
Attachment #629811 - Flags: review?(bugs)
Attachment #629826 - Flags: review?(bugs)
Attachment #629826 - Flags: review?(bugs) → review+
backed out. :( https://hg.mozilla.org/integration/mozilla-inbound/rev/e27433b51442 some other listeners is in mochitest-1 that is hurting this.
Comment on attachment 629826 [details] [diff] [review] patch v.3 we need this or devices may not be shutdown after use. Does change a uuid of an interface this is used internally.
Attachment #629826 - Flags: approval-mozilla-aurora?
Attachment #629826 - Flags: approval-mozilla-aurora?
change the test so that we record the number of listeners at the beginning of the test run, and ensure at the end of the test run we equal that number.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla16
Comment on attachment 629826 [details] [diff] [review] patch v.3 similar to bug 742376 and 759354. Without this, we will not shutdown listeners.
Attachment #629826 - Flags: approval-mozilla-aurora?
Comment on attachment 629826 [details] [diff] [review] patch v.3 [Triage Comment] The IDL change is only in nsIDeviceSensors.idl, which as I understand it is unused externally. Approved for Aurora 15.
Attachment #629826 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Depends on: 782549
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: