Bug 1561435 - Format editor/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35901

--HG--
extra : source : 31c98530f9be7521baab316d7edc309361623fb1
This commit is contained in:
Victor Porof 2019-07-05 10:45:46 +02:00
parent dcd795c16b
commit 5065489a4e
6 changed files with 229 additions and 169 deletions

View file

@ -45,7 +45,6 @@ module.exports = {
"overrides": [{ "overrides": [{
"files": [ "files": [
"devtools/**", "devtools/**",
"editor/**",
"extensions/**", "extensions/**",
"gfx/**", "gfx/**",
"gradle/**", "gradle/**",

View file

@ -40,7 +40,6 @@ toolkit/components/telemetry/datareporting-prefs.js
toolkit/components/telemetry/healthreport-prefs.js toolkit/components/telemetry/healthreport-prefs.js
# Ignore all top-level directories for now. # Ignore all top-level directories for now.
editor/**
extensions/** extensions/**
gfx/** gfx/**
gradle/** gradle/**

View file

@ -2,9 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = [ var EXPORTED_SYMBOLS = ["onSpellCheck"];
"onSpellCheck",
];
const SPELL_CHECK_ENDED_TOPIC = "inlineSpellChecker-spellCheck-ended"; const SPELL_CHECK_ENDED_TOPIC = "inlineSpellChecker-spellCheck-ended";
const SPELL_CHECK_STARTED_TOPIC = "inlineSpellChecker-spellCheck-started"; const SPELL_CHECK_STARTED_TOPIC = "inlineSpellChecker-spellCheck-started";
@ -32,8 +30,9 @@ function onSpellCheck(editableElement, callback) {
let win = editableElement.ownerGlobal; let win = editableElement.ownerGlobal;
editor = win.docShell.editingSession.getEditorForWindow(win); editor = win.docShell.editingSession.getEditorForWindow(win);
} }
if (!editor) if (!editor) {
throw new Error("Unable to find editor for element " + editableElement); throw new Error("Unable to find editor for element " + editableElement);
}
try { try {
// False is important here. Pass false so that the inline spell checker // False is important here. Pass false so that the inline spell checker
@ -50,31 +49,40 @@ function onSpellCheck(editableElement, callback) {
let count = 0; let count = 0;
function observe(subj, topic, data) { function observe(subj, topic, data) {
if (subj != editor) if (subj != editor) {
return; return;
}
count = 0; count = 0;
let expectedTopic = waitingForEnded ? SPELL_CHECK_ENDED_TOPIC : let expectedTopic = waitingForEnded
SPELL_CHECK_STARTED_TOPIC; ? SPELL_CHECK_ENDED_TOPIC
if (topic != expectedTopic) : SPELL_CHECK_STARTED_TOPIC;
if (topic != expectedTopic) {
Cu.reportError("Expected " + expectedTopic + " but got " + topic + "!"); Cu.reportError("Expected " + expectedTopic + " but got " + topic + "!");
}
waitingForEnded = !waitingForEnded; waitingForEnded = !waitingForEnded;
} }
// eslint-disable-next-line mozilla/use-services // eslint-disable-next-line mozilla/use-services
let os = Cc["@mozilla.org/observer-service;1"]. let os = Cc["@mozilla.org/observer-service;1"].getService(
getService(Ci.nsIObserverService); Ci.nsIObserverService
);
os.addObserver(observe, SPELL_CHECK_STARTED_TOPIC); os.addObserver(observe, SPELL_CHECK_STARTED_TOPIC);
os.addObserver(observe, SPELL_CHECK_ENDED_TOPIC); os.addObserver(observe, SPELL_CHECK_ENDED_TOPIC);
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.init(function tick() { timer.init(
function tick() {
// Wait an arbitrarily large number -- 50 -- turns of the event loop before // Wait an arbitrarily large number -- 50 -- turns of the event loop before
// declaring that no spell checks will start. // declaring that no spell checks will start.
if (waitingForEnded || ++count < 50) if (waitingForEnded || ++count < 50) {
return; return;
}
timer.cancel(); timer.cancel();
os.removeObserver(observe, SPELL_CHECK_STARTED_TOPIC); os.removeObserver(observe, SPELL_CHECK_STARTED_TOPIC);
os.removeObserver(observe, SPELL_CHECK_ENDED_TOPIC); os.removeObserver(observe, SPELL_CHECK_ENDED_TOPIC);
callback(); callback();
}, 0, Ci.nsITimer.TYPE_REPEATING_SLACK); },
0,
Ci.nsITimer.TYPE_REPEATING_SLACK
);
} }

View file

@ -1,16 +1,23 @@
add_task(async function() { add_task(async function() {
await new Promise(resolve => waitForFocus(resolve, window)); await new Promise(resolve => waitForFocus(resolve, window));
const kPageURL = "http://example.org/browser/editor/libeditor/tests/bug527935.html"; const kPageURL =
await BrowserTestUtils.withNewTab({ "http://example.org/browser/editor/libeditor/tests/bug527935.html";
await BrowserTestUtils.withNewTab(
{
gBrowser, gBrowser,
url: kPageURL, url: kPageURL,
}, async function(aBrowser) { },
async function(aBrowser) {
var popupShown = false; var popupShown = false;
function listener() { function listener() {
popupShown = true; popupShown = true;
} }
SpecialPowers.addAutoCompletePopupEventListener(window, "popupshowing", listener); SpecialPowers.addAutoCompletePopupEventListener(
window,
"popupshowing",
listener
);
await ContentTask.spawn(aBrowser, {}, async function() { await ContentTask.spawn(aBrowser, {}, async function() {
var window = content.window.wrappedJSObject; var window = content.window.wrappedJSObject;
@ -40,8 +47,18 @@ add_task(async function() {
var event = document.createEvent("KeyboardEvent"); var event = document.createEvent("KeyboardEvent");
event.initKeyEvent("keypress", true, true, null, false, false, event.initKeyEvent(
false, false, 0, "f".charCodeAt(0)); "keypress",
true,
true,
null,
false,
false,
false,
false,
0,
"f".charCodeAt(0)
);
newInput.value = ""; newInput.value = "";
newInput.focus(); newInput.focus();
newInput.dispatchEvent(event); newInput.dispatchEvent(event);
@ -50,8 +67,13 @@ add_task(async function() {
await new Promise(resolve => hitEventLoop(resolve, 100)); await new Promise(resolve => hitEventLoop(resolve, 100));
ok(!popupShown, "Popup must not be opened"); ok(!popupShown, "Popup must not be opened");
SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshowing", listener); SpecialPowers.removeAutoCompletePopupEventListener(
}); window,
"popupshowing",
listener
);
}
);
}); });
function hitEventLoop(func, times) { function hitEventLoop(func, times) {

View file

@ -1,11 +1,14 @@
add_task(async function() { add_task(async function() {
await new Promise(resolve => waitForFocus(resolve, window)); await new Promise(resolve => waitForFocus(resolve, window));
const kPageURL = "http://example.org/browser/editor/libeditor/tests/bug629172.html"; const kPageURL =
await BrowserTestUtils.withNewTab({ "http://example.org/browser/editor/libeditor/tests/bug629172.html";
await BrowserTestUtils.withNewTab(
{
gBrowser, gBrowser,
url: kPageURL, url: kPageURL,
}, async function(browser) { },
async function(browser) {
await ContentTask.spawn(browser, {}, async function() { await ContentTask.spawn(browser, {}, async function() {
var window = content.window.wrappedJSObject; var window = content.window.wrappedJSObject;
var document = window.document; var document = window.document;
@ -44,74 +47,99 @@ add_task(async function() {
// reach the web page. As a result, we need to observe the event in // reach the web page. As a result, we need to observe the event in
// the content process only in e10s mode. // the content process only in e10s mode.
if (gMultiProcessBrowser) { if (gMultiProcessBrowser) {
return EventUtils.synthesizeAndWaitKey("x", {accelKey: true, shiftKey: true}); return EventUtils.synthesizeAndWaitKey("x", {
accelKey: true,
shiftKey: true,
});
} }
EventUtils.synthesizeKey("x", {accelKey: true, shiftKey: true}); EventUtils.synthesizeKey("x", { accelKey: true, shiftKey: true });
return Promise.resolve(); return Promise.resolve();
} }
async function testDirection(initDir, aBrowser) { async function testDirection(initDir, aBrowser) {
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) { await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
initialDir,
}) {
var window = content.window.wrappedJSObject; var window = content.window.wrappedJSObject;
var document = window.document; var document = window.document;
var t = window.t = document.createElement("textarea"); var t = (window.t = document.createElement("textarea"));
t.setAttribute("dir", initialDir); t.setAttribute("dir", initialDir);
t.value = "test."; t.value = "test.";
window.inputEventCount = 0; window.inputEventCount = 0;
t.oninput = function() { window.inputEventCount++; }; t.oninput = function() {
window.inputEventCount++;
};
document.getElementById("content").appendChild(t); document.getElementById("content").appendChild(t);
document.body.clientWidth; document.body.clientWidth;
var s1 = window.snapshotWindow(window); var s1 = window.snapshotWindow(window);
window.ok = ok; // for assertSnapshots window.ok = ok; // for assertSnapshots
window. window.assertSnapshots(
assertSnapshots(s1, window.Screenshots.get(initialDir), true, s1,
window.Screenshots.get(initialDir),
true,
/* fuzz = */ null, /* fuzz = */ null,
"Textarea before switching the direction from " + "Textarea before switching the direction from " + initialDir,
initialDir, "Reference " + initialDir + " textarea"
"Reference " + initialDir + " textarea"); );
t.focus(); t.focus();
is(window.inputEventCount, 0, "input event count must be 0 before"); is(window.inputEventCount, 0, "input event count must be 0 before");
}); });
await simulateCtrlShiftX(aBrowser); await simulateCtrlShiftX(aBrowser);
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) { await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
initialDir,
}) {
var window = content.window.wrappedJSObject; var window = content.window.wrappedJSObject;
var expectedDir = initialDir == "ltr" ? "rtl" : "ltr"; var expectedDir = initialDir == "ltr" ? "rtl" : "ltr";
is(window.t.getAttribute("dir"), expectedDir, is(
"The dir attribute must be correctly updated"); window.t.getAttribute("dir"),
expectedDir,
"The dir attribute must be correctly updated"
);
is(window.inputEventCount, 1, "input event count must be 1 after"); is(window.inputEventCount, 1, "input event count must be 1 after");
window.t.blur(); window.t.blur();
var s2 = window.snapshotWindow(window); var s2 = window.snapshotWindow(window);
window.ok = ok; // for assertSnapshots window.ok = ok; // for assertSnapshots
window. window.assertSnapshots(
assertSnapshots(s2, window.Screenshots.get(expectedDir), true, s2,
window.Screenshots.get(expectedDir),
true,
/* fuzz = */ null, /* fuzz = */ null,
"Textarea after switching the direction from " + "Textarea after switching the direction from " + initialDir,
initialDir, "Reference " + expectedDir + " textarea"
"Reference " + expectedDir + " textarea"); );
window.t.focus(); window.t.focus();
is(window.inputEventCount, 1, "input event count must be 1 before"); is(window.inputEventCount, 1, "input event count must be 1 before");
}); });
await simulateCtrlShiftX(aBrowser); await simulateCtrlShiftX(aBrowser);
await ContentTask.spawn(aBrowser, {initialDir: initDir}, function({initialDir}) { await ContentTask.spawn(aBrowser, { initialDir: initDir }, function({
initialDir,
}) {
var window = content.window.wrappedJSObject; var window = content.window.wrappedJSObject;
is(window.inputEventCount, 2, "input event count must be 2 after"); is(window.inputEventCount, 2, "input event count must be 2 after");
is(window.t.getAttribute("dir"), initialDir == "ltr" ? "ltr" : "rtl", "The dir attribute must be correctly updated"); is(
window.t.getAttribute("dir"),
initialDir == "ltr" ? "ltr" : "rtl",
"The dir attribute must be correctly updated"
);
window.t.blur(); window.t.blur();
var s3 = window.snapshotWindow(window); var s3 = window.snapshotWindow(window);
window.ok = ok; // for assertSnapshots window.ok = ok; // for assertSnapshots
window. window.assertSnapshots(
assertSnapshots(s3, window.Screenshots.get(initialDir), true, s3,
window.Screenshots.get(initialDir),
true,
/* fuzz = */ null, /* fuzz = */ null,
"Textarea after switching back the direction to " + "Textarea after switching back the direction to " + initialDir,
initialDir, "Reference " + initialDir + " textarea"
"Reference " + initialDir + " textarea"); );
window.t.remove(); window.t.remove();
}); });
} }
await testDirection("ltr", browser); await testDirection("ltr", browser);
await testDirection("rtl", browser); await testDirection("rtl", browser);
}); }
);
}); });

View file

@ -3,7 +3,11 @@ function isSpellingCheckOk(aEditor, aMisspelledWords) {
var sel = selcon.getSelection(selcon.SELECTION_SPELLCHECK); var sel = selcon.getSelection(selcon.SELECTION_SPELLCHECK);
var numWords = sel.rangeCount; var numWords = sel.rangeCount;
is(numWords, aMisspelledWords.length, "Correct number of misspellings and words."); is(
numWords,
aMisspelledWords.length,
"Correct number of misspellings and words."
);
if (numWords !== aMisspelledWords.length) { if (numWords !== aMisspelledWords.length) {
return false; return false;