tor-browser

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

browser_boxmodel_editablemodel_allproperties.js (5904B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test editing box model values when all values are set
      7 
      8 const TEST_URI =
      9  "<style>" +
     10  "div { margin: 10px; padding: 3px }" +
     11  "#div1 { margin-top: 5px }" +
     12  "#div2 { border-bottom: 1em solid black; }" +
     13  "#div3 { padding: 2em; }" +
     14  "</style>" +
     15  "<div id='div1'></div><div id='div2'></div><div id='div3'></div>";
     16 
     17 add_task(async function () {
     18  const tab = await addTab("data:text/html," + encodeURIComponent(TEST_URI));
     19  const { inspector, boxmodel } = await openLayoutView();
     20 
     21  const browser = tab.linkedBrowser;
     22  await testEditing(inspector, boxmodel, browser);
     23  await testEditingAndCanceling(inspector, boxmodel, browser);
     24  await testDeleting(inspector, boxmodel, browser);
     25  await testDeletingAndCanceling(inspector, boxmodel, browser);
     26 });
     27 
     28 async function testEditing(inspector, boxmodel, browser) {
     29  info("When all properties are set on the node editing one should work");
     30 
     31  await setStyle(browser, "#div1", "padding", "5px");
     32  await waitForUpdate(inspector);
     33 
     34  await selectNode("#div1", inspector);
     35 
     36  const span = boxmodel.document.querySelector(
     37    ".boxmodel-padding.boxmodel-bottom > span"
     38  );
     39  await waitForElementTextContent(span, "5");
     40 
     41  EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
     42  const editor = boxmodel.document.querySelector(
     43    ".styleinspector-propertyeditor"
     44  );
     45  ok(editor, "Should have opened the editor.");
     46  is(editor.value, "5px", "Should have the right value in the editor.");
     47 
     48  EventUtils.synthesizeKey("7", {}, boxmodel.document.defaultView);
     49  await waitForUpdate(inspector);
     50 
     51  is(editor.value, "7", "Should have the right value in the editor.");
     52  is(
     53    await getStyle(browser, "#div1", "padding-bottom"),
     54    "7px",
     55    "Should have updated the padding"
     56  );
     57 
     58  EventUtils.synthesizeKey("VK_RETURN", {}, boxmodel.document.defaultView);
     59 
     60  is(
     61    await getStyle(browser, "#div1", "padding-bottom"),
     62    "7px",
     63    "Should be the right padding."
     64  );
     65  await waitForElementTextContent(span, "7");
     66 }
     67 
     68 async function testEditingAndCanceling(inspector, boxmodel, browser) {
     69  info(
     70    "When all properties are set on the node editing one and then " +
     71      "cancelling with ESCAPE should work"
     72  );
     73 
     74  await setStyle(browser, "#div1", "padding", "5px");
     75  await waitForUpdate(inspector);
     76 
     77  await selectNode("#div1", inspector);
     78 
     79  const span = boxmodel.document.querySelector(
     80    ".boxmodel-padding.boxmodel-left > span"
     81  );
     82  await waitForElementTextContent(span, "5");
     83 
     84  EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
     85  const editor = boxmodel.document.querySelector(
     86    ".styleinspector-propertyeditor"
     87  );
     88  ok(editor, "Should have opened the editor.");
     89  is(editor.value, "5px", "Should have the right value in the editor.");
     90 
     91  EventUtils.synthesizeKey("8", {}, boxmodel.document.defaultView);
     92  await waitForUpdate(inspector);
     93 
     94  is(editor.value, "8", "Should have the right value in the editor.");
     95  is(
     96    await getStyle(browser, "#div1", "padding-left"),
     97    "8px",
     98    "Should have updated the padding"
     99  );
    100 
    101  EventUtils.synthesizeKey("VK_ESCAPE", {}, boxmodel.document.defaultView);
    102  await waitForUpdate(inspector);
    103 
    104  is(
    105    await getStyle(browser, "#div1", "padding-left"),
    106    "5px",
    107    "Should be the right padding."
    108  );
    109  await waitForElementTextContent(span, "5");
    110 }
    111 
    112 async function testDeleting(inspector, boxmodel, browser) {
    113  info("When all properties are set on the node deleting one should work");
    114 
    115  await selectNode("#div1", inspector);
    116 
    117  const span = boxmodel.document.querySelector(
    118    ".boxmodel-padding.boxmodel-left > span"
    119  );
    120  await waitForElementTextContent(span, "5");
    121 
    122  EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
    123  const editor = boxmodel.document.querySelector(
    124    ".styleinspector-propertyeditor"
    125  );
    126  ok(editor, "Should have opened the editor.");
    127  is(editor.value, "5px", "Should have the right value in the editor.");
    128 
    129  EventUtils.synthesizeKey("VK_DELETE", {}, boxmodel.document.defaultView);
    130  await waitForUpdate(inspector);
    131 
    132  is(editor.value, "", "Should have the right value in the editor.");
    133  is(
    134    await getStyle(browser, "#div1", "padding-left"),
    135    "",
    136    "Should have updated the padding"
    137  );
    138 
    139  EventUtils.synthesizeKey("VK_RETURN", {}, boxmodel.document.defaultView);
    140 
    141  is(
    142    await getStyle(browser, "#div1", "padding-left"),
    143    "",
    144    "Should be the right padding."
    145  );
    146  await waitForElementTextContent(span, "3");
    147 }
    148 
    149 async function testDeletingAndCanceling(inspector, boxmodel, browser) {
    150  info(
    151    "When all properties are set on the node deleting one then cancelling " +
    152      "should work"
    153  );
    154 
    155  await setStyle(browser, "#div1", "padding", "5px");
    156  await waitForUpdate(inspector);
    157 
    158  await selectNode("#div1", inspector);
    159 
    160  const span = boxmodel.document.querySelector(
    161    ".boxmodel-padding.boxmodel-left > span"
    162  );
    163  await waitForElementTextContent(span, "5");
    164 
    165  EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
    166  const editor = boxmodel.document.querySelector(
    167    ".styleinspector-propertyeditor"
    168  );
    169  ok(editor, "Should have opened the editor.");
    170  is(editor.value, "5px", "Should have the right value in the editor.");
    171 
    172  EventUtils.synthesizeKey("VK_DELETE", {}, boxmodel.document.defaultView);
    173  await waitForUpdate(inspector);
    174 
    175  is(editor.value, "", "Should have the right value in the editor.");
    176  is(
    177    await getStyle(browser, "#div1", "padding-left"),
    178    "",
    179    "Should have updated the padding"
    180  );
    181 
    182  EventUtils.synthesizeKey("VK_ESCAPE", {}, boxmodel.document.defaultView);
    183  await waitForUpdate(inspector);
    184 
    185  is(
    186    await getStyle(browser, "#div1", "padding-left"),
    187    "5px",
    188    "Should be the right padding."
    189  );
    190  await waitForElementTextContent(span, "5");
    191 }