Bug 797404 - Sources which take too long to fetch incorrectly show up after a page refresh, reload-same-script orange fix, r=past
authorVictor Porof <vporof@mozilla.com>
Wed, 03 Oct 2012 23:35:11 +0300
changeset 109266 7129a1d713f43cf7834e07b937cbd31c3a38562d
parent 109265 b3a19d36344ae51b7a7985873a53bf69acbefc4b
child 109267 4cb8f88213f5e8c108103f7f167463bedd798542
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerspast
bugs797404
milestone18.0a1
Bug 797404 - Sources which take too long to fetch incorrectly show up after a page refresh, reload-same-script orange fix, r=past
browser/devtools/debugger/test/browser_dbg_reload-same-script.js
--- a/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
+++ b/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
@@ -165,28 +165,34 @@ function test()
     is(gView.Scripts.selected, scriptShownUrl,
       "The shown script is not the the correct one. (" + step + ")");
   }
 
   function switchScript(index)
   {
     let scriptsView = gView.Scripts;
     let scriptLocations = scriptsView.scriptLocations;
-    info("Available scripts: " + scriptLocations);
 
-    if (scriptLocations.length === 2) {
+    // Poll every few milliseconds until the scripts are retrieved.
+    let count = 0;
+    let intervalID = window.setInterval(function() {
+      dump("count: " + count + " ");
+      if (++count > 50) {
+        ok(false, "Timed out while polling for the scripts.");
+        closeDebuggerAndFinish();
+      }
+      if (scriptLocations.length !== 2) {
+        return;
+      }
+      info("Available scripts: " + scriptLocations);
+
       // We got all the scripts, it's safe to switch.
+      window.clearInterval(intervalID);
       scriptsView.selectScript(scriptLocations[index]);
-      return;
-    }
-
-    window.addEventListener("Debugger:AfterNewScript", function _onEvent(aEvent) {
-      window.removeEventListener(aEvent.type, _onEvent);
-      switchScript(index);
-    });
+    }, 100);
   }
 
   function reloadPage()
   {
     gDebuggee.location.reload();
   }
 
   registerCleanupFunction(function() {