summaryrefslogtreecommitdiffstats
path: root/dom/events/test/browser_dragimage.js
blob: 503c0ac4491c8d27736c4a3b28faad047521a941 (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
const TEST_URI = "dragimage.html";

// This test checks that dragging an image onto the same document
// does not drop it, even when the page cancels the dragover event.
add_task(async function dragimage_remote_tab() {
  var tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    "http://www.example.com/browser/dom/events/test/" + TEST_URI
  );

  let dropHappened = false;
  let oldHandler = tab.linkedBrowser.droppedLinkHandler;
  tab.linkedBrowser.droppedLinkHandler = () => {
    dropHappened = true;
  };

  await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
    let image = content.document.body.firstElementChild;
    let target = content.document.body.lastElementChild;

    await EventUtils.synthesizePlainDragAndDrop({
      srcElement: image,
      destElement: target,
      srcWindow: content,
      destWindow: content,
      id: content.windowUtils.DEFAULT_MOUSE_POINTER_ID,
    });
  });

  tab.linkedBrowser.droppedLinkHandler = oldHandler;

  ok(!dropHappened, "drop did not occur");

  BrowserTestUtils.removeTab(tab);
});

// This test checks the same but with an in-process page.
add_task(async function dragimage_local_tab() {
  var tab = await BrowserTestUtils.openNewForegroundTab(
    gBrowser,
    getRootDirectory(gTestPath) + TEST_URI
  );

  let dropHappened = false;
  let oldHandler = tab.linkedBrowser.droppedLinkHandler;
  tab.linkedBrowser.droppedLinkHandler = () => {
    dropHappened = true;
  };

  let image = tab.linkedBrowser.contentDocument.body.firstElementChild;
  let target = tab.linkedBrowser.contentDocument.body.lastElementChild;

  await EventUtils.synthesizePlainDragAndDrop({
    srcElement: image,
    destElement: target,
    srcWindow: tab.linkedBrowser.contentWindow,
    destWindow: tab.linkedBrowser.contentWindow,
  });

  tab.linkedBrowser.droppedLinkHandler = oldHandler;

  ok(!dropHappened, "drop did not occur");

  BrowserTestUtils.removeTab(tab);
});