Bug 1399460 - Fix browser_ext_devtools_inspectedWindow_eval_bindings.js failure. r=rpl
authorNicolas Chevobbe <nchevobbe@mozilla.com>
Thu, 14 Sep 2017 17:59:33 +0200
changeset 665590 e7d1f0e04aaef260f2acd9f998eacf245ea2c363
parent 665589 0f78304723803b6debe7f5cfacf5ad4cd45390d6
child 665591 8b0058e2a4a8a123e09470b7ee975963be88a158
push id80115
push userbmo:eoger@fastmail.com
push dateFri, 15 Sep 2017 18:29:01 +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");