Bug 705731 - Create InspectorUI.notifications.DESTROYED notification; r=prouget
authorRob Campbell <rcampbell@mozilla.com>
Wed, 07 Dec 2011 10:38:41 -0400
changeset 83820 cc69fe7c9f265ffe93256f83c5e142b740b9fa23
parent 83819 bb8169ddc939e8f233f3cd8a43189f8d452b2833
child 83821 6785d3003414c46f93e3d79096bbe2de07772075
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersprouget
bugs705731
milestone11.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 705731 - Create InspectorUI.notifications.DESTROYED notification; r=prouget
browser/devtools/highlighter/inspector.jsm
browser/devtools/highlighter/test/browser_inspector_initialization.js
--- a/browser/devtools/highlighter/inspector.jsm
+++ b/browser/devtools/highlighter/inspector.jsm
@@ -75,16 +75,19 @@ const INSPECTOR_NOTIFICATIONS = {
 
   // Fires once the Inspector completes the initialization and opens up on
   // screen.
   OPENED: "inspector-opened",
 
   // Fires once the Inspector is closed.
   CLOSED: "inspector-closed",
 
+  // Fires once the Inspector is destroyed. Not fired on tab switch.
+  DESTROYED: "inspector-destroyed",
+
   // Fires when the Inspector is reopened after tab-switch.
   STATE_RESTORED: "inspector-state-restored",
 
   // Fires when the Tree Panel is opened and initialized.
   TREEPANELREADY: "inspector-treepanel-ready",
 
   // Fires when the CSS Rule View is opened and initialized.
   RULEVIEWREADY: "inspector-ruleview-ready",
@@ -1041,16 +1044,18 @@ InspectorUI.prototype = {
     // highlighter/HTML panel dismisses the editor
     if (this.treePanel && this.treePanel.editingContext)
       this.treePanel.closeEditor();
 
     if (this.closing || !this.win || !this.browser) {
       return;
     }
 
+    let winId = new String(this.winID); // retain this to notify observers.
+
     this.closing = true;
     this.toolbar.hidden = true;
 
     this.progressListener.destroy();
     delete this.progressListener;
 
     if (!aKeepStore) {
       this.store.deleteStore(this.winID);
@@ -1099,16 +1104,18 @@ InspectorUI.prototype = {
     this.selection = null;
     this.closing = false;
     this.isDirty = false;
 
     delete this.treePanel;
     delete this.stylePanel;
     delete this.toolbar;
     Services.obs.notifyObservers(null, INSPECTOR_NOTIFICATIONS.CLOSED, null);
+    if (!aKeepStore)
+      Services.obs.notifyObservers(null, INSPECTOR_NOTIFICATIONS.DESTROYED, winId);
   },
 
   /**
    * Begin inspecting webpage, attach page event listeners, activate
    * highlighter event listeners.
    */
   startInspecting: function IUI_startInspecting()
   {
--- a/browser/devtools/highlighter/test/browser_inspector_initialization.js
+++ b/browser/devtools/highlighter/test/browser_inspector_initialization.js
@@ -34,16 +34,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 let doc;
 let salutation;
 let closing;
+let winId;
 
 function createDocument()
 {
   doc.body.innerHTML = '<div id="first" style="{ margin: 10em; ' +
     'font-size: 14pt; font-family: helvetica, sans-serif; color: #AAA}">\n' +
     '<h1>Some header text</h1>\n' +
     '<p id="salutation" style="{font-size: 12pt}">hi.</p>\n' +
     '<p id="body" style="{font-size: 12pt}">I am a test-case. This text exists ' +
@@ -177,45 +178,48 @@ function inspectNodesFromContextTestWhil
   ok(closing, "we have the closing statement");
   executeSoon(function() {
     InspectorUI.openInspectorUI(closing);
   });
 }
 
 function inspectNodesFromContextTestHighlight()
 {
+  winId = InspectorUI.winID;
   Services.obs.removeObserver(inspectNodesFromContextTestHighlight, InspectorUI.INSPECTOR_NOTIFICATIONS.HIGHLIGHTING);
-  Services.obs.addObserver(finishInspectorTests, InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED, false);
+  Services.obs.addObserver(finishInspectorTests, InspectorUI.INSPECTOR_NOTIFICATIONS.DESTROYED, false);
   is(InspectorUI.selection, closing, "InspectorUI.selection is header");
   executeSoon(function() {
-    InspectorUI.closeInspectorUI(true);
+    InspectorUI.closeInspectorUI();
   });
 }
 
 function inspectNodesFromContextTestTrap()
 {
   Services.obs.removeObserver(inspectNodesFromContextTestTrap, InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED);
   ok(false, "Inspector UI has been opened again. We Should Not Be Here!");
 }
 
-function finishInspectorTests()
+function finishInspectorTests(subject, topic, aWinIdString)
 {
   Services.obs.removeObserver(finishInspectorTests,
-    InspectorUI.INSPECTOR_NOTIFICATIONS.CLOSED);
+    InspectorUI.INSPECTOR_NOTIFICATIONS.DESTROYED);
 
+  is(parseInt(aWinIdString), winId, "winId of destroyed Inspector matches");
   ok(!InspectorUI.highlighter, "Highlighter is gone");
   ok(!InspectorUI.treePanel, "Inspector Tree Panel is closed");
   ok(!InspectorUI.inspecting, "Inspector is not inspecting");
   ok(!InspectorUI.isSidebarOpen, "Inspector Sidebar is closed");
   ok(!InspectorUI.stylePanel, "Inspector Style Panel is gone");
   ok(!InspectorUI.ruleView, "Inspector Rule View is gone");
   is(InspectorUI.sidebarToolbar.children.length, 0, "No items in the Sidebar toolbar");
   is(InspectorUI.sidebarDeck.children.length, 0, "No items in the Sidebar deck");
   ok(!InspectorUI.toolbar, "toolbar is hidden");
 
+  Services.obs.removeObserver(inspectNodesFromContextTestTrap, InspectorUI.INSPECTOR_NOTIFICATIONS.OPENED);
   gBrowser.removeCurrentTab();
   finish();
 }
 
 function test()
 {
   waitForExplicitFinish();
   ignoreAllUncaughtExceptions();