Bug 1294937 - The context menu does not appear when right-click on the inspector-searchbox. r=gl

MozReview-Commit-ID: 8Ebs5jeYlkq

--HG--
extra : rebase_source : d4358f8c6bb2e3d1e6456190daba6a320c604257
This commit is contained in:
Fred Lin 2016-08-15 11:23:16 +08:00
parent 8738cfff5d
commit 358c4a1bf6
3 changed files with 87 additions and 0 deletions

View File

@ -41,8 +41,12 @@ function InspectorSearch(inspector, input, clearBtn) {
this._onKeyDown = this._onKeyDown.bind(this);
this._onInput = this._onInput.bind(this);
this._onClearSearch = this._onClearSearch.bind(this);
this._onFilterTextboxContextMenu =
this._onFilterTextboxContextMenu.bind(this);
this.searchBox.addEventListener("keydown", this._onKeyDown, true);
this.searchBox.addEventListener("input", this._onInput, true);
this.searchBox.addEventListener("contextmenu",
this._onFilterTextboxContextMenu);
this.searchClearButton.addEventListener("click", this._onClearSearch);
// For testing, we need to be able to wait for the most recent node request
@ -63,6 +67,8 @@ InspectorSearch.prototype = {
destroy: function () {
this.searchBox.removeEventListener("keydown", this._onKeyDown, true);
this.searchBox.removeEventListener("input", this._onInput, true);
this.searchBox.removeEventListener("contextmenu",
this._onFilterTextboxContextMenu);
this.searchClearButton.removeEventListener("click", this._onClearSearch);
this.searchBox = null;
this.searchClearButton = null;
@ -131,6 +137,18 @@ InspectorSearch.prototype = {
}
},
/**
* Context menu handler for filter search box.
*/
_onFilterTextboxContextMenu: function (event) {
try {
let contextmenu = this.inspector.toolbox.textboxContextMenuPopup;
contextmenu.openPopupAtScreen(event.screenX, event.screenY, true);
} catch (e) {
console.error(e);
}
},
_onClearSearch: function () {
this.searchBox.classList.remove("devtools-style-searchbox-no-match");
this.searchBox.value = "";

View File

@ -139,6 +139,7 @@ skip-if = os == "mac" # Full keyboard navigation on OSX only works if Full Keybo
[browser_inspector_search-06.js]
[browser_inspector_search-07.js]
[browser_inspector_search-08.js]
[browser_inspector_search-filter_context-menu.js]
[browser_inspector_search_keyboard_trap.js]
[browser_inspector_search-reserved.js]
[browser_inspector_search-selection.js]

View File

@ -0,0 +1,68 @@
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test inspector's markup view search filter context menu works properly.
const TEST_INPUT = "h1";
const TEST_URI = "<h1>test filter context menu</h1>";
add_task(function* () {
yield addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
let {toolbox, inspector} = yield openInspector();
let {searchBox} = inspector;
yield selectNode("h1", inspector);
let win = inspector.panelWin;
let searchContextMenu = toolbox.textboxContextMenuPopup;
ok(searchContextMenu,
"The search filter context menu is loaded in the inspector");
let cmdUndo = searchContextMenu.querySelector("[command=cmd_undo]");
let cmdDelete = searchContextMenu.querySelector("[command=cmd_delete]");
let cmdSelectAll = searchContextMenu.querySelector("[command=cmd_selectAll]");
let cmdCut = searchContextMenu.querySelector("[command=cmd_cut]");
let cmdCopy = searchContextMenu.querySelector("[command=cmd_copy]");
let cmdPaste = searchContextMenu.querySelector("[command=cmd_paste]");
info("Opening context menu");
let onContextMenuPopup = once(searchContextMenu, "popupshowing");
EventUtils.synthesizeMouse(searchBox, 2, 2,
{type: "contextmenu", button: 2}, win);
yield onContextMenuPopup;
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
info("Closing context menu");
let onContextMenuHidden = once(searchContextMenu, "popuphidden");
searchContextMenu.hidePopup();
yield onContextMenuHidden;
info("Copy text in search field using the context menu");
searchBox.value = TEST_INPUT;
searchBox.select();
EventUtils.synthesizeMouse(searchBox, 2, 2,
{type: "contextmenu", button: 2}, win);
yield onContextMenuPopup;
yield waitForClipboard(() => cmdCopy.click(), TEST_INPUT);
searchContextMenu.hidePopup();
yield onContextMenuHidden;
info("Reopen context menu and check command properties");
EventUtils.synthesizeMouse(searchBox, 2, 2,
{type: "contextmenu", button: 2}, win);
yield onContextMenuPopup;
is(cmdUndo.getAttribute("disabled"), "", "cmdUndo is enabled");
is(cmdDelete.getAttribute("disabled"), "", "cmdDelete is enabled");
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
is(cmdPaste.getAttribute("disabled"), "", "cmdPaste is enabled");
});