summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-dom-mutation-breakpoints.js
blob: e26ca0493bd26a74aed6c915a5e2de8a7e0b4cba (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Tests adding, disble/enable, and removal of dom mutation breakpoints

"use strict";

// Import helpers for the inspector
Services.scriptloader.loadSubScript(
  "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js",
  this
);

const DMB_TEST_URL =
  "https://example.com/browser/devtools/client/debugger/test/mochitest/examples/doc-dom-mutation.html";

async function enableMutationBreakpoints() {
  await pushPref("devtools.debugger.dom-mutation-breakpoints-visible", true);
}

add_task(async function () {
  // Enable features
  await enableMutationBreakpoints();
  await pushPref("devtools.debugger.map-scopes-enabled", true);

  info("Switches over to the inspector pane");

  const { inspector, toolbox } = await openInspectorForURL(DMB_TEST_URL);

  {
    info("Selecting the body node");
    await selectNode("body", inspector);

    info("Adding DOM mutation breakpoints to body");
    const allMenuItems = openContextMenuAndGetAllItems(inspector);

    const attributeMenuItem = allMenuItems.find(
      item => item.id === "node-menu-mutation-breakpoint-attribute"
    );
    attributeMenuItem.click();

    const subtreeMenuItem = allMenuItems.find(
      item => item.id === "node-menu-mutation-breakpoint-subtree"
    );
    subtreeMenuItem.click();
  }

  {
    info("Find and expand the shadow host.");
    const hostFront = await getNodeFront("#host", inspector);
    const hostContainer = inspector.markup.getContainer(hostFront);
    await expandContainer(inspector, hostContainer);

    info("Expand the shadow root");
    const shadowRootContainer = hostContainer.getChildContainers()[0];
    await expandContainer(inspector, shadowRootContainer);

    info("Select the div under the shadow root");
    const divContainer = shadowRootContainer.getChildContainers()[0];
    await selectNode(divContainer.node, inspector);

    const allMenuItems = openContextMenuAndGetAllItems(inspector);
    info("Adding attribute breakpoint.");
    const attributeMenuItem = allMenuItems.find(
      item => item.id === "node-menu-mutation-breakpoint-attribute"
    );
    attributeMenuItem.click();
  }

  info("Switches over to the debugger pane");
  await toolbox.selectTool("jsdebugger");

  const dbg = createDebuggerContext(toolbox);

  info("Confirms that one DOM mutation breakpoint exists");
  const mutationItem = await waitForElement(dbg, "domMutationItem");
  ok(mutationItem, "A DOM mutation breakpoint exists");

  mutationItem.scrollIntoView();

  info("Enabling and disabling the DOM mutation breakpoint works");
  const checkbox = mutationItem.querySelector("input");
  checkbox.click();
  await waitFor(() => !checkbox.checked);
  checkbox.click();
  await waitFor(() => checkbox.checked);

  info("Changing attribute to trigger debugger pause");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#attribute").click();
  });
  await waitForPaused(dbg);
  let whyPaused = await waitFor(
    () => dbg.win.document.querySelector(".why-paused")?.innerText
  );
  is(
    whyPaused,
    `Paused on DOM mutation\nDOM Mutation: 'attributeModified'\nbody`
  );

  await resume(dbg);

  info("Changing style to trigger debugger pause");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#style-attribute").click();
  });
  await waitForPaused(dbg);
  await resume(dbg);

  info("Changing attribute in shadow dom to trigger debugger pause");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#shadow-attribute").click();
  });
  await waitForPaused(dbg);
  await resume(dbg);

  info("Adding element in subtree to trigger debugger pause");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#add-in-subtree").click();
  });
  await waitForPaused(dbg);
  whyPaused = await waitFor(
    () => dbg.win.document.querySelector(".why-paused")?.innerText
  );
  is(
    whyPaused,
    `Paused on DOM mutation\nDOM Mutation: 'subtreeModified'\nbodyAdded:div#dynamic`
  );

  await resume(dbg);

  info("Removing element in subtree to trigger debugger pause");
  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#remove-in-subtree").click();
  });
  await waitForPaused(dbg);
  whyPaused = await waitFor(
    () => dbg.win.document.querySelector(".why-paused")?.innerText
  );
  is(
    whyPaused,
    `Paused on DOM mutation\nDOM Mutation: 'subtreeModified'\nbodyRemoved:div#dynamic`
  );

  await resume(dbg);

  info("Blackboxing the source prevents debugger pause");
  await waitForSource(dbg, "dom-mutation.original.js");

  const source = findSource(dbg, "dom-mutation.original.js");

  await selectSource(dbg, source);
  await clickElement(dbg, "blackbox");
  await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");

  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    content.document.querySelector("#blackbox").click();
  });

  await waitForPaused(dbg, "click.js");
  await resume(dbg);

  await selectSource(dbg, source);
  await clickElement(dbg, "blackbox");
  await waitForDispatch(dbg.store, "UNBLACKBOX_WHOLE_SOURCES");

  info("Removing breakpoints works");
  dbg.win.document.querySelector(".dom-mutation-list .close-btn").click();
  await waitForAllElements(dbg, "domMutationItem", 2, true);
});