From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../styleeditor/test/browser_styleeditor_pretty.js | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 devtools/client/styleeditor/test/browser_styleeditor_pretty.js (limited to 'devtools/client/styleeditor/test/browser_styleeditor_pretty.js') diff --git a/devtools/client/styleeditor/test/browser_styleeditor_pretty.js b/devtools/client/styleeditor/test/browser_styleeditor_pretty.js new file mode 100644 index 0000000000..e8208cb7d6 --- /dev/null +++ b/devtools/client/styleeditor/test/browser_styleeditor_pretty.js @@ -0,0 +1,112 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +"use strict"; + +// Test that only minified sheets are automatically prettified, +// and that the pretty print button behaves as expected. + +const TESTCASE_URI = TEST_BASE_HTTP + "minified.html"; + +const PRETTIFIED_CSS_TEXT = ` +body { + background:white; +} +div { + font-size:4em; + color:red +} +span { + color:green; + @media screen { + background: blue; + &>.myClass { + padding: 1em + } + } +} +`.trimStart(); + +const INLINE_STYLESHEET_ORIGINAL_CSS_TEXT = ` +body { background: red; } +div { +font-size: 5em; +color: red; +}`.trimStart(); + +const INLINE_STYLESHEET_PRETTIFIED_CSS_TEXT = ` +body { + background: red; +} +div { + font-size: 5em; + color: red; +} +`.trimStart(); + +add_task(async function () { + // Use 2 spaces for indent + await pushPref("devtools.editor.expandtab", true); + await pushPref("devtools.editor.tabsize", 2); + + const { panel, ui } = await openStyleEditorForURL(TESTCASE_URI); + is(ui.editors.length, 3, "Three sheets present."); + + info("Testing minified style sheet."); + const minifiedEditor = await ui.editors[0].getSourceEditor(); + + is( + minifiedEditor.sourceEditor.getText(), + PRETTIFIED_CSS_TEXT, + "minified source has been prettified automatically" + ); + + info("Selecting second, non-minified style sheet."); + await ui.selectStyleSheet(ui.editors[1].styleSheet); + + const inlineEditor = ui.editors[1]; + is( + inlineEditor.sourceEditor.getText(), + INLINE_STYLESHEET_ORIGINAL_CSS_TEXT, + "non-minified source has been left untouched" + ); + + const prettyPrintButton = panel.panelWindow.document.querySelector( + ".style-editor-prettyPrintButton" + ); + ok(prettyPrintButton, "Pretty print button is displayed"); + ok( + !prettyPrintButton.hasAttribute("disabled"), + "Pretty print button is enabled" + ); + is( + prettyPrintButton.getAttribute("title"), + "Pretty print style sheet", + "Pretty print button has the expected title attribute" + ); + + const onEditorChange = inlineEditor.sourceEditor.once("changes"); + EventUtils.synthesizeMouseAtCenter(prettyPrintButton, {}, panel.panelWindow); + await onEditorChange; + + is( + inlineEditor.sourceEditor.getText(), + INLINE_STYLESHEET_PRETTIFIED_CSS_TEXT, + "inline stylesheet was prettified as expected when clicking on pretty print button" + ); + + info("Selecting original style sheet."); + await ui.selectStyleSheet(ui.editors[2].styleSheet); + ok( + prettyPrintButton.hasAttribute("disabled"), + "Pretty print button is disabled when selecting an original file" + ); + await waitFor( + () => + prettyPrintButton.getAttribute("title") === + "Can only pretty print CSS files" + ); + ok( + true, + "Pretty print button has the expected title attribute when it's disabled" + ); +}); -- cgit v1.2.3