Bug 1872301 - Make `nsFocusManager::GetSelectionLocation` never fail when found text...
commit9ea801e9946adbda91f2f7914c9c9e8bd21e84d4
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 17 Jan 2024 00:25:04 +0000 (17 00:25 +0000)
committerMasayuki Nakano <masayuki@d-toybox.com>
Wed, 17 Jan 2024 00:25:04 +0000 (17 00:25 +0000)
treee5de81e67bf2d18b5bc8a71b9a42ec30ca2c1b3a
parente12f705e694aca5a958db933ecf3042b1ab0d27a
Bug 1872301 - Make `nsFocusManager::GetSelectionLocation` never fail when found text node has no frame r=NeilDeakin

In the test case, `nsFocusManager::GetSelectionLocation` is called with
collapsed selection at end of the `<svg>` which ends with collapsible
white-spaces.  Therefore, it reaches the white-space only text node and it
does not have a primary frame due to invisible.

Previously, creating `nsFrameIterator` failed and then the method returned
error, but after bug 779684, `nsFrameIterator` constructor wants non-nullptr
frame avoiding crash.  Therefore, I added the `MOZ_ASSERT` there to get a
way to reproduce the case and now we got it.

I think that just removing `MOZ_ASSERT` and keeping returning error is not
correct. The text can be invisible with the other reasons and it does not
collapsed at end of invisible text, this does not return error.  Therefore,
this patch makes just returning the text in the case without error.

Differential Revision: https://phabricator.services.mozilla.com/D198128
dom/base/nsFocusManager.cpp
dom/base/nsFocusManager.h
testing/web-platform/tests/selection/crashtests/selectall-and-find-svg-text-on-selectstart.html [new file with mode: 0644]