Bug 773732 - After reloading a page, the selected script and line should remain the same. r=robcee
authorVictor Porof <vporof@mozilla.com>
Sat, 25 Aug 2012 17:23:23 +0300
changeset 103464 e11af99c55665e44df7318661f524742a0b8952b
parent 103463 155b4c470d2438790cbfad04c3f78e9b3d143bc9
child 103465 4d6471c1cdd925abdbffc40019df0bba6de833d8
push id13991
push userryanvm@gmail.com
push dateSun, 26 Aug 2012 02:29:03 +0000
treeherdermozilla-inbound@c4f20a024113 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs773732
milestone17.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 773732 - After reloading a page, the selected script and line should remain the same. r=robcee
browser/devtools/debugger/debugger-controller.js
browser/devtools/debugger/debugger-view.js
browser/devtools/debugger/test/Makefile.in
browser/devtools/debugger/test/browser_dbg_reload-same-script.js
--- a/browser/devtools/debugger/debugger-controller.js
+++ b/browser/devtools/debugger/debugger-controller.js
@@ -929,16 +929,22 @@ SourceScripts.prototype = {
 
     // Select this script if it's the preferred one.
     if (aPacket.url === DebuggerView.Scripts.preferredScriptUrl) {
       DebuggerView.Scripts.selectScript(aPacket.url);
     }
     // ..or the first entry if there's not one selected yet.
     else if (!DebuggerView.Scripts.selected) {
       DebuggerView.Scripts.selectIndex(0);
+      // Selecting a script would make it "preferred", which is a lie here,
+      // because we're only displaying a script to make sure there's always
+      // something available in the SourceEditor and the scripts menulist.
+      // Hence the need revert back to the initial preferred script, just
+      // in case it will be available soon.
+      DebuggerView.Scripts.preferredScriptUrl = preferredScriptUrl;
     }
 
     // If there are any stored breakpoints for this script, display them again,
     // both in the editor and the pane.
     for each (let breakpoint in DebuggerController.Breakpoints.store) {
       if (breakpoint.location.url == aPacket.url) {
         DebuggerController.Breakpoints.displayBreakpoint(breakpoint);
       }
--- a/browser/devtools/debugger/debugger-view.js
+++ b/browser/devtools/debugger/debugger-view.js
@@ -962,16 +962,22 @@ ScriptsView.prototype = {
   /**
    * Gets the most recently selected script url.
    * @return string | null
    */
   get preferredScriptUrl()
     this._preferredScriptUrl ? this._preferredScriptUrl : null,
 
   /**
+   * Sets the most recently selected script url.
+   * @param string
+   */
+  set preferredScriptUrl(value) this._preferredScriptUrl = value,
+
+  /**
    * Gets the script in the container having the specified label.
    *
    * @param string aLabel
    *        The label used to identify the script.
    * @return element | null
    *         The matched element, or null if nothing is found.
    */
   getScriptByLabel: function DVS_getScriptByLabel(aLabel) {
--- a/browser/devtools/debugger/test/Makefile.in
+++ b/browser/devtools/debugger/test/Makefile.in
@@ -30,17 +30,17 @@ MOCHITEST_BROWSER_TESTS = \
 	browser_dbg_propertyview-04.js \
 	browser_dbg_propertyview-05.js \
 	browser_dbg_propertyview-06.js \
 	browser_dbg_propertyview-07.js \
 	browser_dbg_propertyview-08.js \
 	browser_dbg_propertyview-09.js \
 	browser_dbg_propertyview-10.js \
 	browser_dbg_propertyview-edit.js \
-	$(warning browser_dbg_reload-same-script.js temporarily disabled due to oranges, see bug 780198 & bug 782179) \
+	browser_dbg_reload-same-script.js \
 	browser_dbg_pane-collapse.js \
 	browser_dbg_panesize.js \
 	browser_dbg_panesize-inner.js \
 	browser_dbg_stack-01.js \
 	browser_dbg_stack-02.js \
 	browser_dbg_stack-03.js \
 	browser_dbg_stack-04.js \
 	browser_dbg_stack-05.js \
--- a/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
+++ b/browser/devtools/debugger/test/browser_dbg_reload-same-script.js
@@ -11,91 +11,149 @@ let gPane = null;
 let gTab = null;
 let gDebuggee = null;
 let gDebugger = null;
 let gView = null;
 
 function test()
 {
   let step = 0;
-  let scriptShown = false;
+  let expectedScript = "";
+  let expectedScriptShown = false;
   let scriptShownUrl = null;
   let resumed = false;
   let testStarted = false;
 
   debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPane = aPane;
     gDebugger = gPane.contentWindow;
     gView = gDebugger.DebuggerView;
     resumed = true;
 
-    executeSoon(startTest);
+    startTest();
   });
 
   function onScriptShown(aEvent)
   {
-    scriptShown = aEvent.detail.url.indexOf("-01.js") != -1;
+    expectedScriptShown = aEvent.detail.url.indexOf("-01.js") != -1;
     scriptShownUrl = aEvent.detail.url;
-    executeSoon(startTest);
+    startTest();
   }
 
   function onUlteriorScriptShown(aEvent)
   {
+    ok(expectedScript,
+      "The expected script to show up should have been specified.");
+
+    info("The expected script for this ScriptShown event is: " + expectedScript);
+    info("The current script for this ScriptShown event is: " + aEvent.detail.url);
+
+    expectedScriptShown = aEvent.detail.url.indexOf(expectedScript) != -1;
     scriptShownUrl = aEvent.detail.url;
-    executeSoon(testScriptShown);
+    testScriptShown();
   }
 
   window.addEventListener("Debugger:ScriptShown", onScriptShown);
 
   function startTest()
   {
-    if (scriptShown && resumed && !testStarted) {
+    if (expectedScriptShown && resumed && !testStarted) {
       window.removeEventListener("Debugger:ScriptShown", onScriptShown);
       window.addEventListener("Debugger:ScriptShown", onUlteriorScriptShown);
       testStarted = true;
       Services.tm.currentThread.dispatch({ run: performTest }, 0);
     }
   }
 
   function finishTest()
   {
-    if (scriptShown && resumed && testStarted) {
+    if (expectedScriptShown && resumed && testStarted) {
       window.removeEventListener("Debugger:ScriptShown", onUlteriorScriptShown);
       closeDebuggerAndFinish();
     }
   }
 
   function performTest()
   {
     testCurrentScript("-01.js", step);
-    step = 1;
+    expectedScript = "-01.js";
     reloadPage();
   }
 
   function testScriptShown()
   {
+    if (!expectedScriptShown) {
+      return;
+    }
+    step++;
+
     if (step === 1) {
       testCurrentScript("-01.js", step);
-      step = 2;
+      expectedScript = "-01.js";
       reloadPage();
     }
     else if (step === 2) {
       testCurrentScript("-01.js", step);
-      step = 3;
+      expectedScript = "-02.js";
       gView.Scripts.selectScript(gView.Scripts.scriptLocations[1]);
     }
     else if (step === 3) {
       testCurrentScript("-02.js", step);
-      step = 4;
+      expectedScript = "-02.js";
       reloadPage();
     }
     else if (step === 4) {
       testCurrentScript("-02.js", step);
+      expectedScript = "-01.js";
+      gView.Scripts.selectScript(gView.Scripts.scriptLocations[0]);
+    }
+    else if (step === 5) {
+      testCurrentScript("-01.js", step);
+      expectedScript = "-01.js";
+      reloadPage();
+    }
+    else if (step === 6) {
+      testCurrentScript("-01.js", step);
+      expectedScript = "-01.js";
+      reloadPage();
+    }
+    else if (step === 7) {
+      testCurrentScript("-01.js", step);
+      expectedScript = "-01.js";
+      reloadPage();
+    }
+    else if (step === 8) {
+      testCurrentScript("-01.js", step);
+      expectedScript = "-02.js";
+      gView.Scripts.selectScript(gView.Scripts.scriptLocations[1]);
+    }
+    else if (step === 9) {
+      testCurrentScript("-02.js", step);
+      expectedScript = "-02.js";
+      reloadPage();
+    }
+    else if (step === 10) {
+      testCurrentScript("-02.js", step);
+      expectedScript = "-02.js";
+      reloadPage();
+    }
+    else if (step === 11) {
+      testCurrentScript("-02.js", step);
+      expectedScript = "-02.js";
+      reloadPage();
+    }
+    else if (step === 12) {
+      testCurrentScript("-02.js", step);
+      expectedScript = "-01.js";
+      gView.Scripts.selectScript(gView.Scripts.scriptLocations[0]);
+    }
+    else if (step === 13) {
+      testCurrentScript("-01.js", step);
       finishTest();
     }
   }
 
   function testCurrentScript(part, step)
   {
     info("Currently preferred script: " + gView.Scripts.preferredScriptUrl);
     info("Currently selected script: " + gView.Scripts.selected);
@@ -105,19 +163,17 @@ function test()
     isnot(gView.Scripts.selected.indexOf(part), -1,
       "The selected script isn't the correct one. (" + step + ")");
     is(gView.Scripts.selected, scriptShownUrl,
       "The shown script is not the the correct one. (" + step + ")");
   }
 
   function reloadPage()
   {
-    executeSoon(function() {
-      gDebuggee.location.reload();
-    });
+    gDebuggee.location.reload();
   }
 
   registerCleanupFunction(function() {
     removeTab(gTab);
     gPane = null;
     gTab = null;
     gDebuggee = null;
     gDebugger = null;