Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #388 from ochameau/bug/685929-fix-widget-positions

fix Bug 685929 - Multiple widgets position in same toolbar not persistent after restart r=@gozala
  • Loading branch information...
commit 778701a9400151df2115238d8c2d64500e5467be 2 parents 038ac8b + 1430b71
Irakli Gozalishvili authored March 27, 2012
15  packages/addon-kit/lib/widget.js
@@ -640,11 +640,16 @@ BrowserWindow.prototype = {
640 640
     
641 641
     // Finally insert our widget in the right toolbar and in the right position
642 642
     container.insertItem(id, nextNode, null, false);
643  
-    
644  
-    // Update DOM in order to save position if we remove/readd the widget
645  
-    container.setAttribute("currentset", container.currentSet);
646  
-    // Save DOM attribute in order to save position on new window opened
647  
-    this.window.document.persist(container.id, "currentset");
  643
+
  644
+    // Update DOM in order to save position: which toolbar, and which position 
  645
+    // in this toolbar. But only do this the first time we add it to the toolbar
  646
+    // Otherwise, this code will collide with other instance of Widget module
  647
+    // during Firefox startup. See bug 685929.
  648
+    if (ids.indexOf(id) == -1) {
  649
+      container.setAttribute("currentset", container.currentSet);
  650
+      // Save DOM attribute in order to save position on new window opened
  651
+      this.window.document.persist(container.id, "currentset");
  652
+    }
648 653
   }
649 654
 }
650 655
 
62  packages/addon-kit/tests/test-widget.js
@@ -6,16 +6,13 @@
6 6
 
7 7
 const {Cc,Ci} = require("chrome");
8 8
 const { Loader } = require('./helpers');
  9
+const widgets = require("widget");
  10
+const url = require("url");
  11
+const windowUtils = require("window-utils");
  12
+const tabBrowser = require("tab-browser");
9 13
 
10 14
 exports.testConstructor = function(test) {
11  
-
12  
-  const tabBrowser = require("tab-browser");
13  
-
14 15
   test.waitUntilDone(30000);
15  
-  
16  
-  const widgets = require("widget");
17  
-  const url = require("url");
18  
-  const windowUtils = require("window-utils");
19 16
 
20 17
   let browserWindow = windowUtils.activeBrowserWindow;
21 18
   let doc = browserWindow.document;
@@ -925,6 +922,57 @@ exports.testWidgetWithPound = function testWidgetWithPound(test) {
925 922
   });
926 923
 };
927 924
 
  925
+exports.testNavigationBarWidgets = function testNavigationBarWidgets(test) {
  926
+  test.waitUntilDone();
  927
+
  928
+  let w1 = widgets.Widget({id: "1st", label: "1st widget", content: "1"});
  929
+  let w2 = widgets.Widget({id: "2nd", label: "2nd widget", content: "2"});
  930
+  let w3 = widgets.Widget({id: "3rd", label: "3rd widget", content: "3"});
  931
+
  932
+  // Hack to move 2nd and 3rd widgets manually to the navigation bar, in 5th
  933
+  // position, i.e. after search box. 3rd widget will be in 5th and 2nd in 6th.
  934
+  function getWidgetNode(toolbar, position) {
  935
+    return toolbar.getElementsByTagName("toolbaritem")[position];
  936
+  }
  937
+  let browserWindow = windowUtils.activeBrowserWindow;
  938
+  let doc = browserWindow.document;
  939
+  let addonBar = doc.getElementById("addon-bar");
  940
+  let w2Toolbaritem = getWidgetNode(addonBar, 1);
  941
+  let w3ToolbarItem = getWidgetNode(addonBar, 2);
  942
+  let navBar = doc.getElementById("nav-bar");
  943
+  navBar.insertItem(w2Toolbaritem.id, navBar.childNodes[6], null, false);
  944
+  navBar.insertItem(w3ToolbarItem.id, navBar.childNodes[6], null, false);
  945
+  // Widget and Firefox codes rely on this `currentset` attribute,
  946
+  // so ensure it is correctly saved
  947
+  navBar.setAttribute("currentset", navBar.currentSet);
  948
+  doc.persist(navBar.id, "currentset");
  949
+  // Update addonbar too as we removed widget from there.
  950
+  // Otherwise, widgets may still be added to this toolbar.
  951
+  addonBar.setAttribute("currentset", addonBar.currentSet);
  952
+  doc.persist(addonBar.id, "currentset");
  953
+
  954
+  tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
  955
+    let browserWindow = e.target.defaultView;
  956
+    let doc = browserWindow.document;
  957
+    let navBar = doc.getElementById("nav-bar");
  958
+    let addonBar = doc.getElementById("addon-bar");
  959
+
  960
+    // Ensure that 1st is in addon bar
  961
+    test.assertEqual(getWidgetNode(addonBar, 0).getAttribute("label"), w1.label);
  962
+    // And that 2nd and 3rd keep their original positions in navigation bar
  963
+    test.assertEqual(navBar.childNodes[5].getAttribute("label"), w3.label);
  964
+    test.assertEqual(navBar.childNodes[6].getAttribute("label"), w2.label);
  965
+
  966
+    w1.destroy();
  967
+    w2.destroy();
  968
+    w3.destroy();
  969
+
  970
+    closeBrowserWindow(browserWindow, function() {
  971
+      test.done();
  972
+    });
  973
+  }});
  974
+};
  975
+
928 976
 /******************* helpers *********************/
929 977
 
930 978
 // Helper for calling code at window close

0 notes on commit 778701a

Please sign in to comment.
Something went wrong with that request. Please try again.