Bug 1912868 - [devtools] Emit property-updated-by-dragging once the value was actually set. r=devtools-reviewers,jdescottes.

This will help make browser_rules_edit-size-property-dragging.js more robust and
will help to land the changes from Bug 1885232.

The order of assertions in browser_rules_edit-size-property-dragging.js is modified
to circumvent Bug 1913358.

Differential Revision: https://phabricator.services.mozilla.com/D218921
This commit is contained in:
Nicolas Chevobbe 2024-09-02 13:15:21 +00:00
parent 6b44952143
commit 964100511f
2 changed files with 35 additions and 13 deletions

View File

@ -49,11 +49,14 @@ add_task(async function () {
await pushPref("devtools.inspector.draggable_properties", true);
testDraggingClassIsAddedWhenNeeded(view);
await testIncrementAngleValue(view);
await testDraggingClassIsAddedOnValueUpdate(view);
await testPressingEscapeWhileDragging(view);
await testPressingEscapeWhileDraggingWithinDeadzone(view);
await testUpdateDisabledValue(view);
await testWidthIncrements(view);
await testDraggingClassIsAddedOnValueUpdate(view);
// This needs to happen last as dragging angles are causing further trouble.
// This will be fixed as part of Bug 1885232.
await testIncrementAngleValue(view);
});
const PROPERTIES = [
@ -168,6 +171,24 @@ async function testPressingEscapeWhileDragging(view) {
]);
}
async function testPressingEscapeWhileDraggingWithinDeadzone(view) {
info("Testing pressing escape while dragging with mouse within the deadzone");
const marginPropEditor = getTextProperty(view, 1, {
"margin-bottom": "0px",
}).editor;
await runIncrementTest(marginPropEditor, view, [
{
startValue: "0px",
expectedEndValue: "0px",
expectedEndValueBeforeEscape: "0px",
escape: true,
deadzoneIncluded: true,
distance: marginPropEditor._DRAGGING_DEADZONE_DISTANCE - 1,
description: "Pressing escape to check if value has been reset",
},
]);
}
async function testUpdateDisabledValue(view) {
info("Testing updating a disabled value by dragging mouse");
@ -408,9 +429,12 @@ async function synthesizeMouseDragging(editor, distance, options = {}) {
);
// If the drag will not trigger any update, simply wait for 100ms.
// Otherwise, wait for the next property-updated-by-dragging event.
// Otherwise, wait for the next property-updated-by-dragging event and the rule view change.
const updated = updateExpected
? editor.ruleView.once("property-updated-by-dragging")
? Promise.all([
editor.ruleView.once("ruleview-changed"),
editor.ruleView.once("property-updated-by-dragging"),
])
: wait(100);
EventUtils.synthesizeMouse(
@ -438,15 +462,13 @@ async function synthesizeMouseDragging(editor, distance, options = {}) {
options.expectedEndValueBeforeEscape,
"testing value before pressing escape"
);
const onRuleViewChanged = updateExpected
? editor.ruleView.once("ruleview-changed")
: null;
EventUtils.synthesizeKey("VK_ESCAPE", {}, styleWindow);
await onRuleViewChanged;
}
// If the drag will not trigger any update, simply wait for 100ms.
// Otherwise, wait for the next ruleview-changed event.
const done = updateExpected
? editor.ruleView.once("ruleview-changed")
: wait(100);
EventUtils.synthesizeMouse(
elm,
endPosition[0],
@ -456,7 +478,6 @@ async function synthesizeMouseDragging(editor, distance, options = {}) {
},
styleWindow
);
await done;
// If the drag did not trigger any update, mouseup might open an inline editor.
// Leave the editor.

View File

@ -1571,8 +1571,9 @@ TextPropertyEditor.prototype = {
const { value, unit } = this._draggingValueCache;
// We use toFixed to avoid the case where value is too long, 9.00001px for example
const roundedValue = Number.isInteger(value) ? value : value.toFixed(1);
this.prop.setValue(roundedValue + unit, this.prop.priority);
this.ruleView.emitForTests("property-updated-by-dragging");
this.prop
.setValue(roundedValue + unit, this.prop.priority)
.then(() => this.ruleView.emitForTests("property-updated-by-dragging"));
this._hasDragged = true;
},