Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 5 | |
michael@0 | 6 | "use strict"; |
michael@0 | 7 | |
michael@0 | 8 | function debugClipFlavors(aClip) |
michael@0 | 9 | { |
michael@0 | 10 | let xfer = Cc["@mozilla.org/widget/transferable;1"]. |
michael@0 | 11 | createInstance(Ci.nsITransferable); |
michael@0 | 12 | xfer.init(null); |
michael@0 | 13 | aClip.getData(xfer, Ci.nsIClipboard.kGlobalClipboard); |
michael@0 | 14 | let array = xfer.flavorsTransferableCanExport(); |
michael@0 | 15 | let count = array.Count(); |
michael@0 | 16 | info("flavors:" + count); |
michael@0 | 17 | for (let idx = 0; idx < count; idx++) { |
michael@0 | 18 | let string = array.GetElementAt(idx).QueryInterface(Ci.nsISupportsString); |
michael@0 | 19 | info("[" + idx + "] " + string); |
michael@0 | 20 | } |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function checkContextMenuPositionRange(aElement, aMinLeft, aMaxLeft, aMinTop, aMaxTop) { |
michael@0 | 24 | ok(aElement.left > aMinLeft && aElement.left < aMaxLeft, |
michael@0 | 25 | "Left position is " + aElement.left + ", expected between " + aMinLeft + " and " + aMaxLeft); |
michael@0 | 26 | |
michael@0 | 27 | ok(aElement.top > aMinTop && aElement.top < aMaxTop, |
michael@0 | 28 | "Top position is " + aElement.top + ", expected between " + aMinTop + " and " + aMaxTop); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | gTests.push({ |
michael@0 | 32 | desc: "text context menu", |
michael@0 | 33 | run: function test() { |
michael@0 | 34 | info(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 35 | yield addTab(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 36 | |
michael@0 | 37 | purgeEventQueue(); |
michael@0 | 38 | emptyClipboard(); |
michael@0 | 39 | |
michael@0 | 40 | let win = Browser.selectedTab.browser.contentWindow; |
michael@0 | 41 | |
michael@0 | 42 | yield hideContextUI(); |
michael@0 | 43 | |
michael@0 | 44 | //////////////////////////////////////////////////////////// |
michael@0 | 45 | // Context menu in content on selected text |
michael@0 | 46 | |
michael@0 | 47 | // select some text |
michael@0 | 48 | let span = win.document.getElementById("text1"); |
michael@0 | 49 | win.getSelection().selectAllChildren(span); |
michael@0 | 50 | |
michael@0 | 51 | yield waitForMs(0); |
michael@0 | 52 | |
michael@0 | 53 | // invoke selection context menu |
michael@0 | 54 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 55 | sendContextMenuClickToElement(win, span); |
michael@0 | 56 | yield promise; |
michael@0 | 57 | |
michael@0 | 58 | // should be visible |
michael@0 | 59 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 60 | |
michael@0 | 61 | // selected text context: |
michael@0 | 62 | checkContextUIMenuItemVisibility(["context-copy", |
michael@0 | 63 | "context-search"]); |
michael@0 | 64 | |
michael@0 | 65 | let menuItem = document.getElementById("context-copy"); |
michael@0 | 66 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 67 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 68 | |
michael@0 | 69 | yield promise; |
michael@0 | 70 | |
michael@0 | 71 | // The wait is needed to give time to populate the clipboard. |
michael@0 | 72 | let string = ""; |
michael@0 | 73 | yield waitForCondition(function () { |
michael@0 | 74 | string = SpecialPowers.getClipboardData("text/unicode"); |
michael@0 | 75 | return string === span.textContent; |
michael@0 | 76 | }); |
michael@0 | 77 | ok(string === span.textContent, "copied selected text from span"); |
michael@0 | 78 | |
michael@0 | 79 | win.getSelection().removeAllRanges(); |
michael@0 | 80 | |
michael@0 | 81 | //////////////////////////////////////////////////////////// |
michael@0 | 82 | // Context menu in content on selected text that includes a link |
michael@0 | 83 | |
michael@0 | 84 | // invoke selection with link context menu |
michael@0 | 85 | let link = win.document.getElementById("text2-link"); |
michael@0 | 86 | win.getSelection().selectAllChildren(link); |
michael@0 | 87 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 88 | sendContextMenuClickToElement(win, link); |
michael@0 | 89 | yield promise; |
michael@0 | 90 | |
michael@0 | 91 | // should be visible |
michael@0 | 92 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 93 | |
michael@0 | 94 | // selected text context: |
michael@0 | 95 | checkContextUIMenuItemVisibility(["context-copy", |
michael@0 | 96 | "context-search", |
michael@0 | 97 | "context-open-in-new-tab", |
michael@0 | 98 | "context-copy-link"]); |
michael@0 | 99 | |
michael@0 | 100 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 101 | win.scrollBy(0, 1); |
michael@0 | 102 | let hidden = yield promise; |
michael@0 | 103 | ok(hidden && !(hidden instanceof Error), "scrolling hides the context menu"); |
michael@0 | 104 | win.getSelection().removeAllRanges(); |
michael@0 | 105 | win.scrollBy(0, -1); |
michael@0 | 106 | |
michael@0 | 107 | //////////////////////////////////////////////////////////// |
michael@0 | 108 | // Context menu in content on a link |
michael@0 | 109 | |
michael@0 | 110 | link = win.document.getElementById("text2-link"); |
michael@0 | 111 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 112 | sendContextMenuClickToElement(win, link); |
michael@0 | 113 | yield promise; |
michael@0 | 114 | |
michael@0 | 115 | // should be visible |
michael@0 | 116 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 117 | |
michael@0 | 118 | // selected text context: |
michael@0 | 119 | checkContextUIMenuItemVisibility(["context-open-in-new-tab", |
michael@0 | 120 | "context-copy-link", |
michael@0 | 121 | "context-bookmark-link"]); |
michael@0 | 122 | |
michael@0 | 123 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 124 | ContextMenuUI.hide(); |
michael@0 | 125 | yield promise; |
michael@0 | 126 | |
michael@0 | 127 | //////////////////////////////////////////////////////////// |
michael@0 | 128 | // context in input with no selection, no data on clipboard |
michael@0 | 129 | |
michael@0 | 130 | emptyClipboard(); |
michael@0 | 131 | |
michael@0 | 132 | let input = win.document.getElementById("text3-input"); |
michael@0 | 133 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 134 | sendContextMenuClickToElement(win, input); |
michael@0 | 135 | yield promise; |
michael@0 | 136 | |
michael@0 | 137 | // should be visible |
michael@0 | 138 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 139 | |
michael@0 | 140 | checkContextUIMenuItemVisibility(["context-select", |
michael@0 | 141 | "context-select-all"]); |
michael@0 | 142 | |
michael@0 | 143 | // copy menu item should not exist when no text is selected |
michael@0 | 144 | let menuItem = document.getElementById("context-copy"); |
michael@0 | 145 | ok(menuItem && menuItem.hidden, "menu item is not visible"); |
michael@0 | 146 | |
michael@0 | 147 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 148 | ContextMenuUI.hide(); |
michael@0 | 149 | yield promise; |
michael@0 | 150 | |
michael@0 | 151 | //////////////////////////////////////////////////////////// |
michael@0 | 152 | // context in input with selection copied to clipboard |
michael@0 | 153 | |
michael@0 | 154 | let input = win.document.getElementById("text3-input"); |
michael@0 | 155 | input.value = "hello, I'm sorry but I must be going."; |
michael@0 | 156 | input.setSelectionRange(0, 5); |
michael@0 | 157 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 158 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 159 | yield promise; |
michael@0 | 160 | |
michael@0 | 161 | // should be visible |
michael@0 | 162 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 163 | |
michael@0 | 164 | checkContextUIMenuItemVisibility(["context-cut", |
michael@0 | 165 | "context-copy"]); |
michael@0 | 166 | |
michael@0 | 167 | let menuItem = document.getElementById("context-copy"); |
michael@0 | 168 | let popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 169 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 170 | |
michael@0 | 171 | yield popupPromise; |
michael@0 | 172 | |
michael@0 | 173 | // The wait is needed to give time to populate the clipboard. |
michael@0 | 174 | let string = ""; |
michael@0 | 175 | yield waitForCondition(function () { |
michael@0 | 176 | string = SpecialPowers.getClipboardData("text/unicode"); |
michael@0 | 177 | return string === "hello"; |
michael@0 | 178 | }); |
michael@0 | 179 | |
michael@0 | 180 | ok(string === "hello", "copied selected text"); |
michael@0 | 181 | |
michael@0 | 182 | emptyClipboard(); |
michael@0 | 183 | |
michael@0 | 184 | //////////////////////////////////////////////////////////// |
michael@0 | 185 | // context in input with text selection, no data on clipboard |
michael@0 | 186 | |
michael@0 | 187 | input = win.document.getElementById("text3-input"); |
michael@0 | 188 | input.select(); |
michael@0 | 189 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 190 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 191 | yield promise; |
michael@0 | 192 | |
michael@0 | 193 | // should be visible |
michael@0 | 194 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 195 | |
michael@0 | 196 | // selected text context: |
michael@0 | 197 | checkContextUIMenuItemVisibility(["context-cut", |
michael@0 | 198 | "context-copy"]); |
michael@0 | 199 | |
michael@0 | 200 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 201 | ContextMenuUI.hide(); |
michael@0 | 202 | yield promise; |
michael@0 | 203 | |
michael@0 | 204 | //////////////////////////////////////////////////////////// |
michael@0 | 205 | // context in input with no selection, data on clipboard |
michael@0 | 206 | |
michael@0 | 207 | SpecialPowers.clipboardCopyString("foo"); |
michael@0 | 208 | input = win.document.getElementById("text3-input"); |
michael@0 | 209 | input.select(); |
michael@0 | 210 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 211 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 212 | yield promise; |
michael@0 | 213 | |
michael@0 | 214 | // should be visible |
michael@0 | 215 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 216 | |
michael@0 | 217 | // selected text context: |
michael@0 | 218 | checkContextUIMenuItemVisibility(["context-cut", |
michael@0 | 219 | "context-copy", |
michael@0 | 220 | "context-paste"]); |
michael@0 | 221 | |
michael@0 | 222 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 223 | ContextMenuUI.hide(); |
michael@0 | 224 | yield promise; |
michael@0 | 225 | |
michael@0 | 226 | //////////////////////////////////////////////////////////// |
michael@0 | 227 | // context in input with selection cut to clipboard |
michael@0 | 228 | |
michael@0 | 229 | emptyClipboard(); |
michael@0 | 230 | |
michael@0 | 231 | let input = win.document.getElementById("text3-input"); |
michael@0 | 232 | input.value = "hello, I'm sorry but I must be going."; |
michael@0 | 233 | input.setSelectionRange(0, 5); |
michael@0 | 234 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 235 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 236 | yield promise; |
michael@0 | 237 | |
michael@0 | 238 | // should be visible |
michael@0 | 239 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 240 | |
michael@0 | 241 | checkContextUIMenuItemVisibility(["context-cut", |
michael@0 | 242 | "context-copy"]); |
michael@0 | 243 | |
michael@0 | 244 | let menuItem = document.getElementById("context-cut"); |
michael@0 | 245 | let popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 246 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 247 | |
michael@0 | 248 | yield popupPromise; |
michael@0 | 249 | |
michael@0 | 250 | // The wait is needed to give time to populate the clipboard. |
michael@0 | 251 | let string = ""; |
michael@0 | 252 | yield waitForCondition(function () { |
michael@0 | 253 | string = SpecialPowers.getClipboardData("text/unicode"); |
michael@0 | 254 | return string === "hello"; |
michael@0 | 255 | }); |
michael@0 | 256 | |
michael@0 | 257 | let inputValue = input.value; |
michael@0 | 258 | ok(string === "hello", "cut selected text in clipboard"); |
michael@0 | 259 | ok(inputValue === ", I'm sorry but I must be going.", "cut selected text from input value"); |
michael@0 | 260 | |
michael@0 | 261 | emptyClipboard(); |
michael@0 | 262 | |
michael@0 | 263 | //////////////////////////////////////////////////////////// |
michael@0 | 264 | // context in empty input, data on clipboard (paste operation) |
michael@0 | 265 | |
michael@0 | 266 | SpecialPowers.clipboardCopyString("foo"); |
michael@0 | 267 | input = win.document.getElementById("text3-input"); |
michael@0 | 268 | input.value = ""; |
michael@0 | 269 | |
michael@0 | 270 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 271 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 272 | yield promise; |
michael@0 | 273 | |
michael@0 | 274 | // should be visible |
michael@0 | 275 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 276 | |
michael@0 | 277 | // selected text context: |
michael@0 | 278 | checkContextUIMenuItemVisibility(["context-paste"]); |
michael@0 | 279 | |
michael@0 | 280 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 281 | ContextMenuUI.hide(); |
michael@0 | 282 | yield promise; |
michael@0 | 283 | |
michael@0 | 284 | //////////////////////////////////////////////////////////// |
michael@0 | 285 | // context in empty input, no data on clipboard (??) |
michael@0 | 286 | |
michael@0 | 287 | emptyClipboard(); |
michael@0 | 288 | ContextUI.dismiss(); |
michael@0 | 289 | |
michael@0 | 290 | input = win.document.getElementById("text3-input"); |
michael@0 | 291 | input.value = ""; |
michael@0 | 292 | |
michael@0 | 293 | promise = waitForEvent(Elements.tray, "transitionend"); |
michael@0 | 294 | sendContextMenuClickToElement(win, input, 20); |
michael@0 | 295 | yield promise; |
michael@0 | 296 | |
michael@0 | 297 | // should *not* be visible |
michael@0 | 298 | ok(!ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 299 | |
michael@0 | 300 | // the test above will invoke the app bar |
michael@0 | 301 | yield hideContextUI(); |
michael@0 | 302 | |
michael@0 | 303 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 304 | purgeEventQueue(); |
michael@0 | 305 | } |
michael@0 | 306 | }); |
michael@0 | 307 | |
michael@0 | 308 | gTests.push({ |
michael@0 | 309 | desc: "checks for context menu positioning when browser shifts", |
michael@0 | 310 | run: function test() { |
michael@0 | 311 | info(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 312 | yield addTab(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 313 | |
michael@0 | 314 | purgeEventQueue(); |
michael@0 | 315 | emptyClipboard(); |
michael@0 | 316 | |
michael@0 | 317 | let browserwin = Browser.selectedTab.browser.contentWindow; |
michael@0 | 318 | |
michael@0 | 319 | yield hideContextUI(); |
michael@0 | 320 | |
michael@0 | 321 | //////////////////////////////////////////////////////////// |
michael@0 | 322 | // test for proper context menu positioning when the browser |
michael@0 | 323 | // is offset by a notification box. |
michael@0 | 324 | |
michael@0 | 325 | yield showNotification(); |
michael@0 | 326 | |
michael@0 | 327 | // select some text |
michael@0 | 328 | let span = browserwin.document.getElementById("text4"); |
michael@0 | 329 | browserwin.getSelection().selectAllChildren(span); |
michael@0 | 330 | |
michael@0 | 331 | // invoke selection context menu |
michael@0 | 332 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 333 | sendContextMenuClickToElement(browserwin, span); |
michael@0 | 334 | yield promise; |
michael@0 | 335 | |
michael@0 | 336 | // should be visible and at a specific position |
michael@0 | 337 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 338 | |
michael@0 | 339 | let notificationBox = Browser.getNotificationBox(); |
michael@0 | 340 | let notification = notificationBox.getNotificationWithValue("popup-blocked"); |
michael@0 | 341 | let notificationHeight = notification.boxObject.height; |
michael@0 | 342 | |
michael@0 | 343 | checkContextMenuPositionRange(ContextMenuUI._panel, 0, 15, 220, 230); |
michael@0 | 344 | |
michael@0 | 345 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 346 | ContextMenuUI.hide(); |
michael@0 | 347 | yield promise; |
michael@0 | 348 | |
michael@0 | 349 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 350 | } |
michael@0 | 351 | }); |
michael@0 | 352 | |
michael@0 | 353 | /* |
michael@0 | 354 | XXX code used to diagnose bug 880739 |
michael@0 | 355 | |
michael@0 | 356 | var observeLogger = { |
michael@0 | 357 | observe: function (aSubject, aTopic, aData) { |
michael@0 | 358 | info("observeLogger: " + aTopic); |
michael@0 | 359 | }, |
michael@0 | 360 | QueryInterface: function (aIID) { |
michael@0 | 361 | if (!aIID.equals(Ci.nsIObserver) && |
michael@0 | 362 | !aIID.equals(Ci.nsISupportsWeakReference) && |
michael@0 | 363 | !aIID.equals(Ci.nsISupports)) { |
michael@0 | 364 | throw Components.results.NS_ERROR_NO_INTERFACE; |
michael@0 | 365 | } |
michael@0 | 366 | return this; |
michael@0 | 367 | }, |
michael@0 | 368 | init: function init() { |
michael@0 | 369 | Services.obs.addObserver(observeLogger, "dl-start", true); |
michael@0 | 370 | Services.obs.addObserver(observeLogger, "dl-done", true); |
michael@0 | 371 | Services.obs.addObserver(observeLogger, "dl-failed", true); |
michael@0 | 372 | Services.obs.addObserver(observeLogger, "dl-scanning", true); |
michael@0 | 373 | Services.obs.addObserver(observeLogger, "dl-blocked", true); |
michael@0 | 374 | Services.obs.addObserver(observeLogger, "dl-dirty", true); |
michael@0 | 375 | Services.obs.addObserver(observeLogger, "dl-cancel", true); |
michael@0 | 376 | }, |
michael@0 | 377 | shutdown: function shutdown() { |
michael@0 | 378 | Services.obs.removeObserver(observeLogger, "dl-start"); |
michael@0 | 379 | Services.obs.removeObserver(observeLogger, "dl-done"); |
michael@0 | 380 | Services.obs.removeObserver(observeLogger, "dl-failed"); |
michael@0 | 381 | Services.obs.removeObserver(observeLogger, "dl-scanning"); |
michael@0 | 382 | Services.obs.removeObserver(observeLogger, "dl-blocked"); |
michael@0 | 383 | Services.obs.removeObserver(observeLogger, "dl-dirty"); |
michael@0 | 384 | Services.obs.removeObserver(observeLogger, "dl-cancel"); |
michael@0 | 385 | } |
michael@0 | 386 | } |
michael@0 | 387 | */ |
michael@0 | 388 | |
michael@0 | 389 | // Image context menu tests |
michael@0 | 390 | gTests.push({ |
michael@0 | 391 | desc: "image context menu", |
michael@0 | 392 | setUp: function() { |
michael@0 | 393 | // XXX code used to diagnose bug 880739 |
michael@0 | 394 | //observeLogger.init(); |
michael@0 | 395 | }, |
michael@0 | 396 | tearDown: function() { |
michael@0 | 397 | // XXX code used to diagnose bug 880739 |
michael@0 | 398 | //observeLogger.shutdown(); |
michael@0 | 399 | }, |
michael@0 | 400 | run: function test() { |
michael@0 | 401 | info(chromeRoot + "browser_context_menu_tests_01.html"); |
michael@0 | 402 | yield addTab(chromeRoot + "browser_context_menu_tests_01.html"); |
michael@0 | 403 | |
michael@0 | 404 | let win = Browser.selectedTab.browser.contentWindow; |
michael@0 | 405 | |
michael@0 | 406 | purgeEventQueue(); |
michael@0 | 407 | |
michael@0 | 408 | yield hideContextUI(); |
michael@0 | 409 | |
michael@0 | 410 | // If we don't do this, sometimes the first sendContextMenuClickToWindow |
michael@0 | 411 | // will trigger the app bar. |
michael@0 | 412 | yield waitForImageLoad(win, "image01"); |
michael@0 | 413 | |
michael@0 | 414 | //////////////////////////////////////////////////////////// |
michael@0 | 415 | // Context menu options |
michael@0 | 416 | /* |
michael@0 | 417 | XXX disabled temporarily due to bug 880739 |
michael@0 | 418 | |
michael@0 | 419 | // image01 - 1x1x100x100 |
michael@0 | 420 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 421 | sendContextMenuClickToWindow(win, 10, 10); |
michael@0 | 422 | yield promise; |
michael@0 | 423 | |
michael@0 | 424 | purgeEventQueue(); |
michael@0 | 425 | |
michael@0 | 426 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 427 | |
michael@0 | 428 | checkContextUIMenuItemVisibility(["context-save-image-lib", |
michael@0 | 429 | "context-copy-image", |
michael@0 | 430 | "context-copy-image-loc", |
michael@0 | 431 | "context-open-image-tab"]); |
michael@0 | 432 | |
michael@0 | 433 | //////////////////////////////////////////////////////////// |
michael@0 | 434 | // Save to image library |
michael@0 | 435 | |
michael@0 | 436 | let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 437 | .getService(Components.interfaces.nsIProperties); |
michael@0 | 438 | let saveLocationPath = dirSvc.get("Pict", Components.interfaces.nsIFile); |
michael@0 | 439 | saveLocationPath.append("image01.png"); |
michael@0 | 440 | |
michael@0 | 441 | registerCleanupFunction(function () { |
michael@0 | 442 | saveLocationPath.remove(false); |
michael@0 | 443 | }); |
michael@0 | 444 | |
michael@0 | 445 | if (saveLocationPath.exists()) { |
michael@0 | 446 | info("had to remove old image!"); |
michael@0 | 447 | saveLocationPath.remove(false); |
michael@0 | 448 | } |
michael@0 | 449 | |
michael@0 | 450 | let menuItem = document.getElementById("context-save-image-lib"); |
michael@0 | 451 | ok(menuItem, "menu item exists"); |
michael@0 | 452 | ok(!menuItem.hidden, "menu item visible"); |
michael@0 | 453 | |
michael@0 | 454 | // dl-start, dl-failed, dl-scanning, dl-blocked, dl-dirty, dl-cancel |
michael@0 | 455 | let downloadPromise = waitForObserver("dl-done", 10000); |
michael@0 | 456 | |
michael@0 | 457 | let popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 458 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 459 | yield popupPromise; |
michael@0 | 460 | yield downloadPromise; |
michael@0 | 461 | |
michael@0 | 462 | purgeEventQueue(); |
michael@0 | 463 | |
michael@0 | 464 | ok(saveLocationPath.exists(), "image saved"); |
michael@0 | 465 | */ |
michael@0 | 466 | //////////////////////////////////////////////////////////// |
michael@0 | 467 | // Copy image |
michael@0 | 468 | |
michael@0 | 469 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 470 | sendContextMenuClickToWindow(win, 20, 20); |
michael@0 | 471 | yield promise; |
michael@0 | 472 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 473 | |
michael@0 | 474 | let menuItem = document.getElementById("context-copy-image"); |
michael@0 | 475 | ok(menuItem, "menu item exists"); |
michael@0 | 476 | ok(!menuItem.hidden, "menu item visible"); |
michael@0 | 477 | let popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 478 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 479 | yield popupPromise; |
michael@0 | 480 | |
michael@0 | 481 | purgeEventQueue(); |
michael@0 | 482 | |
michael@0 | 483 | let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); |
michael@0 | 484 | let flavors = ["image/png"]; |
michael@0 | 485 | ok(clip.hasDataMatchingFlavors(flavors, flavors.length, Ci.nsIClipboard.kGlobalClipboard), "clip has my png flavor"); |
michael@0 | 486 | |
michael@0 | 487 | //////////////////////////////////////////////////////////// |
michael@0 | 488 | // Copy image location |
michael@0 | 489 | |
michael@0 | 490 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 491 | sendContextMenuClickToWindow(win, 30, 30); |
michael@0 | 492 | yield promise; |
michael@0 | 493 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 494 | |
michael@0 | 495 | menuItem = document.getElementById("context-copy-image-loc"); |
michael@0 | 496 | ok(menuItem, "menu item exists"); |
michael@0 | 497 | ok(!menuItem.hidden, "menu item visible"); |
michael@0 | 498 | popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 499 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 500 | yield popupPromise; |
michael@0 | 501 | |
michael@0 | 502 | purgeEventQueue(); |
michael@0 | 503 | |
michael@0 | 504 | let clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard); |
michael@0 | 505 | let flavors = ["text/unicode"]; |
michael@0 | 506 | ok(clip.hasDataMatchingFlavors(flavors, flavors.length, Ci.nsIClipboard.kGlobalClipboard), "clip has my text flavor"); |
michael@0 | 507 | |
michael@0 | 508 | let xfer = Cc["@mozilla.org/widget/transferable;1"]. |
michael@0 | 509 | createInstance(Ci.nsITransferable); |
michael@0 | 510 | xfer.init(null); |
michael@0 | 511 | xfer.addDataFlavor("text/unicode"); |
michael@0 | 512 | clip.getData(xfer, Ci.nsIClipboard.kGlobalClipboard); |
michael@0 | 513 | let str = new Object(); |
michael@0 | 514 | let strLength = new Object(); |
michael@0 | 515 | xfer.getTransferData("text/unicode", str, strLength); |
michael@0 | 516 | str = str.value.QueryInterface(Components.interfaces.nsISupportsString); |
michael@0 | 517 | |
michael@0 | 518 | ok(str == chromeRoot + "res/image01.png", "url copied"); |
michael@0 | 519 | |
michael@0 | 520 | //////////////////////////////////////////////////////////// |
michael@0 | 521 | // Open image in new tab |
michael@0 | 522 | |
michael@0 | 523 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 524 | sendContextMenuClickToWindow(win, 40, 40); |
michael@0 | 525 | yield promise; |
michael@0 | 526 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 527 | |
michael@0 | 528 | menuItem = document.getElementById("context-open-image-tab"); |
michael@0 | 529 | ok(menuItem, "menu item exists"); |
michael@0 | 530 | ok(!menuItem.hidden, "menu item visible"); |
michael@0 | 531 | let tabPromise = waitForEvent(document, "TabOpen"); |
michael@0 | 532 | popupPromise = waitForEvent(document, "popuphidden"); |
michael@0 | 533 | EventUtils.synthesizeMouse(menuItem, 10, 10, {}, win); |
michael@0 | 534 | yield popupPromise; |
michael@0 | 535 | let event = yield tabPromise; |
michael@0 | 536 | |
michael@0 | 537 | purgeEventQueue(); |
michael@0 | 538 | |
michael@0 | 539 | let imagetab = Browser.getTabFromChrome(event.originalTarget); |
michael@0 | 540 | ok(imagetab != null, "tab created"); |
michael@0 | 541 | |
michael@0 | 542 | Browser.closeTab(imagetab, { forceClose: true }); |
michael@0 | 543 | } |
michael@0 | 544 | }); |
michael@0 | 545 | |
michael@0 | 546 | gTests.push({ |
michael@0 | 547 | desc: "tests for subframe positioning", |
michael@0 | 548 | run: function test() { |
michael@0 | 549 | info(chromeRoot + "browser_context_menu_tests_03.html"); |
michael@0 | 550 | yield addTab(chromeRoot + "browser_context_menu_tests_03.html"); |
michael@0 | 551 | |
michael@0 | 552 | let win = Browser.selectedTab.browser.contentWindow; |
michael@0 | 553 | |
michael@0 | 554 | // Sometimes the context ui is visible, sometimes it isn't. |
michael@0 | 555 | try { |
michael@0 | 556 | yield waitForCondition(function () { |
michael@0 | 557 | return ContextUI.isVisible; |
michael@0 | 558 | }, 500, 50); |
michael@0 | 559 | } catch (ex) {} |
michael@0 | 560 | |
michael@0 | 561 | ContextUI.dismiss(); |
michael@0 | 562 | |
michael@0 | 563 | let frame1 = win.document.getElementById("frame1"); |
michael@0 | 564 | let link1 = frame1.contentDocument.getElementById("link1"); |
michael@0 | 565 | |
michael@0 | 566 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 567 | sendContextMenuClickToElement(frame1.contentDocument.defaultView, link1, 85, 10); |
michael@0 | 568 | yield promise; |
michael@0 | 569 | |
michael@0 | 570 | // should be visible |
michael@0 | 571 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 572 | |
michael@0 | 573 | checkContextMenuPositionRange(ContextMenuUI._panel, 265, 280, 175, 190); |
michael@0 | 574 | |
michael@0 | 575 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 576 | ContextMenuUI.hide(); |
michael@0 | 577 | yield promise; |
michael@0 | 578 | |
michael@0 | 579 | frame1.contentDocument.defaultView.scrollBy(0, 200); |
michael@0 | 580 | |
michael@0 | 581 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 582 | sendContextMenuClickToElement(frame1.contentDocument.defaultView, link1, 85, 10); |
michael@0 | 583 | yield promise; |
michael@0 | 584 | |
michael@0 | 585 | // should be visible |
michael@0 | 586 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 587 | |
michael@0 | 588 | checkContextMenuPositionRange(ContextMenuUI._panel, 265, 280, 95, 110); |
michael@0 | 589 | |
michael@0 | 590 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 591 | ContextMenuUI.hide(); |
michael@0 | 592 | yield promise; |
michael@0 | 593 | |
michael@0 | 594 | let rlink1 = win.document.getElementById("rlink1"); |
michael@0 | 595 | |
michael@0 | 596 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 597 | sendContextMenuClickToElement(win, rlink1, 40, 10); |
michael@0 | 598 | yield promise; |
michael@0 | 599 | |
michael@0 | 600 | // should be visible |
michael@0 | 601 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 602 | |
michael@0 | 603 | checkContextMenuPositionRange(ContextMenuUI._panel, 295, 310, 540, 555); |
michael@0 | 604 | |
michael@0 | 605 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 606 | ContextMenuUI.hide(); |
michael@0 | 607 | yield promise; |
michael@0 | 608 | |
michael@0 | 609 | win.scrollBy(0, 200); |
michael@0 | 610 | |
michael@0 | 611 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 612 | sendContextMenuClickToElement(win, rlink1, 40, 10); |
michael@0 | 613 | yield promise; |
michael@0 | 614 | |
michael@0 | 615 | // should be visible |
michael@0 | 616 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 617 | |
michael@0 | 618 | checkContextMenuPositionRange(ContextMenuUI._panel, 295, 310, 340, 355); |
michael@0 | 619 | |
michael@0 | 620 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 621 | ContextMenuUI.hide(); |
michael@0 | 622 | yield promise; |
michael@0 | 623 | |
michael@0 | 624 | let link2 = frame1.contentDocument.getElementById("link2"); |
michael@0 | 625 | |
michael@0 | 626 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 627 | sendContextMenuClickToElement(frame1.contentDocument.defaultView, link2, 85, 10); |
michael@0 | 628 | yield promise; |
michael@0 | 629 | |
michael@0 | 630 | // should be visible |
michael@0 | 631 | ok(ContextMenuUI._menuPopup.visible, "is visible"); |
michael@0 | 632 | |
michael@0 | 633 | checkContextMenuPositionRange(ContextMenuUI._panel, 265, 280, 110, 125); |
michael@0 | 634 | |
michael@0 | 635 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 636 | ContextMenuUI.hide(); |
michael@0 | 637 | yield promise; |
michael@0 | 638 | |
michael@0 | 639 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 640 | } |
michael@0 | 641 | }); |
michael@0 | 642 | |
michael@0 | 643 | function reopenSetUp() { |
michael@0 | 644 | info(chromeRoot + "browser_context_menu_tests_04.html"); |
michael@0 | 645 | yield addTab(chromeRoot + "browser_context_menu_tests_04.html"); |
michael@0 | 646 | |
michael@0 | 647 | // Sometimes the context UI won't actually show up. |
michael@0 | 648 | // Since we're just normalizing, we don't want waitForCondition |
michael@0 | 649 | // to cause an orange, so we're putting a try/catch here. |
michael@0 | 650 | try { |
michael@0 | 651 | yield waitForCondition(() => ContextUI.isVisible); |
michael@0 | 652 | ContextUI.dismiss(); |
michael@0 | 653 | } catch(e) {} |
michael@0 | 654 | } |
michael@0 | 655 | |
michael@0 | 656 | function reopenTearDown() { |
michael@0 | 657 | let promise = waitForEvent(document, "popuphidden") |
michael@0 | 658 | ContextMenuUI.hide(); |
michael@0 | 659 | yield promise; |
michael@0 | 660 | ok(!ContextMenuUI._menuPopup.visible, "popup is actually hidden"); |
michael@0 | 661 | |
michael@0 | 662 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 663 | } |
michael@0 | 664 | |
michael@0 | 665 | function getReopenTest(aElementInputFn, aWindowInputFn) { |
michael@0 | 666 | return function () { |
michael@0 | 667 | let win = Browser.selectedTab.browser.contentWindow; |
michael@0 | 668 | let panel = ContextMenuUI._menuPopup._panel; |
michael@0 | 669 | |
michael@0 | 670 | let link1 = win.document.getElementById("text1-link"); |
michael@0 | 671 | let link2 = win.document.getElementById("text2-link"); |
michael@0 | 672 | |
michael@0 | 673 | // Show the menu on link 1 |
michael@0 | 674 | let showpromise = waitForEvent(panel, "popupshown"); |
michael@0 | 675 | aElementInputFn(win, link1); |
michael@0 | 676 | |
michael@0 | 677 | ok((yield showpromise), "popupshown event fired"); |
michael@0 | 678 | ok(ContextMenuUI._menuPopup.visible, "initial popup is visible"); |
michael@0 | 679 | |
michael@0 | 680 | // Show the menu on link 2 |
michael@0 | 681 | let hidepromise = waitForEvent(panel, "popuphidden"); |
michael@0 | 682 | showpromise = waitForEvent(panel, "popupshown"); |
michael@0 | 683 | aElementInputFn(win, link2); |
michael@0 | 684 | |
michael@0 | 685 | ok((yield hidepromise), "popuphidden event fired"); |
michael@0 | 686 | ok((yield showpromise), "popupshown event fired"); |
michael@0 | 687 | ok(ContextMenuUI._menuPopup.visible, "popup is still visible"); |
michael@0 | 688 | |
michael@0 | 689 | // Hide the menu |
michael@0 | 690 | hidepromise = waitForEvent(panel, "popuphidden") |
michael@0 | 691 | aWindowInputFn(win, 10, 10); |
michael@0 | 692 | |
michael@0 | 693 | ok((yield hidepromise), "popuphidden event fired"); |
michael@0 | 694 | ok(!ContextMenuUI._menuPopup.visible, "popup is no longer visible"); |
michael@0 | 695 | } |
michael@0 | 696 | } |
michael@0 | 697 | |
michael@0 | 698 | gTests.push({ |
michael@0 | 699 | desc: "bug 856264 - mouse - context menu should reopen on other links", |
michael@0 | 700 | setUp: reopenSetUp, |
michael@0 | 701 | tearDown: reopenTearDown, |
michael@0 | 702 | run: getReopenTest(sendContextMenuMouseClickToElement, sendMouseClick) |
michael@0 | 703 | }); |
michael@0 | 704 | |
michael@0 | 705 | gTests.push({ |
michael@0 | 706 | desc: "bug 856264 - touch - context menu should reopen on other links", |
michael@0 | 707 | setUp: reopenSetUp, |
michael@0 | 708 | tearDown: reopenTearDown, |
michael@0 | 709 | run: getReopenTest(sendContextMenuClickToElement, sendTap) |
michael@0 | 710 | }); |
michael@0 | 711 | |
michael@0 | 712 | gTests.push({ |
michael@0 | 713 | desc: "Bug 947505 - Right-click in a designMode document should display a " + |
michael@0 | 714 | "context menu", |
michael@0 | 715 | run: function test() { |
michael@0 | 716 | info(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 717 | yield addTab(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 718 | |
michael@0 | 719 | purgeEventQueue(); |
michael@0 | 720 | emptyClipboard(); |
michael@0 | 721 | ContextUI.dismiss(); |
michael@0 | 722 | |
michael@0 | 723 | yield waitForCondition(() => !ContextUI.navbarVisible); |
michael@0 | 724 | |
michael@0 | 725 | let tabWindow = Browser.selectedTab.browser.contentWindow; |
michael@0 | 726 | let testSpan = tabWindow.document.getElementById("text1"); |
michael@0 | 727 | |
michael@0 | 728 | // Case #1: Document isn't in design mode and nothing is selected. |
michael@0 | 729 | tabWindow.document.designMode = "off"; |
michael@0 | 730 | |
michael@0 | 731 | // Simulate right mouse click to reproduce the same step as noted in the |
michael@0 | 732 | // appropriate bug. It's valid for non-touch case only. |
michael@0 | 733 | synthesizeNativeMouseRDown(Browser.selectedTab.browser, 10, 10); |
michael@0 | 734 | synthesizeNativeMouseRUp(Browser.selectedTab.browser, 10, 10); |
michael@0 | 735 | |
michael@0 | 736 | yield waitForCondition(() => ContextUI.navbarVisible); |
michael@0 | 737 | |
michael@0 | 738 | ok(ContextUI.navbarVisible, "Navbar is visible on context menu action."); |
michael@0 | 739 | ok(ContextUI.tabbarVisible, "Tabbar is visible on context menu action."); |
michael@0 | 740 | |
michael@0 | 741 | ContextUI.dismiss(); |
michael@0 | 742 | yield waitForCondition(() => !ContextUI.navbarVisible); |
michael@0 | 743 | |
michael@0 | 744 | // Case #2: Document isn't in design mode and text is selected. |
michael@0 | 745 | tabWindow.getSelection().selectAllChildren(testSpan); |
michael@0 | 746 | |
michael@0 | 747 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 748 | sendContextMenuClickToSelection(tabWindow); |
michael@0 | 749 | yield promise; |
michael@0 | 750 | |
michael@0 | 751 | checkContextUIMenuItemVisibility(["context-copy", "context-search"]); |
michael@0 | 752 | |
michael@0 | 753 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 754 | ContextMenuUI.hide(); |
michael@0 | 755 | yield promise; |
michael@0 | 756 | |
michael@0 | 757 | // Case #3: Document is in design mode and nothing is selected. |
michael@0 | 758 | tabWindow.document.designMode = "on"; |
michael@0 | 759 | tabWindow.getSelection().removeAllRanges(); |
michael@0 | 760 | |
michael@0 | 761 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 762 | sendContextMenuClickToElement(tabWindow, testSpan); |
michael@0 | 763 | yield promise; |
michael@0 | 764 | |
michael@0 | 765 | checkContextUIMenuItemVisibility(["context-select-all", "context-select"]); |
michael@0 | 766 | |
michael@0 | 767 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 768 | ContextMenuUI.hide(); |
michael@0 | 769 | yield promise; |
michael@0 | 770 | |
michael@0 | 771 | // Case #4: Document is in design mode and text is selected. |
michael@0 | 772 | tabWindow.getSelection().selectAllChildren(testSpan); |
michael@0 | 773 | |
michael@0 | 774 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 775 | sendContextMenuClickToSelection(tabWindow); |
michael@0 | 776 | yield promise; |
michael@0 | 777 | |
michael@0 | 778 | checkContextUIMenuItemVisibility(["context-cut", "context-copy", |
michael@0 | 779 | "context-select-all", "context-select", |
michael@0 | 780 | "context-search"]); |
michael@0 | 781 | |
michael@0 | 782 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 783 | ContextMenuUI.hide(); |
michael@0 | 784 | yield promise; |
michael@0 | 785 | |
michael@0 | 786 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 787 | } |
michael@0 | 788 | }); |
michael@0 | 789 | |
michael@0 | 790 | gTests.push({ |
michael@0 | 791 | desc: "Bug 961702 - 'Copy' context menu action does not copy rich content " + |
michael@0 | 792 | "while document in design mode (or inside container that allows to " + |
michael@0 | 793 | "edit its content)", |
michael@0 | 794 | run: function test() { |
michael@0 | 795 | info(chromeRoot + "browser_context_menu_tests_05.html"); |
michael@0 | 796 | yield addTab(chromeRoot + "browser_context_menu_tests_05.html"); |
michael@0 | 797 | |
michael@0 | 798 | purgeEventQueue(); |
michael@0 | 799 | emptyClipboard(); |
michael@0 | 800 | ContextUI.dismiss(); |
michael@0 | 801 | |
michael@0 | 802 | yield waitForCondition(() => !ContextUI.navbarVisible); |
michael@0 | 803 | |
michael@0 | 804 | let tabWindow = Browser.selectedTab.browser.contentWindow; |
michael@0 | 805 | let testDiv = tabWindow.document.getElementById("div1"); |
michael@0 | 806 | |
michael@0 | 807 | // Case #1: Document is in design mode. |
michael@0 | 808 | tabWindow.document.designMode = "on"; |
michael@0 | 809 | |
michael@0 | 810 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 811 | sendContextMenuClickToElement(tabWindow, testDiv); |
michael@0 | 812 | yield promise; |
michael@0 | 813 | |
michael@0 | 814 | let selectAllMenuItem = document.getElementById("context-select-all"); |
michael@0 | 815 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 816 | sendNativeTap(selectAllMenuItem); |
michael@0 | 817 | yield promise; |
michael@0 | 818 | |
michael@0 | 819 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 820 | sendContextMenuClickToSelection(tabWindow); |
michael@0 | 821 | yield promise; |
michael@0 | 822 | |
michael@0 | 823 | let copyMenuItem = document.getElementById("context-copy"); |
michael@0 | 824 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 825 | sendNativeTap(copyMenuItem); |
michael@0 | 826 | yield promise; |
michael@0 | 827 | |
michael@0 | 828 | // The wait is needed to give time to populate the clipboard. |
michael@0 | 829 | let clipboardContent = ""; |
michael@0 | 830 | let contentToCopy = tabWindow.document.body.innerHTML; |
michael@0 | 831 | yield waitForCondition(function () { |
michael@0 | 832 | clipboardContent = SpecialPowers.getClipboardData("text/html"); |
michael@0 | 833 | return clipboardContent == contentToCopy; |
michael@0 | 834 | }); |
michael@0 | 835 | ok(clipboardContent == contentToCopy, "Rich content copied."); |
michael@0 | 836 | |
michael@0 | 837 | // Case #2: Container with editable content. |
michael@0 | 838 | emptyClipboard(); |
michael@0 | 839 | tabWindow.document.designMode = "off"; |
michael@0 | 840 | tabWindow.getSelection().removeAllRanges(); |
michael@0 | 841 | |
michael@0 | 842 | promise = waitForEvent(tabWindow.document.body, "focus"); |
michael@0 | 843 | sendNativeTap(testDiv); |
michael@0 | 844 | yield promise; |
michael@0 | 845 | |
michael@0 | 846 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 847 | sendContextMenuClickToElement(tabWindow, testDiv); |
michael@0 | 848 | yield promise; |
michael@0 | 849 | |
michael@0 | 850 | selectAllMenuItem = document.getElementById("context-select-all"); |
michael@0 | 851 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 852 | sendNativeTap(selectAllMenuItem); |
michael@0 | 853 | yield promise; |
michael@0 | 854 | |
michael@0 | 855 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 856 | sendContextMenuClickToSelection(tabWindow); |
michael@0 | 857 | yield promise; |
michael@0 | 858 | |
michael@0 | 859 | copyMenuItem = document.getElementById("context-copy"); |
michael@0 | 860 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 861 | sendNativeTap(copyMenuItem); |
michael@0 | 862 | yield promise; |
michael@0 | 863 | |
michael@0 | 864 | // The wait is needed to give time to populate the clipboard. |
michael@0 | 865 | clipboardContent = ""; |
michael@0 | 866 | contentToCopy = testDiv.innerHTML; |
michael@0 | 867 | yield waitForCondition(function () { |
michael@0 | 868 | clipboardContent = SpecialPowers.getClipboardData("text/html"); |
michael@0 | 869 | return clipboardContent == contentToCopy; |
michael@0 | 870 | }); |
michael@0 | 871 | ok(clipboardContent == contentToCopy, "Rich content copied."); |
michael@0 | 872 | |
michael@0 | 873 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 874 | } |
michael@0 | 875 | }); |
michael@0 | 876 | |
michael@0 | 877 | gTests.push({ |
michael@0 | 878 | desc: "Bug 963067 - 'Cut' in the cut, copy, paste menu is always active " + |
michael@0 | 879 | "after a browser launch.", |
michael@0 | 880 | run: function test() { |
michael@0 | 881 | info(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 882 | yield addTab(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 883 | |
michael@0 | 884 | purgeEventQueue(); |
michael@0 | 885 | emptyClipboard(); |
michael@0 | 886 | |
michael@0 | 887 | ContextUI.dismiss(); |
michael@0 | 888 | yield waitForCondition(() => !ContextUI.navbarVisible); |
michael@0 | 889 | |
michael@0 | 890 | let tabWindow = Browser.selectedTab.browser.contentWindow; |
michael@0 | 891 | let input = tabWindow.document.getElementById("text3-input"); |
michael@0 | 892 | let cutMenuItem = document.getElementById("context-cut"); |
michael@0 | 893 | |
michael@0 | 894 | input.select(); |
michael@0 | 895 | |
michael@0 | 896 | // Emulate RichListBox's behavior and set first item selected by default. |
michael@0 | 897 | cutMenuItem.selected = true; |
michael@0 | 898 | |
michael@0 | 899 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 900 | sendContextMenuClickToElement(tabWindow, input); |
michael@0 | 901 | yield promise; |
michael@0 | 902 | |
michael@0 | 903 | ok(!cutMenuItem.hidden && !cutMenuItem.selected, |
michael@0 | 904 | "Cut menu item is visible and not selected."); |
michael@0 | 905 | |
michael@0 | 906 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 907 | ContextMenuUI.hide(); |
michael@0 | 908 | yield promise; |
michael@0 | 909 | |
michael@0 | 910 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 911 | } |
michael@0 | 912 | }); |
michael@0 | 913 | |
michael@0 | 914 | gTests.push({ |
michael@0 | 915 | desc: "Bug 867499 - Selecting 'copy' from context menu for selected text " + |
michael@0 | 916 | "dismisses selection.", |
michael@0 | 917 | run: function test() { |
michael@0 | 918 | info(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 919 | yield addTab(chromeRoot + "browser_context_menu_tests_02.html"); |
michael@0 | 920 | |
michael@0 | 921 | emptyClipboard(); |
michael@0 | 922 | ContextUI.dismiss(); |
michael@0 | 923 | |
michael@0 | 924 | yield waitForCondition(() => !ContextUI.navbarVisible); |
michael@0 | 925 | |
michael@0 | 926 | let tabWindow = Browser.selectedTab.browser.contentWindow; |
michael@0 | 927 | let testSpan = tabWindow.document.getElementById("text1"); |
michael@0 | 928 | |
michael@0 | 929 | let promise = waitForEvent(document, "popupshown"); |
michael@0 | 930 | sendContextMenuClickToElement(tabWindow, testSpan, 5, 5); |
michael@0 | 931 | yield promise; |
michael@0 | 932 | |
michael@0 | 933 | yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible); |
michael@0 | 934 | |
michael@0 | 935 | promise = waitForEvent(document, "popupshown"); |
michael@0 | 936 | sendContextMenuClickToSelection(tabWindow); |
michael@0 | 937 | yield promise; |
michael@0 | 938 | |
michael@0 | 939 | let copyMenuItem = document.getElementById("context-copy"); |
michael@0 | 940 | |
michael@0 | 941 | ok(!copyMenuItem.hidden, "Copy menu item should be visible."); |
michael@0 | 942 | |
michael@0 | 943 | promise = waitForEvent(document, "popuphidden"); |
michael@0 | 944 | sendNativeTap(copyMenuItem, 5, 5); |
michael@0 | 945 | yield promise; |
michael@0 | 946 | yield waitForCondition(() => |
michael@0 | 947 | !!SpecialPowers.getClipboardData("text/unicode")); |
michael@0 | 948 | |
michael@0 | 949 | ok(SelectionHelperUI.isSelectionUIVisible, |
michael@0 | 950 | "Selection monocles should stay active after copy action."); |
michael@0 | 951 | |
michael@0 | 952 | Browser.closeTab(Browser.selectedTab, { forceClose: true }); |
michael@0 | 953 | } |
michael@0 | 954 | }); |
michael@0 | 955 | |
michael@0 | 956 | function test() { |
michael@0 | 957 | setDevPixelEqualToPx(); |
michael@0 | 958 | runTests(); |
michael@0 | 959 | } |