Backed out 3 changesets (bug 1497480) for causing Android mochitest failures on editor/libeditor/tests/test_bug. CLOSED TREE

Backed out changeset 6c2a5ce9fad8 (bug 1497480)
Backed out changeset cf74ff09b141 (bug 1497480)
Backed out changeset 31d9a680fb90 (bug 1497480)
This commit is contained in:
Cosmin Sabou 2018-10-31 19:06:35 +02:00
Родитель 46a62df41a
Коммит 223a549fe5
5 изменённых файлов: 53 добавлений и 145 удалений

Просмотреть файл

@ -258,7 +258,6 @@ skip-if = toolkit == 'android' # bug 1315898
[test_bug1406726.html]
[test_bug1409520.html]
[test_bug1425997.html]
[test_bug1497480.html]
[test_abs_positioner_appearance.html]
[test_abs_positioner_positioning_elements.html]

Просмотреть файл

@ -1,93 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1497480
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1497480</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/AddTask.js"></script>
<script src="spellcheck.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1497480">Mozilla Bug 1497480</a>
<p id="display"></p>
<div id="outOfTarget" contenteditable>Bug 1497480</div>
<div id="light"></div>
<script>
/** Test for Bug 1497480 **/
let gMisspeltWords = [];
let onSpellCheck = SpecialPowers.Cu.import(
"resource://testing-common/AsyncSpellCheckTestHelper.jsm", null).onSpellCheck;
const template = document.createElement("template");
template.innerHTML = `<div id="target" contenteditable>Test</div>`;
let shadow = document.getElementById("light").attachShadow({mode: "closed"});
shadow.appendChild(template.content.cloneNode(true));
let target = shadow.getElementById("target");
let outOfTarget = document.getElementById("outOfTarget");
function getEditor() {
var win = window;
var editingSession = SpecialPowers.wrap(win).docShell.editingSession;
return editingSession.getEditorForWindow(win);
}
// Wait for the page to be ready for testing
add_task(async function() {
await new Promise((resolve) => {
SimpleTest.waitForFocus(() => {
SimpleTest.executeSoon(resolve);
}, window);
});
// Wait for first full spell-checking.
await new Promise((resolve) => {
onSpellCheck(outOfTarget, function() {
resolve();
});
});
});
// Should perform spell-checking when anchor navigates away from ShadowDOM.
add_task(async function() {
synthesizeMouseAtCenter(target, {}, window);
sendString(" spellechek");
gMisspeltWords.push("spellechek");
synthesizeMouseAtCenter(outOfTarget, {}, window);
await new Promise((resolve) => {
onSpellCheck(target, function() {
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"Spell-checking should be performed when anchor navigates away from ShadowDOM");
SimpleTest.executeSoon(resolve);
});
});
});
// Should perform spell-checking when pressing enter in contenteditable in ShadowDOM.
add_task(async function() {
synthesizeMouseAtCenter(target, {}, window);
sendString(" spellechck");
gMisspeltWords.push("spellechck");
synthesizeKey("KEY_Enter", {}, window);
await new Promise((resolve) => {
onSpellCheck(target, function() {
ok(isSpellingCheckOk(getEditor(), gMisspeltWords),
"Spell-checking should be performed when pressing enter in contenteditable in ShadowDOM");
SimpleTest.executeSoon(resolve);
});
});
});
</script>
</body>
</html>

Просмотреть файл

@ -86,6 +86,9 @@ using namespace mozilla::dom;
#define INLINESPELL_STARTED_TOPIC "inlineSpellChecker-spellCheck-started"
#define INLINESPELL_ENDED_TOPIC "inlineSpellChecker-spellCheck-ended"
static bool ContentIsDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor);
static const char kMaxSpellCheckSelectionSize[] =
"extensions.spellcheck.inline.max-misspellings";
static const PRTime kMaxSpellCheckTimeInUsec =
@ -225,8 +228,7 @@ mozInlineSpellStatus::InitForNavigation(
return NS_ERROR_FAILURE;
}
// the anchor node might not be in the DOM anymore, check
if (root && aOldAnchorNode &&
!nsContentUtils::ContentIsShadowIncludingDescendantOf(aOldAnchorNode, root)) {
if (root && aOldAnchorNode && ! ContentIsDescendantOf(aOldAnchorNode, root)) {
*aContinue = false;
return NS_OK;
}
@ -1368,12 +1370,8 @@ nsresult mozInlineSpellChecker::DoSpellCheck(mozInlineSpellWordUtil& aWordUtil,
return NS_OK;
}
nsresult rv =
aWordUtil.SetPositionAndEnd(beginNode, beginOffset, endNode, endOffset);
if (NS_FAILED(rv)) {
// Just bail out and don't try to spell-check this
return NS_OK;
}
aWordUtil.SetEnd(endNode, endOffset);
aWordUtil.SetPosition(beginNode, beginOffset);
}
// aWordUtil.SetPosition flushes pending notifications, check editor again.
@ -1726,6 +1724,24 @@ mozInlineSpellChecker::SaveCurrentSelectionPosition()
return NS_OK;
}
// This is a copy of nsContentUtils::ContentIsDescendantOf. Another crime
// for XPCOM's rap sheet
bool // static
ContentIsDescendantOf(nsINode* aPossibleDescendant,
nsINode* aPossibleAncestor)
{
MOZ_ASSERT(aPossibleDescendant, "The possible descendant is null!");
MOZ_ASSERT(aPossibleAncestor, "The possible ancestor is null!");
do {
if (aPossibleDescendant == aPossibleAncestor)
return true;
aPossibleDescendant = aPossibleDescendant->GetParentNode();
} while (aPossibleDescendant);
return false;
}
// mozInlineSpellChecker::HandleNavigationEvent
//
// Acts upon mouse clicks and keyboard navigation changes, spell checking

Просмотреть файл

@ -6,7 +6,6 @@
#include "mozInlineSpellWordUtil.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/HTMLEditor.h"
#include "mozilla/TextEditor.h"
#include "mozilla/dom/Element.h"
@ -61,10 +60,8 @@ mozInlineSpellWordUtil::Init(TextEditor* aTextEditor)
return NS_ERROR_FAILURE;
}
mIsContentEditableOrDesignMode = !!aTextEditor->AsHTMLEditor();
// Find the root node for the editor. For contenteditable the mRootNode could
// change to shadow root if the begin and end are inside the shadowDOM.
// Find the root node for the editor. For contenteditable we'll need something
// cleverer here.
mRootNode = aTextEditor->GetRoot();
if (NS_WARN_IF(!mRootNode)) {
return NS_ERROR_FAILURE;
@ -148,7 +145,7 @@ FindNextTextNode(nsINode* aNode, int32_t aOffset, nsINode* aRoot)
return checkNode;
}
// mozInlineSpellWordUtil::SetPositionAndEnd
// mozInlineSpellWordUtil::SetEnd
//
// We have two ranges "hard" and "soft". The hard boundary is simply
// the scope of the root node. The soft boundary is that which is set
@ -166,44 +163,34 @@ FindNextTextNode(nsINode* aNode, int32_t aOffset, nsINode* aRoot)
// position.
nsresult
mozInlineSpellWordUtil::SetPositionAndEnd(nsINode* aPositionNode,
int32_t aPositionOffset,
nsINode* aEndNode,
int32_t aEndOffset)
mozInlineSpellWordUtil::SetEnd(nsINode* aEndNode, int32_t aEndOffset)
{
MOZ_ASSERT(aPositionNode, "Null begin node?");
MOZ_ASSERT(aEndNode, "Null end node?");
NS_ASSERTION(mRootNode, "Not initialized");
// Find a appropriate root if we are dealing with contenteditable nodes which
// are in the shadow DOM.
if (mIsContentEditableOrDesignMode) {
nsINode* rootNode = aPositionNode->SubtreeRoot();
if (rootNode != aEndNode->SubtreeRoot()) {
return NS_ERROR_FAILURE;
}
if (ShadowRoot::FromNode(rootNode)) {
mRootNode = rootNode;
}
}
InvalidateWords();
if (!IsSpellCheckingTextNode(aPositionNode)) {
// Start at the start of the first text node after aNode/aOffset.
aPositionNode = FindNextTextNode(aPositionNode, aPositionOffset, mRootNode);
aPositionOffset = 0;
}
mSoftBegin = NodeOffset(aPositionNode, aPositionOffset);
if (!IsSpellCheckingTextNode(aEndNode)) {
// End at the start of the first text node after aEndNode/aEndOffset.
aEndNode = FindNextTextNode(aEndNode, aEndOffset, mRootNode);
aEndOffset = 0;
}
mSoftEnd = NodeOffset(aEndNode, aEndOffset);
return NS_OK;
}
nsresult
mozInlineSpellWordUtil::SetPosition(nsINode* aNode, int32_t aOffset)
{
InvalidateWords();
if (!IsSpellCheckingTextNode(aNode)) {
// Start at the start of the first text node after aNode/aOffset.
aNode = FindNextTextNode(aNode, aOffset, mRootNode);
aOffset = 0;
}
mSoftBegin = NodeOffset(aNode, aOffset);
nsresult rv = EnsureWords();
if (NS_FAILED(rv)) {
@ -211,10 +198,8 @@ mozInlineSpellWordUtil::SetPositionAndEnd(nsINode* aPositionNode,
}
int32_t textOffset = MapDOMPositionToSoftTextOffset(mSoftBegin);
if (textOffset < 0) {
if (textOffset < 0)
return NS_OK;
}
mNextWordIndex = FindRealWordContaining(textOffset, HINT_END, true);
return NS_OK;
}

Просмотреть файл

@ -80,27 +80,29 @@ public:
* The basic operation is:
*
* 1. Call Init with the weak pointer to the editor that you're using.
* 2. Call SetPositionAndEnd to to initialize the current position inside the
* previously given range and set where you want to stop spellchecking.
* We'll stop at the word boundary after that. If SetEnd is not called,
* we'll stop at the end of the root element.
* 3. Call GetNextWord over and over until it returns false.
* 2. Call SetEnd to set where you want to stop spellchecking. We'll stop
* at the word boundary after that. If SetEnd is not called, we'll stop
* at the end of the document's root element.
* 3. Call SetPosition to initialize the current position inside the
* previously given range.
* 4. Call GetNextWord over and over until it returns false.
*/
class MOZ_STACK_CLASS mozInlineSpellWordUtil
{
public:
mozInlineSpellWordUtil()
: mIsContentEditableOrDesignMode(false), mRootNode(nullptr),
: mRootNode(nullptr),
mSoftBegin(nullptr, 0), mSoftEnd(nullptr, 0),
mNextWordIndex(-1), mSoftTextValid(false) {}
nsresult Init(mozilla::TextEditor* aTextEditor);
nsresult SetEnd(nsINode* aEndNode, int32_t aEndOffset);
// sets the current position, this should be inside the range. If we are in
// the middle of a word, we'll move to its start.
nsresult SetPositionAndEnd(nsINode* aPositionNode, int32_t aPositionOffset,
nsINode* aEndNode, int32_t aEndOffset);
nsresult SetPosition(nsINode* aNode, int32_t aOffset);
// Given a point inside or immediately following a word, this returns the
// DOM range that exactly encloses that word's characters. The current
@ -136,7 +138,6 @@ private:
// cached stuff for the editor, set by Init
nsCOMPtr<nsIDocument> mDocument;
bool mIsContentEditableOrDesignMode;
// range to check, see SetPosition and SetEnd
nsINode* mRootNode;