Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 685929 - Multiple widgets position in same toolbar not persistent…
Browse files Browse the repository at this point in the history
… after restart
  • Loading branch information
ochameau committed Mar 27, 2012
1 parent 038ac8b commit 1430b71
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
15 changes: 10 additions & 5 deletions packages/addon-kit/lib/widget.js
Expand Up @@ -640,11 +640,16 @@ BrowserWindow.prototype = {

// Finally insert our widget in the right toolbar and in the right position
container.insertItem(id, nextNode, null, false);

// Update DOM in order to save position if we remove/readd the widget
container.setAttribute("currentset", container.currentSet);
// Save DOM attribute in order to save position on new window opened
this.window.document.persist(container.id, "currentset");

// Update DOM in order to save position: which toolbar, and which position
// in this toolbar. But only do this the first time we add it to the toolbar
// Otherwise, this code will collide with other instance of Widget module
// during Firefox startup. See bug 685929.
if (ids.indexOf(id) == -1) {
container.setAttribute("currentset", container.currentSet);
// Save DOM attribute in order to save position on new window opened
this.window.document.persist(container.id, "currentset");
}
}
}

Expand Down
62 changes: 55 additions & 7 deletions packages/addon-kit/tests/test-widget.js
Expand Up @@ -6,16 +6,13 @@

const {Cc,Ci} = require("chrome");
const { Loader } = require('./helpers');
const widgets = require("widget");
const url = require("url");
const windowUtils = require("window-utils");
const tabBrowser = require("tab-browser");

exports.testConstructor = function(test) {

const tabBrowser = require("tab-browser");

test.waitUntilDone(30000);

const widgets = require("widget");
const url = require("url");
const windowUtils = require("window-utils");

let browserWindow = windowUtils.activeBrowserWindow;
let doc = browserWindow.document;
Expand Down Expand Up @@ -925,6 +922,57 @@ exports.testWidgetWithPound = function testWidgetWithPound(test) {
});
};

exports.testNavigationBarWidgets = function testNavigationBarWidgets(test) {
test.waitUntilDone();

let w1 = widgets.Widget({id: "1st", label: "1st widget", content: "1"});
let w2 = widgets.Widget({id: "2nd", label: "2nd widget", content: "2"});
let w3 = widgets.Widget({id: "3rd", label: "3rd widget", content: "3"});

// Hack to move 2nd and 3rd widgets manually to the navigation bar, in 5th
// position, i.e. after search box. 3rd widget will be in 5th and 2nd in 6th.
function getWidgetNode(toolbar, position) {
return toolbar.getElementsByTagName("toolbaritem")[position];
}
let browserWindow = windowUtils.activeBrowserWindow;
let doc = browserWindow.document;
let addonBar = doc.getElementById("addon-bar");
let w2Toolbaritem = getWidgetNode(addonBar, 1);
let w3ToolbarItem = getWidgetNode(addonBar, 2);
let navBar = doc.getElementById("nav-bar");
navBar.insertItem(w2Toolbaritem.id, navBar.childNodes[6], null, false);
navBar.insertItem(w3ToolbarItem.id, navBar.childNodes[6], null, false);
// Widget and Firefox codes rely on this `currentset` attribute,
// so ensure it is correctly saved
navBar.setAttribute("currentset", navBar.currentSet);
doc.persist(navBar.id, "currentset");
// Update addonbar too as we removed widget from there.
// Otherwise, widgets may still be added to this toolbar.
addonBar.setAttribute("currentset", addonBar.currentSet);
doc.persist(addonBar.id, "currentset");

tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
let browserWindow = e.target.defaultView;
let doc = browserWindow.document;
let navBar = doc.getElementById("nav-bar");
let addonBar = doc.getElementById("addon-bar");

// Ensure that 1st is in addon bar
test.assertEqual(getWidgetNode(addonBar, 0).getAttribute("label"), w1.label);
// And that 2nd and 3rd keep their original positions in navigation bar
test.assertEqual(navBar.childNodes[5].getAttribute("label"), w3.label);
test.assertEqual(navBar.childNodes[6].getAttribute("label"), w2.label);

w1.destroy();
w2.destroy();
w3.destroy();

closeBrowserWindow(browserWindow, function() {
test.done();
});
}});
};

/******************* helpers *********************/

// Helper for calling code at window close
Expand Down

0 comments on commit 1430b71

Please sign in to comment.