summaryrefslogtreecommitdiffstats
path: root/devtools/client/webide/test/test_addons.html
blob: 5a1bc7504f0a436992ea92646bc3e60387453837 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>

<html>

  <head>
    <meta charset="utf8">
    <title></title>

    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
    <script type="application/javascript;version=1.8" src="head.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  </head>

  <body>

    <script type="application/javascript;version=1.8">
      window.onload = function() {
        SimpleTest.waitForExplicitFinish();

        const {GetAvailableAddons} = require("devtools/client/webide/modules/addons");
        const {Devices} = Cu.import("resource://devtools/shared/apps/Devices.jsm");
        const {Simulators} = require("devtools/client/webide/modules/simulators");

        let adbAddonsInstalled = promise.defer();
        Devices.on("addon-status-updated", function onUpdate1() {
          Devices.off("addon-status-updated", onUpdate1);
          adbAddonsInstalled.resolve();
        });

        function getVersion(name) {
          return name.match(/(\d+\.\d+)/)[0];
        }

        function onSimulatorInstalled(name) {
          let deferred = promise.defer();
          Simulators.on("updated", function onUpdate() {
            Simulators.findSimulatorAddons().then(addons => {
              for (let addon of addons) {
                if (name == addon.name.replace(" Simulator", "")) {
                  Simulators.off("updated", onUpdate);
                  nextTick().then(deferred.resolve);
                  return;
                }
              }
            });
          });
          return deferred.promise;
        }

        function installSimulatorFromUI(doc, name) {
          let li = doc.querySelector('[addon="simulator-' + getVersion(name) + '"]');
          li.querySelector(".install-button").click();
          return onSimulatorInstalled(name);
        }

        function uninstallSimulatorFromUI(doc, name) {
          let deferred = promise.defer();
          Simulators.on("updated", function onUpdate() {
            nextTick().then(() => {
              let li = doc.querySelector('[status="uninstalled"][addon="simulator-' + getVersion(name) + '"]');
              if (li) {
                Simulators.off("updated", onUpdate);
                deferred.resolve();
              } else {
                deferred.reject("Can't find item");
              }
            });
          });
          let li = doc.querySelector('[status="installed"][addon="simulator-' + getVersion(name) + '"]');
          li.querySelector(".uninstall-button").click();
          return deferred.promise;
        }

        function uninstallADBFromUI(doc) {
          let deferred = promise.defer();
          Devices.on("addon-status-updated", function onUpdate() {
            nextTick().then(() => {
              let li = doc.querySelector('[status="uninstalled"][addon="adb"]');
              if (li) {
                Devices.off("addon-status-updated", onUpdate);
                deferred.resolve();
              } else {
                deferred.reject("Can't find item");
              }
            })
          });
          let li = doc.querySelector('[status="installed"][addon="adb"]');
          li.querySelector(".uninstall-button").click();
          return deferred.promise;
        }

        Task.spawn(function*() {

          ok(!Devices.helperAddonInstalled, "Helper not installed");

          let win = yield openWebIDE(true);
          let docRuntime = getRuntimeDocument(win);

          yield adbAddonsInstalled.promise;

          ok(Devices.helperAddonInstalled, "Helper has been auto-installed");

          yield nextTick();

          let addons = yield GetAvailableAddons();

          is(addons.simulators.length, 3, "3 simulator addons to install");

          let sim10 = addons.simulators.filter(a => a.version == "1.0")[0];
          sim10.install();

          yield onSimulatorInstalled("Firefox OS 1.0");

          win.Cmds.showAddons();

          let frame = win.document.querySelector("#deck-panel-addons");
          let addonDoc = frame.contentWindow.document;
          let lis;

          lis = addonDoc.querySelectorAll("li");
          is(lis.length, 5, "5 addons listed");

          lis = addonDoc.querySelectorAll('li[status="installed"]');
          is(lis.length, 3, "3 addons installed");

          lis = addonDoc.querySelectorAll('li[status="uninstalled"]');
          is(lis.length, 2, "2 addons uninstalled");

          info("Uninstalling Simulator 2.0");

          yield installSimulatorFromUI(addonDoc, "Firefox OS 2.0");

          info("Uninstalling Simulator 3.0");

          yield installSimulatorFromUI(addonDoc, "Firefox OS 3.0");

          yield nextTick();

          let panelNode = docRuntime.querySelector("#runtime-panel");
          let items;

          items = panelNode.querySelectorAll(".runtime-panel-item-usb");
          is(items.length, 1, "Found one runtime button");

          items = panelNode.querySelectorAll(".runtime-panel-item-simulator");
          is(items.length, 3, "Found 3 simulators button");

          yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 1.0");
          yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 2.0");
          yield uninstallSimulatorFromUI(addonDoc, "Firefox OS 3.0");

          items = panelNode.querySelectorAll(".runtime-panel-item-simulator");
          is(items.length, 0, "No simulator listed");

          let w = addonDoc.querySelector(".warning");
          let display = addonDoc.defaultView.getComputedStyle(w).display
          is(display, "none", "Warning about missing ADB hidden");

          yield uninstallADBFromUI(addonDoc, "adb");

          items = panelNode.querySelectorAll(".runtime-panel-item-usb");
          is(items.length, 0, "No usb runtime listed");

          display = addonDoc.defaultView.getComputedStyle(w).display
          is(display, "block", "Warning about missing ADB present");

          yield closeWebIDE(win);

          SimpleTest.finish();

        });
      }
    </script>
  </body>
</html>