summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_bug523784.js
blob: d0fac12d7113b855ca7180d88efd6313693ee366 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const URI_BLOCKLIST_DIALOG =
  "chrome://mozapps/content/extensions/blocklist.xhtml";

// This tests that the blocklist dialog still affects soft-blocked add-ons
// if the user clicks the "Restart Later" button. It also ensures that the
// "Cancel" button is correctly renamed (to "Restart Later").
var args = {
  restart: false,
  list: [
    {
      name: "Bug 523784 softblocked addon",
      version: "1",
      icon: "chrome://global/skin/plugins/plugin.svg",
      disable: false,
      blocked: false,
      url: "http://example.com/bug523784_1",
    },
  ],
};

function test() {
  waitForExplicitFinish();

  let windowObserver = function(win, aTopic, aData) {
    if (aTopic != "domwindowopened") {
      return;
    }

    Services.ww.unregisterNotification(windowObserver);

    win.addEventListener(
      "load",
      function() {
        executeSoon(() => bug523784_test1(win));
      },
      { once: true }
    );
  };
  Services.ww.registerNotification(windowObserver);

  args.wrappedJSObject = args;
  Services.ww.openWindow(
    null,
    URI_BLOCKLIST_DIALOG,
    "",
    "chrome,centerscreen,dialog,titlebar",
    args
  );
}

function bug523784_test1(win) {
  let bundle = Services.strings.createBundle(
    "chrome://mozapps/locale/update/updates.properties"
  );
  let cancelButton = win.document
    .getElementById("BlocklistDialog")
    .getButton("cancel");
  let moreInfoLink = win.document.getElementById("moreInfo");

  is(
    cancelButton.getAttribute("label"),
    bundle.GetStringFromName("restartLaterButton"),
    "Text should be changed on Cancel button"
  );
  is(
    cancelButton.getAttribute("accesskey"),
    bundle.GetStringFromName("restartLaterButton.accesskey"),
    "Accesskey should also be changed on Cancel button"
  );
  is(
    moreInfoLink.getAttribute("href"),
    "http://example.com/bug523784_1",
    "More Info link should link to a detailed blocklist page."
  );
  let windowObserver = function(aSubject, aTopic, aData) {
    if (aTopic != "domwindowclosed") {
      return;
    }

    Services.ww.unregisterNotification(windowObserver);

    ok(args.list[0].disable, "Should be blocking add-on");
    ok(!args.restart, "Should not restart browser immediately");

    executeSoon(bug523784_test2);
  };
  Services.ww.registerNotification(windowObserver);

  cancelButton.doCommand();
}

function bug523784_test2(win) {
  let windowObserver = function(win, aTopic, aData) {
    if (aTopic != "domwindowopened") {
      return;
    }

    Services.ww.unregisterNotification(windowObserver);
    win.addEventListener(
      "load",
      function() {
        executeSoon(function() {
          let moreInfoLink = win.document.getElementById("moreInfo");
          let cancelButton = win.document
            .getElementById("BlocklistDialog")
            .getButton("cancel");
          is(
            moreInfoLink.getAttribute("href"),
            Services.urlFormatter.formatURLPref(
              "extensions.blocklist.detailsURL"
            ),
            "More Info link should link to the general blocklist page."
          );
          cancelButton.doCommand();
          executeSoon(finish);
        });
      },
      { once: true }
    );
  };
  Services.ww.registerNotification(windowObserver);

  // Add 2 more addons to the blocked list to check that the more info link
  // points to the general blocked list page.
  args.list.push({
    name: "Bug 523784 softblocked addon 2",
    version: "2",
    icon: "chrome://global/skin/plugins/plugin.svg",
    disable: false,
    blocked: false,
    url: "http://example.com/bug523784_2",
  });
  args.list.push({
    name: "Bug 523784 softblocked addon 3",
    version: "4",
    icon: "chrome://global/skin/plugins/plugin.svg",
    disable: false,
    blocked: false,
    url: "http://example.com/bug523784_3",
  });

  args.wrappedJSObject = args;
  Services.ww.openWindow(
    null,
    URI_BLOCKLIST_DIALOG,
    "",
    "chrome,centerscreen,dialog,titlebar",
    args
  );
}