tests/pointerevents-v1/submissions/Nokia/webidl_pointerevent.html
author jrossi2
Tue, 15 Apr 2014 10:51:42 -0700
changeset 136 52401ccaf7eb
parent 69 bcce5d7cb3e6
permissions -rw-r--r--
Fixed a couple typos (editorial)
     1 <!DOCTYPE HTML>
     2 <html>
     3 <!-- 
     4      Test cases for Pointer Events v1 spec
     5 
     6      These test test the Web IDL of the PointerEvent event.
     7 
     8      This document references Test Assertions (abbrev TA below) written by Cathy Chan
     9      http://www.w3.org/wiki/PointerEvents/TestAssertions
    10 -->
    11 
    12 <head>
    13   <title>PointerEvent Web IDL test</title>
    14   <meta name="viewport" content="width=device-width">
    15   <script src="http://w3c-test.org/resources/testharness.js"></script>
    16   <script>
    17     setup({explicit_done: true});
    18 
    19     // Check a PointerEvent's atrributes for conformance to WebIDL: attribute exists,
    20     // has proper type and if the attribute is "readonly", it cannot be changed.
    21     // TA: 1.{1,2}
    22     function check_PointerEvent(ev) {
    23         test(function() {
    24            assert_true(ev instanceof PointerEvent, "event is a PointerEvent event");
    25         }, ev.type + " event is a PointerEvent event");
    26 
    27         [
    28           ["readonly", "long", "pointerId"],
    29           ["readonly", "long", "width"],
    30           ["readonly", "long", "height"],
    31           ["readonly", "float", "pressure"],
    32           ["readonly", "long", "tiltX"],
    33           ["readonly", "long", "tiltY"],
    34           ["readonly", "DOMString", "pointerType"],
    35           ["readonly", "boolean", "isPrimary"],
    36         ].forEach(function(attr) {
    37             var readonly = attr[0];
    38             var type = attr[1];
    39             var name = attr[2];
    40 
    41             // readonly check
    42             if (readonly === "readonly") {
    43                 test(function() {
    44                     assert_readonly(ev.type, name, ev.type + "." + name + " cannot be changed");
    45                 }, ev.type + "." + name + " is readonly");
    46             }
    47 
    48             // existence check
    49             test(function() {
    50                 assert_true(name in ev, name + " attribute in " + ev.type + " event");
    51             }, ev.type + "." + name + " attribute exists");
    52 
    53             // type check
    54             switch(type) {
    55             case "boolean":
    56                 test(function() {
    57                     assert_equals(typeof ev[name], "boolean", name + " attribute of type boolean");
    58                 }, ev.type + "." + name + " attribute is of type boolean");
    59                 break;
    60             case "float":
    61                 test(function() {
    62                     assert_equals(typeof ev[name], "number", name + " attribute of type float");
    63                 }, ev.type + "." + name + " attribute is of type number (float)");
    64                 break;
    65             case "long":
    66                 test(function() {
    67                     assert_equals(typeof ev[name], "number", name + " attribute of type long");
    68                 }, ev.type + "." + name + " attribute is of type number (long)");
    69                 break;
    70             case "DOMString":
    71                 test(function() {
    72                     assert_equals(typeof ev[name], "DOMString", name + " attribute of type DOMString");
    73                 }, ev.type + "." + name + " attribute is of type DOMString");
    74                 break;
    75             default:
    76                 break;
    77             }
    78        }); 
    79     }
    80     
    81     function run() {
    82       var target0 = document.getElementById("target0");
    83 
    84       // Set up a timeout so that if the UA doesn't support PointerEvents,
    85       // the framework will report "NOT RUN"
    86       var test_pe = async_test("This User Agent does Not support PointerEvents.");
    87 
    88       on_event(target0, "PointerDown", function onPointerDown(ev) {
    89           ev.preventDefault();
    90           check_PointerEvent(ev);
    91       }, "PointerDown tests OK ...");
    92     }
    93 </script>
    94 
    95 <style>
    96   div {
    97     margin: 0em;
    98     padding: 2em;
    99   }
   100   #target0 {
   101     background: yellow;
   102     border: 1px solid orange;
   103   }
   104 </style>
   105 
   106 </head>
   107 <body onload="run()">
   108   <h1>PointerEvents: check Web IDL of PointerEvent event</h1>
   109   <div id="target0">
   110     Touch this box with one finger (or other pointing device) ...
   111   </div>
   112 
   113   <div id="log"></div>
   114 </body>
   115 </html>