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