Bug 1399460 - Fix browser_ext_devtools_inspectedWindow_eval_bindings.js failure. r=rpl draft
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 14 Sep 2017 17:59:33 +0200
changeset 665448 273772a99821c875de5b1bd0a616547743ec5117
parent 665447 3d238dc88760667938906b31a8f4ac8adc75fe62
child 665449 3bba7411aec243d8d5530402eae4cbb3bd83ba5a
push id80054
push userbmo:nchevobbe@mozilla.com
push dateFri, 15 Sep 2017 12:06:11 +0000
reviewersrpl
bugs1399460
milestone57.0a1
Bug 1399460 - Fix browser_ext_devtools_inspectedWindow_eval_bindings.js failure. r=rpl The bug was failing because we were calling the server but the connection was already closed. In order to prevent such things, we check the number of nodes of the tree, and if it has only one, then we wait on a mutation that will ensure that server calls are done. MozReview-Commit-ID: 7kHAkYs2I4K
browser/components/extensions/test/browser/browser_ext_devtools_inspectedWindow_eval_bindings.js
--- a/browser/components/extensions/test/browser/browser_ext_devtools_inspectedWindow_eval_bindings.js
+++ b/browser/components/extensions/test/browser/browser_ext_devtools_inspectedWindow_eval_bindings.js
@@ -133,16 +133,44 @@ add_task(async function test_devtools_in
             resolve(m.node);
             jsterm.hud.off("new-messages", onThisMessage);
             return;
           }
         });
       });
       let objectInspectors = [...messageNode.querySelectorAll(".tree")];
       is(objectInspectors.length, 1, "There is the expected number of object inspectors");
+
+      // We need to wait for the object to be expanded so we don't call the server on a closed connection.
+      const [oi] = objectInspectors;
+      let nodes = oi.querySelectorAll(".node");
+
+      ok(nodes.length >= 1, "The object preview is rendered as expected");
+
+      // The tree can still be collapsed since the properties are fetched asynchronously.
+      if (nodes.length === 1) {
+        info("Waiting for the object properties to be displayed");
+        // If this is the case, we wait for the properties to be fetched and displayed.
+        await new Promise(resolve => {
+          const observer = new MutationObserver(mutations => {
+            resolve();
+            observer.disconnect();
+          });
+          observer.observe(oi, {childList: true});
+        });
+
+        // Retrieve the new nodes.
+        nodes = oi.querySelectorAll(".node");
+      }
+
+      // We should have 3 nodes :
+      //   ▼ Object { testkey: "testvalue" }
+      //   |  testkey: "testvalue"
+      //   |  ▶︎ __proto__: Object { … }
+      is(nodes.length, 3, "The object preview has the expected number of nodes");
     } else {
       const options = await new Promise(resolve => {
         jsterm.once("variablesview-open", (evt, view, options) => resolve(options));
       });
 
       const objectType = options.objectActor.type;
       const objectPreviewProperties = options.objectActor.preview.ownProperties;
       is(objectType, "object", "The inspected object has the expected type");