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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug523784.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const URI_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul";
     1.8 +
     1.9 +// This tests that the blocklist dialog still affects soft-blocked add-ons
    1.10 +// if the user clicks the "Restart Later" button. It also ensures that the
    1.11 +// "Cancel" button is correctly renamed (to "Restart Later").
    1.12 +let args = {
    1.13 +  restart: false,
    1.14 +  list: [{
    1.15 +    name: "Bug 523784 softblocked addon",
    1.16 +    version: "1",
    1.17 +    icon: "chrome://mozapps/skin/plugins/pluginGeneric.png",
    1.18 +    disable: false,
    1.19 +    blocked: false,
    1.20 +    url: 'http://example.com/bug523784_1',
    1.21 +  }],
    1.22 +};
    1.23 +
    1.24 +function test() {
    1.25 +  waitForExplicitFinish();
    1.26 +
    1.27 +  let windowObserver = function(aSubject, aTopic, aData) {
    1.28 +    if (aTopic != "domwindowopened")
    1.29 +      return;
    1.30 +
    1.31 +    Services.ww.unregisterNotification(windowObserver);
    1.32 +
    1.33 +    let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    1.34 +    win.addEventListener("load", function() {
    1.35 +      win.removeEventListener("load", arguments.callee, false);
    1.36 +
    1.37 +      executeSoon(function() bug523784_test1(win));
    1.38 +    }, false);
    1.39 +  };
    1.40 +  Services.ww.registerNotification(windowObserver);
    1.41 +
    1.42 +  args.wrappedJSObject = args;
    1.43 +  Services.ww.openWindow(null, URI_BLOCKLIST_DIALOG, "",
    1.44 +                         "chrome,centerscreen,dialog,titlebar", args);
    1.45 +}
    1.46 +
    1.47 +function bug523784_test1(win) {
    1.48 +  let bundle = Services.strings.
    1.49 +              createBundle("chrome://mozapps/locale/update/updates.properties");
    1.50 +  let cancelButton = win.document.documentElement.getButton("cancel");
    1.51 +  let moreInfoLink = win.document.getElementById("moreInfo");
    1.52 +
    1.53 +  is(cancelButton.getAttribute("label"),
    1.54 +     bundle.GetStringFromName("restartLaterButton"),
    1.55 +     "Text should be changed on Cancel button");
    1.56 +  is(cancelButton.getAttribute("accesskey"),
    1.57 +     bundle.GetStringFromName("restartLaterButton.accesskey"),
    1.58 +     "Accesskey should also be changed on Cancel button");
    1.59 +  is(moreInfoLink.getAttribute("href"),
    1.60 +     'http://example.com/bug523784_1',
    1.61 +     "More Info link should link to a detailed blocklist page.");
    1.62 +  let windowObserver = function(aSubject, aTopic, aData) {
    1.63 +    if (aTopic != "domwindowclosed")
    1.64 +      return;
    1.65 +
    1.66 +    Services.ww.unregisterNotification(windowObserver);
    1.67 +
    1.68 +    ok(args.list[0].disable, "Should be blocking add-on");
    1.69 +    ok(!args.restart, "Should not restart browser immediately");
    1.70 +
    1.71 +    executeSoon(bug523784_test2);
    1.72 +  };
    1.73 +  Services.ww.registerNotification(windowObserver);
    1.74 +
    1.75 +  cancelButton.doCommand();
    1.76 +}
    1.77 +
    1.78 +function bug523784_test2(win) {
    1.79 +  let windowObserver = function(aSubject, aTopic, aData) {
    1.80 +    if (aTopic != "domwindowopened")
    1.81 +      return;
    1.82 +
    1.83 +    Services.ww.unregisterNotification(windowObserver);
    1.84 +    let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    1.85 +    win.addEventListener("load", function() {
    1.86 +      win.removeEventListener("load", arguments.callee, false);
    1.87 +
    1.88 +    executeSoon(function(){
    1.89 +      let moreInfoLink = win.document.getElementById("moreInfo");
    1.90 +      let cancelButton = win.document.documentElement.getButton("cancel");
    1.91 +      is(moreInfoLink.getAttribute("href"),
    1.92 +         Services.urlFormatter.formatURLPref("extensions.blocklist.detailsURL"),
    1.93 +         "More Info link should link to the general blocklist page.");
    1.94 +      cancelButton.doCommand();
    1.95 +      executeSoon(finish);
    1.96 +    })
    1.97 +    }, false);
    1.98 +  };
    1.99 +  Services.ww.registerNotification(windowObserver);
   1.100 +
   1.101 +  // Add 2 more addons to the blocked list to check that the more info link
   1.102 +  // points to the general blocked list page.
   1.103 +  args.list.push({
   1.104 +    name: "Bug 523784 softblocked addon 2",
   1.105 +    version: "2",
   1.106 +    icon: "chrome://mozapps/skin/plugins/pluginGeneric.png",
   1.107 +    disable: false,
   1.108 +    blocked: false,
   1.109 +    url: 'http://example.com/bug523784_2'
   1.110 +  });
   1.111 +  args.list.push({
   1.112 +    name: "Bug 523784 softblocked addon 3",
   1.113 +    version: "4",
   1.114 +    icon: "chrome://mozapps/skin/plugins/pluginGeneric.png",
   1.115 +    disable: false,
   1.116 +    blocked: false,
   1.117 +    url: 'http://example.com/bug523784_3'
   1.118 +  });
   1.119 +
   1.120 +  args.wrappedJSObject = args;
   1.121 +  Services.ww.openWindow(null, URI_BLOCKLIST_DIALOG, "",
   1.122 +                         "chrome,centerscreen,dialog,titlebar", args);
   1.123 +}

mercurial