summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_debug_button.js
blob: 3f371e9069cdf49bf8620278bc302534907f86c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

/**
 * Tests debug button for addons in list view
 */

let { Promise } = Components.utils.import("resource://gre/modules/Promise.jsm", {});
let { Task } = Components.utils.import("resource://gre/modules/Task.jsm", {});

const getDebugButton = node =>
    node.ownerDocument.getAnonymousElementByAttribute(node, "anonid", "debug-btn");
const addonDebuggingEnabled = bool =>
  Services.prefs.setBoolPref("devtools.chrome.enabled", !!bool);
const remoteDebuggingEnabled = bool =>
  Services.prefs.setBoolPref("devtools.debugger.remote-enabled", !!bool);

function test() {
  requestLongerTimeout(2);

  waitForExplicitFinish();


  var gProvider = new MockProvider();
  gProvider.createAddons([{
    id: "non-debuggable@tests.mozilla.org",
    name: "No debug",
    description: "foo"
  },
  {
    id: "debuggable@tests.mozilla.org",
    name: "Debuggable",
    description: "bar",
    isDebuggable: true
  }]);

  Task.spawn(function* () {
    addonDebuggingEnabled(false);
    remoteDebuggingEnabled(false);

    yield testDOM((nondebug, debuggable) => {
      is(nondebug.disabled, true,
        "addon:disabled::remote:disabled button is disabled for legacy addons");
      is(nondebug.hidden, true,
        "addon:disabled::remote:disabled button is hidden for legacy addons");
      is(debuggable.disabled, true,
        "addon:disabled::remote:disabled button is disabled for debuggable addons");
      is(debuggable.hidden, true,
        "addon:disabled::remote:disabled button is hidden for debuggable addons");
    });
    
    addonDebuggingEnabled(true);
    remoteDebuggingEnabled(false);

    yield testDOM((nondebug, debuggable) => {
      is(nondebug.disabled, true,
        "addon:enabled::remote:disabled button is disabled for legacy addons");
      is(nondebug.disabled, true,
        "addon:enabled::remote:disabled button is hidden for legacy addons");
      is(debuggable.disabled, true,
        "addon:enabled::remote:disabled button is disabled for debuggable addons");
      is(debuggable.disabled, true,
        "addon:enabled::remote:disabled button is hidden for debuggable addons");
    });
    
    addonDebuggingEnabled(false);
    remoteDebuggingEnabled(true);

    yield testDOM((nondebug, debuggable) => {
      is(nondebug.disabled, true,
        "addon:disabled::remote:enabled button is disabled for legacy addons");
      is(nondebug.disabled, true,
        "addon:disabled::remote:enabled button is hidden for legacy addons");
      is(debuggable.disabled, true,
        "addon:disabled::remote:enabled button is disabled for debuggable addons");
      is(debuggable.disabled, true,
        "addon:disabled::remote:enabled button is hidden for debuggable addons");
    });
    
    addonDebuggingEnabled(true);
    remoteDebuggingEnabled(true);

    yield testDOM((nondebug, debuggable) => {
      is(nondebug.disabled, true,
        "addon:enabled::remote:enabled button is disabled for legacy addons");
      is(nondebug.disabled, true,
        "addon:enabled::remote:enabled button is hidden for legacy addons");
      is(debuggable.disabled, false,
        "addon:enabled::remote:enabled button is enabled for debuggable addons");
      is(debuggable.hidden, false,
        "addon:enabled::remote:enabled button is visible for debuggable addons");
    });

    finish();
  });

  function testDOM (testCallback) {
    let deferred = Promise.defer();
    open_manager("addons://list/extension", function(aManager) {
      const {document} = aManager;
      const addonList = document.getElementById("addon-list");
      const nondebug = addonList.querySelector("[name='No debug']");
      const debuggable = addonList.querySelector("[name='Debuggable']");

      testCallback.apply(null, [nondebug, debuggable].map(getDebugButton));

      close_manager(aManager, deferred.resolve);
    });
    return deferred.promise;
  }
}