tor-browser

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

test_input_attributes_reflection.html (6958B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for HTMLInputElement attributes reflection</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="application/javascript" src="../reflect.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 <p id="display"></p>
     11 <div id="content">
     12 </div>
     13 <pre id="test">
     14 <script type="application/javascript">
     15 
     16 /** Test for HTMLInputElement attributes reflection */
     17 
     18 // TODO: maybe make those reflections be tested against all input types.
     19 
     20 function testWidthHeight(attr) {
     21  var element = document.createElement('input');
     22  is(element[attr], 0, attr + ' always returns 0 if not type=image');
     23  element.setAttribute(attr, '42');
     24  is(element[attr], 0, attr + ' always returns 0 if not type=image');
     25  is(element.getAttribute(attr), '42');
     26  element[attr] = 0;
     27  is(element.getAttribute(attr), '0', 'setting ' + attr + ' changes the content attribute');
     28  element[attr] = 12;
     29  is(element.getAttribute(attr), '12', 'setting ' + attr + ' changes the content attribute');
     30 
     31  element.removeAttribute(attr);
     32  is(element.getAttribute(attr), null);
     33 
     34  element = document.createElement('input');
     35  element.type = 'image';
     36  element.style.display = "inline";
     37  document.getElementById('content').appendChild(element);
     38  isnot(element[attr], 0, attr + ' represents the dimension of the element if type=image');
     39 
     40  element.setAttribute(attr, '42');
     41  isnot(element[attr], 0, attr + ' represents the dimension of the element if type=image');
     42  isnot(element[attr], 42, attr + ' represents the dimension of the element if type=image');
     43  is(element.getAttribute(attr), '42');
     44  element[attr] = 0;
     45  is(element.getAttribute(attr), '0', 'setting ' + attr + ' changes the content attribute');
     46  element[attr] = 12;
     47  is(element.getAttribute(attr), '12', 'setting ' + attr + ' changes the content attribute');
     48 
     49  element.removeAttribute(attr);
     50  is(element.getAttribute(attr), null);
     51 }
     52 
     53 // .accept
     54 reflectString({
     55  element: document.createElement("input"),
     56  attribute: "accept",
     57  otherValues: [ "audio/*", "video/*", "image/*", "image/png",
     58                 "application/msword", "appplication/pdf" ],
     59 });
     60 
     61 // .alt
     62 reflectString({
     63  element: document.createElement("input"),
     64  attribute: "alt",
     65 });
     66 
     67 // .autocomplete
     68 reflectLimitedEnumerated({
     69  element: document.createElement("input"),
     70  attribute: "autocomplete",
     71  validValues: [ "on", "off" ],
     72  invalidValues: [ "", "default", "foo", "tulip" ],
     73 });
     74 
     75 // .autofocus
     76 reflectBoolean({
     77  element: document.createElement("input"),
     78  attribute: "autofocus",
     79 });
     80 
     81 // .defaultChecked
     82 reflectBoolean({
     83  element: document.createElement("input"),
     84  attribute: { idl: "defaultChecked", content: "checked" },
     85 });
     86 
     87 // .checked doesn't reflect a content attribute.
     88 
     89 // .dirName
     90 reflectString({
     91  element: document.createElement("input"),
     92  attribute: "dirName"
     93 });
     94 
     95 // .disabled
     96 reflectBoolean({
     97  element: document.createElement("input"),
     98  attribute: "disabled",
     99 });
    100 
    101 // TODO: form (HTMLFormElement)
    102 // TODO: files (FileList)
    103 
    104 // .formAction
    105 reflectURL({
    106  element: document.createElement("button"),
    107  attribute: "formAction",
    108 });
    109 
    110 // .formEnctype
    111 reflectLimitedEnumerated({
    112  element: document.createElement("input"),
    113  attribute: "formEnctype",
    114  validValues: [ "application/x-www-form-urlencoded", "multipart/form-data",
    115                 "text/plain" ],
    116  invalidValues: [ "", "foo", "tulip", "multipart/foo" ],
    117  defaultValue: { invalid: "application/x-www-form-urlencoded", missing: "" }
    118 });
    119 
    120 // .formMethod
    121 reflectLimitedEnumerated({
    122  element: document.createElement("input"),
    123  attribute: "formMethod",
    124  validValues: [ "get", "post" ],
    125  invalidValues: [ "", "foo", "tulip" ],
    126  defaultValue: { invalid: "get", missing: "" }
    127 });
    128 
    129 // .formNoValidate
    130 reflectBoolean({
    131  element: document.createElement("input"),
    132  attribute: "formNoValidate",
    133 });
    134 
    135 // .formTarget
    136 reflectString({
    137  element: document.createElement("input"),
    138  attribute: "formTarget",
    139  otherValues: [ "_blank", "_self", "_parent", "_top" ],
    140 });
    141 
    142 // .height
    143 testWidthHeight('height');
    144 
    145 // .indeterminate doesn't reflect a content attribute.
    146 
    147 // TODO: list (HTMLElement)
    148 
    149 // .max
    150 reflectString({
    151  element: document.createElement('input'),
    152  attribute: 'max',
    153 });
    154 
    155 // .maxLength
    156 reflectInt({
    157  element: document.createElement("input"),
    158  attribute: "maxLength",
    159  nonNegative: true,
    160 });
    161 
    162 // .min
    163 reflectString({
    164  element: document.createElement('input'),
    165  attribute: 'min',
    166 });
    167 
    168 // .multiple
    169 reflectBoolean({
    170  element: document.createElement("input"),
    171  attribute: "multiple",
    172 });
    173 
    174 // .name
    175 reflectString({
    176  element: document.createElement("input"),
    177  attribute: "name",
    178  otherValues: [ "isindex", "_charset_" ],
    179 });
    180 
    181 // .pattern
    182 reflectString({
    183  element: document.createElement("input"),
    184  attribute: "pattern",
    185  otherValues: [ "[0-9][A-Z]{3}" ],
    186 });
    187 
    188 // .placeholder
    189 reflectString({
    190  element: document.createElement("input"),
    191  attribute: "placeholder",
    192  otherValues: [ "foo\nbar", "foo\rbar", "foo\r\nbar" ],
    193 });
    194 
    195 // .readOnly
    196 reflectBoolean({
    197  element: document.createElement("input"),
    198  attribute: "readOnly",
    199 });
    200 
    201 // .required
    202 reflectBoolean({
    203  element: document.createElement("input"),
    204  attribute: "required",
    205 });
    206 
    207 // .size
    208 reflectUnsignedInt({
    209  element: document.createElement("input"),
    210  attribute: "size",
    211  nonZero: true,
    212  defaultValue: 20,
    213 });
    214 
    215 // .src (URL)
    216 reflectURL({
    217  element: document.createElement('input'),
    218  attribute: 'src',
    219 });
    220 
    221 // .step
    222 reflectString({
    223  element: document.createElement('input'),
    224  attribute: 'step',
    225 });
    226 
    227 // .type
    228 reflectLimitedEnumerated({
    229  element: document.createElement("input"),
    230  attribute: "type",
    231  validValues: [ "hidden", "text", "search", "tel", "url", "email", "password",
    232                 "checkbox", "radio", "file", "submit", "image", "reset",
    233                 "button", "date", "time", "number", "range", "color", "month",
    234                 "week", "datetime-local" ],
    235  invalidValues: [ "this-is-probably-a-wrong-type", "", "tulip" ],
    236  defaultValue: "text"
    237 });
    238 
    239 // .defaultValue
    240 reflectString({
    241  element: document.createElement("input"),
    242  attribute: { idl: "defaultValue", content: "value" },
    243  otherValues: [ "foo\nbar", "foo\rbar", "foo\r\nbar" ],
    244 });
    245 
    246 // .value doesn't reflect a content attribute.
    247 
    248 // .valueAsDate
    249 is("valueAsDate" in document.createElement("input"), true,
    250   "valueAsDate should be available");
    251 
    252 // Deeper check will be done with bug 763305.
    253 is('valueAsNumber' in document.createElement("input"), true,
    254   "valueAsNumber should be available");
    255 
    256 // .selectedOption
    257 todo("selectedOption" in document.createElement("input"),
    258     "selectedOption isn't implemented yet");
    259 
    260 // .width
    261 testWidthHeight('width');
    262 
    263 // .willValidate doesn't reflect a content attribute.
    264 // .validity doesn't reflect a content attribute.
    265 // .validationMessage doesn't reflect a content attribute.
    266 // .labels doesn't reflect a content attribute.
    267 
    268 </script>
    269 </pre>
    270 </body>
    271 </html>