Closed Bug 964769 Opened 11 years ago Closed 10 years ago

Not able to access navigator.mozSetMessageHandler() from the test script without UI

Categories

(Core :: DOM: Device Interfaces, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

()

RESOLVED INVALID
blocking-b2g 1.4+

People

(Reporter: vasanth, Unassigned)

References

Details

Objective is to receive the broadcast message [1] in a test script.
Only way seems like using navigator.mozSetMessageHandler() with the broadcast message name.

That returns following error when tried from marionette test script without UI.
However the same script is able to access navigtor.mozMobileConnection, mozSettings etc.,

[JavaScript Error: "principal.URI is null" {file: "jar:file:///system/b2g/omni.ja!/components/SystemMessageManager.js" line: 256}]

Why this error comes and how can we resolve this?

[1] http://dxr.mozilla.org/mozilla-central/source/dom/messages/interfaces/nsISystemMessagesInternal.idl#34
No longer blocks: b2g--telephony-1.4
(In reply to vasanth from comment #0)
> Objective is to receive the broadcast message [1] in a test script.
> Only way seems like using navigator.mozSetMessageHandler() with the
> broadcast message name.
> 
> That returns following error when tried from marionette test script without
> UI.
> However the same script is able to access navigtor.mozMobileConnection,
> mozSettings etc.,
> 
> [JavaScript Error: "principal.URI is null" {file:
> "jar:file:///system/b2g/omni.ja!/components/SystemMessageManager.js" line:
> 256}]
> 
> Why this error comes and how can we resolve this?
> 
> [1]
> http://dxr.mozilla.org/mozilla-central/source/dom/messages/interfaces/
> nsISystemMessagesInternal.idl#34

Hi vasanth,

May I know how you ran your marionette test script and what system message
you expect to receive? I tried on my desktop (call navigator.mozSetMessageHandler)
and got no error like you said. 

Thanks.
Blocks QC CS for 1.4
blocking-b2g: --- → 1.4+
Component: General → DOM: Device Interfaces
Product: Firefox OS → Core
Why are we blocking on a testing enhancement? That seems a bit strange to me that this is a FC blocker.
Flags: needinfo?(mvines)
(In reply to Henry Chang [:henry] from comment #1)
@henry What Vasanth means is that the tests are running in the chrome context ie.

 MARIONETTE_CONTEXT = 'chrome';
(In reply to Jason Smith [:jsmith] from comment #3)
> Why are we blocking on a testing enhancement? That seems a bit strange to me
> that this is a FC blocker.

This issue is blocking some of our FC test execution.
Flags: needinfo?(mvines)
(In reply to Henry Chang [:henry] from comment #1)
> May I know how you ran your marionette test script and what system message
> you expect to receive? I tried on my desktop (call
> navigator.mozSetMessageHandler)
> and got no error like you said. 

My marionette script is something like this [1] 
I was expecting a system message something like this [2]
I guess these scripts cannot access Gaia apps/UI. But from error message, it seems an URI is needed
to deliver system message?[3]
Can you share yours if its able to get system message [2] in marionette script like [1] (chrome context)?

[1] http://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/tests
[2] https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/carrier_info_notifier.js#L11
[3] http://dxr.mozilla.org/mozilla-central/source/dom/messages/SystemMessageManager.js#255
Hi vasanth,

From what I know and the implementation, system message does require an URL as an identifier
to deliver messages. Needinfo Gene to make sure if it's by design. If you want test mixing
content and chrome context, you might need to use gaia-ui-test, which lets you write python
test script with marionette capabilities and switch chrome/content back and forth.

(In reply to vasanth from comment #6)
> (In reply to Henry Chang [:henry] from comment #1)
> > May I know how you ran your marionette test script and what system message
> > you expect to receive? I tried on my desktop (call
> > navigator.mozSetMessageHandler)
> > and got no error like you said. 
> 
> My marionette script is something like this [1] 
> I was expecting a system message something like this [2]
> I guess these scripts cannot access Gaia apps/UI. But from error message, it
> seems an URI is needed
> to deliver system message?[3]
> Can you share yours if its able to get system message [2] in marionette
> script like [1] (chrome context)?
> 
> [1] http://dxr.mozilla.org/mozilla-central/source/dom/system/gonk/tests
> [2]
> https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/
> carrier_info_notifier.js#L11
> [3]
> http://dxr.mozilla.org/mozilla-central/source/dom/messages/
> SystemMessageManager.js#255
Flags: needinfo?(gene.lian)
Henri is correct, we need the page URI to register message handlers. I you want pure chrome tests (why? it's a web page API), you will need to "mock" the content side in some way.
Running in the chrome context, among other things, allows us to interact with web APIs without obscuring the screen with a test page.  How can we go about creating mock content?
Fabrice has already answered the question.
Michael,

Please check on next steps here.
Flags: needinfo?(mschwart)
(In reply to Fabrice Desré [:fabrice] from comment #8)
> Henri is correct, we need the page URI to register message handlers. I you
> want pure chrome tests (why? it's a web page API), you will need to "mock"
> the content side in some way.
Fabrice, can you point us to an example of creating mock content?
I don't have any to show... mocking the full window object is no small task.

If you are only interested in testing message broadcasting, you could make it so we don't throw at https://mxr.mozilla.org/mozilla-central/source/dom/messages/SystemMessageManager.js#255 and keep an undefined _uri. That should be enough for broadcastMessage(), but not for sendMessage()
Flags: needinfo?(gene.lian)
(In reply to Fabrice Desré [:fabrice] from comment #13)
> If you are only interested in testing message broadcasting, you could make
> it so we don't throw at
> https://mxr.mozilla.org/mozilla-central/source/dom/messages/
> SystemMessageManager.js#255 and keep an undefined _uri. That should be
> enough for broadcastMessage(), but not for sendMessage()

Hi Fabrice, 
Our intention is to receive the broadcast message in test script like [1]
I see _uri is a property in SystemMessageManager and as of now test script doesn't access SystemMessageManager similar to [1]
Could you be more specific what exactly we can add in test script so we can avoid this error?

[1]  https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/carrier_info_notifier.js#L11
Flags: needinfo?(mschwart) → needinfo?(fabrice)
You need to patch SystemMessageManager.js to make it not fail in the case where _uri is undefined or null.

Probably as simple as:
this._uri = principal.URI ? principal.URI.spec : null;
instead of https://mxr.mozilla.org/mozilla-central/source/dom/messages/SystemMessageManager.js#255 should work.
Flags: needinfo?(fabrice)
Vasanth

Please review if we need anything else from MOZ
Flags: needinfo?(vasanth)
With Fabrice's suggestion, script doesn't throw error. But still we don't receive the broadcast message. Will debug and update here.
With Fabrice's suggestion, setting mozSetMessageHandler() bails out here [1] since uri and manifest are null. Now I do realize this api needs a manifest uri/page to deliver the messages.

BTW, why the test script is not able to make use of current document's page uri and manifest?

[1] http://dxr.mozilla.org/mozilla-central/source/dom/messages/SystemMessageInternal.js#412
Flags: needinfo?(vasanth)
Vasanth, who is your question directed to? Please add ni to get quick response.
Flags: needinfo?(vasanth)
Henry, I guess you might know the answer? Please move to the correct person if I'm wrong
Flags: needinfo?(vasanth) → needinfo?(hchang)
(In reply to vasanth from comment #20)
> Henry, I guess you might know the answer? Please move to the correct person
> if I'm wrong

Hi Vasanth,

That's because your marionette script will be running in the chrome context, which means your script is running in neither system app nor any of other apps. Is there any chance to run your script in the content context?

Thanks!
Flags: needinfo?(hchang)
Thanks Henry. 
Will try to find and update here.
I'm just going to set ni on Vasanth so it's clear what the status here is.
Flags: needinfo?(vasanth)
I see navigator.mozSetMessageHandler() (or any UI dependent APIs) is not supported in chrome based tests. 
That makes this bug invalid. 
Is there somewhere it is documented? So next time we won't try this way.
Closing this.
Status: NEW → RESOLVED
Closed: 10 years ago
Flags: needinfo?(vasanth)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.