Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | /* Bug 699130 */ |
michael@0 | 5 | |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | function test() |
michael@0 | 9 | { |
michael@0 | 10 | waitForExplicitFinish(); |
michael@0 | 11 | |
michael@0 | 12 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 13 | gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
michael@0 | 14 | gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
michael@0 | 15 | openScratchpad(runTests); |
michael@0 | 16 | }, true); |
michael@0 | 17 | |
michael@0 | 18 | content.location = "data:text/html,test Edit menu updates Scratchpad - bug 699130"; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | function runTests() |
michael@0 | 22 | { |
michael@0 | 23 | let sp = gScratchpadWindow.Scratchpad; |
michael@0 | 24 | let doc = gScratchpadWindow.document; |
michael@0 | 25 | let winUtils = gScratchpadWindow.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 26 | getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 27 | let OS = Services.appinfo.OS; |
michael@0 | 28 | |
michael@0 | 29 | info("will test the Edit menu"); |
michael@0 | 30 | |
michael@0 | 31 | let pass = 0; |
michael@0 | 32 | |
michael@0 | 33 | sp.setText("bug 699130: hello world! (edit menu)"); |
michael@0 | 34 | |
michael@0 | 35 | let editMenu = doc.getElementById("sp-edit-menu"); |
michael@0 | 36 | ok(editMenu, "the Edit menu"); |
michael@0 | 37 | let menubar = editMenu.parentNode; |
michael@0 | 38 | ok(menubar, "menubar found"); |
michael@0 | 39 | |
michael@0 | 40 | let editMenuIndex = -1; |
michael@0 | 41 | for (let i = 0; i < menubar.children.length; i++) { |
michael@0 | 42 | if (menubar.children[i] === editMenu) { |
michael@0 | 43 | editMenuIndex = i; |
michael@0 | 44 | break; |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | isnot(editMenuIndex, -1, "Edit menu index is correct"); |
michael@0 | 48 | |
michael@0 | 49 | let menuPopup = editMenu.menupopup; |
michael@0 | 50 | ok(menuPopup, "the Edit menupopup"); |
michael@0 | 51 | let cutItem = doc.getElementById("menu_cut"); |
michael@0 | 52 | ok(cutItem, "the Cut menuitem"); |
michael@0 | 53 | let pasteItem = doc.getElementById("menu_paste"); |
michael@0 | 54 | ok(pasteItem, "the Paste menuitem"); |
michael@0 | 55 | |
michael@0 | 56 | let anchor = doc.documentElement; |
michael@0 | 57 | let isContextMenu = false; |
michael@0 | 58 | |
michael@0 | 59 | let openMenu = function(aX, aY, aCallback) { |
michael@0 | 60 | if (!editMenu || OS != "Darwin") { |
michael@0 | 61 | menuPopup.addEventListener("popupshown", function onPopupShown() { |
michael@0 | 62 | menuPopup.removeEventListener("popupshown", onPopupShown, false); |
michael@0 | 63 | executeSoon(aCallback); |
michael@0 | 64 | }, false); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | executeSoon(function() { |
michael@0 | 68 | if (editMenu) { |
michael@0 | 69 | if (OS == "Darwin") { |
michael@0 | 70 | winUtils.forceUpdateNativeMenuAt(editMenuIndex); |
michael@0 | 71 | executeSoon(aCallback); |
michael@0 | 72 | } else { |
michael@0 | 73 | editMenu.open = true; |
michael@0 | 74 | } |
michael@0 | 75 | } else { |
michael@0 | 76 | menuPopup.openPopup(anchor, "overlap", aX, aY, isContextMenu, false); |
michael@0 | 77 | } |
michael@0 | 78 | }); |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | let closeMenu = function(aCallback) { |
michael@0 | 82 | if (!editMenu || OS != "Darwin") { |
michael@0 | 83 | menuPopup.addEventListener("popuphidden", function onPopupHidden() { |
michael@0 | 84 | menuPopup.removeEventListener("popuphidden", onPopupHidden, false); |
michael@0 | 85 | executeSoon(aCallback); |
michael@0 | 86 | }, false); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | executeSoon(function() { |
michael@0 | 90 | if (editMenu) { |
michael@0 | 91 | if (OS == "Darwin") { |
michael@0 | 92 | winUtils.forceUpdateNativeMenuAt(editMenuIndex); |
michael@0 | 93 | executeSoon(aCallback); |
michael@0 | 94 | } else { |
michael@0 | 95 | editMenu.open = false; |
michael@0 | 96 | } |
michael@0 | 97 | } else { |
michael@0 | 98 | menuPopup.hidePopup(); |
michael@0 | 99 | } |
michael@0 | 100 | }); |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | let firstShow = function() { |
michael@0 | 104 | ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled"); |
michael@0 | 105 | closeMenu(firstHide); |
michael@0 | 106 | }; |
michael@0 | 107 | |
michael@0 | 108 | let firstHide = function() { |
michael@0 | 109 | sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 10 }); |
michael@0 | 110 | openMenu(11, 11, showAfterSelect); |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | let showAfterSelect = function() { |
michael@0 | 114 | ok(!cutItem.hasAttribute("disabled"), "cut menuitem is enabled after select"); |
michael@0 | 115 | closeMenu(hideAfterSelect); |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | let hideAfterSelect = function() { |
michael@0 | 119 | sp.editor.on("change", onCut); |
michael@0 | 120 | waitForFocus(function () { |
michael@0 | 121 | let selectedText = sp.editor.getSelection(); |
michael@0 | 122 | ok(selectedText.length > 0, "non-empty selected text will be cut"); |
michael@0 | 123 | |
michael@0 | 124 | EventUtils.synthesizeKey("x", {accelKey: true}, gScratchpadWindow); |
michael@0 | 125 | }, gScratchpadWindow); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | let onCut = function() { |
michael@0 | 129 | sp.editor.off("change", onCut); |
michael@0 | 130 | openMenu(12, 12, showAfterCut); |
michael@0 | 131 | }; |
michael@0 | 132 | |
michael@0 | 133 | let showAfterCut = function() { |
michael@0 | 134 | ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled after cut"); |
michael@0 | 135 | ok(!pasteItem.hasAttribute("disabled"), "paste menuitem is enabled after cut"); |
michael@0 | 136 | closeMenu(hideAfterCut); |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | let hideAfterCut = function() { |
michael@0 | 140 | sp.editor.on("change", onPaste); |
michael@0 | 141 | waitForFocus(function () { |
michael@0 | 142 | EventUtils.synthesizeKey("v", {accelKey: true}, gScratchpadWindow); |
michael@0 | 143 | }, gScratchpadWindow); |
michael@0 | 144 | }; |
michael@0 | 145 | |
michael@0 | 146 | let onPaste = function() { |
michael@0 | 147 | sp.editor.off("change", onPaste); |
michael@0 | 148 | openMenu(13, 13, showAfterPaste); |
michael@0 | 149 | }; |
michael@0 | 150 | |
michael@0 | 151 | let showAfterPaste = function() { |
michael@0 | 152 | ok(cutItem.hasAttribute("disabled"), "cut menuitem is disabled after paste"); |
michael@0 | 153 | ok(!pasteItem.hasAttribute("disabled"), "paste menuitem is enabled after paste"); |
michael@0 | 154 | closeMenu(hideAfterPaste); |
michael@0 | 155 | }; |
michael@0 | 156 | |
michael@0 | 157 | let hideAfterPaste = function() { |
michael@0 | 158 | if (pass == 0) { |
michael@0 | 159 | pass++; |
michael@0 | 160 | testContextMenu(); |
michael@0 | 161 | } else { |
michael@0 | 162 | finish(); |
michael@0 | 163 | } |
michael@0 | 164 | }; |
michael@0 | 165 | |
michael@0 | 166 | let testContextMenu = function() { |
michael@0 | 167 | info("will test the context menu"); |
michael@0 | 168 | |
michael@0 | 169 | editMenu = null; |
michael@0 | 170 | isContextMenu = true; |
michael@0 | 171 | |
michael@0 | 172 | menuPopup = doc.getElementById("scratchpad-text-popup"); |
michael@0 | 173 | ok(menuPopup, "the context menupopup"); |
michael@0 | 174 | cutItem = doc.getElementById("cMenu_cut"); |
michael@0 | 175 | ok(cutItem, "the Cut menuitem"); |
michael@0 | 176 | pasteItem = doc.getElementById("cMenu_paste"); |
michael@0 | 177 | ok(pasteItem, "the Paste menuitem"); |
michael@0 | 178 | |
michael@0 | 179 | sp.setText("bug 699130: hello world! (context menu)"); |
michael@0 | 180 | openMenu(10, 10, firstShow); |
michael@0 | 181 | }; |
michael@0 | 182 | |
michael@0 | 183 | openMenu(10, 10, firstShow); |
michael@0 | 184 | } |