toolkit/content/tests/chrome/window_browser_drop.xul

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:99d29e739e05
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3
4 <window title="Browser Drop Tests"
5 onload="loaded()"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
7
8 <script type="application/javascript"
9 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript"
11 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12 <script type="application/javascript"
13 src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"/>
14
15 <script>
16 <![CDATA[
17
18 var link = null, name = null;
19 function handleLink(event, uri, linkname) { link = uri; name = linkname; }
20
21 function runTest()
22 {
23 function expectLink(element, expectedLink, expectedName, data, testid)
24 {
25 link = "";
26 name = "";
27 synthesizeDrop(element, element, data, "", element.ownerDocument.defaultView);
28
29 is(link, expectedLink, testid + " link");
30 is(name, expectedName, testid + " name");
31 }
32
33 ["chrome", "content"].forEach(function (type) {
34 var child = document.getElementById(type + "child");
35 child.droppedLinkHandler = handleLink;
36
37 expectLink(child, "http://www.mozilla.org", "http://www.mozilla.org",
38 [ [ { type: "text/plain", data: "http://www.mozilla.org" } ] ],
39 "text/plain drop on browser " + type);
40 expectLink(child, "", "",
41 [ [ { type: "text/link", data: "http://www.mozilla.org" } ] ],
42 "text/link drop on browser " + type);
43 expectLink(child, "http://www.example.com", "http://www.example.com",
44 [ [ { type: "text/uri-list", data: "http://www.example.com\nhttp://www.mozilla.org" } ] ],
45 "text/uri-list drop on browser " + type);
46 expectLink(child, "http://www.example.com", "Example.com",
47 [ [ { type: "text/x-moz-url", data: "http://www.example.com\nExample.com" } ] ],
48 "text/x-moz-url drop on browser " + type);
49 // dropping a chrome url should fail as we don't have a source node set,
50 // defaulting to a source of file:///
51 expectLink(child, "", "",
52 [ [ { type: "text/x-moz-url", data: "chrome://browser/content/browser.xul" } ] ],
53 "text/x-moz-url chrome url drop on browser " + type);
54 });
55
56 // stopPropagation should not prevent the browser link handling from occuring
57 frames[1].wrappedJSObject.stopMode = true;
58 var body = document.getElementById("contentchild").contentDocument.body;
59 expectLink(body, "http://www.mozilla.org", "http://www.mozilla.org",
60 [ [ { type: "text/uri-list", data: "http://www.mozilla.org" } ] ],
61 "text/x-moz-url drop on browser with stopPropagation drop event");
62
63 // canceling the event, however, should prevent the link from being handled
64 frames[1].wrappedJSObject.cancelMode = true;
65 expectLink(body, "", "",
66 [ [ { type: "text/uri-list", data: "http://www.example.org" } ] ],
67 "text/x-moz-url drop on browser with cancelled drop event");
68
69 window.close();
70 window.opener.wrappedJSObject.SimpleTest.finish();
71 }
72
73 function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
74 function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
75
76 function loaded()
77 {
78 SimpleTest.waitForFocus(runTest);
79 }
80
81 ]]>
82 </script>
83
84 <browser id="chromechild" src="about:blank"/>
85 <browser id="contentchild" type="content" width="100" height="100"
86 src="data:text/html,&lt;html draggable='true'&gt;&lt;body draggable='true' style='width: 100px; height: 100px;' ondragover='event.preventDefault()' ondrop='if (window.stopMode) event.stopPropagation(); if (window.cancelMode) event.preventDefault();'&gt;&lt;/body&gt;&lt;/html&gt;"/>
87
88 </window>

mercurial