[Alarm] Clock UI not updated when alarm(s) are deleted via the api

RESOLVED INVALID

Status

()

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

People

(Reporter: rwood, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

5 years ago
Start the Clock app. If no alarms exist, create at least one new alarm and verify it appears in the Clock app's alarm list.

Leave the Clock app running, and now use the WebAPI to delete all alarms, (i.e. from WebQA's gaia-ui suite):

  deleteAllAlarms: function() {
    window.wrappedJSObject.AlarmManager.getAlarmList (function(aList) {
      aList.forEach(function(aAlarm) {
         console.log("Deleting alarm with id '" + aAlarm.id + "'");
         window.wrappedJSObject.AlarmManager.delete(aAlarm);
      });
    });
  }

Now notice the alarm 'bell' icon at the top/ribbon bar has disappeared as expected, however the alarm list in the Clock app has not been updated / cleared; the alarms still show as existing even though they have been deleted. To have the list refreshed a new alarm must be created, or the Clock app closed and restarted.

Couldn't there be cases where other Firefox apps delete existing alarms when the Clock app may already be running?
Bug 841736 might make this a real problem.
Depends on: 841736
Was the code snippet in the description run as an app, or with elevated permissions? I'm surprised with how this code managed to delete alarms for another app. Other firefox apps should never be able to delete alarms belonging to the clock app.
(Reporter)

Comment 3

5 years ago
The code snippet above is part of the gaia-ui test suite utility functions, driven by Marionette. Dave can you provide insight here re: 'elevated permissions'?
Flags: needinfo?(dave.hunt)
It doesn't use special powers, if that's what you mean, but it does require the Clock application to be open. Therefore, I'm not sure if another application would be able to remove alarms in this way.
Flags: needinfo?(dave.hunt)
Hi Ian,

As Nikhil's comment #2, an app shouldn't be able to delete alarms that don't belong to it through the .delete() API, because the API will internally checks if the manifest URL of the calling window is matched.

I'm wondering the root cause of comment #0 is: the alarms have been successfully deleted from the API's DB but not yet done from the Clock App's DB. Could you please verify what's happening from the Gaia's perspective? Thanks!

(In reply to Mounir Lamouri (:mounir) from comment #1)
> Bug 841736 might make this a real problem.

I don't quite understand how bug 841736 is related. :O
Flags: needinfo?(iliu)
I suspect the alarms have been deleted but the app hasn't refreshed to reflect that. I wouldn't consider this a bug as it's not how a user would delete alarms from the app. Rob: Can you try adding a marionette.refresh() to see if this removes the alarms from the UI?
(In reply to Gene Lian [:gene] from comment #5)
> Hi Ian,
> 
> As Nikhil's comment #2, an app shouldn't be able to delete alarms that don't
> belong to it through the .delete() API, because the API will internally
> checks if the manifest URL of the calling window is matched.
> 
> I'm wondering the root cause of comment #0 is: the alarms have been
> successfully deleted from the API's DB but not yet done from the Clock App's
> DB. Could you please verify what's happening from the Gaia's perspective?
> Thanks!
> 
Gene and Dave are exactly right. Clock app has its own database and maintain itself. For example, there are three section to maintain Clock app's DB.

* Set an alarm
https://github.com/mozilla-b2g/gaia/blob/master/apps/clock/js/alarmManager.js#L109

* Unset an alarm
https://github.com/mozilla-b2g/gaia/blob/master/apps/clock/js/alarmManager.js#L142

* Delete an alarm
https://github.com/mozilla-b2g/gaia/blob/master/apps/clock/js/alarmManager.js#L159

As the user story occurred, we set/unset/toggle/delete an alarm via the interface of AlarmManager. These methods will maintain Clock app's DB after received onsuccess callback, some status updating... Then, you could also find out the methods of "AlarmManager.putAlarm(); AlarmManager.delete();" to update its DB directly. 

Hoping above information could help you to build up UITest. Thanks.
Flags: needinfo?(iliu)
(Reporter)

Comment 8

5 years ago
Thanks guys. If I am understanding correctly, the utility function in the gaia-ui test framework needs to be updated to delete alarms directly from the Clock app database instead of the API's db? Is that correct/possible?

For now the workaround in the test_endurance_set_alarm test works fine, deleting all alarms and then shutting down and restarting the Clock app. (Marionette.refresh doesn't do it). So the Clock app shutdown and restart must be forcing the Clock app's db to be updated/sync'd with changes from the API db, is that right?
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.