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 debug button for addons in list view michael@0: */ michael@0: michael@0: let { Promise } = Components.utils.import("resource://gre/modules/Promise.jsm", {}); michael@0: let { Task } = Components.utils.import("resource://gre/modules/Task.jsm", {}); michael@0: michael@0: const getDebugButton = node => michael@0: node.ownerDocument.getAnonymousElementByAttribute(node, "anonid", "debug-btn"); michael@0: const addonDebuggingEnabled = bool => michael@0: Services.prefs.setBoolPref("devtools.chrome.enabled", !!bool); michael@0: const remoteDebuggingEnabled = bool => michael@0: Services.prefs.setBoolPref("devtools.debugger.remote-enabled", !!bool); michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: michael@0: var gProvider = new MockProvider(); michael@0: gProvider.createAddons([{ michael@0: id: "non-debuggable@tests.mozilla.org", michael@0: name: "No debug", michael@0: description: "foo" michael@0: }, michael@0: { michael@0: id: "debuggable@tests.mozilla.org", michael@0: name: "Debuggable", michael@0: description: "bar", michael@0: isDebuggable: true michael@0: }]); michael@0: michael@0: Task.spawn(function* () { michael@0: addonDebuggingEnabled(false); michael@0: remoteDebuggingEnabled(false); michael@0: michael@0: yield testDOM((nondebug, debuggable) => { michael@0: is(nondebug.disabled, true, michael@0: "addon:disabled::remote:disabled button is disabled for legacy addons"); michael@0: is(nondebug.hidden, true, michael@0: "addon:disabled::remote:disabled button is hidden for legacy addons"); michael@0: is(debuggable.disabled, true, michael@0: "addon:disabled::remote:disabled button is disabled for debuggable addons"); michael@0: is(debuggable.hidden, true, michael@0: "addon:disabled::remote:disabled button is hidden for debuggable addons"); michael@0: }); michael@0: michael@0: addonDebuggingEnabled(true); michael@0: remoteDebuggingEnabled(false); michael@0: michael@0: yield testDOM((nondebug, debuggable) => { michael@0: is(nondebug.disabled, true, michael@0: "addon:enabled::remote:disabled button is disabled for legacy addons"); michael@0: is(nondebug.disabled, true, michael@0: "addon:enabled::remote:disabled button is hidden for legacy addons"); michael@0: is(debuggable.disabled, true, michael@0: "addon:enabled::remote:disabled button is disabled for debuggable addons"); michael@0: is(debuggable.disabled, true, michael@0: "addon:enabled::remote:disabled button is hidden for debuggable addons"); michael@0: }); michael@0: michael@0: addonDebuggingEnabled(false); michael@0: remoteDebuggingEnabled(true); michael@0: michael@0: yield testDOM((nondebug, debuggable) => { michael@0: is(nondebug.disabled, true, michael@0: "addon:disabled::remote:enabled button is disabled for legacy addons"); michael@0: is(nondebug.disabled, true, michael@0: "addon:disabled::remote:enabled button is hidden for legacy addons"); michael@0: is(debuggable.disabled, true, michael@0: "addon:disabled::remote:enabled button is disabled for debuggable addons"); michael@0: is(debuggable.disabled, true, michael@0: "addon:disabled::remote:enabled button is hidden for debuggable addons"); michael@0: }); michael@0: michael@0: addonDebuggingEnabled(true); michael@0: remoteDebuggingEnabled(true); michael@0: michael@0: yield testDOM((nondebug, debuggable) => { michael@0: is(nondebug.disabled, true, michael@0: "addon:enabled::remote:enabled button is disabled for legacy addons"); michael@0: is(nondebug.disabled, true, michael@0: "addon:enabled::remote:enabled button is hidden for legacy addons"); michael@0: is(debuggable.disabled, false, michael@0: "addon:enabled::remote:enabled button is enabled for debuggable addons"); michael@0: is(debuggable.hidden, false, michael@0: "addon:enabled::remote:enabled button is visible for debuggable addons"); michael@0: }); michael@0: michael@0: finish(); michael@0: }); michael@0: michael@0: function testDOM (testCallback) { michael@0: let deferred = Promise.defer(); michael@0: open_manager("addons://list/extension", function(aManager) { michael@0: const {document} = aManager; michael@0: const addonList = document.getElementById("addon-list"); michael@0: const nondebug = addonList.querySelector("[name='No debug']"); michael@0: const debuggable = addonList.querySelector("[name='Debuggable']"); michael@0: michael@0: testCallback.apply(null, [nondebug, debuggable].map(getDebugButton)); michael@0: michael@0: close_manager(aManager, deferred.resolve); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: }