dom/events/test/test_bug563329.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug563329.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=563329
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 563329</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <script type="text/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=563329">Mozilla Bug 563329</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;version=1.7">
    1.23 +
    1.24 +/** Test for Bug 563329 **/
    1.25 +/*  ui.click_hold_context_menus preference */
    1.26 +
    1.27 +var target = null;
    1.28 +var tests = getTests();
    1.29 +var currentTest = null;
    1.30 +
    1.31 +function getTests() {
    1.32 +  let tests = [
    1.33 +    { "func": function() { setTimeout(doCheckContextMenu, 100)}, "message": "Context menu should has fired"},
    1.34 +    { "func": function() { setTimeout(doCheckDuration, 100)}, "message": "Context menu should has fired with delay"},
    1.35 +    { "func": function() { setTimeout(finishTest, 100)}, "message": "" }
    1.36 +  ];
    1.37 +
    1.38 +  let i = 0;
    1.39 +  while (i < tests.length)
    1.40 +    yield tests[i++];
    1.41 +}
    1.42 +
    1.43 +function doTest() {
    1.44 +  // Enable context menus
    1.45 +  SpecialPowers.setBoolPref("ui.click_hold_context_menus", true);
    1.46 +
    1.47 +  target = document.getElementById("testTarget");
    1.48 +
    1.49 +  document.documentElement.addEventListener("contextmenu", function() {
    1.50 +    SimpleTest.ok(true, currentTest.message);
    1.51 +    synthesizeMouse(target, 0, 0, {type: "mouseup"});
    1.52 +    SimpleTest.executeSoon(function() {
    1.53 +      currentTest = tests.next();
    1.54 +      currentTest.func();
    1.55 +    });
    1.56 +  }, false);
    1.57 +
    1.58 +  SimpleTest.executeSoon(function() {
    1.59 +    currentTest = tests.next();
    1.60 +    currentTest.func();
    1.61 +  });
    1.62 +}
    1.63 +
    1.64 +function doCheckContextMenu() {
    1.65 +  synthesizeMouse(target, 0, 0, {type: "mousedown"});
    1.66 +}
    1.67 +
    1.68 +function doCheckDuration() {
    1.69 +  var duration = 50;
    1.70 +
    1.71 +  // Change click hold delay
    1.72 +  SpecialPowers.setIntPref("ui.click_hold_context_menus.delay", duration);
    1.73 +
    1.74 +  synthesizeMouse(target, 0, 0, {type: "mousedown"});
    1.75 +}
    1.76 +
    1.77 +function finishTest() {
    1.78 +  synthesizeKey("VK_ESCAPE", {}, window);
    1.79 +  try {
    1.80 +    SpecialPowers.clearUserPref("ui.click_hold_context_menus");
    1.81 +  }
    1.82 +  catch(e) {}
    1.83 +
    1.84 +  try {
    1.85 +    SpecialPowers.clearUserPref("ui.click_hold_context_menus.delay");
    1.86 +  }
    1.87 +  catch(e) {}
    1.88 +
    1.89 +  SimpleTest.finish();
    1.90 +}
    1.91 +
    1.92 +SimpleTest.waitForExplicitFinish();
    1.93 +addLoadEvent(doTest);
    1.94 +
    1.95 +</script>
    1.96 +</pre>
    1.97 +<span id="testTarget" style="border: 1px solid black;">testTarget</span>
    1.98 +</body>
    1.99 +</html>

mercurial