1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug562890.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +/** 1.9 + * Tests the Preferences button for addons in list view 1.10 + */ 1.11 + 1.12 +function test() { 1.13 + requestLongerTimeout(2); 1.14 + 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + var addonPrefsURI = CHROMEROOT + "addon_prefs.xul"; 1.18 + 1.19 + var gProvider = new MockProvider(); 1.20 + gProvider.createAddons([{ 1.21 + id: "test1@tests.mozilla.org", 1.22 + name: "Test add-on 1", 1.23 + description: "foo" 1.24 + }, 1.25 + { 1.26 + id: "test2@tests.mozilla.org", 1.27 + name: "Test add-on 2", 1.28 + description: "bar", 1.29 + optionsURL: addonPrefsURI 1.30 + }]); 1.31 + 1.32 + open_manager("addons://list/extension", function(aManager) { 1.33 + var addonList = aManager.document.getElementById("addon-list"); 1.34 + for (var addonItem of addonList.childNodes) { 1.35 + if (addonItem.hasAttribute("name") && 1.36 + addonItem.getAttribute("name") == "Test add-on 1") 1.37 + break; 1.38 + } 1.39 + var prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, 1.40 + "anonid", 1.41 + "preferences-btn"); 1.42 + is(prefsBtn.hidden, true, "Prefs button should be hidden for addon with no optionsURL set") 1.43 + 1.44 + for (addonItem of addonList.childNodes) { 1.45 + if (addonItem.hasAttribute("name") && 1.46 + addonItem.getAttribute("name") == "Test add-on 2") 1.47 + break; 1.48 + } 1.49 + prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, 1.50 + "anonid", 1.51 + "preferences-btn"); 1.52 + is(prefsBtn.hidden, false, "Prefs button should be shown for addon with a optionsURL set") 1.53 + 1.54 + Services.ww.registerNotification(function TEST_ww_observer(aSubject, aTopic, aData) { 1.55 + if (aTopic == "domwindowclosed") { 1.56 + Services.ww.unregisterNotification(TEST_ww_observer); 1.57 + // Give the preference window a chance to finish closing before closing 1.58 + // the add-ons manager. 1.59 + executeSoon(function() { 1.60 + close_manager(aManager, finish); 1.61 + }); 1.62 + } else if (aTopic == "domwindowopened") { 1.63 + let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); 1.64 + win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); 1.65 + win.addEventListener("load", function TEST_ww_onLoad() { 1.66 + if (win.location != addonPrefsURI) 1.67 + return; 1.68 + 1.69 + win.removeEventListener("load", TEST_ww_onLoad, false); 1.70 + is(win.location, addonPrefsURI, 1.71 + "The correct addon pref window should have opened"); 1.72 + win.close(); 1.73 + }, false); 1.74 + } 1.75 + }); 1.76 + 1.77 + addonList.ensureElementIsVisible(addonItem); 1.78 + EventUtils.synthesizeMouseAtCenter(prefsBtn, { }, aManager); 1.79 + }); 1.80 + 1.81 +}