summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_html_edit_04.js
blob: be56b47368871257af5de34a6b6b806507de1366 (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that outerHTML editing keybindings work as expected and that the <svg>
// root element can be edited correctly.

const TEST_URL =
  "data:image/svg+xml," +
  '<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">' +
  '<circle cx="50" cy="50" r="50"/>' +
  "</svg>";

requestLongerTimeout(2);

add_task(async function () {
  const { inspector } = await openInspectorForURL(TEST_URL);

  inspector.markup._frame.focus();

  info("Check that editing the <svg> element works like other nodes");
  await testDocumentElement(inspector);

  info("Check (again) that editing the <svg> element works like other nodes");
  await testDocumentElement2(inspector);
});

async function testDocumentElement(inspector) {
  const currentDocElementOuterHTML = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [],
    () => content.document.documentElement.outerHTML
  );
  const docElementSVG =
    '<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">' +
    '<rect x="10" y="10" width="180" height="180"/>' +
    "</svg>";
  const docElementFront = await inspector.markup.walker.documentElement();

  const onReselected = inspector.markup.once("reselectedonremoved");
  await inspector.markup.updateNodeOuterHTML(
    docElementFront,
    docElementSVG,
    currentDocElementOuterHTML
  );
  await onReselected;

  is(
    await getContentPageElementAttribute("svg", "width"),
    "200",
    "<svg> width has been updated"
  );
  is(
    await getContentPageElementAttribute("svg", "height"),
    "200",
    "<svg> height has been updated"
  );
  is(
    await getContentPageElementProperty("svg", "outerHTML"),
    docElementSVG,
    "<svg> markup has been updated"
  );
}

async function testDocumentElement2(inspector) {
  const currentDocElementOuterHTML = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [],
    () => content.document.documentElement.outerHTML
  );
  const docElementSVG =
    '<svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">' +
    '<ellipse cx="150" cy="150" rx="150" ry="100"/>' +
    "</svg>";
  const docElementFront = await inspector.markup.walker.documentElement();

  const onReselected = inspector.markup.once("reselectedonremoved");
  inspector.markup.updateNodeOuterHTML(
    docElementFront,
    docElementSVG,
    currentDocElementOuterHTML
  );
  await onReselected;

  is(
    await getContentPageElementAttribute("svg", "width"),
    "300",
    "<svg> width has been updated"
  );
  is(
    await getContentPageElementAttribute("svg", "height"),
    "300",
    "<svg> height has been updated"
  );
  is(
    await getContentPageElementProperty("svg", "outerHTML"),
    docElementSVG,
    "<svg> markup has been updated"
  );
}