Closed Bug 850302 Opened 12 years ago Closed 11 years ago

B2G mochitests time out on tests using window.open

Categories

(Testing :: Mochitest, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
mozilla23

People

(Reporter: martijn.martijn, Assigned: martijn.martijn)

References

Details

Attachments

(1 file, 3 obsolete files)

Window.open doesn't work with the mochitest app.

From bug 807137, comment 8:
"
You're running these tests inside <iframe mozbrowser>, I take it?

You have to handle the mozbrowseropenwindow and mozbrowserclose events (fired on the main iframe and the popup iframe, respectively), otherwise window.open and window.close won't do anything.

You'd want to do something like

iframe.addEventListener('mozbrowseropenwindow', function(e) {
  var popupIframe = e.detail.frameElement;
  popupIframe.addEventListener('mozbrowserclose', function(e) {
    document.body.removeChild(popupIframe);
  });

  popupIframe.addEventListener('mozbrowseropenwindow', function(e) {
    // yes, the popup can call window.open too!
  });

  document.body.appendElement(popupIframe);
});

in addition, you'd probably want to make the test fail if any popups are still open when the test completes.
"

I tried adding this code here:
http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/runtestsb2g.py#71

But that doesn't seem to work.
I can't seem to get the 'mozbrowseropenwindow' to fire on the 'container' iframe, even though I used:
container.setAttribute('mozbrowser', 'true');

At this point, I don't know where to add this code to the mochitest framework.
This looks suspicious:

> let homescreen = document.getElementById('homescreen');
> let container = homescreen.contentWindow.document.getElementById('test-container');
> container.setAttribute('mozapp', 'http://mochi.test:8888/manifest.webapp');

I wonder if container is even a mozapp frame.  You can't set that property whenever you want; I'm pretty sure you have to set mozapp before you insert the iframe into the DOM.

Also you have to have the mozbrowser attribute on the frame before you insert it into the DOM, otherwise it's not an app.

What does container.hasAttribute('mozbrowser') return?  Do you get any other mozbrowser events on the frame (e.g. mozbrowserloadstart)?
Ok, thanks. I'm on vacation for 2 weeks and don't have my computer with me.
I'll try your suggestion as soon as I can.
I can't seem to find where the iframe id="test-container" is being created:
http://mxr.mozilla.org/mozilla-central/search?string=test-container

I can only find iframe id="testframe":
http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/server.js#631
Ok, thanks.
I guess that this part should be removed then in order for it to work, perhaps:
http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/runtestsb2g.py#70
70 container.setAttribute('mozapp', 'http://mochi.test:8888/manifest.webapp');
Yes, that line seems redundant.
Attached patch patch (obsolete) (deleted) — Splinter Review
Ok, got it working now. I can see problems with this patch, but it seems to make most of the mochitests working that uses window.open() calls.
I can see problems when doing 2 times window.open('blah.html', 'a', '') for instance. The 2nd time, no new window should be opened.
Window sizes are completely wrong of course, but I wonder if that even can be fixed.

I ran these through the content/ subdirectory for the tests that use window.open.
These were passing with this test:
        "content/base/test/test_bug426646.html": "",
        "content/base/test/test_bug557892.html": "",
        "content/events/test/test_bug322588.html" : "",
        "content/events/test/test_bug493251.html" : "",
        "content/events/test/test_bug545268.html" : "",
        "content/events/test/test_bug656379-1.html" : "",
        "content/html/content/test/test_iframe_sandbox_general.html" : "",
        "content/xml/document/test/test_bug691215.html" : "",
        "content/html/content/test/forms/test_formaction_attribute.html" : ""

These were still failing:
        "content/html/content/test/test_iframe_sandbox_navigation.html" : "unknown error",
        "content/html/content/test/test_fullscreen-api.html" : "focus issue, then full screen issue",
        "content/events/test/test_bug426082.html" : "forms.css has button:active:hover rule, b2g content.css has only button:acive rule",
        "content/html/document/test/test_bug741266.html" : "popup window needs correct size, also innerWidth",
        "content/xbl/test/test_bug310107.html" : "xbl not working currently",
        "content/media/test/test_delay_load.html" : "video files not found?",
        "content/html/document/test/test_bug199692.html" : "this needs popup window to have correct size",
        "content/events/test/test_bug659071.html" : "ctrl-wheel zoom not working",
        "content/html/document/test/test_bug369370.html" : "needs to be converted to specialpowers pref setting",
        "content/events/test/test_bug457672.html" : "needs to be converted to specialpowers pref setting",
        "content/base/test/test_x-frame-options.html" : "addobserver problem",
        "content/base/test/test_plugin_freezing.html": "test plugin needed",
        "content/base/test/test_bug326337.html": "document.domain setting?",
        "content/media/test/test_access_control.html" : "other domain",
        "content/events/test/test_wheel_default_action.html" : "specialpowers problem"

I'm surprised that window.opener seems to work magically, apparently. I wonder if doing stuff like window.opener.document.body.innerHTML = 'foopy' is working.
Attachment #733439 - Flags: review?(justin.lebar+bug)
> +  popupIframe.remote = 'true';
> +  popupIframe.mozbrowser = 'true';
> +  popupIframe.mozapp = 'http://mochi.test:8888/manifest.webapp';
> +  popupIframe.src = aEvent.detail.url;
> +  popupIframe.name = aEvent.detail.name;

None of this should be necessary.  If it is necessary, something is probably wrong.

> when doing 2 times window.open('blah.html', 'a', '') for instance. The 2nd time, no new window 
> should be opened.

This should work properly today.  Does it not work?

> I'm surprised that window.opener seems to work magically, apparently.

Yep.

> I wonder if doing stuff like window.opener.document.body.innerHTML = 'foopy' is working.

It should.

> +    container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.activateRemoteFrame();
> +    popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.activateRemoteFrame();

These should not be necessary.  If they are, something is wrong.

Can you please verify if things still work with these bits of code removed?
Attachment #733439 - Flags: review?(justin.lebar+bug)
> Window sizes are completely wrong of course, but I wonder if that even can be fixed.

Sure can, but you have to parse e.detail.features yourself.
(In reply to Justin Lebar [:jlebar] from comment #8)
> > +    container.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.activateRemoteFrame();
> > +    popupIframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.activateRemoteFrame();
> 
> These should not be necessary.  If they are, something is wrong.
> 
> Can you please verify if things still work with these bits of code removed?

The activateRemoteFrame() stuff is needed, otherwise I get failures and timeouts.
The other things were indeed not needed.
Attached patch patch (obsolete) (deleted) — Splinter Review
Attachment #734862 - Flags: review?(justin.lebar+bug)
> The activateRemoteFrame() stuff is needed, otherwise I get failures and timeouts.

AFAICT activateRemoteFrame is not called outside this file, which makes me suspect pretty strongly that there's probably some other way to accomplish whatever this accomplishes.  If we can avoid calling it, that would be advantageous, since it would make the test environment more closely match the production environment, which does not make this call.

What are the failures and timeouts?  Does an iframe.focus() call suffice?  I also asked for help in bug 788866.

Since smaug already r+'ed an activateRemoteFrame, I'm not going to gate my review on it.
Attachment #734862 - Flags: review?(justin.lebar+bug) → review+
Attached patch patch (obsolete) (deleted) — Splinter Review
Ok, .focus() on the iframe seems to work too, so using that instead of .activateRemoteFrame().

It makes me wonder what activateRemoteFrame() is useful for, though.
Attachment #733439 - Attachment is obsolete: true
Attachment #734862 - Attachment is obsolete: true
Attachment #736268 - Flags: review?(justin.lebar+bug)
Attached patch patch for check-in (deleted) — Splinter Review
Blocks: 860748
> It makes me wonder what activateRemoteFrame() is useful for, though.

If you remove the other activateRemoteFrame() call in this file, nobody will be using it!
Attachment #736268 - Attachment is obsolete: true
Attachment #736268 - Flags: review?(justin.lebar+bug)
(In reply to Justin Lebar [:jlebar] from comment #15)
> > It makes me wonder what activateRemoteFrame() is useful for, though.
> 
> If you remove the other activateRemoteFrame() call in this file, nobody will
> be using it!

Yeah, and since iframe.focus() seems to be doing the same thing, I wonder what the use case for activateRemoteFrame() is.
Keywords: checkin-needed
I suspect it has to do with the subtlety in Olli's comment previously: /if the iframe is focusable/, then .focus() will work.  Perhaps there are cases when we have a remote frame that's inside something that's not focusable.  But I don't know more than that.
https://hg.mozilla.org/mozilla-central/rev/ed313842afec
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
(In reply to Martijn Wargers [:mw22] (QA - IRC nick: mw22) from comment #7)
>         "content/html/document/test/test_bug369370.html" : "needs to be
> converted to specialpowers pref setting",
>         "content/events/test/test_bug457672.html" : "needs to be converted
> to specialpowers pref setting",

This is being done in bug 861674.
Assignee: nobody → martijn.martijn
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: