test: Added tests for https://github.com/zen-browser/desktop/issues/7385, b=(closes #7385), c=tests, vendor

This commit is contained in:
Mr. M
2025-05-10 15:00:22 +02:00
parent 5a59eb6902
commit 3b4f96ab2f
5 changed files with 59 additions and 3 deletions

View File

@@ -1 +0,0 @@
run.sh

View File

@@ -5,3 +5,4 @@ support-files = [
]
["browser_floating_urlbar.js"]
["browser_issue_7385.js"]

View File

@@ -0,0 +1,31 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
'use strict';
ChromeUtils.defineESModuleGetters(this, {
UrlbarTestUtils: 'resource://testing-common/UrlbarTestUtils.sys.mjs',
});
add_task(async function test_Selection_Remains_Double_Toolbar() {
await goToMultipleLayouts(async () => {
const untrimmedValue = 'http://example.com';
let trimmedValue = UrlbarTestUtils.trimURL(untrimmedValue);
gURLBar._setValue(untrimmedValue, {
allowTrim: true,
valueIsTyped: false,
});
gURLBar.blur();
await SimpleTest.promiseFocus(window);
Assert.equal(gURLBar.value, trimmedValue, 'Value has been trimmed');
await selectWithMouseDrag(100, 200);
Assert.greater(gURLBar.selectionStart, 0, 'Selection start is positive.');
Assert.greater(gURLBar.selectionEnd, gURLBar.selectionStart, 'Selection is not empty.');
Assert.equal(gURLBar.value, untrimmedValue, `Value should be untrimmed`);
gURLBar.handleRevert();
gURLBar.view.close();
});
});

View File

@@ -9,3 +9,29 @@ function simulateClick(win = window) {
EventUtils.synthesizeMouseAtCenter(target, {});
return promise;
}
function selectWithMouseDrag(fromX, toX, win = window) {
let target = win.gURLBar.inputField;
let rect = target.getBoundingClientRect();
let promise = BrowserTestUtils.waitForEvent(target, 'mouseup');
EventUtils.synthesizeMouse(target, fromX, rect.height / 2, { type: 'mousemove' }, target.ownerGlobal);
EventUtils.synthesizeMouse(target, fromX, rect.height / 2, { type: 'mousedown' }, target.ownerGlobal);
EventUtils.synthesizeMouse(target, toX, rect.height / 2, { type: 'mousemove' }, target.ownerGlobal);
EventUtils.synthesizeMouse(target, toX, rect.height / 2, { type: 'mouseup' }, target.ownerGlobal);
return promise;
}
function goToMultipleLayouts(callback) {
return new Promise(async (resolve) => {
await SpecialPowers.pushPrefEnv({
set: [['zen.view.use-single-toolbar', false]],
});
setTimeout(async () => {
await callback();
await SpecialPowers.popPrefEnv();
setTimeout(() => {
resolve();
}, 1000); // Wait for new layout
}, 1000); // Wait for new layout
});
}

File diff suppressed because one or more lines are too long