summaryrefslogtreecommitdiff
path: root/devtools/client
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-05-14 12:22:48 +0000
committerMoonchild <moonchild@palemoon.org>2022-05-14 12:22:48 +0000
commit5338dcd13292cf25ee3a1a3626838b6b03300978 (patch)
tree581fc71c6627da420c4298353e738613769102a6 /devtools/client
parenta9d3c2b52aa320c7d31d27bd182574baaf672299 (diff)
downloaduxp-5338dcd13292cf25ee3a1a3626838b6b03300978.tar.gz
Issue #1899 - Make sure the test for it still works
Some hoops to make sure the test still works if the default value for the pref is false, requiring setting and resetting it and making sure the observers have time to react to these changes before testing.
Diffstat (limited to 'devtools/client')
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-01.js43
-rw-r--r--devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-03.js4
2 files changed, 45 insertions, 2 deletions
diff --git a/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-01.js b/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-01.js
index 6fd8fb8150..00582bbe1d 100644
--- a/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-01.js
+++ b/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-01.js
@@ -20,6 +20,11 @@
* code by having a tag called "padding" and a property
* value called "margin".
*/
+
+const { PrefObserver } = require("devtools/client/shared/prefs");
+const PREF_ENABLE_MDN_DOCS_TOOLTIP =
+ "devtools.inspector.mdnDocsTooltip.enabled";
+
const TEST_URI = `
<html>
<head>
@@ -35,13 +40,51 @@ const TEST_URI = `
`;
add_task(function* () {
+ info("Ensure the pref is true to begin with");
+ let initial = Services.prefs.getBoolPref(PREF_ENABLE_MDN_DOCS_TOOLTIP);
+ if (initial != true) {
+ yield setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, true);
+ }
+
yield addTab("data:text/html;charset=utf8," + encodeURIComponent(TEST_URI));
let {inspector, view} = yield openRuleView();
yield selectNode("padding", inspector);
yield testMdnContextMenuItemVisibility(view);
+
+ info("Ensure the pref is reset to its initial value");
+ let eventual = Services.prefs.getBoolPref(PREF_ENABLE_MDN_DOCS_TOOLTIP);
+ if (eventual != initial) {
+ yield setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, initial);
+ }
});
/**
+ * Set a boolean pref, and wait for the pref observer to
+ * trigger, so that code listening for the pref change
+ * has had a chance to update itself.
+ *
+ * @param pref {string} Name of the pref to change
+ * @param state {boolean} Desired value of the pref.
+ *
+ * Note that if the pref already has the value in `state`,
+ * then the prefObserver will not trigger. So you should only
+ * call this function if you know the pref's current value is
+ * not `state`.
+ */
+function* setBooleanPref(pref, state) {
+ let oncePrefChanged = defer();
+ let prefObserver = new PrefObserver("devtools.");
+ prefObserver.on(pref, oncePrefChanged.resolve);
+
+ info("Set the pref " + pref + " to: " + state);
+ Services.prefs.setBoolPref(pref, state);
+
+ info("Wait for prefObserver to call back so the UI can update");
+ yield oncePrefChanged.promise;
+ prefObserver.off(pref, oncePrefChanged.resolve);
+}
+
+/**
* Tests that the MDN context menu item is shown when it should be,
* and hidden when it should be.
* - iterate through every node in the rule view
diff --git a/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-03.js b/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-03.js
index ac5f636a20..eb1527d7b9 100644
--- a/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-03.js
+++ b/devtools/client/inspector/rules/test/browser_rules_context-menu-show-mdn-docs-03.js
@@ -32,7 +32,7 @@ add_task(function* () {
info("Ensure the pref is true to begin with");
let initial = Services.prefs.getBoolPref(PREF_ENABLE_MDN_DOCS_TOOLTIP);
if (initial != true) {
- setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, true);
+ yield setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, true);
}
yield addTab("data:text/html;charset=utf8," + encodeURIComponent(TEST_DOC));
@@ -58,7 +58,7 @@ add_task(function* () {
info("Ensure the pref is reset to its initial value");
let eventual = Services.prefs.getBoolPref(PREF_ENABLE_MDN_DOCS_TOOLTIP);
if (eventual != initial) {
- setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, initial);
+ yield setBooleanPref(PREF_ENABLE_MDN_DOCS_TOOLTIP, initial);
}
});