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
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
// Test that inplace editors can be blurred by clicking outside of the editor.
const TEST_URI = `<style>
#div1 {
margin: 10px;
padding: 3px;
}
</style>
<div id="div1"></div>`;
add_task(async function () {
// Make sure the toolbox is tall enough to have empty space below the
// boxmodel-container.
await pushPref("devtools.toolbox.footer.height", 500);
await addTab("data:text/html," + encodeURIComponent(TEST_URI));
const { inspector, boxmodel } = await openLayoutView();
await selectNode("#div1", inspector);
await testClickingOutsideEditor(boxmodel);
await testClickingBelowContainer(boxmodel);
});
async function testClickingOutsideEditor(boxmodel) {
info("Test that clicking outside the editor blurs it");
const span = boxmodel.document.querySelector(
".boxmodel-margin.boxmodel-top > span"
);
await waitForElementTextContent(span, "10");
EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
const editor = boxmodel.document.querySelector(
".styleinspector-propertyeditor"
);
ok(editor, "Should have opened the editor.");
info("Click next to the opened editor input.");
const onBlur = once(editor, "blur");
const rect = editor.getBoundingClientRect();
EventUtils.synthesizeMouse(
editor,
rect.width + 10,
rect.height / 2,
{},
boxmodel.document.defaultView
);
await onBlur;
is(
boxmodel.document.querySelector(".styleinspector-propertyeditor"),
null,
"Inplace editor has been removed."
);
}
async function testClickingBelowContainer(boxmodel) {
info("Test that clicking below the box-model container blurs it");
const span = boxmodel.document.querySelector(
".boxmodel-margin.boxmodel-top > span"
);
await waitForElementTextContent(span, "10");
info(
"Test that clicking below the boxmodel-container blurs the opened editor"
);
EventUtils.synthesizeMouseAtCenter(span, {}, boxmodel.document.defaultView);
const editor = boxmodel.document.querySelector(
".styleinspector-propertyeditor"
);
ok(editor, "Should have opened the editor.");
const onBlur = once(editor, "blur");
const container = boxmodel.document.querySelector(".boxmodel-container");
// Using getBoxQuads here because getBoundingClientRect (and therefore synthesizeMouse)
// use an erroneous height of ~50px for the boxmodel-container.
const bounds = container
.getBoxQuads({ relativeTo: boxmodel.document })[0]
.getBounds();
EventUtils.synthesizeMouseAtPoint(
bounds.left + 10,
bounds.top + bounds.height + 10,
{},
boxmodel.document.defaultView
);
await onBlur;
is(
boxmodel.document.querySelector(".styleinspector-propertyeditor"),
null,
"Inplace editor has been removed."
);
}
|