forked from mirrors/gecko-dev
Bug 1874711 - [devtools] Fix browser_styleeditor_init.js intermittent. r=devtools-reviewers,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D210699
This commit is contained in:
parent
ce181d5c3d
commit
383cbdab66
4 changed files with 23 additions and 31 deletions
|
|
@ -24,11 +24,11 @@ add_task(async function () {
|
|||
const { ui } = await openStyleEditorForURL(TESTCASE_URI);
|
||||
|
||||
is(ui.editors.length, 2, "The UI contains two style sheets.");
|
||||
checkSheet(ui.editors[0], EXPECTED_SHEETS[0]);
|
||||
checkSheet(ui.editors[1], EXPECTED_SHEETS[1]);
|
||||
await checkSheet(ui.editors[0], EXPECTED_SHEETS[0]);
|
||||
await checkSheet(ui.editors[1], EXPECTED_SHEETS[1]);
|
||||
});
|
||||
|
||||
function checkSheet(editor, expected) {
|
||||
async function checkSheet(editor, expected) {
|
||||
is(
|
||||
editor.styleSheet.styleSheetIndex,
|
||||
expected.sheetIndex,
|
||||
|
|
@ -41,8 +41,7 @@ function checkSheet(editor, expected) {
|
|||
.getAttribute("value");
|
||||
ok(expected.name.test(name), "The name '" + name + "' is correct.");
|
||||
|
||||
const ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
|
||||
is(parseInt(ruleCount, 10), expected.rules, "the rule count is correct");
|
||||
await assertRuleCount(editor, expected.rules);
|
||||
|
||||
is(
|
||||
summary.classList.contains("splitview-active"),
|
||||
|
|
|
|||
|
|
@ -59,14 +59,7 @@ async function checkSheet(editor, expected) {
|
|||
.getAttribute("value");
|
||||
ok(expected.name.test(name), "The name '" + name + "' is correct.");
|
||||
|
||||
// The rule count is displayed via l10n.setArgs which only applies the value
|
||||
// asynchronously, so wait for it to be applied.
|
||||
await waitFor(() => {
|
||||
const count = summary.querySelector(".stylesheet-rule-count").textContent;
|
||||
return parseInt(count, 10) === expected.rules;
|
||||
});
|
||||
const ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
|
||||
is(parseInt(ruleCount, 10), expected.rules, "the rule count is correct");
|
||||
await assertRuleCount(editor, expected.rules);
|
||||
|
||||
is(
|
||||
summary.classList.contains("splitview-active"),
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ function onPropertyChange(editor) {
|
|||
async function testInitialState(editor) {
|
||||
info("Testing the initial state of the new editor");
|
||||
|
||||
let summary = editor.summary;
|
||||
|
||||
ok(editor.sourceLoaded, "new editor is loaded when attached");
|
||||
ok(editor.isNew, "new editor has isNew flag");
|
||||
|
||||
|
|
@ -51,9 +49,7 @@ async function testInitialState(editor) {
|
|||
}
|
||||
ok(editor.sourceEditor.hasFocus(), "new editor has focus");
|
||||
|
||||
summary = editor.summary;
|
||||
const ruleCount = summary.querySelector(".stylesheet-rule-count").textContent;
|
||||
is(parseInt(ruleCount, 10), 0, "new editor initially shows 0 rules");
|
||||
await assertRuleCount(editor, 0);
|
||||
|
||||
const color = await getComputedStyleProperty({
|
||||
selector: "body",
|
||||
|
|
@ -88,19 +84,7 @@ async function testUpdated(editor, originalHref) {
|
|||
"rule bracket has been auto-closed"
|
||||
);
|
||||
|
||||
const count = await waitFor(() => {
|
||||
const int = parseInt(
|
||||
editor.summary.querySelector(".stylesheet-rule-count").textContent,
|
||||
10
|
||||
);
|
||||
if (int == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return int;
|
||||
});
|
||||
|
||||
is(count, 1, "new editor shows 1 rule after modification");
|
||||
await assertRuleCount(editor, 1);
|
||||
|
||||
is(editor.styleSheet.href, originalHref, "style sheet href did not change");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,3 +199,19 @@ function getRootElement(panel) {
|
|||
function getContextMenuElement(panel) {
|
||||
return panel.panelWindow.document.getElementById("sidebar-context");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the number of rules displayed in UI
|
||||
*
|
||||
* @param {StyleSheetEditor} editor
|
||||
* @param {Number} expected
|
||||
*/
|
||||
async function assertRuleCount(editor, expected) {
|
||||
// The rule count is displayed via l10n.setArgs which only applies the value
|
||||
// asynchronously, so wait for it to be applied.
|
||||
const element = editor.summary.querySelector(".stylesheet-rule-count");
|
||||
await waitFor(() => {
|
||||
return parseInt(element.textContent, 10) === expected;
|
||||
});
|
||||
is(parseInt(element.textContent, 10), expected, "the rule count is correct");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue