summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_tag_edit_07.js
blob: 38f7361725c0bdea90a47055026ecb7655b457ea (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from helper_attributes_test_runner.js */
"use strict";

// One more test testing various add-attributes configurations
// Some of the test data below asserts that long attributes get collapsed

loadHelperScript("helper_attributes_test_runner.js");

/*eslint-disable */
const LONG_ATTRIBUTE =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const LONG_ATTRIBUTE_COLLAPSED =
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEF\u2026UVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const DATA_URL_INLINE_STYLE =
  'color: red; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC");';
const DATA_URL_INLINE_STYLE_COLLAPSED =
  'color: red; background: url("data:image/png;base64,iVBORw0KG\u2026NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC");';
const DATA_URL_ATTRIBUTE =
  "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC";
const DATA_URL_ATTRIBUTE_COLLAPSED =
  "data:image/png;base64,iVBORw0K\u20269/AFGGFyjOXZtQAAAAAElFTkSuQmCC";
/* eslint-enable */

var TEST_URL = "data:text/html,<div>markup-view attributes addition test</div>";
var TEST_DATA = [
  {
    desc: "Add an attribute value containing < > &uuml; \" & '",
    text: "src=\"somefile.html?param1=<a>&param2=&uuml;&param3='&quot;'\"",
    expectedAttributes: {
      src: "somefile.html?param1=<a>&param2=\xfc&param3='\"'",
    },
  },
  {
    desc: "Add an attribute by clicking the empty space after a node",
    text: 'class="newclass" style="color:green"',
    expectedAttributes: {
      class: "newclass",
      style: "color:green",
    },
  },
  {
    desc:
      'Try add an attribute containing a quote (") attribute by ' +
      "clicking the empty space after a node - this should result " +
      "in it being set to an empty string",
    text: 'class="newclass" style="""',
    expectedAttributes: {
      class: "newclass",
      style: "",
    },
  },
  {
    desc:
      "Try to add long data URL to make sure it is collapsed in attribute " +
      "editor.",
    text: `style='${DATA_URL_INLINE_STYLE}'`,
    expectedAttributes: {
      style: DATA_URL_INLINE_STYLE,
    },
    validate: (container, inspector) => {
      const editor = container.editor;
      const visibleAttrText = editor.attrElements
        .get("style")
        .querySelector(".attr-value").textContent;
      is(visibleAttrText, DATA_URL_INLINE_STYLE_COLLAPSED);
    },
  },
  {
    desc:
      "Try to add long attribute to make sure it is collapsed in attribute " +
      "editor.",
    text: `data-long="${LONG_ATTRIBUTE}"`,
    expectedAttributes: {
      "data-long": LONG_ATTRIBUTE,
    },
    validate: (container, inspector) => {
      const editor = container.editor;
      const visibleAttrText = editor.attrElements
        .get("data-long")
        .querySelector(".attr-value").textContent;
      is(visibleAttrText, LONG_ATTRIBUTE_COLLAPSED);
    },
  },
  {
    desc:
      "Try to add long data URL to make sure it is collapsed in attribute " +
      "editor.",
    text: `src="${DATA_URL_ATTRIBUTE}"`,
    expectedAttributes: {
      src: DATA_URL_ATTRIBUTE,
    },
    validate: (container, inspector) => {
      const editor = container.editor;
      const visibleAttrText = editor.attrElements
        .get("src")
        .querySelector(".attr-value").textContent;
      is(visibleAttrText, DATA_URL_ATTRIBUTE_COLLAPSED);
    },
  },
  {
    desc:
      "Try to add long attribute with collapseAttributes == false" +
      "to make sure it isn't collapsed in attribute editor.",
    text: `data-long="${LONG_ATTRIBUTE}"`,
    expectedAttributes: {
      "data-long": LONG_ATTRIBUTE,
    },
    setUp(inspector) {
      Services.prefs.setBoolPref("devtools.markup.collapseAttributes", false);
    },
    validate: (container, inspector) => {
      const editor = container.editor;
      const visibleAttrText = editor.attrElements
        .get("data-long")
        .querySelector(".attr-value").textContent;
      is(visibleAttrText, LONG_ATTRIBUTE);
    },
    tearDown(inspector) {
      Services.prefs.clearUserPref("devtools.markup.collapseAttributes");
    },
  },
  {
    desc: "Try to collapse attributes with collapseAttributeLength == 5",
    text: `data-long="${LONG_ATTRIBUTE}"`,
    expectedAttributes: {
      "data-long": LONG_ATTRIBUTE,
    },
    setUp(inspector) {
      Services.prefs.setIntPref("devtools.markup.collapseAttributeLength", 2);
    },
    validate: (container, inspector) => {
      const firstChar = LONG_ATTRIBUTE[0];
      const lastChar = LONG_ATTRIBUTE[LONG_ATTRIBUTE.length - 1];
      const collapsed = firstChar + "\u2026" + lastChar;
      const editor = container.editor;
      const visibleAttrText = editor.attrElements
        .get("data-long")
        .querySelector(".attr-value").textContent;
      is(visibleAttrText, collapsed);
    },
    tearDown(inspector) {
      Services.prefs.clearUserPref("devtools.markup.collapseAttributeLength");
    },
  },
];

add_task(async function () {
  const { inspector } = await openInspectorForURL(TEST_URL);
  await runAddAttributesTests(TEST_DATA, "div", inspector);
});