Backed out changeset d6d95a998ee9 (bug 1565273) for causing bug 1569813.

--HG--
extra : rebase_source : fc813c3c59dac61e77968d6c785e61ffce50fd6a
This commit is contained in:
Cosmin Sabou 2019-07-30 03:46:10 +03:00
Родитель 6808dc0e6f
Коммит 98f1f23f7e
3 изменённых файлов: 10 добавлений и 229 удалений

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

@ -1413,13 +1413,11 @@ 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(ignoreClickSelectsAllPref = false) {
_maybeSelectAll() {
if (
!this._preventClickSelectsAll &&
(ignoreClickSelectsAllPref || UrlbarPrefs.get("clickSelectsAll")) &&
UrlbarPrefs.get("clickSelectsAll") &&
this._compositionState != UrlbarUtils.COMPOSITION.COMPOSING &&
this.document.activeElement == this.inputField &&
this.inputField.selectionStart == this.inputField.selectionEnd
@ -1479,14 +1477,19 @@ 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;
}
// If the user right clicks, we select all regardless of the value of
// the browser.urlbar.clickSelectsAll pref.
this._maybeSelectAll(/* ignoreClickSelectsAllPref */ event.button == 2);
this._maybeSelectAll();
}
_on_focus(event) {

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

@ -129,7 +129,6 @@ 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

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

@ -1,221 +0,0 @@
/* 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]],
});
// On macOS, we must "warm up" the Urlbar to get the first test to pass.
gURLBar.value = "";
await click(gURLBar.inputField);
gURLBar.blur();
});
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."
);
});