1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/chrome/test_sanityChromeUtils.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,192 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.6 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.8 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.9 + type="text/css"?> 1.10 +<window title="Test ChromeUtils functions" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.14 + <!-- ChromeUtils.js depends on EventUtils.js --> 1.15 + <script type="application/javascript" 1.16 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.17 + <script type="text/javascript"> 1.18 + var start = new Date(); 1.19 + </script> 1.20 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> 1.21 + <script type="text/javascript"> 1.22 + var loadTime = new Date(); 1.23 + </script> 1.24 + <script type="application/javascript"> 1.25 + <![CDATA[ 1.26 + info("\nProfile::ChromeUtilsLoadTime: " + (loadTime - start) + "\n"); 1.27 + var testFile = Components.classes["@mozilla.org/file/directory_service;1"]. 1.28 + getService(Components.interfaces.nsIProperties). 1.29 + get("CurWorkD", Components.interfaces.nsIFile); 1.30 + var regularDtForDrag1 = null; 1.31 + var gSetDropEffect = true; 1.32 + var gData; 1.33 + var gEnter = false; 1.34 + var gOver = false; 1.35 + var dragDrop = [[ 1.36 + { type : "text/plain", 1.37 + data : "This is a test" } 1.38 + ]]; 1.39 + // this is the expected data arrays 1.40 + // for testing drag of 2 items create 2 inner arrays 1.41 + var drag1 = [[ 1.42 + { type : "text/uri-list", 1.43 + data : "http://www.mozilla.org/" } 1.44 + ]]; 1.45 + var drag2items = [[ 1.46 + { type : "text/uri-list", 1.47 + data : "http://www.mozilla.org/" } 1.48 + ],[ 1.49 + { type : "text/uri-list", 1.50 + data : "http://www.mozilla.org/" } 1.51 + ]]; 1.52 + var drag1WrongFlavor = [[ 1.53 + { type : "text/plain", 1.54 + data : "this is text/plain" } 1.55 + ]]; 1.56 + var drag2 = [[ 1.57 + { type : "text/plain", 1.58 + data : "this is text/plain" }, 1.59 + { type : "text/uri-list", 1.60 + data : "http://www.mozilla.org/" } 1.61 + ]]; 1.62 + var drag2WrongOrder = [[ 1.63 + { type : "text/uri-list", 1.64 + data : "http://www.mozilla.org/" }, 1.65 + { type : "text/plain", 1.66 + data : "this is text/plain" } 1.67 + ]]; 1.68 + var dragfile = [[ 1.69 + { type : "application/x-moz-file", 1.70 + data : testFile, 1.71 + eqTest : function(actualData, expectedData) {return expectedData.equals(actualData);} } 1.72 + ]]; 1.73 + 1.74 + function doOnDrop(aEvent) { 1.75 + gData = aEvent.dataTransfer.getData(dragDrop[0][0].type); 1.76 + aEvent.preventDefault(); // cancels event and keeps dropEffect 1.77 + // as was before event. 1.78 + } 1.79 + 1.80 + function doOnDragStart(aEvent) { 1.81 + var dt = aEvent.dataTransfer; 1.82 + switch (aEvent.currentTarget.id) { 1.83 + case "drag2" : 1.84 + dt.setData("text/plain", "this is text/plain"); 1.85 + case "drag1" : 1.86 + regularDtForDrag1 = dt; 1.87 + dt.setData("text/uri-list", "http://www.mozilla.org/"); 1.88 + break; 1.89 + case "dragfile" : 1.90 + dt.mozSetDataAt("application/x-moz-file", testFile, 0); 1.91 + break; 1.92 + } 1.93 + dt.effectAllowed = "all"; 1.94 + } 1.95 + 1.96 + function doOnDragEnter(aEvent) { 1.97 + gEnter = true; 1.98 + aEvent.dataTransfer.effectAllowed = "all"; 1.99 + aEvent.preventDefault(); // sets target this element 1.100 + } 1.101 + 1.102 + function doOnDragOver(aEvent) { 1.103 + gOver = true; 1.104 + if (gSetDropEffect) 1.105 + aEvent.dataTransfer.dropEffect = "copy"; 1.106 + aEvent.preventDefault(); 1.107 + } 1.108 + 1.109 + SimpleTest.waitForExplicitFinish(); 1.110 + function test() { 1.111 + var startTime = new Date(); 1.112 + var result; 1.113 + 1.114 + /* test synthesizeDragStart */ 1.115 + result = synthesizeDragStart($("drag1"), drag1, window); 1.116 + is(result, null, "drag1 is text/uri-list"); 1.117 + result = synthesizeDragStart($("drag1"), drag1WrongFlavor, window); 1.118 + isnot(result, null, "drag1 is not text/plain"); 1.119 + result = synthesizeDragStart($("drag1"), drag2items, window); 1.120 + isnot(result, null, "drag1 is not 2 items"); 1.121 + result = synthesizeDragStart($("drag2"), drag2, window); 1.122 + is(result, null, "drag2 is ordered text/plain then text/uri-list"); 1.123 + result = synthesizeDragStart($("drag2"), drag1, window); 1.124 + isnot(result, null, "drag2 is not one flavor"); 1.125 + result = synthesizeDragStart($("drag2"), drag2WrongOrder, window); 1.126 + isnot(result, null, "drag2 is not ordered text/uri-list then text/plain"); 1.127 + result = synthesizeDragStart($("dragfile"), dragfile, window); 1.128 + is(result, null, "dragfile is nsIFile"); 1.129 + result = synthesizeDragStart($("drag1"), null, window); 1.130 + is(result, regularDtForDrag1, "synthesizeDragStart accepts null expectedDragData"); 1.131 + 1.132 + /* test synthesizeDrop */ 1.133 + result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, null, window); 1.134 + ok(gEnter, "Fired dragenter"); 1.135 + ok(gOver, "Fired dragover"); 1.136 + is(result, "copy", "copy is dropEffect"); 1.137 + is(gData, dragDrop[0][0].data, "Received valid drop data"); 1.138 + 1.139 + gSetDropEffect = false; 1.140 + result = synthesizeDrop($("dragDrop"), $("dragDrop"), dragDrop, "link", window); 1.141 + is(result, "link", "link is dropEffect"); 1.142 + gSetDropEffect = true; 1.143 + 1.144 + $("textB").focus(); 1.145 + var content = synthesizeQueryTextContent(0, 100); 1.146 + ok(content, "synthesizeQueryTextContent should not be null"); 1.147 + ok(content.succeeded, "synthesizeQueryTextContent should succeed"); 1.148 + is(content.text, "I haz a content", "synthesizeQueryTextContent should be 'I haz a content': " + content.text); 1.149 + 1.150 + content = synthesizeQueryCaretRect(0); 1.151 + ok(content, "synthesizeQueryCaretRect should not be null"); 1.152 + ok(content.succeeded, "synthesizeQueryCaretRect should succeed"); 1.153 + 1.154 + content = synthesizeQueryTextRect(0, 100); 1.155 + ok(content, "synthesizeQueryTextRect should not be null"); 1.156 + ok(content.succeeded, "synthesizeQueryTextRect should succeed"); 1.157 + 1.158 + content = synthesizeQueryEditorRect(); 1.159 + ok(content, "synthesizeQueryEditorRect should not be null"); 1.160 + ok(content.succeeded, "synthesizeQueryEditorRect should succeed"); 1.161 + 1.162 + content = synthesizeCharAtPoint(0, 0); 1.163 + ok(content, "synthesizeCharAtPoint should not be null"); 1.164 + ok(content.succeeded, "synthesizeCharAtPoint should succeed"); 1.165 + 1.166 + content = synthesizeSelectionSet(0, 100); 1.167 + ok(content, "synthesizeSelectionSet should not be null"); 1.168 + is(content, true, "synthesizeSelectionSet should succeed"); 1.169 + 1.170 + var endTime = new Date(); 1.171 + info("\nProfile::ChromeUtilsRunTime: " + (endTime-startTime) + "\n"); 1.172 + SimpleTest.finish(); 1.173 + }; 1.174 + ]]> 1.175 + </script> 1.176 + 1.177 + <body xmlns="http://www.w3.org/1999/xhtml" onload="setTimeout('test()', 0)"> 1.178 + <input id="textB" value="I haz a content"/> 1.179 + <p id="display"></p> 1.180 + <div id="content" style="display:none;"></div> 1.181 + <pre id="test"></pre> 1.182 + <div id="drag1" ondragstart="doOnDragStart(event);">Need some space here</div> 1.183 + <p id="display"></p> 1.184 + <div id="content" style="display:none;"></div> 1.185 + <pre id="test"></pre> 1.186 + <div id="dragDrop" ondragover ="doOnDragOver(event);" 1.187 + ondragenter ="doOnDragEnter(event);" 1.188 + ondragleave ="doOnDragLeave(event);" 1.189 + ondrop ="doOnDrop(event);"> 1.190 + Need some depth and height to drag here 1.191 + </div> 1.192 + <div id="drag2" ondragstart="doOnDragStart(event);">Need more space</div> 1.193 + <div id="dragfile" ondragstart="doOnDragStart(event);">Sure why not here too</div> 1.194 + </body> 1.195 +</window>