tor-browser

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

test_bug590363.html (4592B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=590363
      5 -->
      6 <head>
      7  <title>Test for Bug 590363</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=590363">Mozilla Bug 590363</a>
     13 <p id="display"></p>
     14 <div id="content" style="display: none">
     15  
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 
     20 /** Test for Bug 590363 */
     21 
     22 var testData = [
     23  /* type to test | is the value reset when changing to file then reverting */
     24  [ "button",   false ],
     25  [ "checkbox", false ],
     26  [ "hidden",   false ],
     27  [ "reset",    false ],
     28  [ "image",    false ],
     29  [ "radio",    false ],
     30  [ "submit",   false ],
     31  [ "tel",      true ],
     32  [ "text",     true ],
     33  [ "url",      true ],
     34  [ "email",    true ],
     35  [ "search",   true ],
     36  [ "password", true ],
     37  [ "number",   true ],
     38  [ "date",     true ],
     39  [ "time",     true ],
     40  [ "range",    true ],
     41  [ "color",    true ],
     42  [ 'month',    true ],
     43  [ 'week',     true ],
     44  [ 'datetime-local', true ]
     45  // 'file' is treated separately.
     46 ];
     47 
     48 var nonTrivialSanitizing = [ 'number', 'date', 'time', 'color', 'month', 'week',
     49                             'datetime-local' ];
     50 
     51 var length = testData.length;
     52 for (var i=0; i<length; ++i) {
     53  for (var j=0; j<length; ++j) {
     54    var e = document.createElement('input');
     55    e.type = testData[i][0];
     56 
     57    var expectedValue;
     58 
     59    // range will sanitize its value to 50 (the default) if it isn't a valid
     60    // number. We need to handle that specially.
     61    if (testData[j][0] == 'range' || testData[i][0] == 'range') {
     62      if (testData[j][0] == 'date' || testData[j][0] == 'time' ||
     63          testData[j][0] == 'month' || testData[j][0] == 'week' ||
     64          testData[j][0] == 'datetime-local') {
     65        expectedValue = '';
     66      } else if (testData[j][0] == 'color') {
     67        expectedValue = '#000000';
     68      } else {
     69        expectedValue = '50';
     70      }
     71    } else if (testData[i][0] == 'color' || testData[j][0] == 'color') {
     72        if (testData[j][0] == 'number' || testData[j][0] == 'date' ||
     73            testData[j][0] == 'time' || testData[j][0] == 'month' ||
     74            testData[j][0] == 'week' || testData[j][0] == 'datetime-local') {
     75          expectedValue = ''
     76        } else {
     77          expectedValue = '#000000';
     78        }
     79    } else if (nonTrivialSanitizing.includes(testData[i][0]) &&
     80               nonTrivialSanitizing.includes(testData[j][0])) {
     81      expectedValue = '';
     82    } else if (testData[i][0] == 'number' || testData[j][0] == 'number') {
     83      expectedValue = '42';
     84    } else if (testData[i][0] == 'date' || testData[j][0] == 'date') {
     85      expectedValue = '2012-12-21';
     86    } else if (testData[i][0] == 'time' || testData[j][0] == 'time') {
     87      expectedValue = '21:21';
     88    } else if (testData[i][0] == 'month' || testData[j][0] == 'month') {
     89      expectedValue = '2013-03';
     90    } else if (testData[i][0] == 'week' || testData[j][0] == 'week') {
     91      expectedValue = '2016-W35';
     92    } else if (testData[i][0] == 'datetime-local' ||
     93               testData[j][0] == 'datetime-local') {
     94      expectedValue = '2016-11-07T16:40';
     95    } else {
     96      expectedValue = "foo";
     97    }
     98    e.value = expectedValue;
     99 
    100    e.type = testData[j][0];
    101    is(e.value, expectedValue, ".value should still return the same value after " +
    102       "changing type from " + testData[i][0] + " to " + testData[j][0]);
    103  }
    104 }
    105 
    106 // For type='file' .value doesn't behave the same way.
    107 // We are just going to check that we do not loose the value.
    108 for (var data of testData) {
    109  var e = document.createElement('input');
    110  e.type = data[0];
    111  e.value = 'foo';
    112  e.type = 'file';
    113  e.type = data[0];
    114 
    115  if (data[0] == 'range') {
    116    is(e.value, '50', ".value should still return the same value after " +
    117       "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
    118  } else if (data[0] == 'color') {
    119    is(e.value, '#000000', ".value should have been reset to the default color after " +
    120       "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
    121  } else if (data[1]) {
    122    is(e.value, '', ".value should have been reset to the empty string after " +
    123       "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
    124  } else {
    125    is(e.value, 'foo', ".value should still return the same value after " +
    126       "changing type from " + data[0] + " to 'file' then reverting to " + data[0]);
    127  }
    128 }
    129 
    130 </script>
    131 </pre>
    132 </body>
    133 </html>