michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: /** michael@0: * Tests the Preferences button for addons in list view michael@0: */ michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: var addonPrefsURI = CHROMEROOT + "addon_prefs.xul"; michael@0: michael@0: var gProvider = new MockProvider(); michael@0: gProvider.createAddons([{ michael@0: id: "test1@tests.mozilla.org", michael@0: name: "Test add-on 1", michael@0: description: "foo" michael@0: }, michael@0: { michael@0: id: "test2@tests.mozilla.org", michael@0: name: "Test add-on 2", michael@0: description: "bar", michael@0: optionsURL: addonPrefsURI michael@0: }]); michael@0: michael@0: open_manager("addons://list/extension", function(aManager) { michael@0: var addonList = aManager.document.getElementById("addon-list"); michael@0: for (var addonItem of addonList.childNodes) { michael@0: if (addonItem.hasAttribute("name") && michael@0: addonItem.getAttribute("name") == "Test add-on 1") michael@0: break; michael@0: } michael@0: var prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, michael@0: "anonid", michael@0: "preferences-btn"); michael@0: is(prefsBtn.hidden, true, "Prefs button should be hidden for addon with no optionsURL set") michael@0: michael@0: for (addonItem of addonList.childNodes) { michael@0: if (addonItem.hasAttribute("name") && michael@0: addonItem.getAttribute("name") == "Test add-on 2") michael@0: break; michael@0: } michael@0: prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, michael@0: "anonid", michael@0: "preferences-btn"); michael@0: is(prefsBtn.hidden, false, "Prefs button should be shown for addon with a optionsURL set") michael@0: michael@0: Services.ww.registerNotification(function TEST_ww_observer(aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowclosed") { michael@0: Services.ww.unregisterNotification(TEST_ww_observer); michael@0: // Give the preference window a chance to finish closing before closing michael@0: // the add-ons manager. michael@0: executeSoon(function() { michael@0: close_manager(aManager, finish); michael@0: }); michael@0: } else if (aTopic == "domwindowopened") { michael@0: let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); michael@0: win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); michael@0: win.addEventListener("load", function TEST_ww_onLoad() { michael@0: if (win.location != addonPrefsURI) michael@0: return; michael@0: michael@0: win.removeEventListener("load", TEST_ww_onLoad, false); michael@0: is(win.location, addonPrefsURI, michael@0: "The correct addon pref window should have opened"); michael@0: win.close(); michael@0: }, false); michael@0: } michael@0: }); michael@0: michael@0: addonList.ensureElementIsVisible(addonItem); michael@0: EventUtils.synthesizeMouseAtCenter(prefsBtn, { }, aManager); michael@0: }); michael@0: michael@0: }