Closed Bug 788866 Opened 12 years ago Closed 11 years ago

[B2G] mochitests fail to focus test window

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla23
blocking-b2g tef+
Tracking Status
firefox21 --- wontfix
firefox22 --- wontfix
firefox23 --- fixed
b2g18 --- fixed
b2g18-v1.0.0 --- wontfix
b2g18-v1.0.1 --- fixed

People

(Reporter: jgriffin, Unassigned)

References

Details

Attachments

(2 files)

Mochitests running in B2G fail to focus the test window, resulting in this warning for every test:

Error: Unable to restore focus, expect failures and timeouts.

Mochitest tries to set the focus to the test window using this code:

http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/tests/SimpleTest/TestRunner.js#214

In this code, document.hasFocus() is always returning false, even after calls to window.focus() and iframe.focus().

It's possible this issue is causing some of the B2G mochitest failures, although the bulk of them do not appear to be caused by this.

A representative log:  http://brasstacks.mozilla.com/autologserver/showlog?file=af55d500-f7a9-11e1-9dc1-22000af4858b.txt.gz
When run on a debug build, this assertion occurs each time:

[Child 21981] ###!!! ASSERTION: TabChild::SetFocus not supported in TabChild: 'Not Reached', file /Users/jgriffin/gaia-hack/src/dom/ipc/TabChild.cpp, line 742
mozilla::dom::TabChild::SetFocus()+0x00000033 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0200EBF3]
non-virtual thunk to mozilla::dom::TabChild::SetFocus()+0x0000001C [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0200EC1C]
nsGlobalWindow::Focus()+0x0000055C [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01091BCC]
nsGlobalWindow::Focus()+0x00000098 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01091708]
NS_InvokeByIndex_P+0x00000219 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0265E0E9]
CallMethodHelper::Invoke()+0x00000054 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01957754]
CallMethodHelper::Call()+0x0000013C [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01955AAC]
XPCWrappedNative::CallMethod(XPCCallContext&, XPCWrappedNative::CallMode)+0x00000303 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01952013]
XPC_WN_CallMethod(JSContext*, unsigned int, JS::Value*)+0x0000024B [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0196219B]
js::CallJSNative(JSContext*, int (*)(JSContext*, unsigned int, JS::Value*), JS::CallArgs const&)+0x000000A8 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x035721E8]
js::InvokeKernel(JSContext*, JS::CallArgs, js::MaybeConstruct)+0x000003CE [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0356741E]
js::Interpret(JSContext*, js::StackFrame*, js::InterpMode)+0x00005B2B [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0356062B]
js::RunScript(JSContext*, JS::Handle<JSScript*>, js::StackFrame*)+0x0000033B [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0355A9EB]
js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value const&, js::ExecuteType, js::StackFrame*, JS::Value*)+0x0000027A [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0356859A]
js::Execute(JSContext*, JS::Handle<JSScript*>, JSObject&, JS::Value*)+0x00000247 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x03568887]
JS::Evaluate(JSContext*, JS::Handle<JSObject*>, JS::CompileOptions, unsigned short const*, unsigned long, JS::Value*)+0x0000034F [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0345DA0F]
nsJSContext::EvaluateString(nsAString_internal const&, JSObject*, nsIPrincipal*, nsIPrincipal*, char const*, unsigned int, JSVersion, nsAString_internal*, bool*)+0x000007F9 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01057BF9]
nsGlobalWindow::RunTimeoutHandler(nsTimeout*, nsIScriptContext*)+0x000002C9 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x010A74F9]
nsGlobalWindow::RunTimeout(nsTimeout*)+0x000004CE [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0109AA8E]
nsGlobalWindow::TimerCallback(nsITimer*, void*)+0x00000050 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x010A7090]
nsTimerImpl::Fire()+0x00000400 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0262F230]
nsTimerEvent::Run()+0x000000E2 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0262F5C2]
nsThread::ProcessNextEvent(bool, bool*)+0x00000644 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x02624E44]
NS_ProcessPendingEvents_P(nsIThread*, unsigned int)+0x000000A2 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0258D582]
nsBaseAppShell::NativeEventCallback()+0x000000BF [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01E7B70F]
nsAppShell::ProcessGeckoEvents(void*)+0x000001AC [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01E0DE3C]
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+0x00000011 [/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation +0x000124F1]
__CFRunLoopDoSources0+0x000000FD [/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation +0x00011D5D]
__CFRunLoopRun+0x00000389 [/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation +0x00038B49]
CFRunLoopRunSpecific+0x000000E6 [/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation +0x00038486]
RunCurrentEventLoopInMode+0x00000115 [/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox +0x000022BF]
ReceiveNextEventCommon+0x00000163 [/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox +0x0000956D]
BlockUntilNextEventMatchingListInMode+0x0000003E [/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox +0x000093FA]
_DPSNextEvent+0x00000293 [/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit +0x00008779]
-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]+0x00000087 [/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit +0x0000807D]
-[GeckoNSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]+0x00000077 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01E0C6A7]
-[NSApplication run]+0x000001D6 [/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit +0x000049B9]
nsAppShell::Run()+0x0000008C [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x01E0E8BC]
XRE_RunAppShell+0x0000014D [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x00028D8D]
mozilla::ipc::MessagePumpForChildProcess::Run(base::MessagePump::Delegate*)+0x0000007E [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x020641EE]
MessageLoop::RunInternal()+0x00000076 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x026AA3D6]
MessageLoop::RunHandler()+0x00000015 [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x026AA2E5]
MessageLoop::Run()+0x0000002D [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x026AA28D]
XRE_InitChildProcess+0x000009AD [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/XUL +0x0002868D]
main+0x0000005C [/Users/jgriffin/gaia-hack/build/dist/B2GDebug.app/Contents/MacOS/plugin-container.app/Contents/MacOS/plugin-container +0x00000DAC]

It appears that we can't call focus across processes?
IIRC you just need to activate the child from parent.
Isn't there is something like activateRemoteFrame in nsIFrameLoader.
Oh, or are you trying to focus window from child? That might not be, perhaps correctly, supported.
Blocks: 851187
Shouldn't the homescreen app always give focus to the child app process when it has finished loading?
http://mxr.mozilla.org/mozilla-central/source/b2g/chrome/content/shell.js#261
Attached patch patchSplinter Review
This makes the messages go away and seems to make the tests run much faster (bug 851187).
Tested this on:
content/html/content/test/forms/test_formaction_attribute.html
which times out without this patch (because it fails to focus) and passes with this patch.

I'm wondering why something like this is not happening when any app on b2g is started up or brought to the foreground.
Attachment #733009 - Flags: review?(bugs)
Comment on attachment 733009 [details] [diff] [review]
patch

Someone familiar with test framework setup should review this too.
But sounds about right.
I wonder if the remote frame should be re-activated after each test?
(I don't know how we run the tests)
Attachment #733009 - Flags: review?(bugs) → review+
Attachment #733009 - Flags: feedback?(ahalberstadt)
The remote frame is the mochitest app. The tests themselves are inside an iframe inside the mochitest app, which is not remote. So I don't think the mochitest app needs re-activation after every test.
Comment on attachment 733009 [details] [diff] [review]
patch

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

Thanks for the patch! This will help a lot. In reply to comment 5, the mochitests are loaded in a special certified test-container app which iirc replaces the homescreen app.
Attachment #733009 - Flags: feedback?(ahalberstadt) → feedback+
https://hg.mozilla.org/mozilla-central/rev/1f65b5204c8b
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
This patch cuts down about 25 min per chunk, nice!
Checked into b2g18 so we can enjoy the perf win there as well:
https://hg.mozilla.org/releases/mozilla-b2g18/rev/b32166f6703b
Requesting tef+ on this so we can land on the v1.0.1 branch as well. It's test-only, but the release drivers should probably have a say.
blocking-b2g: --- → tef?
Why did we activateRemoteFrame instead of doing container.focus()?  Are they different?
I'm pretty sure I tried something like container.focus(), which didn't work.
Flags: needinfo?(bugs)
hmm, focus() might work too if container is focusable.
Flags: needinfo?(bugs)
blocking-b2g: tef? → tef+
(In reply to Olli Pettay [:smaug] from comment #18)
> hmm, focus() might work too if container is focusable.

Yes, that seems to work too. I'll post a patch, using that in but 850302.
(In reply to Olli Pettay [:smaug] from comment #7)
> I wonder if the remote frame should be re-activated after each test?
> (I don't know how we run the tests)

I found a case, where this might be needed, I filed bug 861689 for it.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: