Bug 1597046 - addressing the revision. r=sebo
authorTanny_m <tanmaya.march@gmail.com>
Tue, 10 Dec 2019 21:54:05 +0000
changeset 515623 c25ed6f634e7e932fe2bb6cee0421843151fd21a
parent 515622 0860e1962a65de21b11eca29bb1aeac098e9210f
child 515624 2fb440de0e0c5d104296309fd1cf207ddff14aec
push id37159
push useropoprus@mozilla.com
push dateWed, 26 Feb 2020 16:25:51 +0000
treeherdermozilla-central@94c8f28a15e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebo
bugs1597046
milestone75.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1597046 - addressing the revision. r=sebo Differential Revision: https://phabricator.services.mozilla.com/D55384
devtools/server/actors/highlighters/utils/markup.js
devtools/server/tests/browser/browser_canvasframe_helper_01.js
--- a/devtools/server/actors/highlighters/utils/markup.js
+++ b/devtools/server/actors/highlighters/utils/markup.js
@@ -70,21 +70,30 @@ ClassList.prototype = {
   remove(token) {
     const index = this[_tokens].indexOf(token);
 
     if (index > -1) {
       this[_tokens].splice(index, 1);
     }
     EventEmitter.emit(this, "update");
   },
-  toggle(token) {
-    if (this.contains(token)) {
+  toggle(token, force) {
+    // If force parameter undefined retain the toggle behavior
+    if (force === undefined) {
+      if (this.contains(token)) {
+        this.remove(token);
+      } else {
+        this.add(token);
+      }
+    } else if (force) {
+      // If force is true, enforce token addition
+      this.add(token);
+    } else {
+      // If force is falsy value, enforce token removal
       this.remove(token);
-    } else {
-      this.add(token);
     }
   },
   get length() {
     return this[_tokens].length;
   },
   [Symbol.iterator]: function*() {
     for (let i = 0; i < this.tokens.length; i++) {
       yield this[_tokens][i];
--- a/devtools/server/tests/browser/browser_canvasframe_helper_01.js
+++ b/devtools/server/tests/browser/browser_canvasframe_helper_01.js
@@ -104,16 +104,54 @@ add_task(async function() {
       "The ID attribute was retrieve correctly"
     );
     is(
       el.getAttribute("class"),
       "child-element",
       "The class attribute was retrieve correctly"
     );
 
+    info("Test the toggle API");
+    el.classList.toggle("test"); // This will set the class
+    is(
+      el.getAttribute("class"),
+      "child-element test",
+      "After toggling the class 'test', the class attribute contained the 'test' class"
+    );
+    el.classList.toggle("test"); // This will remove the class
+    is(
+      el.getAttribute("class"),
+      "child-element",
+      "After toggling the class 'test' again, the class attribute removed the 'test' class"
+    );
+    el.classList.toggle("test", true); // This will set the class
+    is(
+      el.getAttribute("class"),
+      "child-element test",
+      "After toggling the class 'test' again and keeping force=true, the class attribute added the 'test' class"
+    );
+    el.classList.toggle("test", true); // This will keep the class set
+    is(
+      el.getAttribute("class"),
+      "child-element test",
+      "After toggling the class 'test' again and keeping force=true,the class attribute contained the 'test' class"
+    );
+    el.classList.toggle("test", false); // This will remove the class
+    is(
+      el.getAttribute("class"),
+      "child-element",
+      "After toggling the class 'test' again and keeping force=false, the class attribute removed the 'test' class"
+    );
+    el.classList.toggle("test", false); // This will keep the class removed
+    is(
+      el.getAttribute("class"),
+      "child-element",
+      "After toggling the class 'test' again and keeping force=false, the class attribute removed the 'test' class"
+    );
+
     info("Destroying the helper");
     helper.destroy();
     env.destroy();
 
     ok(
       !helper.getTextContentForElement("child-element"),
       "No text content was retrieved after the helper was destroyed"
     );