tor-browser

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

browser_markup_textcontent_edit_01.js (3137B)


      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 a node's text content
      7 
      8 const TEST_URL = URL_ROOT + "doc_markup_edit.html";
      9 const {
     10  DEFAULT_VALUE_SUMMARY_LENGTH,
     11 } = require("resource://devtools/server/actors/inspector/walker.js");
     12 
     13 add_task(async function () {
     14  const { inspector } = await openInspectorForURL(TEST_URL);
     15 
     16  info("Expanding all nodes");
     17  await inspector.markup.expandAll();
     18  await waitForMultipleChildrenUpdates(inspector);
     19 
     20  await editContainer(inspector, {
     21    selector: ".node6",
     22    newValue: "New text",
     23    oldValue: "line6",
     24  });
     25 
     26  await editContainer(inspector, {
     27    selector: "#node17",
     28    newValue:
     29      "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
     30      "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
     31    oldValue:
     32      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
     33      "Donec posuere placerat magna et imperdiet.",
     34  });
     35 
     36  await editContainer(inspector, {
     37    selector: "#node17",
     38    newValue: "New value",
     39    oldValue:
     40      "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
     41      "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
     42  });
     43 
     44  await editContainer(inspector, {
     45    selector: "#node17",
     46    newValue:
     47      "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
     48      "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
     49    oldValue: "New value",
     50  });
     51 });
     52 
     53 async function editContainer(inspector, { selector, newValue, oldValue }) {
     54  let nodeValue = await getFirstChildNodeValue(selector);
     55  is(nodeValue, oldValue, "The test node's text content is correct");
     56 
     57  info("Changing the text content");
     58  const onMutated = inspector.once("markupmutation");
     59  const container = await focusNode(selector, inspector);
     60 
     61  const isOldValueInline = oldValue.length <= DEFAULT_VALUE_SUMMARY_LENGTH;
     62  is(
     63    !!container.inlineTextChild,
     64    isOldValueInline,
     65    "inlineTextChild is as expected"
     66  );
     67  is(
     68    !container.canExpand,
     69    isOldValueInline,
     70    "canExpand property is as expected"
     71  );
     72 
     73  const field = container.elt.querySelector("pre");
     74  is(
     75    field.textContent,
     76    oldValue,
     77    "The text node has the correct original value after selecting"
     78  );
     79  setEditableFieldValue(field, newValue, inspector);
     80 
     81  info("Listening to the markupmutation event");
     82  await onMutated;
     83 
     84  nodeValue = await getFirstChildNodeValue(selector);
     85  is(nodeValue, newValue, "The test node's text content has changed");
     86 
     87  const isNewValueInline = newValue.length <= DEFAULT_VALUE_SUMMARY_LENGTH;
     88  is(
     89    !!container.inlineTextChild,
     90    isNewValueInline,
     91    "inlineTextChild is as expected"
     92  );
     93  is(
     94    !container.canExpand,
     95    isNewValueInline,
     96    "canExpand property is as expected"
     97  );
     98 
     99  if (isOldValueInline != isNewValueInline) {
    100    is(
    101      container.expanded,
    102      !isNewValueInline,
    103      "Container was automatically expanded/collapsed"
    104    );
    105  }
    106 
    107  info("Selecting the <body> to reset the selection");
    108  const bodyContainer = await getContainerForSelector("body", inspector);
    109  inspector.markup.markNodeAsSelected(bodyContainer.node);
    110 }