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

RESOLVED FIXED in mozilla16

Status

()

Core
DOM: Device Interfaces
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: dougt, Assigned: dougt)

Tracking

unspecified
mozilla16
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 2 obsolete attachments)

(Assignee)

Description

5 years ago
Created attachment 628592 [details] [diff] [review]
patch v.1

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 1

5 years ago
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-
(Assignee)

Comment 2

5 years ago
> 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.
(Assignee)

Comment 3

5 years ago
Created attachment 629811 [details] [diff] [review]
patch v.2

converting test to use SpecialPowers.
Assignee: nobody → doug.turner
Attachment #628592 - Attachment is obsolete: true
Attachment #629811 - Flags: review?(bugs)
(Assignee)

Comment 4

5 years ago
Created attachment 629826 [details] [diff] [review]
patch v.3

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)
(Assignee)

Updated

5 years ago
Attachment #629826 - Flags: review?(bugs)

Updated

5 years ago
Attachment #629826 - Flags: review?(bugs) → review+
(Assignee)

Comment 5

5 years ago
http://hg.mozilla.org/integration/mozilla-inbound/rev/2f4307a63c18
(Assignee)

Comment 6

5 years ago
backed out. :(  https://hg.mozilla.org/integration/mozilla-inbound/rev/e27433b51442

some other listeners is in mochitest-1 that is hurting this.
(Assignee)

Comment 7

5 years ago
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?
(Assignee)

Updated

5 years ago
Attachment #629826 - Flags: approval-mozilla-aurora?
(Assignee)

Comment 8

5 years ago
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.
(Assignee)

Comment 9

5 years ago
Try:
  https://tbpl.mozilla.org/?tree=Try&rev=c297db179679

Inbound:
  https://hg.mozilla.org/integration/mozilla-inbound/rev/a9024396eeb7
https://hg.mozilla.org/mozilla-central/rev/a9024396eeb7

(Merged by Ed Morley)
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla16
(Assignee)

Comment 11

5 years ago
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+

Updated

5 years ago
Depends on: 782549
You need to log in before you can comment on or make changes to this bug.