tor-browser

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

browser_boxmodel.js (5430B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the box model displays the right values and that it updates when
      7 // the node's style is changed
      8 
      9 // Expected values:
     10 var res1 = [
     11  {
     12    selector: ".boxmodel-element-size",
     13    value: "160" + "\u00D7" + "160.117",
     14  },
     15  {
     16    selector: ".boxmodel-size > .boxmodel-width",
     17    value: "100",
     18  },
     19  {
     20    selector: ".boxmodel-size > .boxmodel-height",
     21    value: "100.117",
     22  },
     23  {
     24    selector: ".boxmodel-position.boxmodel-top > span",
     25    value: "42",
     26  },
     27  {
     28    selector: ".boxmodel-position.boxmodel-left > span",
     29    value: "42",
     30  },
     31  {
     32    selector: ".boxmodel-margin.boxmodel-top > span",
     33    value: "30",
     34  },
     35  {
     36    selector: ".boxmodel-margin.boxmodel-left > span",
     37    value: "auto",
     38  },
     39  {
     40    selector: ".boxmodel-margin.boxmodel-bottom > span",
     41    value: "30",
     42  },
     43  {
     44    selector: ".boxmodel-margin.boxmodel-right > span",
     45    value: "auto",
     46  },
     47  {
     48    selector: ".boxmodel-padding.boxmodel-top > span",
     49    value: "20",
     50  },
     51  {
     52    selector: ".boxmodel-padding.boxmodel-left > span",
     53    value: "20",
     54  },
     55  {
     56    selector: ".boxmodel-padding.boxmodel-bottom > span",
     57    value: "20",
     58  },
     59  {
     60    selector: ".boxmodel-padding.boxmodel-right > span",
     61    value: "20",
     62  },
     63  {
     64    selector: ".boxmodel-border.boxmodel-top > span",
     65    value: "10",
     66  },
     67  {
     68    selector: ".boxmodel-border.boxmodel-left > span",
     69    value: "10",
     70  },
     71  {
     72    selector: ".boxmodel-border.boxmodel-bottom > span",
     73    value: "10",
     74  },
     75  {
     76    selector: ".boxmodel-border.boxmodel-right > span",
     77    value: "10",
     78  },
     79 ];
     80 
     81 var res2 = [
     82  {
     83    selector: ".boxmodel-element-size",
     84    value: "190" + "\u00D7" + "210",
     85  },
     86  {
     87    selector: ".boxmodel-size > .boxmodel-width",
     88    value: "100",
     89  },
     90  {
     91    selector: ".boxmodel-size > .boxmodel-height",
     92    value: "150",
     93  },
     94  {
     95    selector: ".boxmodel-position.boxmodel-top > span",
     96    value: "50",
     97  },
     98  {
     99    selector: ".boxmodel-position.boxmodel-left > span",
    100    value: "42",
    101  },
    102  {
    103    selector: ".boxmodel-margin.boxmodel-top > span",
    104    value: "30",
    105  },
    106  {
    107    selector: ".boxmodel-margin.boxmodel-left > span",
    108    value: "auto",
    109  },
    110  {
    111    selector: ".boxmodel-margin.boxmodel-bottom > span",
    112    value: "30",
    113  },
    114  {
    115    selector: ".boxmodel-margin.boxmodel-right > span",
    116    value: "auto",
    117  },
    118  {
    119    selector: ".boxmodel-padding.boxmodel-top > span",
    120    value: "20",
    121  },
    122  {
    123    selector: ".boxmodel-padding.boxmodel-left > span",
    124    value: "20",
    125  },
    126  {
    127    selector: ".boxmodel-padding.boxmodel-bottom > span",
    128    value: "20",
    129  },
    130  {
    131    selector: ".boxmodel-padding.boxmodel-right > span",
    132    value: "50",
    133  },
    134  {
    135    selector: ".boxmodel-border.boxmodel-top > span",
    136    value: "10",
    137  },
    138  {
    139    selector: ".boxmodel-border.boxmodel-left > span",
    140    value: "10",
    141  },
    142  {
    143    selector: ".boxmodel-border.boxmodel-bottom > span",
    144    value: "10",
    145  },
    146  {
    147    selector: ".boxmodel-border.boxmodel-right > span",
    148    value: "10",
    149  },
    150 ];
    151 
    152 var res3 = [
    153  {
    154    selector: ".boxmodel-element-size",
    155    value: "0" + "\u00D7" + "0",
    156  },
    157  {
    158    selector: ".boxmodel-size > .boxmodel-width",
    159    value: "auto",
    160  },
    161  {
    162    selector: ".boxmodel-size > .boxmodel-height",
    163    value: "auto",
    164  },
    165 ];
    166 
    167 add_task(async function () {
    168  const style =
    169    "div { position: absolute; top: 42px; left: 42px; " +
    170    "height: 100.111px; width: 100px; border: 10px solid black; " +
    171    "padding: 20px; margin: 30px auto;}";
    172  const html = "<style>" + style + "</style><div></div>";
    173 
    174  await addTab("data:text/html," + encodeURIComponent(html));
    175  const { inspector, boxmodel } = await openLayoutView();
    176  await selectNode("div", inspector);
    177 
    178  testInitialValues(inspector, boxmodel);
    179  await testChangingValues(inspector, boxmodel);
    180  await testContentValueForHiddenElement(inspector, boxmodel);
    181 });
    182 
    183 function testInitialValues(inspector, boxmodel) {
    184  info("Test that the initial values of the box model are correct");
    185  const doc = boxmodel.document;
    186 
    187  for (let i = 0; i < res1.length; i++) {
    188    const elt = doc.querySelector(res1[i].selector);
    189    is(
    190      elt.textContent,
    191      res1[i].value,
    192      res1[i].selector + " has the right value."
    193    );
    194  }
    195 }
    196 
    197 async function testChangingValues(inspector, boxmodel) {
    198  info("Test that changing the document updates the box model");
    199  const doc = boxmodel.document;
    200 
    201  const onUpdated = waitForUpdate(inspector);
    202  await setContentPageElementAttribute(
    203    "div",
    204    "style",
    205    "height:150px;padding-right:50px;top:50px"
    206  );
    207  await onUpdated;
    208 
    209  for (let i = 0; i < res2.length; i++) {
    210    const elt = doc.querySelector(res2[i].selector);
    211    is(
    212      elt.textContent,
    213      res2[i].value,
    214      res2[i].selector + " has the right value after style update."
    215    );
    216  }
    217 }
    218 
    219 async function testContentValueForHiddenElement(inspector, boxmodel) {
    220  info("Test that content shows 'auto' x 'auto' for hidden elements");
    221  const doc = boxmodel.document;
    222 
    223  const onUpdated = waitForUpdate(inspector);
    224  await setContentPageElementAttribute(
    225    "div",
    226    "style",
    227    "padding: 10%; display: none;"
    228  );
    229  await onUpdated;
    230 
    231  for (let i = 0; i < res3.length; i++) {
    232    const elt = doc.querySelector(res3[i].selector);
    233    is(
    234      elt.textContent,
    235      res3[i].value,
    236      res3[i].selector + " has the right value after hiding element."
    237    );
    238  }
    239 }