Closed Bug 1037346 Opened 5 years ago Closed 5 years ago

Unexpected assertion in nsTextStore at running toolkit/content/tests/chrome/test_dialogfocus.xul

Categories

(Core :: Widget: Win32, defect)

x86_64
Windows 7
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla33

People

(Reporter: masayuki, Assigned: masayuki)

References

()

Details

(Keywords: assertion, inputmethod)

Attachments

(1 file)

https://tbpl.mozilla.org/php/getParsedLog.php?id=43589225&full=1&branch=try#error0
Windows 7 32-bit try debug test mochitest-other on 2014-07-11 00:04:35 PDT for push 8173e0e3e672

> 00:27:31     INFO -  4738 INFO TEST-START | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul

> 00:27:32     INFO -  4820 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | runTest(), step = 8, expected = textbox-yes
> 00:27:32     INFO -  4821 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:32     INFO -  4822 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | target not an Element
> 00:27:32     INFO -  4823 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:32     INFO -  4824 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | target not an Element
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_TRUE(aSelection->GetRangeCount()) failed: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\base\nsEditor.cpp, line 3815
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\base\nsEditor.cpp, line 3794
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_SUCCESS(res, res) failed with result 0x80004005: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\text\nsTextEditRules.cpp, line 441
> 00:27:33     INFO -  4825 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:33     INFO -  4826 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | match = true
> 00:27:33     INFO -  4827 INFO TEST-PASS | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | focus step 8
> 00:27:33     INFO -  4828 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | must wait for focus
> 00:27:33     INFO -  4829 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | runTest(), step = 9, expected = one
> 00:27:33     INFO -  4830 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:33     INFO -  4831 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | target not an Element
> 00:27:33     INFO -  4832 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:33     INFO -  4833 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | target not an Element
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_TRUE(aSelection->GetRangeCount()) failed: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\base\nsEditor.cpp, line 3815
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\base\nsEditor.cpp, line 3794
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_SUCCESS(res, res) failed with result 0x80004005: file c:\builds\moz2_slave\try-w32-d-00000000000000000000\build\editor\libeditor\text\nsTextEditRules.cpp, line 441
> 00:27:33     INFO -  4834 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:33     INFO -  4835 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | match = false
> 00:27:33     INFO -  [Parent 912] WARNING: NS_ENSURE_TRUE(bRet) failed: file c:/builds/moz2_slave/try-w32-d-00000000000000000000/build/widget/windows/nsTextStore.cpp, line 3101
> 00:27:33     INFO -  [Parent 912] ###!!! ASSERTION: Disassociating focus failed: 'SUCCEEDED(hr)', file c:/builds/moz2_slave/try-w32-d-00000000000000000000/build/widget/windows/nsTextStore.cpp, line 3124
> 00:27:33     INFO -  mozilla::widget::IMEHandler::NotifyIME(nsWindow *,mozilla::widget::IMENotification const &) [widget/windows/WinIMEHandler.cpp:175]
> 00:27:33     INFO -  nsWindow::NotifyIME(mozilla::widget::IMENotification const &) [widget/windows/nsWindow.cpp:6821]
> 00:27:33     INFO -  mozilla::IMEContentObserver::Destroy() [dom/events/IMEContentObserver.cpp:172]
> 00:27:33     INFO -  mozilla::IMEStateManager::DestroyTextStateManager() [dom/events/IMEStateManager.cpp:707]
> 00:27:33     INFO -  mozilla::IMEStateManager::OnChangeFocusInternal(nsPresContext *,nsIContent *,mozilla::widget::InputContextAction) [dom/events/IMEStateManager.cpp:186]
> 00:27:33     INFO -  mozilla::IMEStateManager::OnChangeFocus(nsPresContext *,nsIContent *,mozilla::widget::InputContextAction::Cause) [dom/events/IMEStateManager.cpp:159]
> 00:27:33     INFO -  nsFocusManager::Blur(nsPIDOMWindow *,nsPIDOMWindow *,bool,bool) [dom/base/nsFocusManager.cpp:1537]
> 00:27:33     INFO -  nsFocusManager::SetFocusInner(nsIContent *,int,bool,bool) [dom/base/nsFocusManager.cpp:1242]
> 00:27:33     INFO -  nsFocusManager::MoveFocus(nsIDOMWindow *,nsIDOMElement *,unsigned int,unsigned int,nsIDOMElement * *) [dom/base/nsFocusManager.cpp:522]
> 00:27:33     INFO -  nsXULCommandDispatcher::AdvanceFocusIntoSubtree(nsIDOMElement *) [content/xul/document/src/nsXULCommandDispatcher.cpp:249]
> 00:27:33     INFO -  NS_InvokeByIndex [xpcom/reflect/xptcall/md/win32/xptcinvoke.cpp:71]
> 00:27:33     INFO -  CallMethodHelper::Invoke() [js/xpconnect/src/XPCWrappedNative.cpp:2395]
> 00:27:33     INFO -  XPCWrappedNative::CallMethod(XPCCallContext &,XPCWrappedNative::CallMode) [js/xpconnect/src/XPCWrappedNative.cpp:1703]
> 00:27:33     INFO -  XPC_WN_CallMethod(JSContext *,unsigned int,JS::Value *) [js/xpconnect/src/XPCWrappedNativeJSOps.cpp:1272]
> 00:27:33     INFO -  js::CallJSNative(JSContext *,bool (*)(JSContext *,unsigned int,JS::Value *),JS::CallArgs const &) [js/src/jscntxtinlines.h:230]
> 00:27:33     INFO -  js::Invoke(JSContext *,JS::CallArgs,js::MaybeConstruct) [js/src/vm/Interpreter.cpp:454]
> 00:27:33     INFO -  Interpret [js/src/vm/Interpreter.cpp:2558]
> 00:27:33     INFO -  js::RunScript(JSContext *,js::RunState &) [js/src/vm/Interpreter.cpp:408]
> 00:27:33     INFO -  js::Invoke(JSContext *,JS::CallArgs,js::MaybeConstruct) [js/src/vm/Interpreter.cpp:480]
> 00:27:33     INFO -  js::Invoke(JSContext *,JS::Value const &,JS::Value const &,unsigned int,JS::Value const *,JS::MutableHandle<JS::Value>) [js/src/vm/Interpreter.cpp:517]
> 00:27:33     INFO -  JS::Call(JSContext *,JS::Handle<JS::Value>,JS::Handle<JS::Value>,JS::HandleValueArray const &,JS::MutableHandle<JS::Value>) [js/src/jsapi.cpp:5075]
> 00:27:33     INFO -  mozilla::dom::Function::Call(JSContext *,JS::Handle<JS::Value>,nsTArray<JS::Value> const &,JS::MutableHandle<JS::Value>,mozilla::ErrorResult &) [obj-firefox/dom/bindings/FunctionBinding.cpp:35]
> 00:27:33     INFO -  mozilla::dom::Function::Call<nsCOMPtr<nsISupports> >(nsCOMPtr<nsISupports> const &,nsTArray<JS::Value> const &,JS::MutableHandle<JS::Value>,mozilla::ErrorResult &,mozilla::dom::CallbackObject::ExceptionHandling) [obj-firefox/dist/include/mozilla/dom/FunctionBinding.h:58]
> 00:27:33     INFO -  nsGlobalWindow::RunTimeoutHandler(nsTimeout *,nsIScriptContext *) [dom/base/nsGlobalWindow.cpp:12143]
> 00:27:33     INFO -  nsGlobalWindow::RunTimeout(nsTimeout *) [dom/base/nsGlobalWindow.cpp:12368]
> 00:27:33     INFO -  nsGlobalWindow::TimerCallback(nsITimer *,void *) [dom/base/nsGlobalWindow.cpp:12613]
> 00:27:33     INFO -  nsTimerImpl::Fire() [xpcom/threads/nsTimerImpl.cpp:618]
> 00:27:33     INFO -  nsTimerEvent::Run() [xpcom/threads/nsTimerImpl.cpp:716]
> 00:27:33     INFO -  nsThread::ProcessNextEvent(bool,bool *) [xpcom/threads/nsThread.cpp:766]

> 00:27:33     INFO -  [Parent 912] ###!!! ASSERTION: different documentMgr has been associated with the window: 'prevFocusedDocumentMgr == sTsfTextStore->mDocumentMgr', file c:/builds/moz2_slave/try-w32-d-00000000000000000000/build/widget/windows/nsTextStore.cpp, line 3126
> 00:27:33     INFO -  4836 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | checkDialogFocus()
> 00:27:33     INFO -  4837 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | match = true
> 00:27:33     INFO -  4838 INFO TEST-PASS | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | focus step 9
> 00:27:33     INFO -  4839 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | must wait for focus
> 00:27:33     INFO -  --DOCSHELL 27A03400 == 13 [pid = 912] [id = 900]
> 00:27:33     INFO -  4840 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | runTest(), step = 10, expected = undefined
> 00:27:33     INFO -  4841 INFO TEST-INFO | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | finishing
> 00:27:33     INFO -  4842 INFO TEST-INFO | MEMORY STAT vsize after test: 1049067520
> 00:27:33     INFO -  4843 INFO TEST-INFO | MEMORY STAT vsizeMaxContiguous after test: 545587200
> 00:27:33     INFO -  4844 INFO TEST-INFO | MEMORY STAT residentFast after test: 300797952
> 00:27:33     INFO -  4845 INFO TEST-INFO | MEMORY STAT heapAllocated after test: 106780600
> 00:27:33     INFO -  4846 INFO TEST-END | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | finished in 1974ms
> 00:27:33     INFO -  ++DOMWINDOW == 100 (13D26400) [pid = 912] [serial = 4133] [outer = 1BD5FC00]
> 00:27:33     INFO -  4847 ERROR TEST-UNEXPECTED-FAIL | chrome://mochitests/content/chrome/toolkit/content/tests/chrome/test_dialogfocus.xul | Assertion count 2 is greater than expected range 0-0 assertions.
Attached patch PatchSplinter Review
The orange occurs when a dialog which sets focus to an editor is opened and closed at focus event of the window in capture phase.

What happens at that time is, IMEStateManager::OnChangeFocusInternal() is called and it calls GetNewIMEState() *before* updating sPresContext and sContent.
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEStateManager.cpp?rev=839bf025c534#197
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEStateManager.cpp?rev=839bf025c534#227

IMEStateManager::GetNewIMEState() calls nsIContent::GetDesiredIMEState() in this case.
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEStateManager.cpp?rev=839bf025c534#374

Then, the method needs an instance of its editor. Then, nsEditor::PostCreate() calls IMEStateManager::UpdateIMEState().
http://mxr.mozilla.org/mozilla-central/source/editor/libeditor/base/nsEditor.cpp?rev=0d3889868608#321

So, while IMEStateManager::OnChangeFocusInternal() is running, UpdateIMEState() is also called. UpdateIMEState() calls CreateIMEContentObserver() with sContent which hasn't been updated yet.
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEStateManager.cpp?rev=839bf025c534#346

And the created IMEContentObserver instance notifies IME of focus with such broken information.
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEContentObserver.cpp?rev=a9a093d2881a#116

Finally, IMEStateManager::OnFoucsInEditor() is called by nsEditorEventListener::Focus() and it tries to create IMEContentObserver instance.
http://mxr.mozilla.org/mozilla-central/source/dom/events/IMEStateManager.cpp?rev=839bf025c534#303

However, there is already unexpected instance of IMEContentObserver. Therefore, creating new one causes nsTextStore confused.

This patch sets a blocker flag before calling nsIContent::GetDesiredIMEState(). And IMEStateManager::UpdateIMEState() checks the blocker flag. If it's true, UpdateIMEState() does nothing. Then, OnChangeFocusInternal() and OnFocusInEditor() work as expected.
Assignee: nobody → masayuki
Status: NEW → ASSIGNED
Attachment #8456740 - Flags: review?(bugs)
Attachment #8456740 - Flags: review?(bugs) → review+
https://hg.mozilla.org/mozilla-central/rev/f646e874e2f6
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla33
You need to log in before you can comment on or make changes to this bug.