editor/libeditor/html/tests/test_bug674770-2.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/html/tests/test_bug674770-2.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,401 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=674770
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 674770</title>
    1.11 +  <script type="application/javascript" src="/MochiKit/packed.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=674770">Mozilla Bug 674770</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content">
    1.20 +<iframe id="iframe" style="display: block; height: 14em;"
    1.21 +  src="data:text/html,<input id='text' value='pasted'><input id='input' style='display: block;'><p id='editor1' contenteditable>editor1:</p><p id='editor2' contenteditable>editor2:</p>"></iframe>
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +<script type="application/javascript">
    1.25 +
    1.26 +/** Test for Bug 674770 **/
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +var iframe = document.getElementById("iframe");
    1.30 +var frameWindow, frameDocument;
    1.31 +
    1.32 +var gClicked = false;
    1.33 +var gClicking = null;
    1.34 +var gDoPreventDefault1 = null;
    1.35 +var gDoPreventDefault2 = null;
    1.36 +
    1.37 +function clickEventHnalder(aEvent)
    1.38 +{
    1.39 +  if (aEvent.button == 1 && aEvent.target == gClicking) {
    1.40 +    gClicked = true;
    1.41 +  }
    1.42 +  if (gDoPreventDefault1 == aEvent.target) {
    1.43 +    aEvent.preventDefault();
    1.44 +  }
    1.45 +  if (gDoPreventDefault2 == aEvent.target) {
    1.46 +    aEvent.preventDefault();
    1.47 +  }
    1.48 +}
    1.49 +
    1.50 +// NOTE: tests need to check the result *after* the content is actually
    1.51 +//       modified.  Sometimes, the modification is delayed. Therefore, there
    1.52 +//       are a lot of functions and SimpleTest.executeSoon()s.
    1.53 +
    1.54 +SimpleTest.waitForFocus(function() {
    1.55 +  SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
    1.56 +  SpecialPowers.setBoolPref("middlemouse.paste", true);
    1.57 +
    1.58 +  frameWindow = iframe.contentWindow;
    1.59 +  frameDocument = iframe.contentDocument;
    1.60 +
    1.61 +  frameDocument.getElementById("input").addEventListener("click", clickEventHnalder, false);
    1.62 +  frameDocument.getElementById("editor1").addEventListener("click", clickEventHnalder, false);
    1.63 +  frameDocument.getElementById("editor2").addEventListener("click", clickEventHnalder, false);
    1.64 +
    1.65 +  var text = frameDocument.getElementById("text");
    1.66 +
    1.67 +  text.focus();
    1.68 +
    1.69 +  SimpleTest.executeSoon(function() {
    1.70 +    if (navigator.platform.indexOf("Linux") == 0) {
    1.71 +      synthesizeKey("a", { altKey: true }, frameWindow);
    1.72 +    } else {
    1.73 +      synthesizeKey("a", { accelKey: true }, frameWindow);
    1.74 +    }
    1.75 +    // Windows and Mac don't have primary selection, we should copy the text to
    1.76 +    // the global clipboard.
    1.77 +    if (!SpecialPowers.supportsSelectionClipboard()) {
    1.78 +      SimpleTest.waitForClipboard("pasted",
    1.79 +        function() { synthesizeKey("c", { accelKey: true }, frameWindow); },
    1.80 +        function() { SimpleTest.executeSoon(runInputTests1) },
    1.81 +        cleanup);
    1.82 +    } else {
    1.83 +      // Otherwise, don't call waitForClipboard since it breaks primary
    1.84 +      // selection.
    1.85 +      runInputTests1();
    1.86 +    }
    1.87 +  });
    1.88 +});
    1.89 +
    1.90 +function runInputTests1()
    1.91 +{
    1.92 +  var input = frameDocument.getElementById("input");
    1.93 +
    1.94 +  // first, copy text.
    1.95 +
    1.96 +  // when middle clicked in focused input element, text should be pasted.
    1.97 +  input.value = "";
    1.98 +  input.focus();
    1.99 +
   1.100 +  SimpleTest.executeSoon(function() {
   1.101 +    gClicked = false;
   1.102 +    gClicking = input;
   1.103 +    gDoPreventDefault1 = null;
   1.104 +    gDoPreventDefault2 = null;
   1.105 +
   1.106 +    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
   1.107 +
   1.108 +    SimpleTest.executeSoon(function() {
   1.109 +      todo(gClicked, "click event hasn't been fired for runInputTests1");
   1.110 +      is(input.value, "pasted", "failed to paste in input element");
   1.111 +
   1.112 +      SimpleTest.executeSoon(runInputTests2);
   1.113 +    });
   1.114 +  });
   1.115 +}
   1.116 +
   1.117 +function runInputTests2()
   1.118 +{
   1.119 +  var input = frameDocument.getElementById("input");
   1.120 +
   1.121 +  // even if the input element hasn't had focus, middle click should set focus
   1.122 +  // to it and paste the text.
   1.123 +  input.value = "";
   1.124 +  input.blur();
   1.125 +
   1.126 +  SimpleTest.executeSoon(function() {
   1.127 +    gClicked = false;
   1.128 +    gClicking = input;
   1.129 +    gDoPreventDefault1 = null;
   1.130 +    gDoPreventDefault2 = null;
   1.131 +
   1.132 +    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
   1.133 +
   1.134 +    SimpleTest.executeSoon(function() {
   1.135 +      todo(gClicked, "click event hasn't been fired for runInputTests2");
   1.136 +      is(input.value, "pasted",
   1.137 +         "failed to paste in input element when it hasn't had focus yet");
   1.138 +
   1.139 +      SimpleTest.executeSoon(runInputTests3);
   1.140 +    });
   1.141 +  });
   1.142 +}
   1.143 +
   1.144 +function runInputTests3()
   1.145 +{
   1.146 +  var input = frameDocument.getElementById("input");
   1.147 +  var editor1 = frameDocument.getElementById("editor1");
   1.148 +
   1.149 +  // preventDefault() of HTML editor's click event handler shouldn't prevent
   1.150 +  // middle click pasting in input element.
   1.151 +  input.value = "";
   1.152 +  input.focus();
   1.153 +
   1.154 +  SimpleTest.executeSoon(function() {
   1.155 +    gClicked = false;
   1.156 +    gClicking = input;
   1.157 +    gDoPreventDefault1 = editor1;
   1.158 +    gDoPreventDefault2 = null;
   1.159 +
   1.160 +    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
   1.161 +
   1.162 +    SimpleTest.executeSoon(function() {
   1.163 +      todo(gClicked, "click event hasn't been fired for runInputTests3");
   1.164 +      is(input.value, "pasted",
   1.165 +         "failed to paste in input element when editor1 does preventDefault()");
   1.166 +
   1.167 +      SimpleTest.executeSoon(runInputTests4);
   1.168 +    });
   1.169 +  });
   1.170 +}
   1.171 +
   1.172 +function runInputTests4()
   1.173 +{
   1.174 +  var input = frameDocument.getElementById("input");
   1.175 +  var editor1 = frameDocument.getElementById("editor1");
   1.176 +
   1.177 +  // preventDefault() of input element's click event handler should prevent
   1.178 +  // middle click pasting in it.
   1.179 +  input.value = "";
   1.180 +  input.focus();
   1.181 +
   1.182 +  SimpleTest.executeSoon(function() {
   1.183 +    gClicked = false;
   1.184 +    gClicking = input;
   1.185 +    gDoPreventDefault1 = input;
   1.186 +    gDoPreventDefault2 = null;
   1.187 +
   1.188 +    synthesizeMouseAtCenter(input, {button: 1}, frameWindow);
   1.189 +
   1.190 +    SimpleTest.executeSoon(function() {
   1.191 +      todo(gClicked, "click event hasn't been fired for runInputTests4");
   1.192 +      todo_is(input.value, "",
   1.193 +         "pasted in input element when it does preventDefault()");
   1.194 +
   1.195 +      SimpleTest.executeSoon(runContentEditableTests1);
   1.196 +    });
   1.197 +  });
   1.198 +}
   1.199 +
   1.200 +function runContentEditableTests1()
   1.201 +{
   1.202 +  var editor1 = frameDocument.getElementById("editor1");
   1.203 +
   1.204 +  // when middle clicked in focused contentediable editor, text should be
   1.205 +  // pasted.
   1.206 +  editor1.innerHTML = "editor1:";
   1.207 +  editor1.focus();
   1.208 +
   1.209 +  SimpleTest.executeSoon(function() {
   1.210 +    gClicked = false;
   1.211 +    gClicking = editor1;
   1.212 +    gDoPreventDefault1 = null;
   1.213 +    gDoPreventDefault2 = null;
   1.214 +
   1.215 +    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
   1.216 +
   1.217 +    SimpleTest.executeSoon(function() {
   1.218 +      todo(gClicked, "click event hasn't been fired for runContentEditableTests1");
   1.219 +      is(editor1.innerHTML, "editor1:pasted",
   1.220 +         "failed to paste text in contenteditable editor");
   1.221 +      SimpleTest.executeSoon(runContentEditableTests2);
   1.222 +    });
   1.223 +  });
   1.224 +}
   1.225 +
   1.226 +function runContentEditableTests2()
   1.227 +{
   1.228 +  var editor1 = frameDocument.getElementById("editor1");
   1.229 +
   1.230 +  // even if the contenteditable editor hasn't had focus, middle click should
   1.231 +  // set focus to it and paste the text.
   1.232 +  editor1.innerHTML = "editor1:";
   1.233 +  editor1.blur();
   1.234 +
   1.235 +  SimpleTest.executeSoon(function() {
   1.236 +    gClicked = false;
   1.237 +    gClicking = editor1;
   1.238 +    gDoPreventDefault1 = null;
   1.239 +    gDoPreventDefault2 = null;
   1.240 +
   1.241 +    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
   1.242 +
   1.243 +    SimpleTest.executeSoon(function() {
   1.244 +      todo(gClicked, "click event hasn't been fired for runContentEditableTests2");
   1.245 +      is(editor1.innerHTML, "editor1:pasted",
   1.246 +         "failed to paste in contenteditable editor #1 when it hasn't had focus yet");
   1.247 +      SimpleTest.executeSoon(runContentEditableTests3);
   1.248 +    });
   1.249 +  });
   1.250 +}
   1.251 +
   1.252 +function runContentEditableTests3()
   1.253 +{
   1.254 +  var editor1 = frameDocument.getElementById("editor1");
   1.255 +  var editor2 = frameDocument.getElementById("editor2");
   1.256 +
   1.257 +  // When editor1 has focus but editor2 is middle clicked, should be pasted
   1.258 +  // in the editor2.
   1.259 +  editor1.innerHTML = "editor1:";
   1.260 +  editor2.innerHTML = "editor2:";
   1.261 +  editor1.focus();
   1.262 +
   1.263 +  SimpleTest.executeSoon(function() {
   1.264 +    gClicked = false;
   1.265 +    gClicking = editor2;
   1.266 +    gDoPreventDefault1 = null;
   1.267 +    gDoPreventDefault2 = null;
   1.268 +
   1.269 +    synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
   1.270 +
   1.271 +    SimpleTest.executeSoon(function() {
   1.272 +      todo(gClicked, "click event hasn't been fired for runContentEditableTests3");
   1.273 +      is(editor1.innerHTML, "editor1:",
   1.274 +         "pasted in contenteditable editor #1 when editor2 is clicked");
   1.275 +      is(editor2.innerHTML, "editor2:pasted",
   1.276 +         "failed to paste in contenteditable editor #2 when editor2 is clicked");
   1.277 +      SimpleTest.executeSoon(runContentEditableTests4);
   1.278 +    });
   1.279 +  });
   1.280 +}
   1.281 +
   1.282 +function runContentEditableTests4()
   1.283 +{
   1.284 +  var editor1 = frameDocument.getElementById("editor1");
   1.285 +
   1.286 +  // preventDefault() of editor1's click event handler should prevent
   1.287 +  // middle click pasting in it.
   1.288 +  editor1.innerHTML = "editor1:";
   1.289 +  editor1.focus();
   1.290 +
   1.291 +  SimpleTest.executeSoon(function() {
   1.292 +    gClicked = false;
   1.293 +    gClicking = editor1;
   1.294 +    gDoPreventDefault1 = editor1;
   1.295 +    gDoPreventDefault2 = null;
   1.296 +
   1.297 +    synthesizeMouseAtCenter(editor1, {button: 1}, frameWindow);
   1.298 +
   1.299 +    SimpleTest.executeSoon(function() {
   1.300 +      todo(gClicked, "click event hasn't been fired for runContentEditableTests4");
   1.301 +      todo_is(editor1.innerHTML, "editor1:",
   1.302 +         "pasted in contenteditable editor #1 when it does preventDefault()");
   1.303 +      SimpleTest.executeSoon(runContentEditableTests5);
   1.304 +    });
   1.305 +  });
   1.306 +}
   1.307 +
   1.308 +function runContentEditableTests5()
   1.309 +{
   1.310 +  var editor1 = frameDocument.getElementById("editor1");
   1.311 +  var editor2 = frameDocument.getElementById("editor2");
   1.312 +
   1.313 +  // preventDefault() of editor1's click event handler shouldn't prevent
   1.314 +  // middle click pasting in editor2.
   1.315 +  editor1.innerHTML = "editor1:";
   1.316 +  editor2.innerHTML = "editor2:";
   1.317 +  editor2.focus();
   1.318 +
   1.319 +  SimpleTest.executeSoon(function() {
   1.320 +    gClicked = false;
   1.321 +    gClicking = editor2;
   1.322 +    gDoPreventDefault1 = editor1;
   1.323 +    gDoPreventDefault2 = null;
   1.324 +
   1.325 +    synthesizeMouseAtCenter(editor2, {button: 1}, frameWindow);
   1.326 +
   1.327 +    SimpleTest.executeSoon(function() {
   1.328 +      todo(gClicked, "click event hasn't been fired for runContentEditableTests5");
   1.329 +      is(editor1.innerHTML, "editor1:",
   1.330 +         "pasted in contenteditable editor #1?");
   1.331 +      is(editor2.innerHTML, "editor2:pasted",
   1.332 +         "failed to paste in contenteditable editor #2");
   1.333 +
   1.334 +      SimpleTest.executeSoon(initForBodyEditableDocumentTests);
   1.335 +    });
   1.336 +  });
   1.337 +}
   1.338 +
   1.339 +function initForBodyEditableDocumentTests()
   1.340 +{
   1.341 +  frameDocument.getElementById("input").removeEventListener("click", clickEventHnalder, false);
   1.342 +  frameDocument.getElementById("editor1").removeEventListener("click", clickEventHnalder, false);
   1.343 +  frameDocument.getElementById("editor2").removeEventListener("click", clickEventHnalder, false);
   1.344 +
   1.345 +  iframe.onload =
   1.346 +    function (aEvent) { SimpleTest.executeSoon(runBodyEditableDocumentTests1); };
   1.347 +  iframe.src =
   1.348 +    "data:text/html,<body contenteditable>body:</body>";
   1.349 +}
   1.350 +
   1.351 +function runBodyEditableDocumentTests1()
   1.352 +{
   1.353 +  frameWindow = iframe.contentWindow;
   1.354 +  frameDocument = iframe.contentDocument;
   1.355 +
   1.356 +  var body = frameDocument.body;
   1.357 +
   1.358 +  is(body.innerHTML, "body:",
   1.359 +     "failed to initialize at runBodyEditableDocumentTests1");
   1.360 +
   1.361 +  // middle click on html element should cause pasting text in its body.
   1.362 +  synthesizeMouseAtCenter(frameDocument.documentElement, {button: 1}, frameWindow);
   1.363 +
   1.364 +  SimpleTest.executeSoon(function() {
   1.365 +    is(body.innerHTML,
   1.366 +       "body:pasted",
   1.367 +       "failed to paste in editable body element when clicked on html element");
   1.368 +
   1.369 +    SimpleTest.executeSoon(runBodyEditableDocumentTests2);
   1.370 +  });
   1.371 +}
   1.372 +
   1.373 +function runBodyEditableDocumentTests2()
   1.374 +{
   1.375 +  frameDocument.body.innerHTML = "body:<span id='span' contenteditable='false'>non-editable</span>";
   1.376 +
   1.377 +  var body = frameDocument.body;
   1.378 +
   1.379 +  is(body.innerHTML, "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
   1.380 +     "failed to initialize at runBodyEditableDocumentTests2");
   1.381 +
   1.382 +  synthesizeMouseAtCenter(frameDocument.getElementById("span"), {button: 1}, frameWindow);
   1.383 +
   1.384 +  SimpleTest.executeSoon(function() {
   1.385 +    is(body.innerHTML,
   1.386 +       "body:<span id=\"span\" contenteditable=\"false\">non-editable</span>",
   1.387 +       "pasted when middle clicked in non-editable element");
   1.388 +
   1.389 +    SimpleTest.executeSoon(cleanup);
   1.390 +  });
   1.391 +}
   1.392 +
   1.393 +function cleanup()
   1.394 +{
   1.395 +  SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
   1.396 +  SpecialPowers.clearUserPref("middlemouse.paste");
   1.397 +
   1.398 +  SimpleTest.finish();
   1.399 +}
   1.400 +
   1.401 +</script>
   1.402 +</pre>
   1.403 +</body>
   1.404 +</html>

mercurial