summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/content-tabs/browser_installXpi.js
blob: e90b18bca4fcc03811255834e02e98bdb79b9392 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm");

var { open_content_tab_with_url } = ChromeUtils.import(
  "resource://testing-common/mozmill/ContentTabHelpers.jsm"
);
var { mc } = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);

var url =
  "http://mochi.test:8888/browser/comm/mail/test/browser/content-tabs/html/";

var gDocument;
var gNewTab;

add_setup(function () {
  gDocument = mc.window.document;
  gNewTab = open_content_tab_with_url(url + "installxpi.html");
});

registerCleanupFunction(function () {
  mc.window.document.getElementById("tabmail").closeTab(gNewTab);
});

async function waitForNotification(id, buttonToClickSelector, callback) {
  let notificationSelector = `#notification-popup > #${id}-notification`;
  let notification;
  utils.waitFor(() => {
    notification = gDocument.querySelector(notificationSelector);
    return notification && !notification.hidden;
  });
  // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
  await new Promise(resolve => setTimeout(resolve, 500));
  if (callback) {
    callback();
  }
  if (buttonToClickSelector) {
    let button = notification.querySelector(buttonToClickSelector);
    EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, mc.window);
  }
  utils.waitFor(() => !gDocument.querySelector(notificationSelector));
}

add_task(async function test_install_corrupt_xpi() {
  // This install with give us a corrupt xpi warning.
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#corruptlink",
    {},
    gNewTab.browser
  );
  await waitForNotification(
    "addon-install-blocked",
    ".popup-notification-primary-button"
  );
  await waitForNotification(
    "addon-install-failed",
    ".popup-notification-primary-button"
  );
});

add_task(async function test_install_xpi_offer() {
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#installlink",
    {},
    gNewTab.browser
  );
  await waitForNotification(
    "addon-install-blocked",
    ".popup-notification-primary-button"
  );
  await waitForNotification(
    "addon-install-failed",
    ".popup-notification-primary-button"
  );
});

add_task(async function test_xpinstall_disabled() {
  Services.prefs.setBoolPref("xpinstall.enabled", false);

  // Try installation again - this time we'll get an install has been disabled message.
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#installlink",
    {},
    gNewTab.browser
  );
  await waitForNotification(
    "xpinstall-disabled",
    ".popup-notification-secondary-button"
  );

  Services.prefs.clearUserPref("xpinstall.enabled");
});

add_task(async function test_xpinstall_actually_install() {
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#installlink",
    {},
    gNewTab.browser
  );
  await waitForNotification(
    "addon-install-blocked",
    ".popup-notification-primary-button"
  );
  await waitForNotification(
    "addon-install-failed",
    ".popup-notification-primary-button"
  );
});

add_task(async function test_xpinstall_webext_actually_install() {
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#installwebextlink",
    {},
    gNewTab.browser
  );
  await waitForNotification(
    "addon-install-blocked",
    ".popup-notification-primary-button"
  );
  await waitForNotification("addon-progress");
  await waitForNotification(
    "addon-webext-permissions",
    ".popup-notification-primary-button",
    () => {
      let permission = gDocument.getElementById(
        "addon-webext-perm-single-entry"
      );
      Assert.ok(!permission.hidden);
    }
  );
  await waitForNotification(
    "addon-installed",
    ".popup-notification-primary-button"
  );

  Assert.report(
    false,
    undefined,
    undefined,
    "Test ran to completion successfully"
  );
});