Skip to content

Commit bf6b646

Browse files
committed
Bug 1968677 - [devtools] Revert user agent input to its previous value on Escape. r=devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D251370
1 parent 0b38a65 commit bf6b646

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

devtools/client/responsive/components/UserAgentInput.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class UserAgentInput extends PureComponent {
106106
}
107107

108108
if (keyCode == KeyCodes.DOM_VK_ESCAPE) {
109+
this.setState({ value: this.props.userAgent });
109110
target.blur();
110111
}
111112
}

devtools/client/responsive/test/browser/browser_user_agent_input.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ addRDMTask(TEST_URL, async function ({ ui }) {
2727
info("Check the default state of the user agent input");
2828
await testUserAgent(ui, DEFAULT_UA);
2929

30+
info(`Change the user agent input to ${NEW_USER_AGENT} and press Escape`);
31+
await changeUserAgentInput(ui, NEW_USER_AGENT, "VK_ESCAPE");
32+
await testUserAgent(ui, DEFAULT_UA);
33+
3034
info(`Change the user agent input to ${NEW_USER_AGENT}`);
3135
await changeUserAgentInput(ui, NEW_USER_AGENT);
3236
await testUserAgent(ui, NEW_USER_AGENT);

devtools/client/responsive/test/browser/head.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,11 @@ function testViewportDimensions(ui, w, h) {
724724
);
725725
}
726726

727-
async function changeUserAgentInput(ui, value) {
727+
async function changeUserAgentInput(
728+
ui,
729+
value,
730+
keyPressedAfterChange = "VK_RETURN"
731+
) {
728732
const { Simulate } = ui.toolWindow.require(
729733
"resource://devtools/client/shared/vendor/react-dom-test-utils.js"
730734
);
@@ -733,17 +737,27 @@ async function changeUserAgentInput(ui, value) {
733737

734738
const userAgentInput = document.getElementById("user-agent-input");
735739
userAgentInput.value = value;
740+
userAgentInput.focus();
736741
Simulate.change(userAgentInput);
737742

738-
const userAgentChanged = waitUntilState(
739-
store,
740-
state => state.ui.userAgent === value
741-
);
742-
const changed = once(ui, "user-agent-changed");
743+
function pressKey() {
744+
EventUtils.synthesizeKey(keyPressedAfterChange, {}, ui.toolWindow);
745+
}
743746

744-
const waitForDevToolsReload = await watchForDevToolsReload(browser);
745-
Simulate.keyUp(userAgentInput, { keyCode: KeyCodes.DOM_VK_RETURN });
746-
await Promise.all([changed, waitForDevToolsReload(), userAgentChanged]);
747+
if (keyPressedAfterChange === "VK_ESCAPE") {
748+
pressKey();
749+
} else {
750+
const userAgentChanged = waitUntilState(
751+
store,
752+
state => state.ui.userAgent === value
753+
);
754+
const changed = once(ui, "user-agent-changed");
755+
const waitForDevToolsReload = await watchForDevToolsReload(browser);
756+
757+
pressKey();
758+
759+
await Promise.all([changed, waitForDevToolsReload(), userAgentChanged]);
760+
}
747761
}
748762

749763
/**

0 commit comments

Comments
 (0)