summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_textcontent_edit_01.js
blob: f27b5664703f33cde87ca72b171a059374eca621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test editing a node's text content

const TEST_URL = URL_ROOT + "doc_markup_edit.html";
const {DEFAULT_VALUE_SUMMARY_LENGTH} = require("devtools/server/actors/inspector");

add_task(function* () {
  let {inspector, testActor} = yield openInspectorForURL(TEST_URL);

  info("Expanding all nodes");
  yield inspector.markup.expandAll();
  yield waitForMultipleChildrenUpdates(inspector);

  yield editContainer(inspector, testActor, {
    selector: ".node6",
    newValue: "New text",
    oldValue: "line6"
  });

  yield editContainer(inspector, testActor, {
    selector: "#node17",
    newValue: "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
              "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
    oldValue: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
              "Donec posuere placerat magna et imperdiet."
  });

  yield editContainer(inspector, testActor, {
    selector: "#node17",
    newValue: "New value",
    oldValue: "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
              "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET."
  });

  yield editContainer(inspector, testActor, {
    selector: "#node17",
    newValue: "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT. " +
              "DONEC POSUERE PLACERAT MAGNA ET IMPERDIET.",
    oldValue: "New value"
  });
});

function* editContainer(inspector, testActor,
                        {selector, newValue, oldValue}) {
  let nodeValue = yield getFirstChildNodeValue(selector, testActor);
  is(nodeValue, oldValue, "The test node's text content is correct");

  info("Changing the text content");
  let onMutated = inspector.once("markupmutation");
  let container = yield focusNode(selector, inspector);

  let isOldValueInline = oldValue.length <= DEFAULT_VALUE_SUMMARY_LENGTH;
  is(!!container.inlineTextChild, isOldValueInline, "inlineTextChild is as expected");
  is(!container.canExpand, isOldValueInline, "canExpand property is as expected");

  let field = container.elt.querySelector("pre");
  is(field.textContent, oldValue,
     "The text node has the correct original value after selecting");
  setEditableFieldValue(field, newValue, inspector);

  info("Listening to the markupmutation event");
  yield onMutated;

  nodeValue = yield getFirstChildNodeValue(selector, testActor);
  is(nodeValue, newValue, "The test node's text content has changed");

  let isNewValueInline = newValue.length <= DEFAULT_VALUE_SUMMARY_LENGTH;
  is(!!container.inlineTextChild, isNewValueInline, "inlineTextChild is as expected");
  is(!container.canExpand, isNewValueInline, "canExpand property is as expected");

  if (isOldValueInline != isNewValueInline) {
    is(container.expanded, !isNewValueInline,
      "Container was automatically expanded/collapsed");
  }

  info("Selecting the <body> to reset the selection");
  let bodyContainer = yield getContainerForSelector("body", inspector);
  inspector.markup.markNodeAsSelected(bodyContainer.node);
}