tor-browser

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

test_minlength_attribute.html (5363B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=345624
      5 -->
      6 <head>
      7  <title>Test for Bug 345624</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/EventUtils.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11  <style>
     12    input, textarea { background-color: rgb(0,0,0) !important; }
     13    :-moz-any(input,textarea):valid   { background-color: rgb(0,255,0) !important; }
     14    :-moz-any(input,textarea):invalid { background-color: rgb(255,0,0) !important; }
     15  </style>
     16 </head>
     17 <body>
     18 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=345624">Mozilla Bug 345624</a>
     19 <p id="display"></p>
     20 <div id="content">
     21  <input id='i'>
     22  <textarea id='t'></textarea>
     23 </div>
     24 <pre id="test">
     25 <script type="application/javascript">
     26 
     27 /** Test for Bug 345624 */
     28 
     29 /**
     30 * This test is checking only tooShort related features
     31 * related to constraint validation.
     32 */
     33 
     34 function checkTooShortValidity(element)
     35 {
     36  element.value = "foo";
     37  ok(!element.validity.tooShort,
     38    "Element should not be too short when minlength is not set");
     39  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     40     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
     41  ok(element.validity.valid, "Element should be valid");
     42  ok(element.checkValidity(), "The element should be valid");
     43 
     44  element.minLength = 5;
     45  ok(!element.validity.tooShort,
     46    "Element should not be too short unless the user edits it");
     47  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     48     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
     49  ok(element.validity.valid, "Element should be valid");
     50  ok(element.checkValidity(), "The element should be valid");
     51 
     52  element.focus();
     53 
     54  sendString("o");
     55  is(element.value, "fooo", "value should have changed");
     56  ok(element.validity.tooShort,
     57    "Element should be too short after a user edit that does not make it short enough");
     58  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     59     "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
     60  ok(!element.validity.valid, "Element should be invalid");
     61  ok(!element.checkValidity(), "The element should not be valid");
     62  is(element.validationMessage,
     63          "Please use at least 5 characters (you are currently using 4 characters).",
     64          "The validation message text is not correct");
     65 
     66  sendString("o");
     67  is(element.value, "foooo", "value should have changed");
     68  ok(!element.validity.tooShort,
     69    "Element should not be too short after a user edit makes it long enough");
     70  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     71     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
     72  ok(element.validity.valid, "Element should be valid");
     73 
     74  element.minLength = 2;
     75  ok(!element.validity.tooShort,
     76    "Element should remain valid if minlength changes but minlength < length");
     77  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     78     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
     79  ok(element.validity.valid, "Element should be valid");
     80 
     81  element.minLength = 1;
     82  ok(!element.validity.tooShort,
     83    "Element should remain valid if minlength changes but minlength = length");
     84  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     85     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
     86  ok(element.validity.valid, "Element should be valid");
     87  ok(element.checkValidity(), "The element should be valid");
     88 
     89  element.minLength = 6;
     90  ok(element.validity.tooShort,
     91    "Element should become invalid if minlength changes and minlength > length");
     92  is(window.getComputedStyle(element).getPropertyValue('background-color'),
     93     "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
     94  ok(!element.validity.valid, "Element should be invalid");
     95  ok(!element.checkValidity(), "The element should not be valid");
     96  is(element.validationMessage,
     97          "Please use at least 6 characters (you are currently using 5 characters).",
     98          "The validation message text is not correct");
     99 
    100  element.minLength = 5;
    101  ok(!element.validity.tooShort,
    102    "Element should become valid if minlength changes and minlength = length");
    103  is(window.getComputedStyle(element).getPropertyValue('background-color'),
    104     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
    105  ok(element.validity.valid, "Element should be valid");
    106  ok(element.checkValidity(), "The element should be valid");
    107 
    108  element.value = "test";
    109  ok(!element.validity.tooShort,
    110    "Element should stay valid after programmatic edit (even if value is too short)");
    111  is(window.getComputedStyle(element).getPropertyValue('background-color'),
    112     "rgb(0, 255, 0)", ":valid pseudo-class should apply");
    113  ok(element.validity.valid, "Element should be valid");
    114  ok(element.checkValidity(), "The element should be valid");
    115 
    116  element.setCustomValidity("custom message");
    117  is(window.getComputedStyle(element).getPropertyValue('background-color'),
    118     "rgb(255, 0, 0)", ":invalid pseudo-class should apply");
    119  is(element.validationMessage, "custom message",
    120    "Custom message should be shown instead of too short one");
    121 }
    122 
    123 checkTooShortValidity(document.getElementById('i'));
    124 checkTooShortValidity(document.getElementById('t'));
    125 
    126 </script>
    127 </pre>
    128 </body>
    129 </html>