tor-browser

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

test_reframe_table_in_ib_split.html (5777B)


      1 <!doctype html>
      2 <meta charset="utf-8">
      3 <title>
      4 Test for bug 1850834: Replacing the contents of a table should reframe the same amount, regardless of whether it's in an IB split.
      5 </title>
      6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
      7 <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8 <div id="content">
      9  <!-- Reference case: Table as child of block-level element -->
     10  <div>
     11    <table id="tableInBlock"></table>
     12  </div>
     13  <!-- Test case: Table as child of inline-level element (forming IB split) -->
     14  <span>
     15    aaa
     16    <table id="tableInIBSplit"></table>
     17    bbb
     18  </span>
     19 </div>
     20 <script>
     21 const utils = SpecialPowers.getDOMWindowUtils(window);
     22 
     23 /*
     24 * This utility function invokes callbackFunc(callbackArg) and returns the
     25 * number of frames that are reconstructed in the process.
     26 */
     27 function countReframesForTweak(callbackFunc, callbackArg) {
     28  document.documentElement.offsetTop;
     29  const previousConstructCount = utils.framesConstructed;
     30 
     31  callbackFunc(callbackArg)
     32 
     33  document.documentElement.offsetTop;
     34  return utils.framesConstructed - previousConstructCount;
     35 }
     36 
     37 /*
     38 * Helper for expectSameReframesForTweak, to reduce boilerplate.
     39 * Sets the provided innerHTML in both tables, and then performs the
     40 * dynamic-modification-callback on both tables, and asserts that the
     41 * frame construction counts match.
     42 */
     43 function testWithInitialTableContent(callbackFunc, startingInnerHTML, message) {
     44  tableInBlock.innerHTML = tableInIBSplit.innerHTML = startingInnerHTML;
     45 
     46  let actual = countReframesForTweak(callbackFunc, tableInIBSplit);
     47  let expected = countReframesForTweak(callbackFunc, tableInBlock);
     48  is(actual, expected, message);
     49 }
     50 
     51 /*
     52 * This utility function runs the provided callback function for both of the
     53 * tables, from various starting-conditions. In each case, we check that
     54 * the number of frames that are reconstructed is the same, between the
     55 * two tables.
     56 */
     57 function expectSameReframesForTweak(callbackFunc, message) {
     58  testWithInitialTableContent(callbackFunc, "", /* <-- empty string */
     59                              `${message} (starting with empty table)`);
     60 
     61  testWithInitialTableContent(callbackFunc, "  ", /* <-- two space chars */
     62                              `${message} (starting with ` +
     63                              `empty-aside-from-whitespace table)`);
     64 
     65  testWithInitialTableContent(callbackFunc, "Some text",
     66                              `${message} (starting with text node child)`);
     67 
     68  testWithInitialTableContent(callbackFunc, "<caption></caption>",
     69                              `${message} (starting with empty caption)`);
     70 
     71  testWithInitialTableContent(callbackFunc, "<tbody></tbody>",
     72                              `${message} (starting with empty tbody)`);
     73 
     74  testWithInitialTableContent(callbackFunc, "<tr></tr>",
     75                              `${message} (starting with empty tr)`);
     76 
     77  testWithInitialTableContent(callbackFunc, "<td></td>",
     78                              `${message} (starting with empty td)`);
     79 
     80  testWithInitialTableContent(callbackFunc,
     81                              "<col></col>",
     82                              `${message} (starting with an empty col)`);
     83 
     84  testWithInitialTableContent(callbackFunc,
     85                              "<colgroup></colgroup>",
     86                              `${message} (starting with an empty colgroup)`);
     87 
     88  testWithInitialTableContent(callbackFunc,
     89                              "<colgroup><col></col></colgroup>",
     90                              `${message} (starting with a colgroup/col)`);
     91 
     92  testWithInitialTableContent(callbackFunc,
     93                              "<tbody><tr><td>Contents</td></tr></tbody>",
     94                              `${message} (starting with full subtree)`);
     95 }
     96 
     97 // The actual test logic begins here!
     98 // We invoke expectSameReframesForTweak to compare reframe counts between our
     99 // two tables, for various types of dynamic modifications:
    100 expectSameReframesForTweak((elem)=> { elem.textContent = ""; },
    101  "Reframe count should be the same when clearing table.textContent"
    102 );
    103 
    104 expectSameReframesForTweak((elem)=> { elem.textContent = " "; },
    105  "Reframe count should be the same when setting table.textContent to a space"
    106 );
    107 
    108 expectSameReframesForTweak((elem)=> { elem.textContent = "modified"; },
    109   "Reframe count should be the same when setting table.textContent");
    110 
    111 expectSameReframesForTweak(
    112   (elem) => { elem.innerHTML = "<tbody><tr><td>content</td></tr></tbody>"; },
    113   "Reframe count should be the same when setting table.innerHTML to " +
    114   "table subtree with full hierarchy specified");
    115 
    116 expectSameReframesForTweak(
    117   (elem) => { elem.innerHTML = "<caption>caption</caption>" +
    118               "<tbody><tr><td>content</td></tr></tbody>"; },
    119   "Reframe count should be the same when setting table.innerHTML to " +
    120   "table subtree with full hierarchy specified, including a caption");
    121 
    122 expectSameReframesForTweak(
    123   (elem) => { elem.innerHTML = "<tbody>just a tbody</tbody>"; },
    124   "Reframe count should be the same when setting table.innerHTML to " +
    125   "just a tbody");
    126 
    127 expectSameReframesForTweak(
    128   (elem) => { elem.innerHTML = "<tr>just a tr</tr>"; },
    129   "Reframe count should be the same when setting table.innerHTML to " +
    130   "just a tr");
    131 
    132 expectSameReframesForTweak(
    133   (elem) => { elem.innerHTML = "<td>just a td</td>"; },
    134   "Reframe count should be the same when setting table.innerHTML to " +
    135   "just a td");
    136 
    137 expectSameReframesForTweak(
    138   (elem) => { elem.innerHTML = "<col></col>"; },
    139   "Reframe count should be the same when setting table.innerHTML to " +
    140   "just a col");
    141 
    142 expectSameReframesForTweak(
    143   (elem) => { elem.innerHTML = "<colgroup></colgroup>"; },
    144   "Reframe count should be the same when setting table.innerHTML to " +
    145   "just a colgroup");
    146 </script>