зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1565273 - Context menu clicks ignore browser.urlbar.clickSelectsAll pref. Add tests for selectAll behaviour. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D37796 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
90b33f2950
Коммит
3907dcbea0
|
@ -1413,11 +1413,13 @@ class UrlbarInput {
|
|||
/**
|
||||
* Determines if we should select all the text in the Urlbar based on the
|
||||
* clickSelectsAll pref, Urlbar state, and whether the selection is empty.
|
||||
* @param {boolean} [ignoreClickSelectsAllPref]
|
||||
* If true, the browser.urlbar.clickSelectsAll pref will be ignored.
|
||||
*/
|
||||
_maybeSelectAll() {
|
||||
_maybeSelectAll(ignoreClickSelectsAllPref = false) {
|
||||
if (
|
||||
!this._preventClickSelectsAll &&
|
||||
UrlbarPrefs.get("clickSelectsAll") &&
|
||||
(ignoreClickSelectsAllPref || UrlbarPrefs.get("clickSelectsAll")) &&
|
||||
this._compositionState != UrlbarUtils.COMPOSITION.COMPOSING &&
|
||||
this.document.activeElement == this.inputField &&
|
||||
this.inputField.selectionStart == this.inputField.selectionEnd
|
||||
|
@ -1477,19 +1479,14 @@ class UrlbarInput {
|
|||
}
|
||||
|
||||
_on_contextmenu(event) {
|
||||
// On Windows, the context menu appears on mouseup. macOS and Linux require
|
||||
// special handling to selectAll when the contextmenu is displayed.
|
||||
// See bug 576135 comment 4 for details.
|
||||
if (AppConstants.platform == "win") {
|
||||
return;
|
||||
}
|
||||
|
||||
// Context menu opened via keyboard shortcut.
|
||||
if (!event.button) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._maybeSelectAll();
|
||||
// If the user right clicks, we select all regardless of the value of
|
||||
// the browser.urlbar.clickSelectsAll pref.
|
||||
this._maybeSelectAll(/* ignoreClickSelectsAllPref */ event.button == 2);
|
||||
}
|
||||
|
||||
_on_focus(event) {
|
||||
|
|
|
@ -128,6 +128,7 @@ support-files =
|
|||
run-if = e10s
|
||||
[browser_urlbar_remove_match.js]
|
||||
[browser_urlbar_searchsettings.js]
|
||||
[browser_urlbar_selection.js]
|
||||
[browser_urlbar_speculative_connect.js]
|
||||
support-files =
|
||||
searchSuggestionEngine2.xml
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const exampleSearch = "f oo bar";
|
||||
const exampleUrl = "https://example.com/1";
|
||||
|
||||
const { UrlbarTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/UrlbarTestUtils.jsm"
|
||||
);
|
||||
|
||||
function click(target) {
|
||||
let promise = BrowserTestUtils.waitForEvent(target, "click");
|
||||
EventUtils.synthesizeMouseAtCenter(target, {}, target.ownerGlobal);
|
||||
return promise;
|
||||
}
|
||||
|
||||
function openContextMenu(target) {
|
||||
let popupShownPromise = BrowserTestUtils.waitForEvent(
|
||||
target.ownerGlobal,
|
||||
"contextmenu"
|
||||
);
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(
|
||||
target,
|
||||
{
|
||||
type: "contextmenu",
|
||||
button: 2,
|
||||
},
|
||||
target.ownerGlobal
|
||||
);
|
||||
return popupShownPromise;
|
||||
}
|
||||
|
||||
function drag(target, fromX, fromY, toX, toY) {
|
||||
let promise = BrowserTestUtils.waitForEvent(target, "mouseup");
|
||||
EventUtils.synthesizeMouse(
|
||||
target,
|
||||
fromX,
|
||||
fromY,
|
||||
{ type: "mousemove" },
|
||||
target.ownerGlobal
|
||||
);
|
||||
EventUtils.synthesizeMouse(
|
||||
target,
|
||||
fromX,
|
||||
fromY,
|
||||
{ type: "mousedown" },
|
||||
target.ownerGlobal
|
||||
);
|
||||
EventUtils.synthesizeMouse(
|
||||
target,
|
||||
toX,
|
||||
toY,
|
||||
{ type: "mousemove" },
|
||||
target.ownerGlobal
|
||||
);
|
||||
EventUtils.synthesizeMouse(
|
||||
target,
|
||||
toX,
|
||||
toY,
|
||||
{ type: "mouseup" },
|
||||
target.ownerGlobal
|
||||
);
|
||||
return promise;
|
||||
}
|
||||
|
||||
add_task(async function setup() {
|
||||
SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.urlbar.clickSelectsAll", true]],
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function leftClickSelectsAll() {
|
||||
gURLBar.value = exampleSearch;
|
||||
await click(gURLBar.inputField);
|
||||
Assert.equal(
|
||||
gURLBar.selectionStart,
|
||||
0,
|
||||
"The entire search term should be selected."
|
||||
);
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
exampleSearch.length,
|
||||
"The entire search term should be selected."
|
||||
);
|
||||
gURLBar.blur();
|
||||
});
|
||||
|
||||
add_task(async function leftClickSelectsUrl() {
|
||||
gURLBar.value = exampleUrl;
|
||||
await click(gURLBar.inputField);
|
||||
Assert.equal(gURLBar.selectionStart, 0, "The entire url should be selected.");
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
exampleUrl.length,
|
||||
"The entire url should be selected."
|
||||
);
|
||||
gURLBar.blur();
|
||||
});
|
||||
|
||||
// Test to ensure that the doubleClickSelectsAll pref does not interfere with
|
||||
// single click behaviour (Double CSA itself is tested in
|
||||
// urlbar/tests/browser_doubleClickSelectsAll.js).
|
||||
add_task(async function bothPrefsEnabled() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.doubleClickSelectsAll", true);
|
||||
gURLBar.value = exampleSearch;
|
||||
await click(gURLBar.inputField);
|
||||
Assert.equal(
|
||||
gURLBar.selectionStart,
|
||||
0,
|
||||
"The entire search term should be selected."
|
||||
);
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
exampleSearch.length,
|
||||
"The entire search term should be selected."
|
||||
);
|
||||
gURLBar.blur();
|
||||
Services.prefs.clearUserPref("browser.urlbar.doubleClickSelectsAll");
|
||||
});
|
||||
|
||||
add_task(async function rightClickSelectsAll() {
|
||||
// The text should be selected even when the pref is disabled.
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.urlbar.clickSelectsAll", false]],
|
||||
});
|
||||
|
||||
gURLBar.inputField.focus();
|
||||
gURLBar.value = exampleUrl;
|
||||
|
||||
// Remove the selection so the focus() call above doesn't influence the test.
|
||||
gURLBar.selectionStart = gURLBar.selectionEnd = 0;
|
||||
|
||||
await openContextMenu(gURLBar.inputField);
|
||||
|
||||
Assert.equal(gURLBar.selectionStart, 0, "The entire URL should be selected.");
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
exampleUrl.length,
|
||||
"The entire URL should be selected."
|
||||
);
|
||||
|
||||
let contextMenu = gURLBar.querySelector("moz-input-box").menupopup;
|
||||
|
||||
// While the context menu is open, test the "Select All" button.
|
||||
let contextMenuItem = contextMenu.firstElementChild;
|
||||
while (
|
||||
contextMenuItem.nextElementSibling &&
|
||||
contextMenuItem.getAttribute("cmd") != "cmd_selectAll"
|
||||
) {
|
||||
contextMenuItem = contextMenuItem.nextElementSibling;
|
||||
}
|
||||
if (contextMenuItem) {
|
||||
let controller = document.commandDispatcher.getControllerForCommand(
|
||||
contextMenuItem.getAttribute("cmd")
|
||||
);
|
||||
let enabled = controller.isCommandEnabled(
|
||||
contextMenuItem.getAttribute("cmd")
|
||||
);
|
||||
if (enabled) {
|
||||
await click(contextMenuItem);
|
||||
Assert.equal(
|
||||
gURLBar.selectionStart,
|
||||
0,
|
||||
"The entire URL should be selected after clicking selectAll button."
|
||||
);
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
exampleUrl.length,
|
||||
"The entire URL should be selected after clicking selectAll button."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
gURLBar.querySelector("moz-input-box").menupopup.hidePopup();
|
||||
gURLBar.blur();
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
add_task(async function contextMenuDoesNotCancelSelection() {
|
||||
gURLBar.inputField.focus();
|
||||
gURLBar.value = exampleUrl;
|
||||
|
||||
gURLBar.selectionStart = 3;
|
||||
gURLBar.selectionEnd = 7;
|
||||
|
||||
await openContextMenu(gURLBar.inputField);
|
||||
|
||||
Assert.equal(
|
||||
gURLBar.selectionStart,
|
||||
3,
|
||||
"The selection should not have changed."
|
||||
);
|
||||
Assert.equal(
|
||||
gURLBar.selectionEnd,
|
||||
7,
|
||||
"The selection should not have changed."
|
||||
);
|
||||
|
||||
gURLBar.querySelector("moz-input-box").menupopup.hidePopup();
|
||||
gURLBar.blur();
|
||||
});
|
||||
|
||||
add_task(async function dragSelect() {
|
||||
gURLBar.value = exampleSearch.repeat(10);
|
||||
// Drags from an artibrary offset of 30 to test for bug 1562145: that the
|
||||
// selection does not start at the beginning.
|
||||
await drag(gURLBar.inputField, 30, 0, 60, 0);
|
||||
Assert.greater(
|
||||
gURLBar.selectionStart,
|
||||
0,
|
||||
"Selection should not start at the beginning of the string."
|
||||
);
|
||||
});
|
Загрузка…
Ссылка в новой задаче