Closed Bug 951895 Opened 11 years ago Closed 11 years ago

Listeners in SpecialPowers don't receive notifications from parent on B2G

Categories

(Testing :: Mochitest, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla29

People

(Reporter: grobinson, Assigned: jgriffin)

References

Details

Attachments

(2 files)

In working on Bug 945268, I added code to proxy events in the parent process to the child process through SpecialPowers. This works on single-process and e10s, but does not work on B2G. The problem appears to be that the child process never receives messages sent from the parent through the Message Manager.

The basic flow looks like this:

in SpecialPowersObserver.js (runs in the parent process)

* listens for events from the nsIObserverService (which are received)
* on event, sends an async message through the global message manager (nsIMessageBroadcaster)

AIUI, all chrome listeners should receive this message.

in specialpowersAPI.js (runs in the child process)

* add a listener for the message being sent by the parent

In single-process and e10s, this message is received and everything else works normally. On B2G, this listener never receives the message.

I cannot understand why this is happening, but suspect it has something to do with the B2G test runner, which uses Cu.Sandbox, iframes, and other techniques to load the mochitest code.

Attached is my patch for 945268, with debug messages. To reproduce, apply, then run ./mach mochitest-remote content/base/test/csp/test_CSP.html. You will see that the parent process receives events ("http-on-modify-request" observer topics in the parent), but the child does not receive any of the "specialpowers-http-notify-request" messages it subsequently sends.
Blocks: 945268
Component: Gaia::TestAgent → Mochitest
Product: Firefox OS → Testing
One big difference with mochitests in B2G is that they are run in a child process, whereas in Firefox they're run in the parent process.  So, either the SpecialPowers API's being used are either buggy or not designed to work in that environment, or we're not hooking up SpecialPowers correctly.

We'll have to do some debugging to see which is the case.
So, I think the problem is that SpecialPowers is not hooked up correctly.  For B2G, we don't rely on the block of code here:

http://mxr.mozilla.org/mozilla-central/source/testing/specialpowers/components/SpecialPowersObserver.js#51

Instead, we set up the message listeners separately, here:

http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/b2g_start_script.js#60

But, this means that this._sendAsyncMessage in SpecialPowersObserver.js doesn't work...it uses the global message broadcaster, which doesn't send messages to OOP iframes, such as the one that B2G mochitests are run in.

Instead, we need to use the iframe message sender from here:  http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/b2g_start_script.js#60
This might do the trick.
Assignee: nobody → jgriffin
Thanks so much, jgriffin! Testing now.
Looks like this did the trick! I am able to get test_nonce_source.html (another CSP test) passing on B2G (running locally in the emulator). How do we get this landed?

Here's a try run with just the "Hook up SpecialPowers messagemanager correctly for B2G" patch applied, to make sure it doesn't accidentally break anything else: https://tbpl.mozilla.org/?tree=Try&rev=eb960b277cf2

test_CSP.html still doesn't pass, but from a quick scan almost all of the tests are passing. None are failing, it just times out - indicating some test(s) did not run. Since test_CSP tests all of CSP's directives, this could be due to a difference in handling some kind of content type on B2G. Investigating further (but that investigation can continue in bug 945268).
Try looks good!
Attachment #8350405 - Flags: review?(ahalberstadt)
Comment on attachment 8350405 [details] [diff] [review]
Hook up SpecialPowers messagemanager correctly for B2G

Review of attachment 8350405 [details] [diff] [review]:
-----------------------------------------------------------------

Why does the global message manager not broadcast to oop iframes? This looks good to me though.
Attachment #8350405 - Flags: review?(ahalberstadt) → review+
(In reply to Andrew Halberstadt [:ahal] from comment #7)
> Comment on attachment 8350405 [details] [diff] [review]
> Hook up SpecialPowers messagemanager correctly for B2G
> 
> Review of attachment 8350405 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Why does the global message manager not broadcast to oop iframes? This looks
> good to me though.

AFAIUI, the global message manager broadcasts messages through the hierarchy of listeners in the current process; it doesn't broadcast to child processes.  I'm needinfo'ing smaug to confirm this understanding.

Even if the global message manager did reach child frames, I don't think we'd want to use it here, since that could cause tests to send messages to other gaia apps, which could potentially cause unpredictable behavior.
Flags: needinfo?(bugs)
I was mostly just asking out of curiosity, the patch makes sense to me.
Global MM broadcasts to xul window's MMs, and those broadcast to the frame MMs in their document.

So if there is some non-XUL document and inside that a frame MM, broadcasting won't work, 
currently.
Flags: needinfo?(bugs)
https://hg.mozilla.org/mozilla-central/rev/284aefc9d822
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla29
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: