tor-browser

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

FormControlRange-toString.html (2613B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <body></body>
      5 <script>
      6 test(() => {
      7  document.body.innerHTML = '<input type="text" value="Test">';
      8  const input = document.body.firstElementChild;
      9  const range = new FormControlRange();
     10 
     11  range.setFormControlRange(input, 0, 4);
     12  // Full replacement collapses to start.
     13  input.value = "New";
     14  assert_true(range.collapsed, "range collapses on full replacement");
     15  assert_equals(range.startOffset, 0);
     16  assert_equals(range.endOffset, 0);
     17  assert_equals(range.toString(), "");
     18 }, "FormControlRange collapses on full .value= replacement.");
     19 
     20 test(() => {
     21  document.body.innerHTML = '<input type="text" value="Hello">';
     22  const input = document.body.firstElementChild;
     23  const range = new FormControlRange();
     24 
     25  range.setFormControlRange(input, 1, 4);
     26  // Full replacement (shorter) also collapses to start.
     27  input.value = "Hi";
     28  assert_true(range.collapsed, "range collapses on full replacement (shorter)");
     29  assert_equals(range.startOffset, 0);
     30  assert_equals(range.endOffset, 0);
     31  assert_equals(range.toString(), "");
     32 }, "FormControlRange collapses on full .value= replacement (shorter).");
     33 
     34 test(() => {
     35  document.body.innerHTML = '<textarea>LongText</textarea>';
     36  const textarea = document.body.firstElementChild;
     37  const range = new FormControlRange();
     38 
     39  range.setFormControlRange(textarea, 2, 6);
     40  // Value length is shorter than range.
     41  textarea.value = "Hi";
     42  assert_equals(range.toString(), "");
     43 }, "FormControlRange toString() handles value shorter than range.");
     44 
     45 test(() => {
     46  document.body.innerHTML = '<input type="text" value="Test">';
     47  const input = document.body.firstElementChild;
     48  const range = new FormControlRange();
     49 
     50  range.setFormControlRange(input, 3, 1);
     51  assert_equals(range.toString(), "");
     52  assert_true(range.collapsed);
     53 }, "FormControlRange toString() handles auto-collapsed backwards ranges.");
     54 
     55 test(() => {
     56  // Test input with value attribute vs IDL value.
     57  document.body.innerHTML = '<input type="text" value="AttrValue">';
     58  const input = document.body.firstElementChild;
     59 
     60  input.value = "NewValue";
     61 
     62  const range = new FormControlRange();
     63  range.setFormControlRange(input, 0, input.value.length);
     64 
     65  // FormControlRange should use current .value, not attribute.
     66  assert_equals(range.toString(), "NewValue");
     67 
     68  input.setAttribute("value", "AttrChanged");
     69  assert_equals(input.value, "NewValue");
     70  assert_equals(range.toString(), "NewValue");
     71 
     72 }, "FormControlRange uses current input.value, not value attribute.");
     73 </script>