зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1682340 - [devtools] Prevent triggering Reader Mode with reverse search keyboard shortcut on Windows. r=bomsy.
We weren't calling preventDefault on the event handler, which was allowing the browser to consume it, and toggle reader mode on windows, which shares the same keyboard shortcut (F9). A test is added to ensure we don't regress this (the test is failing without the fix). Differential Revision: https://phabricator.services.mozilla.com/D101919
This commit is contained in:
Родитель
71555984ed
Коммит
0a6af59794
|
@ -145,6 +145,8 @@ class App extends Component {
|
|||
actions.reverseSearchInputToggle({ initialValue, access: "keyboard" })
|
||||
);
|
||||
event.stopPropagation();
|
||||
// Prevent Reader Mode to be enabled (See Bug 1682340)
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
|
@ -25,6 +25,7 @@ support-files =
|
|||
!/devtools/client/framework/browser-toolbox/test/helpers-browser-toolbox.js
|
||||
!/devtools/client/shared/test/telemetry-test-helpers.js
|
||||
!/devtools/client/shared/test/test-actor.js
|
||||
../../../../../toolkit/components/reader/test/readerModeArticle.html
|
||||
|
||||
[browser_jsterm_add_edited_input_to_history.js]
|
||||
[browser_jsterm_autocomplete_accept_no_scroll.js]
|
||||
|
@ -106,6 +107,7 @@ skip-if = os != 'mac' # The tested ctrl+key shortcuts are OSX only
|
|||
[browser_jsterm_editor_toggle_keyboard_shortcut.js]
|
||||
[browser_jsterm_editor_resize.js]
|
||||
[browser_jsterm_editor_reverse_search_button.js]
|
||||
[browser_jsterm_editor_reverse_search_keyboard_navigation.js]
|
||||
[browser_jsterm_editor_toolbar.js]
|
||||
[browser_jsterm_error_docs.js]
|
||||
[browser_jsterm_error_outside_valid_range.js]
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Ensure keyboard navigation works in editor mode and does
|
||||
// not trigger reader mode (See 1682340).
|
||||
|
||||
const TEST_URI = `http://example.com/browser/toolkit/components/reader/test/readerModeArticle.html`;
|
||||
/*
|
||||
const TEST_URI = `http://example.com/document-builder.sjs?html=
|
||||
<html>
|
||||
<head>
|
||||
<meta name="description" content="this is the description">
|
||||
<title>Article title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Firefox DevTools Rock</h1>
|
||||
${"<p>I shall not trigger reader mode".repeat(1000)}
|
||||
</body>
|
||||
</html>
|
||||
`;*/
|
||||
const isMacOS = AppConstants.platform === "macosx";
|
||||
|
||||
add_task(async function() {
|
||||
await pushPref("devtools.webconsole.input.editor", true);
|
||||
await pushPref("reader.parse-on-load.enabled", true);
|
||||
|
||||
const readerModeButtonEl = document.querySelector("#reader-mode-button");
|
||||
|
||||
const hud = await openNewTabAndConsole(TEST_URI);
|
||||
await waitFor(() => !readerModeButtonEl.hidden);
|
||||
|
||||
const jstermHistory = [
|
||||
`document`,
|
||||
`document
|
||||
.querySelectorAll("*")
|
||||
.forEach(console.log)`,
|
||||
`Dog = "Snoopy"`,
|
||||
];
|
||||
|
||||
const onLastMessage = waitForMessage(hud, `"Snoopy"`, ".result");
|
||||
for (const input of jstermHistory) {
|
||||
execute(hud, input);
|
||||
}
|
||||
await onLastMessage;
|
||||
await openReverseSearch(hud);
|
||||
|
||||
// Wait for a bit so reader mode would have some time to initialize.
|
||||
await wait(1000);
|
||||
is(
|
||||
readerModeButtonEl.getAttribute("readeractive"),
|
||||
"",
|
||||
"reader mode wasn't activated"
|
||||
);
|
||||
|
||||
EventUtils.sendString("d");
|
||||
const infoElement = await waitFor(() => getReverseSearchInfoElement(hud));
|
||||
is(
|
||||
infoElement.textContent,
|
||||
"3 of 3 results",
|
||||
"The reverse info has the expected text"
|
||||
);
|
||||
|
||||
is(getInputValue(hud), jstermHistory[2], "JsTerm has the expected input");
|
||||
is(
|
||||
hud.jsterm.autocompletePopup.isOpen,
|
||||
false,
|
||||
"Setting the input value did not trigger the autocompletion"
|
||||
);
|
||||
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "previous",
|
||||
expectedInfoText: "2 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[1],
|
||||
});
|
||||
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "previous",
|
||||
expectedInfoText: "1 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[0],
|
||||
});
|
||||
|
||||
info(
|
||||
"Check that we go back to the last matching item if we were at the first"
|
||||
);
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "previous",
|
||||
expectedInfoText: "3 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[2],
|
||||
});
|
||||
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "next",
|
||||
expectedInfoText: "1 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[0],
|
||||
});
|
||||
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "next",
|
||||
expectedInfoText: "2 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[1],
|
||||
});
|
||||
|
||||
await navigateResultsAndCheckState(hud, {
|
||||
direction: "next",
|
||||
expectedInfoText: "3 of 3 results",
|
||||
expectedJsTermInputValue: jstermHistory[2],
|
||||
});
|
||||
|
||||
info(
|
||||
"Check that trying to navigate when there's only 1 result does not throw"
|
||||
);
|
||||
EventUtils.sendString("og");
|
||||
await waitFor(
|
||||
() => getReverseSearchInfoElement(hud).textContent === "1 result"
|
||||
);
|
||||
triggerPreviousResultShortcut();
|
||||
triggerNextResultShortcut();
|
||||
|
||||
info("Check that trying to navigate when there's no result does not throw");
|
||||
EventUtils.sendString("g");
|
||||
await waitFor(
|
||||
() => getReverseSearchInfoElement(hud).textContent === "No results"
|
||||
);
|
||||
triggerPreviousResultShortcut();
|
||||
triggerNextResultShortcut();
|
||||
|
||||
is(
|
||||
readerModeButtonEl.getAttribute("readeractive"),
|
||||
"",
|
||||
"reader mode still wasn't activated"
|
||||
);
|
||||
});
|
||||
|
||||
async function navigateResultsAndCheckState(
|
||||
hud,
|
||||
{ direction, expectedInfoText, expectedJsTermInputValue }
|
||||
) {
|
||||
const onJsTermValueChanged = hud.jsterm.once("set-input-value");
|
||||
if (direction === "previous") {
|
||||
triggerPreviousResultShortcut();
|
||||
} else {
|
||||
triggerNextResultShortcut();
|
||||
}
|
||||
await onJsTermValueChanged;
|
||||
|
||||
is(getInputValue(hud), expectedJsTermInputValue, "JsTerm has expected value");
|
||||
|
||||
const infoElement = getReverseSearchInfoElement(hud);
|
||||
is(
|
||||
infoElement.textContent,
|
||||
expectedInfoText,
|
||||
"The reverse info has the expected text"
|
||||
);
|
||||
is(
|
||||
isReverseSearchInputFocused(hud),
|
||||
true,
|
||||
"reverse search input is still focused"
|
||||
);
|
||||
}
|
||||
|
||||
function triggerPreviousResultShortcut() {
|
||||
if (isMacOS) {
|
||||
EventUtils.synthesizeKey("r", { ctrlKey: true });
|
||||
} else {
|
||||
EventUtils.synthesizeKey("VK_F9");
|
||||
}
|
||||
}
|
||||
|
||||
function triggerNextResultShortcut() {
|
||||
if (isMacOS) {
|
||||
EventUtils.synthesizeKey("s", { ctrlKey: true });
|
||||
} else {
|
||||
EventUtils.synthesizeKey("VK_F9", { shiftKey: true });
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче