mozilla-b2g/gaia — pull request #12523 by jrburke (2013-09-27 22:28:46+00:00)
Title: Bug 917465 - [Email] launching a mail notification will cause Email app to spin and load forever

The issue was my poor understanding of notification API: it triggers mozSetMessageHandler listeners for every notification closed. So what was happening:

* email is sent to two email addresses, both configured to be syncing messages.
* this results in two notifications, one for each account.
* one notification is clicked.
* due to an implementation detail in the system notification code, it also then closes all notifications for associated with the app that gets the notification click.
* This results in the system firing three events to the 'notification' message handler in the email app: one for the click and two close notifications.

I should have been checking message.clicked to know if the message handler notification was from a click or a close, and not do the goofy notifyId checking I was doing before. The notifyId checking was added because I saw to message handler events when testing with one account configured. Turns out the second was the "onclose" message. The notifyId setup was not sufficient with these three events because the third event is for a close of an unrelated notification. This caused the bug.

So the fix is: check for message.clicked, and only do work in those cases. I then removed the hacky notifyId stuff, and then updated the integration test to pass .clicked to operate correctly. I also fixed a bad assumption in email_sync test code, and updated the tests to use email_sync's setup() to do the message handler mock injection.