summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_pretty.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /devtools/client/styleeditor/test/browser_styleeditor_pretty.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/styleeditor/test/browser_styleeditor_pretty.js')
-rw-r--r--devtools/client/styleeditor/test/browser_styleeditor_pretty.js112
1 files changed, 112 insertions, 0 deletions
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"
+ );
+});