/toolkit/content/tests/chrome/window_browser_drop.xul

http://github.com/zpao/v8monkey · Unknown · 88 lines · 72 code · 16 blank · 0 comment · 0 complexity · 392640a4d8c418209468779e9de03d6e MD5 · raw file

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