tor-browser

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

test_bug598643.html (2141B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=598643
      5 -->
      6 <head>
      7  <title>Test for Bug 598643</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=598643">Mozilla Bug 598643</a>
     13 <p id="display"></p>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 598643 */
     18 
     19 function createFileWithData(fileName, fileData)
     20 {
     21  return new File([new Blob([fileData], { type: "text/plain" })], fileName);
     22 }
     23 
     24 function testFileControl(aElement)
     25 {
     26  aElement.type = 'file';
     27 
     28  var file = createFileWithData("file_bug598643", "file content");
     29  SpecialPowers.wrap(aElement).mozSetFileArray([file]);
     30 
     31  ok(aElement.validity.valid, "the file control should be valid");
     32  ok(!aElement.validity.tooLong,
     33     "the file control shouldn't suffer from being too long");
     34 }
     35 
     36 var types = [
     37  // These types can be too long.
     38  [ "text", "email", "password", "url", "search", "tel" ],
     39  // These types can't be too long.
     40  [ "radio", "checkbox", "submit", "button", "reset", "image", "hidden",
     41    'number', 'range', 'date', 'time', 'color', 'month', 'week',
     42    'datetime-local' ],
     43 ];
     44 
     45 var input = document.createElement("input");
     46 input.maxLength = 1;
     47 input.value = "foo";
     48 
     49 // Too long types.
     50 for (type of types[0]) {
     51  input.type = type
     52  if (type == 'email') {
     53    input.value = "foo@bar.com";
     54  } else if (type == 'url') {
     55    input.value = 'http://foo.org';
     56  }
     57 
     58  todo(!input.validity.valid, "the element should be invalid [type=" + type + "]");
     59  todo(input.validity.tooLong,
     60       "the element should suffer from being too long [type=" + type + "]");
     61 
     62  if (type == 'email' || type == 'url') {
     63    input.value = 'foo';
     64  }
     65 }
     66 
     67 // Not too long types.
     68 for (type of types[1]) {
     69  input.type = type
     70  ok(input.validity.valid, "the element should be valid [type=" + type + "]");
     71  ok(!input.validity.tooLong,
     72     "the element shouldn't suffer from being too long [type=" + type + "]");
     73 }
     74 
     75 testFileControl(input);
     76 
     77 </script>
     78 </pre>
     79 </body>
     80 </html>