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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Tests for browser context menu</title> |
michael@0 | 5 | <script type="text/javascript" src="/MochiKit/packed.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 8 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 9 | </head> |
michael@0 | 10 | <body> |
michael@0 | 11 | Browser context menu tests for input. |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | |
michael@0 | 14 | <div id="content"> |
michael@0 | 15 | </div> |
michael@0 | 16 | |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script type="text/javascript" src="contextmenu_common.js"></script> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | const Ci = SpecialPowers.Ci; |
michael@0 | 22 | |
michael@0 | 23 | /* |
michael@0 | 24 | * runTest |
michael@0 | 25 | * |
michael@0 | 26 | * Called by a popupshowing event handler. Each test checks for expected menu |
michael@0 | 27 | * contents, closes the popup, and finally triggers the popup on a new element |
michael@0 | 28 | * (thus kicking off another cycle). |
michael@0 | 29 | * |
michael@0 | 30 | */ |
michael@0 | 31 | function runTest(testNum) { |
michael@0 | 32 | ok(true, "Starting test #" + testNum); |
michael@0 | 33 | |
michael@0 | 34 | switch (testNum) { |
michael@0 | 35 | case 1: |
michael@0 | 36 | openContextMenuFor(input); // Invoke context menu for next test. |
michael@0 | 37 | break; |
michael@0 | 38 | |
michael@0 | 39 | case 2: |
michael@0 | 40 | // Context menu for text input field. |
michael@0 | 41 | checkContextMenu(["context-undo", false, |
michael@0 | 42 | "---", null, |
michael@0 | 43 | "context-cut", false, |
michael@0 | 44 | "context-copy", false, |
michael@0 | 45 | "context-paste", null, // ignore clipboard state |
michael@0 | 46 | "context-delete", false, |
michael@0 | 47 | "---", null, |
michael@0 | 48 | "context-selectall", false, |
michael@0 | 49 | "---", null, |
michael@0 | 50 | "spell-check-enabled", true, |
michael@0 | 51 | "---", null, |
michael@0 | 52 | "context-inspect", true]); |
michael@0 | 53 | closeContextMenu(); |
michael@0 | 54 | input.setAttribute('spellcheck', 'true'); |
michael@0 | 55 | openContextMenuFor(input); // Invoke context menu for next test. |
michael@0 | 56 | break; |
michael@0 | 57 | |
michael@0 | 58 | case 3: |
michael@0 | 59 | var value = SpecialPowers.Services.appinfo.OS != "Darwin"; |
michael@0 | 60 | // Context menu for spell-check input. |
michael@0 | 61 | checkContextMenu(["context-undo", value, |
michael@0 | 62 | "---", null, |
michael@0 | 63 | "context-cut", value, |
michael@0 | 64 | "context-copy", value, |
michael@0 | 65 | "context-paste", null, // ignore clipboard state |
michael@0 | 66 | "context-delete", value, |
michael@0 | 67 | "---", null, |
michael@0 | 68 | "context-selectall", value, |
michael@0 | 69 | "---", null, |
michael@0 | 70 | "spell-check-enabled", true, |
michael@0 | 71 | "spell-dictionaries", true, |
michael@0 | 72 | [/*"spell-check-dictionary-en-US", true,*/ |
michael@0 | 73 | "---", null, |
michael@0 | 74 | "spell-add-dictionaries", true], null, |
michael@0 | 75 | "---", null, |
michael@0 | 76 | "context-inspect", true]); |
michael@0 | 77 | |
michael@0 | 78 | closeContextMenu(); |
michael@0 | 79 | input.removeAttribute('spellcheck'); |
michael@0 | 80 | openContextMenuFor(inputspellwrong); // Invoke context menu for next test. |
michael@0 | 81 | break; |
michael@0 | 82 | |
michael@0 | 83 | case 4: |
michael@0 | 84 | var value = SpecialPowers.Services.appinfo.OS != "Darwin"; |
michael@0 | 85 | // Context menu for spell-check input with a unknwon word. |
michael@0 | 86 | checkContextMenu([/*"*prodigality", true,*/ // spelling suggestion |
michael@0 | 87 | /*"spell-add-to-dictionary", true,*/ |
michael@0 | 88 | /*"---", null,*/ |
michael@0 | 89 | "context-undo", value, |
michael@0 | 90 | "---", null, |
michael@0 | 91 | "context-cut", value, |
michael@0 | 92 | "context-copy", value, |
michael@0 | 93 | "context-paste", null, // ignore clipboard state |
michael@0 | 94 | "context-delete", value, |
michael@0 | 95 | "---", null, |
michael@0 | 96 | "context-selectall", true, |
michael@0 | 97 | "---", null, |
michael@0 | 98 | "spell-check-enabled", true, |
michael@0 | 99 | "spell-dictionaries", true, |
michael@0 | 100 | [/*"spell-check-dictionary-en-US", true,*/ |
michael@0 | 101 | "---", null, |
michael@0 | 102 | "spell-add-dictionaries", true], null, |
michael@0 | 103 | "---", null, |
michael@0 | 104 | "context-inspect", true]); |
michael@0 | 105 | |
michael@0 | 106 | closeContextMenu(); |
michael@0 | 107 | openContextMenuFor(inputspellcorrect); // Invoke context menu for next test. |
michael@0 | 108 | break; |
michael@0 | 109 | |
michael@0 | 110 | case 5: |
michael@0 | 111 | var value = SpecialPowers.Services.appinfo.OS != "Darwin"; |
michael@0 | 112 | // Context menu for spell-check input with a known word. |
michael@0 | 113 | checkContextMenu(["context-undo", value, |
michael@0 | 114 | "---", null, |
michael@0 | 115 | "context-cut", value, |
michael@0 | 116 | "context-copy", value, |
michael@0 | 117 | "context-paste", null, // ignore clipboard state |
michael@0 | 118 | "context-delete", value, |
michael@0 | 119 | "---", null, |
michael@0 | 120 | "context-selectall", true, |
michael@0 | 121 | "---", null, |
michael@0 | 122 | "spell-check-enabled", true, |
michael@0 | 123 | "spell-dictionaries", true, |
michael@0 | 124 | [/*"spell-check-dictionary-en-US", true,*/ |
michael@0 | 125 | "---", null, |
michael@0 | 126 | "spell-add-dictionaries", true], null, |
michael@0 | 127 | "---", null, |
michael@0 | 128 | "context-inspect", true]); |
michael@0 | 129 | |
michael@0 | 130 | closeContextMenu(); |
michael@0 | 131 | input.disabled = true; |
michael@0 | 132 | openContextMenuFor(input); // Invoke context menu for next test. |
michael@0 | 133 | break; |
michael@0 | 134 | |
michael@0 | 135 | case 6: |
michael@0 | 136 | // Context menu for disabled input. |
michael@0 | 137 | checkContextMenu(["context-undo", false, |
michael@0 | 138 | "---", null, |
michael@0 | 139 | "context-cut", false, |
michael@0 | 140 | "context-copy", false, |
michael@0 | 141 | "context-paste", null, // ignore clipboard state |
michael@0 | 142 | "context-delete", false, |
michael@0 | 143 | "---", null, |
michael@0 | 144 | "context-selectall", true, |
michael@0 | 145 | "---", null, |
michael@0 | 146 | "spell-check-enabled", true, |
michael@0 | 147 | "---", null, |
michael@0 | 148 | "context-inspect", true]); |
michael@0 | 149 | |
michael@0 | 150 | closeContextMenu(); |
michael@0 | 151 | input.disabled = false; |
michael@0 | 152 | input.type = 'password'; |
michael@0 | 153 | openContextMenuFor(input); // Invoke context menu for next test. |
michael@0 | 154 | break; |
michael@0 | 155 | |
michael@0 | 156 | case 7: // password |
michael@0 | 157 | case 8: // email |
michael@0 | 158 | case 9: // url |
michael@0 | 159 | case 10: // tel |
michael@0 | 160 | // Context menu for tel, password, email and url input fields. |
michael@0 | 161 | checkContextMenu(["context-undo", false, |
michael@0 | 162 | "---", null, |
michael@0 | 163 | "context-cut", false, |
michael@0 | 164 | "context-copy", false, |
michael@0 | 165 | "context-paste", null, // ignore clipboard state |
michael@0 | 166 | "context-delete", false, |
michael@0 | 167 | "---", null, |
michael@0 | 168 | "context-selectall", false, |
michael@0 | 169 | "---", null, |
michael@0 | 170 | "context-inspect", true]); |
michael@0 | 171 | |
michael@0 | 172 | closeContextMenu(); |
michael@0 | 173 | |
michael@0 | 174 | if (testNum == 7) { |
michael@0 | 175 | input.type = 'email'; |
michael@0 | 176 | } else if (testNum == 8) { |
michael@0 | 177 | input.type = 'url'; |
michael@0 | 178 | } else if (testNum == 9) { |
michael@0 | 179 | input.type = 'tel'; |
michael@0 | 180 | } else if (testNum == 10) { |
michael@0 | 181 | input.type = 'date'; |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | openContextMenuFor(input); // Invoke context menu for next test. |
michael@0 | 185 | break; |
michael@0 | 186 | |
michael@0 | 187 | case 11: // type='date' |
michael@0 | 188 | case 12: // type='time' |
michael@0 | 189 | case 13: // type='number' |
michael@0 | 190 | case 14: // type='color' |
michael@0 | 191 | case 15: // type='range' |
michael@0 | 192 | checkContextMenu(["context-back", false, |
michael@0 | 193 | "context-forward", false, |
michael@0 | 194 | "context-reload", true, |
michael@0 | 195 | "---", null, |
michael@0 | 196 | "context-bookmarkpage", true, |
michael@0 | 197 | "context-savepage", true, |
michael@0 | 198 | "---", null, |
michael@0 | 199 | "context-viewbgimage", false, |
michael@0 | 200 | "context-selectall", null, |
michael@0 | 201 | "---", null, |
michael@0 | 202 | "context-viewsource", true, |
michael@0 | 203 | "context-viewinfo", true, |
michael@0 | 204 | "---", null, |
michael@0 | 205 | "context-inspect", true]); |
michael@0 | 206 | closeContextMenu(); |
michael@0 | 207 | |
michael@0 | 208 | if (testNum == 11) { |
michael@0 | 209 | input.type = 'time'; |
michael@0 | 210 | } else if (testNum == 12) { |
michael@0 | 211 | input.type = 'number'; |
michael@0 | 212 | } else if (testNum == 13) { |
michael@0 | 213 | input.type = 'color'; |
michael@0 | 214 | } else if (testNum == 14) { |
michael@0 | 215 | input.type = 'range'; |
michael@0 | 216 | } else { |
michael@0 | 217 | input.type = 'search'; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | openContextMenuFor(input); |
michael@0 | 221 | break; |
michael@0 | 222 | |
michael@0 | 223 | case 16: // type='search' |
michael@0 | 224 | // Context menu for search input fields. |
michael@0 | 225 | checkContextMenu(["context-undo", false, |
michael@0 | 226 | "---", null, |
michael@0 | 227 | "context-cut", false, |
michael@0 | 228 | "context-copy", false, |
michael@0 | 229 | "context-paste", null, // ignore clipboard state |
michael@0 | 230 | "context-delete", false, |
michael@0 | 231 | "---", null, |
michael@0 | 232 | "context-selectall", false, |
michael@0 | 233 | "---", null, |
michael@0 | 234 | "spell-check-enabled", true, |
michael@0 | 235 | "---", null, |
michael@0 | 236 | "context-inspect", true]); |
michael@0 | 237 | |
michael@0 | 238 | closeContextMenu(); |
michael@0 | 239 | |
michael@0 | 240 | // Add some todos to make sure all input fields got a test. |
michael@0 | 241 | var todos = [ "datetime", "month", "week", "datetime-local" ]; |
michael@0 | 242 | todos.forEach(function(type) { |
michael@0 | 243 | input.type = type; |
michael@0 | 244 | todo_is(input.type, type, "TODO: add test for " + type + " input fields"); |
michael@0 | 245 | }); |
michael@0 | 246 | |
michael@0 | 247 | input.type = 'text'; |
michael@0 | 248 | input.readOnly = true; |
michael@0 | 249 | openContextMenuFor(input); |
michael@0 | 250 | break; |
michael@0 | 251 | |
michael@0 | 252 | case 17: |
michael@0 | 253 | // Context menu for a read-only input. |
michael@0 | 254 | checkContextMenu(["context-undo", false, |
michael@0 | 255 | "---", null, |
michael@0 | 256 | "context-cut", false, |
michael@0 | 257 | "context-copy", false, |
michael@0 | 258 | "context-paste", null, // ignore clipboard state |
michael@0 | 259 | "context-delete", false, |
michael@0 | 260 | "---", null, |
michael@0 | 261 | "context-selectall", false, |
michael@0 | 262 | "---", null, |
michael@0 | 263 | "context-inspect", true]); |
michael@0 | 264 | closeContextMenu(); |
michael@0 | 265 | |
michael@0 | 266 | // Clean-up. |
michael@0 | 267 | subwindow.close(); |
michael@0 | 268 | SimpleTest.finish(); |
michael@0 | 269 | return; |
michael@0 | 270 | |
michael@0 | 271 | default: |
michael@0 | 272 | ok(false, "Unexpected invocation of test #" + testNum); |
michael@0 | 273 | subwindow.close(); |
michael@0 | 274 | SimpleTest.finish(); |
michael@0 | 275 | return; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | |
michael@0 | 281 | var gTestNum = 1; |
michael@0 | 282 | var subwindow, chromeWin, contextMenu; |
michael@0 | 283 | var input, inputspellwrong, inputspellcorrect; |
michael@0 | 284 | |
michael@0 | 285 | function startTest() { |
michael@0 | 286 | chromeWin = SpecialPowers.wrap(subwindow) |
michael@0 | 287 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 288 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 289 | .QueryInterface(Ci.nsIDocShellTreeItem) |
michael@0 | 290 | .rootTreeItem |
michael@0 | 291 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 292 | .getInterface(Ci.nsIDOMWindow) |
michael@0 | 293 | .QueryInterface(Ci.nsIDOMChromeWindow); |
michael@0 | 294 | contextMenu = chromeWin.document.getElementById("contentAreaContextMenu"); |
michael@0 | 295 | ok(contextMenu, "Got context menu XUL"); |
michael@0 | 296 | |
michael@0 | 297 | if (chromeWin.document.getElementById("Browser:Stop").getAttribute("disabled") != "true") { |
michael@0 | 298 | SimpleTest.executeSoon(startTest); |
michael@0 | 299 | return; |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | var inputs = subwindow.document.getElementsByTagName('input'); |
michael@0 | 303 | input = inputs[0]; |
michael@0 | 304 | inputspellwrong = inputs[1]; |
michael@0 | 305 | inputspellcorrect = inputs[2]; |
michael@0 | 306 | |
michael@0 | 307 | contextMenu.addEventListener("popupshown", function() { runTest(++gTestNum); }, false); |
michael@0 | 308 | runTest(1); |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | // We open this in a separate window, because the Mochitests run inside a frame. |
michael@0 | 312 | // The frame causes an extra menu item, and prevents running the test |
michael@0 | 313 | // standalone (ie, clicking the test name in the Mochitest window) to see |
michael@0 | 314 | // success/failure messages. |
michael@0 | 315 | var painted = false, loaded = false; |
michael@0 | 316 | |
michael@0 | 317 | function waitForEvents(event) |
michael@0 | 318 | { |
michael@0 | 319 | if (event.type == "MozAfterPaint") |
michael@0 | 320 | painted = true; |
michael@0 | 321 | else if (event.type == "load") |
michael@0 | 322 | loaded = true; |
michael@0 | 323 | if (painted && loaded) { |
michael@0 | 324 | subwindow.removeEventListener("MozAfterPaint", waitForEvents, false); |
michael@0 | 325 | subwindow.onload = null; |
michael@0 | 326 | startTest(); |
michael@0 | 327 | } |
michael@0 | 328 | } |
michael@0 | 329 | |
michael@0 | 330 | var subwindow = window.open("data:text/html,<!DOCTYPE html><input><input spellcheck='true' value='prodkjfgigrty'><input spellcheck='true' value='foo'><input readonly spellcheck='false'>", "contextmenu-subtext", "width=600,height=700"); |
michael@0 | 331 | subwindow.addEventListener("MozAfterPaint", waitForEvents, false); |
michael@0 | 332 | subwindow.onload = waitForEvents; |
michael@0 | 333 | |
michael@0 | 334 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 335 | </script> |
michael@0 | 336 | </pre> |
michael@0 | 337 | </body> |
michael@0 | 338 | </html> |