summaryrefslogtreecommitdiffstats
path: root/devtools/client/projecteditor/test/browser_projecteditor_contextmenu_02.js
blob: cf43b3e21fb57307d0f7fc25b9456091ff7f6cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

loadHelperScript("helper_edits.js");

// Test context menu enabled / disabled state in editor

add_task(function* () {
  let projecteditor = yield addProjectEditorTabForTempDirectory();
  ok(projecteditor, "ProjectEditor has loaded");

  let {textEditorContextMenuPopup} = projecteditor;

  // Update menu items for a clean slate, so previous tests cannot
  // affect paste, and possibly other side effects
  projecteditor._updateMenuItems();

  let cmdDelete = textEditorContextMenuPopup.querySelector("[command=cmd_delete]");
  let cmdSelectAll = textEditorContextMenuPopup.querySelector("[command=cmd_selectAll]");
  let cmdCut = textEditorContextMenuPopup.querySelector("[command=cmd_cut]");
  let cmdCopy = textEditorContextMenuPopup.querySelector("[command=cmd_copy]");
  let cmdPaste = textEditorContextMenuPopup.querySelector("[command=cmd_paste]");

  info("Opening resource");
  let resource = projecteditor.project.allResources()[2];
  yield selectFile(projecteditor, resource);
  let editor = projecteditor.currentEditor;
  editor.editor.focus();

  info("Opening context menu on resource");
  yield openContextMenuForEditor(editor, textEditorContextMenuPopup);

  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"), "", "cmdPaste is enabled");

  info("Setting a selection and repening context menu on resource");
  yield closeContextMenuForEditor(editor, textEditorContextMenuPopup);
  editor.editor.setSelection({line: 0, ch: 0}, {line: 0, ch: 2});
  yield openContextMenuForEditor(editor, textEditorContextMenuPopup);

  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");
});

function* openContextMenuForEditor(editor, contextMenu) {
  let editorDoc = editor.editor.container.contentDocument;
  let shown = onPopupShow(contextMenu);
  EventUtils.synthesizeMouse(editorDoc.body, 2, 2,
    {type: "contextmenu", button: 2}, editorDoc.defaultView);
  yield shown;
}
function* closeContextMenuForEditor(editor, contextMenu) {
  let editorDoc = editor.editor.container.contentDocument;
  let hidden = onPopupHidden(contextMenu);
  contextMenu.hidePopup();
  yield hidden;
}