toolkit/mozapps/extensions/test/browser/browser_debug_button.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 debug button for addons in list view
michael@0 7 */
michael@0 8
michael@0 9 let { Promise } = Components.utils.import("resource://gre/modules/Promise.jsm", {});
michael@0 10 let { Task } = Components.utils.import("resource://gre/modules/Task.jsm", {});
michael@0 11
michael@0 12 const getDebugButton = node =>
michael@0 13 node.ownerDocument.getAnonymousElementByAttribute(node, "anonid", "debug-btn");
michael@0 14 const addonDebuggingEnabled = bool =>
michael@0 15 Services.prefs.setBoolPref("devtools.chrome.enabled", !!bool);
michael@0 16 const remoteDebuggingEnabled = bool =>
michael@0 17 Services.prefs.setBoolPref("devtools.debugger.remote-enabled", !!bool);
michael@0 18
michael@0 19 function test() {
michael@0 20 requestLongerTimeout(2);
michael@0 21
michael@0 22 waitForExplicitFinish();
michael@0 23
michael@0 24
michael@0 25 var gProvider = new MockProvider();
michael@0 26 gProvider.createAddons([{
michael@0 27 id: "non-debuggable@tests.mozilla.org",
michael@0 28 name: "No debug",
michael@0 29 description: "foo"
michael@0 30 },
michael@0 31 {
michael@0 32 id: "debuggable@tests.mozilla.org",
michael@0 33 name: "Debuggable",
michael@0 34 description: "bar",
michael@0 35 isDebuggable: true
michael@0 36 }]);
michael@0 37
michael@0 38 Task.spawn(function* () {
michael@0 39 addonDebuggingEnabled(false);
michael@0 40 remoteDebuggingEnabled(false);
michael@0 41
michael@0 42 yield testDOM((nondebug, debuggable) => {
michael@0 43 is(nondebug.disabled, true,
michael@0 44 "addon:disabled::remote:disabled button is disabled for legacy addons");
michael@0 45 is(nondebug.hidden, true,
michael@0 46 "addon:disabled::remote:disabled button is hidden for legacy addons");
michael@0 47 is(debuggable.disabled, true,
michael@0 48 "addon:disabled::remote:disabled button is disabled for debuggable addons");
michael@0 49 is(debuggable.hidden, true,
michael@0 50 "addon:disabled::remote:disabled button is hidden for debuggable addons");
michael@0 51 });
michael@0 52
michael@0 53 addonDebuggingEnabled(true);
michael@0 54 remoteDebuggingEnabled(false);
michael@0 55
michael@0 56 yield testDOM((nondebug, debuggable) => {
michael@0 57 is(nondebug.disabled, true,
michael@0 58 "addon:enabled::remote:disabled button is disabled for legacy addons");
michael@0 59 is(nondebug.disabled, true,
michael@0 60 "addon:enabled::remote:disabled button is hidden for legacy addons");
michael@0 61 is(debuggable.disabled, true,
michael@0 62 "addon:enabled::remote:disabled button is disabled for debuggable addons");
michael@0 63 is(debuggable.disabled, true,
michael@0 64 "addon:enabled::remote:disabled button is hidden for debuggable addons");
michael@0 65 });
michael@0 66
michael@0 67 addonDebuggingEnabled(false);
michael@0 68 remoteDebuggingEnabled(true);
michael@0 69
michael@0 70 yield testDOM((nondebug, debuggable) => {
michael@0 71 is(nondebug.disabled, true,
michael@0 72 "addon:disabled::remote:enabled button is disabled for legacy addons");
michael@0 73 is(nondebug.disabled, true,
michael@0 74 "addon:disabled::remote:enabled button is hidden for legacy addons");
michael@0 75 is(debuggable.disabled, true,
michael@0 76 "addon:disabled::remote:enabled button is disabled for debuggable addons");
michael@0 77 is(debuggable.disabled, true,
michael@0 78 "addon:disabled::remote:enabled button is hidden for debuggable addons");
michael@0 79 });
michael@0 80
michael@0 81 addonDebuggingEnabled(true);
michael@0 82 remoteDebuggingEnabled(true);
michael@0 83
michael@0 84 yield testDOM((nondebug, debuggable) => {
michael@0 85 is(nondebug.disabled, true,
michael@0 86 "addon:enabled::remote:enabled button is disabled for legacy addons");
michael@0 87 is(nondebug.disabled, true,
michael@0 88 "addon:enabled::remote:enabled button is hidden for legacy addons");
michael@0 89 is(debuggable.disabled, false,
michael@0 90 "addon:enabled::remote:enabled button is enabled for debuggable addons");
michael@0 91 is(debuggable.hidden, false,
michael@0 92 "addon:enabled::remote:enabled button is visible for debuggable addons");
michael@0 93 });
michael@0 94
michael@0 95 finish();
michael@0 96 });
michael@0 97
michael@0 98 function testDOM (testCallback) {
michael@0 99 let deferred = Promise.defer();
michael@0 100 open_manager("addons://list/extension", function(aManager) {
michael@0 101 const {document} = aManager;
michael@0 102 const addonList = document.getElementById("addon-list");
michael@0 103 const nondebug = addonList.querySelector("[name='No debug']");
michael@0 104 const debuggable = addonList.querySelector("[name='Debuggable']");
michael@0 105
michael@0 106 testCallback.apply(null, [nondebug, debuggable].map(getDebugButton));
michael@0 107
michael@0 108 close_manager(aManager, deferred.resolve);
michael@0 109 });
michael@0 110 return deferred.promise;
michael@0 111 }
michael@0 112 }

mercurial