dom/events/test/test_bug534833.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug534833.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=534833
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 534833</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=534833">Mozilla Bug 534833</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript">
    1.23 +
    1.24 +/** Test for Bug 534833 **/
    1.25 +SimpleTest.waitForExplicitFinish();
    1.26 +addLoadEvent(runTests);
    1.27 +
    1.28 +var input1GotClick = 0;
    1.29 +var input2GotClick = 0;
    1.30 +var textarea1GotClick = 0;
    1.31 +var textarea2GotClick = 0;
    1.32 +var div1GotClick = 0;
    1.33 +var div2GotClick = 0;
    1.34 +
    1.35 +var tests = [ { element: "text",  clickText: true  },
    1.36 +              { element: "text2", clickText: false },
    1.37 +              { element: "area",  clickText: true  },
    1.38 +              { element: "area2", clickText: false  },
    1.39 +              { element: "d",     clickText: true  },
    1.40 +              { element: "d",     clickText: false },
    1.41 +              { element: "d2",    clickText: true  },
    1.42 +              { element: "d2",    clickText: false }
    1.43 +             ];
    1.44 +
    1.45 +function nextTest_() {
    1.46 +  if (!tests.length) {
    1.47 +    finishTests();
    1.48 +    return;
    1.49 +  }
    1.50 +
    1.51 +  var test = tests.shift();
    1.52 +  var el = document.getElementById(test.element);
    1.53 +  el.scrollIntoView(true);
    1.54 +  if (test.clickText) {
    1.55 +    synthesizeMouse(el, 5, 5, {type : "mousedown" });
    1.56 +    synthesizeMouse(el, 5, 5, {type : "mouseup" });
    1.57 +  } else {
    1.58 +    synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mousedown" });
    1.59 +    synthesizeMouse(el, el.getBoundingClientRect().width - 5, 5, {type : "mouseup" });
    1.60 +  }
    1.61 +  nextTest();
    1.62 +}
    1.63 +
    1.64 +function nextTest() {
    1.65 +  var el = document.getElementById("initialfocus");
    1.66 +
    1.67 +  el.addEventListener("focus", function() {
    1.68 +    el.removeEventListener("focus", arguments.callee, false);
    1.69 +    setTimeout(nextTest_, 0);
    1.70 +  }, false);
    1.71 +  el.focus();
    1.72 +}
    1.73 +
    1.74 +function runTests() {
    1.75 +  var t = document.getElementById("text");
    1.76 +  var t2 = document.getElementById("text2");
    1.77 +  var a = document.getElementById("area");
    1.78 +  var a2 = document.getElementById("area2");
    1.79 +  var d = document.getElementById("d");
    1.80 +  var d2 = document.getElementById("d2");
    1.81 +
    1.82 +  // input 1
    1.83 +  t.onfocus = function(e) {
    1.84 +    t.value = "";
    1.85 +  }
    1.86 +  t.onclick = function(e) {
    1.87 +    ++input1GotClick;
    1.88 +  }
    1.89 +
    1.90 +  // input 2
    1.91 +  t2.onfocus = function(e) {
    1.92 +    t2.value = "";
    1.93 +  }
    1.94 +  t2.onclick = function(e) {
    1.95 +    ++input2GotClick;
    1.96 +  }
    1.97 +
    1.98 +  // textarea 1
    1.99 +  a.onfocus = function(e) {
   1.100 +    a.value = "";
   1.101 +  }
   1.102 +  a.onclick = function(e) {
   1.103 +    ++textarea1GotClick;
   1.104 +  }
   1.105 +
   1.106 +  // textarea 2
   1.107 +  a2.onfocus = function(e) {
   1.108 +    a2.value = "";
   1.109 +  }
   1.110 +  a2.onclick = function(e) {
   1.111 +    ++textarea2GotClick;
   1.112 +  }
   1.113 +
   1.114 +  // div 1
   1.115 +  var c = 0;
   1.116 +  d.onmousedown = function(e) {
   1.117 +    d.textContent = (++c) + " / click before or after |";
   1.118 +  }
   1.119 +  d.onclick = function(e) {
   1.120 +    ++div1GotClick;
   1.121 +  }
   1.122 +
   1.123 +  // div 2
   1.124 +  var c2 = 0;
   1.125 +  d2.onmousedown = function(e) {
   1.126 +    d2.firstChild.data = (++c2) + " / click before or after |";
   1.127 +  }
   1.128 +  d2.onclick = function(e) {
   1.129 +    ++div2GotClick;
   1.130 +  }
   1.131 +  nextTest();
   1.132 +}
   1.133 +
   1.134 +function finishTests() {
   1.135 +  is(input1GotClick, 1, "input element should have got a click!");
   1.136 +  is(input2GotClick, 1, "input element should have got a click! (2)");
   1.137 +  is(textarea1GotClick, 1, "textarea element should have got a click!");
   1.138 +  is(textarea2GotClick, 1, "textarea element should have got a click! (2)");
   1.139 +  is(div1GotClick, 2, "div element's content text was replaced, it should have got 2 click!");
   1.140 +  is(div2GotClick, 2, "div element's content text was modified, it should have got 2 clicks!");
   1.141 +  SimpleTest.finish();
   1.142 +}
   1.143 +
   1.144 +</script>
   1.145 +</pre>
   1.146 +<input type="text" id="initialfocus"><br>
   1.147 +<input type="text" id="text" value="click before |" style="width: 95%;"><br>
   1.148 +<input type="text" id="text2" value="click after |" style="width: 95%;">
   1.149 +<br>
   1.150 +<textarea id="area" rows="2" style="width: 95%;">
   1.151 + click before
   1.152 +            |
   1.153 +</textarea><br>
   1.154 +<textarea id="area2" rows="2" style="width: 95%;">
   1.155 + click after |
   1.156 +</textarea>
   1.157 +<div id="d" style="border: 1px solid black;">click before or after |</div>
   1.158 +<div id="d2" style="border: 1px solid black;">click before or after |</div>
   1.159 +</body>
   1.160 +</html>

mercurial