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 | <?xml version="1.0"?> |
michael@0 | 2 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 5 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 6 | type="text/css"?> |
michael@0 | 7 | <window title="Test ChromeUtils functions" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
michael@0 | 11 | <!-- ChromeUtils.js depends on EventUtils.js --> |
michael@0 | 12 | <script type="application/javascript" |
michael@0 | 13 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
michael@0 | 14 | <script type="text/javascript"> |
michael@0 | 15 | var start = new Date(); |
michael@0 | 16 | </script> |
michael@0 | 17 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> |
michael@0 | 18 | <script type="text/javascript"> |
michael@0 | 19 | var loadTime = new Date(); |
michael@0 | 20 | </script> |
michael@0 | 21 | <script type="application/javascript"> |
michael@0 | 22 | <![CDATA[ |
michael@0 | 23 | info("\nProfile::ChromeUtilsLoadTime: " + (loadTime - start) + "\n"); |
michael@0 | 24 | var testFile = Components.classes["@mozilla.org/file/directory_service;1"]. |
michael@0 | 25 | getService(Components.interfaces.nsIProperties). |
michael@0 | 26 | get("CurWorkD", Components.interfaces.nsIFile); |
michael@0 | 27 | var regularDtForDrag1 = null; |
michael@0 | 28 | var gSetDropEffect = true; |
michael@0 | 29 | var gData; |
michael@0 | 30 | var gEnter = false; |
michael@0 | 31 | var gOver = false; |
michael@0 | 32 | var dragDrop = [[ |
michael@0 | 33 | { type : "text/plain", |
michael@0 | 34 | data : "This is a test" } |
michael@0 | 35 | ]]; |
michael@0 | 36 | // this is the expected data arrays |
michael@0 | 37 | // for testing drag of 2 items create 2 inner arrays |
michael@0 | 38 | var drag1 = [[ |
michael@0 | 39 | { type : "text/uri-list", |
michael@0 | 40 | data : "http://www.mozilla.org/" } |
michael@0 | 41 | ]]; |
michael@0 | 42 | var drag2items = [[ |
michael@0 | 43 | { type : "text/uri-list", |
michael@0 | 44 | data : "http://www.mozilla.org/" } |
michael@0 | 45 | ],[ |
michael@0 | 46 | { type : "text/uri-list", |
michael@0 | 47 | data : "http://www.mozilla.org/" } |
michael@0 | 48 | ]]; |
michael@0 | 49 | var drag1WrongFlavor = [[ |
michael@0 | 50 | { type : "text/plain", |
michael@0 | 51 | data : "this is text/plain" } |
michael@0 | 52 | ]]; |
michael@0 | 53 | var drag2 = [[ |
michael@0 | 54 | { type : "text/plain", |
michael@0 | 55 | data : "this is text/plain" }, |
michael@0 | 56 | { type : "text/uri-list", |
michael@0 | 57 | data : "http://www.mozilla.org/" } |
michael@0 | 58 | ]]; |
michael@0 | 59 | var drag2WrongOrder = [[ |
michael@0 | 60 | { type : "text/uri-list", |
michael@0 | 61 | data : "http://www.mozilla.org/" }, |
michael@0 | 62 | { type : "text/plain", |
michael@0 | 63 | data : "this is text/plain" } |
michael@0 | 64 | ]]; |
michael@0 | 65 | var dragfile = [[ |
michael@0 | 66 | { type : "application/x-moz-file", |
michael@0 | 67 | data : testFile, |
michael@0 | 68 | eqTest : function(actualData, expectedData) {return expectedData.equals(actualData);} } |
michael@0 | 69 | ]]; |
michael@0 | 70 | |
michael@0 | 71 | function doOnDrop(aEvent) { |
michael@0 | 72 | gData = aEvent.dataTransfer.getData(dragDrop[0][0].type); |
michael@0 | 73 | aEvent.preventDefault(); // cancels event and keeps dropEffect |
michael@0 | 74 | // as was before event. |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function doOnDragStart(aEvent) { |
michael@0 | 78 | var dt = aEvent.dataTransfer; |
michael@0 | 79 | switch (aEvent.currentTarget.id) { |
michael@0 | 80 | case "drag2" : |
michael@0 | 81 | dt.setData("text/plain", "this is text/plain"); |
michael@0 | 82 | case "drag1" : |
michael@0 | 83 | regularDtForDrag1 = dt; |
michael@0 | 84 | dt.setData("text/uri-list", "http://www.mozilla.org/"); |
michael@0 | 85 | break; |
michael@0 | 86 | case "dragfile" : |
michael@0 | 87 | dt.mozSetDataAt("application/x-moz-file", testFile, 0); |
michael@0 | 88 | break; |
michael@0 | 89 | } |
michael@0 | 90 | dt.effectAllowed = "all"; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function doOnDragEnter(aEvent) { |
michael@0 | 94 | gEnter = true; |
michael@0 | 95 | aEvent.dataTransfer.effectAllowed = "all"; |
michael@0 | 96 | aEvent.preventDefault(); // sets target this element |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function doOnDragOver(aEvent) { |
michael@0 | 100 | gOver = true; |
michael@0 | 101 | if (gSetDropEffect) |
michael@0 | 102 | aEvent.dataTransfer.dropEffect = "copy"; |
michael@0 | 103 | aEvent.preventDefault(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 107 | function test() { |
michael@0 | 108 | var startTime = new Date(); |
michael@0 | 109 | var result; |
michael@0 | 110 | |
michael@0 | 111 | /* test synthesizeDragStart */ |
michael@0 | 112 | result = synthesizeDragStart($("drag1"), drag1, window); |
michael@0 | 113 | is(result, null, "drag1 is text/uri-list"); |
michael@0 | 114 | result = synthesizeDragStart($("drag1"), drag1WrongFlavor, window); |
michael@0 | 115 | isnot(result, null, "drag1 is not text/plain"); |
michael@0 | 116 | result = synthesizeDragStart($("drag1"), drag2items, window); |
michael@0 | 117 | isnot(result, null, "drag1 is not 2 items"); |
michael@0 | 118 | result = synthesizeDragStart($("drag2"), drag2, window); |
michael@0 | 119 | is(result, null, "drag2 is ordered text/plain then text/uri-list"); |
michael@0 | 120 | result = synthesizeDragStart($("drag2"), drag1, window); |
michael@0 | 121 | isnot(result, null, "drag2 is not one flavor"); |
michael@0 | 122 | result = synthesizeDragStart($("drag2"), drag2WrongOrder, window); |
michael@0 | 123 | isnot(result, null, "drag2 is not ordered text/uri-list then text/plain"); |
michael@0 | 124 | result = synthesizeDragStart($("dragfile"), dragfile, window); |
michael@0 | 125 | is(result, null, "dragfile is nsIFile"); |
michael@0 | 126 | result = synthesizeDragStart($("drag1"), null, window); |
michael@0 | 127 | is(result, regularDtForDrag1, "synthesizeDragStart accepts null expectedDragData"); |
michael@0 | 128 | |
michael@0 | 129 | /* test synthesizeDrop */ |
michael@0 | 130 | result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, null, window); |
michael@0 | 131 | ok(gEnter, "Fired dragenter"); |
michael@0 | 132 | ok(gOver, "Fired dragover"); |
michael@0 | 133 | is(result, "copy", "copy is dropEffect"); |
michael@0 | 134 | is(gData, dragDrop[0][0].data, "Received valid drop data"); |
michael@0 | 135 | |
michael@0 | 136 | gSetDropEffect = false; |
michael@0 | 137 | result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, "link", window); |
michael@0 | 138 | is(result, "link", "link is dropEffect"); |
michael@0 | 139 | gSetDropEffect = true; |
michael@0 | 140 | |
michael@0 | 141 | $("textB").focus(); |
michael@0 | 142 | var content = synthesizeQueryTextContent(0, 100); |
michael@0 | 143 | ok(content, "synthesizeQueryTextContent should not be null"); |
michael@0 | 144 | ok(content.succeeded, "synthesizeQueryTextContent should succeed"); |
michael@0 | 145 | is(content.text, "I haz a content", "synthesizeQueryTextContent should be 'I haz a content': " + content.text); |
michael@0 | 146 | |
michael@0 | 147 | content = synthesizeQueryCaretRect(0); |
michael@0 | 148 | ok(content, "synthesizeQueryCaretRect should not be null"); |
michael@0 | 149 | ok(content.succeeded, "synthesizeQueryCaretRect should succeed"); |
michael@0 | 150 | |
michael@0 | 151 | content = synthesizeQueryTextRect(0, 100); |
michael@0 | 152 | ok(content, "synthesizeQueryTextRect should not be null"); |
michael@0 | 153 | ok(content.succeeded, "synthesizeQueryTextRect should succeed"); |
michael@0 | 154 | |
michael@0 | 155 | content = synthesizeQueryEditorRect(); |
michael@0 | 156 | ok(content, "synthesizeQueryEditorRect should not be null"); |
michael@0 | 157 | ok(content.succeeded, "synthesizeQueryEditorRect should succeed"); |
michael@0 | 158 | |
michael@0 | 159 | content = synthesizeCharAtPoint(0, 0); |
michael@0 | 160 | ok(content, "synthesizeCharAtPoint should not be null"); |
michael@0 | 161 | ok(content.succeeded, "synthesizeCharAtPoint should succeed"); |
michael@0 | 162 | |
michael@0 | 163 | content = synthesizeSelectionSet(0, 100); |
michael@0 | 164 | ok(content, "synthesizeSelectionSet should not be null"); |
michael@0 | 165 | is(content, true, "synthesizeSelectionSet should succeed"); |
michael@0 | 166 | |
michael@0 | 167 | var endTime = new Date(); |
michael@0 | 168 | info("\nProfile::ChromeUtilsRunTime: " + (endTime-startTime) + "\n"); |
michael@0 | 169 | SimpleTest.finish(); |
michael@0 | 170 | }; |
michael@0 | 171 | ]]> |
michael@0 | 172 | </script> |
michael@0 | 173 | |
michael@0 | 174 | <body xmlns="http://www.w3.org/1999/xhtml" onload="setTimeout('test()', 0)"> |
michael@0 | 175 | <input id="textB" value="I haz a content"/> |
michael@0 | 176 | <p id="display"></p> |
michael@0 | 177 | <div id="content" style="display:none;"></div> |
michael@0 | 178 | <pre id="test"></pre> |
michael@0 | 179 | <div id="drag1" ondragstart="doOnDragStart(event);">Need some space here</div> |
michael@0 | 180 | <p id="display"></p> |
michael@0 | 181 | <div id="content" style="display:none;"></div> |
michael@0 | 182 | <pre id="test"></pre> |
michael@0 | 183 | <div id="dragDrop" ondragover ="doOnDragOver(event);" |
michael@0 | 184 | ondragenter ="doOnDragEnter(event);" |
michael@0 | 185 | ondragleave ="doOnDragLeave(event);" |
michael@0 | 186 | ondrop ="doOnDrop(event);"> |
michael@0 | 187 | Need some depth and height to drag here |
michael@0 | 188 | </div> |
michael@0 | 189 | <div id="drag2" ondragstart="doOnDragStart(event);">Need more space</div> |
michael@0 | 190 | <div id="dragfile" ondragstart="doOnDragStart(event);">Sure why not here too</div> |
michael@0 | 191 | </body> |
michael@0 | 192 | </window> |