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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Tests saving presets
const {
CSSFilterEditorWidget,
} = require("resource://devtools/client/shared/widgets/FilterWidget.js");
const TEST_URI = CHROME_URL_ROOT + "doc_filter-editor-01.html";
add_task(async function () {
const { doc } = await createHost("bottom", TEST_URI);
const container = doc.querySelector("#filter-container");
const widget = new CSSFilterEditorWidget(container, "none");
// First render
await widget.once("render");
const VALUE = "blur(2px) contrast(150%)";
const NAME = "Test";
await showFilterPopupPresetsAndCreatePreset(widget, NAME, VALUE);
const preset = widget.el.querySelector(".preset");
is(
preset.querySelector("label").textContent,
NAME,
"Should show preset name correctly"
);
is(
preset.querySelector("span").textContent,
VALUE,
"Should show preset value preview correctly"
);
let list = await widget.getPresets();
const input = widget.el.querySelector(".presets-list .footer input");
let data = list[0];
is(data.name, NAME, "Should add the preset to asyncStorage - name property");
is(
data.value,
VALUE,
"Should add the preset to asyncStorage - name property"
);
info("Test overriding preset by using the same name");
const VALUE_2 = "saturate(50%) brightness(10%)";
widget.setCssValue(VALUE_2);
await savePreset(widget);
is(
widget.el.querySelectorAll(".preset").length,
1,
"Should override the preset with the same name - render"
);
list = await widget.getPresets();
data = list[0];
is(
list.length,
1,
"Should override the preset with the same name - asyncStorage"
);
is(
data.name,
NAME,
"Should override the preset with the same name - prop name"
);
is(
data.value,
VALUE_2,
"Should override the preset with the same name - prop value"
);
await widget.setPresets([]);
info("Test saving a preset without name");
input.value = "";
await savePreset(widget, "preset-save-error");
list = await widget.getPresets();
is(list.length, 0, "Should not add a preset without name");
info("Test saving a preset without filters");
input.value = NAME;
widget.setCssValue("none");
await savePreset(widget, "preset-save-error");
list = await widget.getPresets();
is(list.length, 0, "Should not add a preset without filters (value: none)");
});
/**
* Call savePreset on widget and wait for the specified event to emit
* @param {CSSFilterWidget} widget
* @param {string} expectEvent="render" The event to listen on
* @return {Promise}
*/
function savePreset(widget, expectEvent = "render") {
const onEvent = widget.once(expectEvent);
widget._savePreset({
preventDefault: () => {},
});
return onEvent;
}
|