tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug648573.html (4203B)


      1 <!-- This Source Code Form is subject to the terms of the Mozilla Public
      2   - License, v. 2.0. If a copy of the MPL was not distributed with this
      3   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
      4 
      5 <!DOCTYPE html>
      6 <html>
      7  <!--
      8       https://bugzilla.mozilla.org/show_bug.cgi?id=648573
      9     -->
     10  <head>
     11    <title>Test for Bug 648573</title>
     12    <script src="/tests/SimpleTest/SimpleTest.js"></script>
     13    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     14  </head>
     15  <body>
     16    <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=648573">Mozilla Bug 648573</a>
     17    <p id="display"></p>
     18    <div id="content" style="display: none">
     19 
     20    </div>
     21    <pre id="test">
     22      <script type="application/javascript">
     23 
     24      /** Test for Bug 648573 */
     25      SimpleTest.waitForExplicitFinish();
     26 
     27      function runTest() {
     28        var iframe = document.createElement("iframe");
     29        document.body.appendChild(iframe);
     30        var win = iframe.contentWindow;
     31        var doc = iframe.contentDocument;
     32 
     33        var utils = SpecialPowers.getDOMWindowUtils(win);
     34 
     35        ok("createTouch" in doc, "Should have createTouch function");
     36        ok("createTouchList" in doc, "Should have createTouchList function");
     37        ok(doc.createEvent("touchevent"), "Should be able to create TouchEvent objects");
     38 
     39        var t1 = doc.createTouch(win, doc, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
     40        is(t1.target, doc, "Wrong target");
     41        is(t1.identifier, 1, "Wrong identifier");
     42        is(t1.pageX, 2, "Wrong pageX");
     43        is(t1.pageY, 3, "Wrong pageY");
     44        is(t1.screenX, 4, "Wrong screenX");
     45        is(t1.screenY, 5, "Wrong screenY");
     46        is(t1.clientX, 6, "Wrong clientX");
     47        is(t1.clientY, 7, "Wrong clientY");
     48        is(t1.radiusX, 8, "Wrong radiusX");
     49        is(t1.radiusY, 9, "Wrong radiusY");
     50        is(t1.rotationAngle, 10, "Wrong rotationAngle");
     51        is(t1.force, 11, "Wrong force");
     52 
     53        var t2 = doc.createTouch();
     54 
     55        var l1 = doc.createTouchList(t1);
     56        is(l1.length, 1, "Wrong length");
     57        is(l1.item(0), t1, "Wront item (1)");
     58        is(l1[0], t1, "Wront item (2)");
     59 
     60        var l2 = doc.createTouchList([t1, t2]);
     61        is(l2.length, 2, "Wrong length");
     62        is(l2.item(0), t1, "Wront item (3)");
     63        is(l2.item(1), t2, "Wront item (4)");
     64        is(l2[0], t1, "Wront item (5)");
     65        is(l2[1], t2, "Wront item (6)");
     66 
     67        var l3 = doc.createTouchList();
     68 
     69        var e = doc.createEvent("touchevent");
     70        e.initTouchEvent("touchmove", true, true, win, 0, true, true, true, true,
     71                         l1, l2, l3);
     72        is(e.touches, l1, "Wrong list (1)");
     73        is(e.targetTouches, l2, "Wrong list (2)");
     74        is(e.changedTouches, l3, "Wrong list (3)");
     75        ok(e.altKey, "Alt should be true");
     76        ok(e.metaKey, "Meta should be true");
     77        ok(e.ctrlKey, "Ctrl should be true");
     78        ok(e.shiftKey, "Shift should be true");
     79 
     80 
     81        var events =
     82        ["touchstart",
     83         "touchend",
     84         "touchmove",
     85         "touchcancel"];
     86 
     87        function runEventTest(type) {
     88          var event = doc.createEvent("touchevent");
     89          event.initTouchEvent(type, true, true, win, 0, true, true, true, true,
     90                               l1, l2, l3);
     91          var t = doc.createElement("div");
     92          // Testing target.onFoo;
     93          var didCall = false;
     94          t["on" + type] = function (evt) {
     95            is(evt, event, "Wrong event");
     96            evt.target.didCall = true;
     97          }
     98          t.dispatchEvent(event);
     99          ok(t.didCall, "Should have called the listener(1)");
    100 
    101          // Testing <element onFoo="">
    102          t = doc.createElement("div");
    103          t.setAttribute("on" + type, "this.didCall = true;");
    104          t.dispatchEvent(event);
    105          ok(t.didCall, "Should have called the listener(2)");
    106        }
    107 
    108        for (var i = 0; i < events.length; ++i) {
    109          runEventTest(events[i]);
    110        }
    111 
    112        SimpleTest.finish();
    113      }
    114 
    115      SpecialPowers.pushPrefEnv(
    116        {"set": [["dom.w3c_touch_events.legacy_apis.enabled", true]]}, runTest);
    117      </script>
    118    </pre>
    119  </body>
    120 </html>