Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | * Tests the Preferences button for addons in list view |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | requestLongerTimeout(2); |
michael@0 | 11 | |
michael@0 | 12 | waitForExplicitFinish(); |
michael@0 | 13 | |
michael@0 | 14 | var addonPrefsURI = CHROMEROOT + "addon_prefs.xul"; |
michael@0 | 15 | |
michael@0 | 16 | var gProvider = new MockProvider(); |
michael@0 | 17 | gProvider.createAddons([{ |
michael@0 | 18 | id: "test1@tests.mozilla.org", |
michael@0 | 19 | name: "Test add-on 1", |
michael@0 | 20 | description: "foo" |
michael@0 | 21 | }, |
michael@0 | 22 | { |
michael@0 | 23 | id: "test2@tests.mozilla.org", |
michael@0 | 24 | name: "Test add-on 2", |
michael@0 | 25 | description: "bar", |
michael@0 | 26 | optionsURL: addonPrefsURI |
michael@0 | 27 | }]); |
michael@0 | 28 | |
michael@0 | 29 | open_manager("addons://list/extension", function(aManager) { |
michael@0 | 30 | var addonList = aManager.document.getElementById("addon-list"); |
michael@0 | 31 | for (var addonItem of addonList.childNodes) { |
michael@0 | 32 | if (addonItem.hasAttribute("name") && |
michael@0 | 33 | addonItem.getAttribute("name") == "Test add-on 1") |
michael@0 | 34 | break; |
michael@0 | 35 | } |
michael@0 | 36 | var prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, |
michael@0 | 37 | "anonid", |
michael@0 | 38 | "preferences-btn"); |
michael@0 | 39 | is(prefsBtn.hidden, true, "Prefs button should be hidden for addon with no optionsURL set") |
michael@0 | 40 | |
michael@0 | 41 | for (addonItem of addonList.childNodes) { |
michael@0 | 42 | if (addonItem.hasAttribute("name") && |
michael@0 | 43 | addonItem.getAttribute("name") == "Test add-on 2") |
michael@0 | 44 | break; |
michael@0 | 45 | } |
michael@0 | 46 | prefsBtn = aManager.document.getAnonymousElementByAttribute(addonItem, |
michael@0 | 47 | "anonid", |
michael@0 | 48 | "preferences-btn"); |
michael@0 | 49 | is(prefsBtn.hidden, false, "Prefs button should be shown for addon with a optionsURL set") |
michael@0 | 50 | |
michael@0 | 51 | Services.ww.registerNotification(function TEST_ww_observer(aSubject, aTopic, aData) { |
michael@0 | 52 | if (aTopic == "domwindowclosed") { |
michael@0 | 53 | Services.ww.unregisterNotification(TEST_ww_observer); |
michael@0 | 54 | // Give the preference window a chance to finish closing before closing |
michael@0 | 55 | // the add-ons manager. |
michael@0 | 56 | executeSoon(function() { |
michael@0 | 57 | close_manager(aManager, finish); |
michael@0 | 58 | }); |
michael@0 | 59 | } else if (aTopic == "domwindowopened") { |
michael@0 | 60 | let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); |
michael@0 | 61 | win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); |
michael@0 | 62 | win.addEventListener("load", function TEST_ww_onLoad() { |
michael@0 | 63 | if (win.location != addonPrefsURI) |
michael@0 | 64 | return; |
michael@0 | 65 | |
michael@0 | 66 | win.removeEventListener("load", TEST_ww_onLoad, false); |
michael@0 | 67 | is(win.location, addonPrefsURI, |
michael@0 | 68 | "The correct addon pref window should have opened"); |
michael@0 | 69 | win.close(); |
michael@0 | 70 | }, false); |
michael@0 | 71 | } |
michael@0 | 72 | }); |
michael@0 | 73 | |
michael@0 | 74 | addonList.ensureElementIsVisible(addonItem); |
michael@0 | 75 | EventUtils.synthesizeMouseAtCenter(prefsBtn, { }, aManager); |
michael@0 | 76 | }); |
michael@0 | 77 | |
michael@0 | 78 | } |