toolkit/mozapps/extensions/test/browser/browser_bug590347.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_bug590347.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 +
     1.8 +// Bug 590347
     1.9 +// Tests if softblock notifications are exposed in preference to incompatible
    1.10 +// notifications when compatibility checking is disabled
    1.11 +
    1.12 +var gProvider;
    1.13 +var gManagerWindow;
    1.14 +var gCategoryUtilities;
    1.15 +
    1.16 +var gApp = document.getElementById("bundle_brand").getString("brandShortName");
    1.17 +var gVersion = Services.appinfo.version;
    1.18 +
    1.19 +// Opens the details view of an add-on
    1.20 +function open_details(aId, aType, aCallback) {
    1.21 +  requestLongerTimeout(2);
    1.22 +
    1.23 +  gCategoryUtilities.openType(aType, function() {
    1.24 +    var list = gManagerWindow.document.getElementById("addon-list");
    1.25 +    var item = list.firstChild;
    1.26 +    while (item) {
    1.27 +      if ("mAddon" in item && item.mAddon.id == aId) {
    1.28 +        list.ensureElementIsVisible(item);
    1.29 +        EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
    1.30 +        EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
    1.31 +        wait_for_view_load(gManagerWindow, aCallback);
    1.32 +        return;
    1.33 +      }
    1.34 +      item = item.nextSibling;
    1.35 +    }
    1.36 +    ok(false, "Should have found the add-on in the list");
    1.37 +  });
    1.38 +}
    1.39 +
    1.40 +function get_list_view_warning_node() {
    1.41 +  let item = gManagerWindow.document.getElementById("addon-list").firstChild;
    1.42 +  let found = false;
    1.43 +  while (item) {
    1.44 +    if (item.mAddon.name == "Test add-on") {
    1.45 +      found = true;
    1.46 +      break;
    1.47 +    }
    1.48 +    item = item.nextSibling;
    1.49 +  }
    1.50 +  ok(found, "Test add-on node should have been found.");
    1.51 +  return item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning");
    1.52 +}
    1.53 +
    1.54 +function get_detail_view_warning_node(aManagerWindow) {
    1.55 +  if(aManagerWindow)
    1.56 +    return aManagerWindow.document.getElementById("detail-warning");
    1.57 +}
    1.58 +
    1.59 +function test() {
    1.60 +  waitForExplicitFinish();
    1.61 +
    1.62 +  gProvider = new MockProvider();
    1.63 +
    1.64 +  gProvider.createAddons([{
    1.65 +    id: "addon1@tests.mozilla.org",
    1.66 +    name: "Test add-on",
    1.67 +    description: "A test add-on",
    1.68 +    isCompatible: false,
    1.69 +    blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
    1.70 +  }]);
    1.71 +
    1.72 +  open_manager(null, function(aWindow) {
    1.73 +    gManagerWindow = aWindow;
    1.74 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.75 +    run_next_test();
    1.76 +  });
    1.77 +}
    1.78 +
    1.79 +function end_test() {
    1.80 +  close_manager(gManagerWindow, function() {
    1.81 +    finish();
    1.82 +  });
    1.83 +}
    1.84 +
    1.85 +// Check with compatibility checking enabled
    1.86 +add_test(function() {
    1.87 +  gCategoryUtilities.openType("extension", function() {
    1.88 +    Services.prefs.setBoolPref(PREF_CHECK_COMPATIBILITY, true);
    1.89 +    let warning_node = get_list_view_warning_node();
    1.90 +    is_element_visible(warning_node, "Warning message should be visible");
    1.91 +    is(warning_node.textContent, "Test add-on is incompatible with " + gApp + " " + gVersion + ".", "Warning message should be correct");
    1.92 +    run_next_test();
    1.93 +  });
    1.94 +});
    1.95 +
    1.96 +add_test(function() {
    1.97 +  open_details("addon1@tests.mozilla.org", "extension", function() {
    1.98 +    let warning_node = get_detail_view_warning_node(gManagerWindow);
    1.99 +    is_element_visible(warning_node, "Warning message should be visible");
   1.100 +    is(warning_node.textContent, "Test add-on is incompatible with " + gApp + " " + gVersion + ".", "Warning message should be correct");
   1.101 +    Services.prefs.setBoolPref(PREF_CHECK_COMPATIBILITY, false);
   1.102 +    run_next_test();
   1.103 +  });
   1.104 +});
   1.105 +
   1.106 +// Check with compatibility checking disabled
   1.107 +add_test(function() {
   1.108 +  gCategoryUtilities.openType("extension", function() {
   1.109 +    let warning_node = get_list_view_warning_node();
   1.110 +    is_element_visible(warning_node, "Warning message should be visible");
   1.111 +    is(warning_node.textContent, "Test add-on is known to cause security or stability issues.", "Warning message should be correct");
   1.112 +    run_next_test();
   1.113 +  });
   1.114 +});
   1.115 +
   1.116 +add_test(function() {
   1.117 +  open_details("addon1@tests.mozilla.org", "extension", function() {
   1.118 +    let warning_node = get_detail_view_warning_node(gManagerWindow);
   1.119 +    is_element_visible(warning_node, "Warning message should be visible");
   1.120 +    is(warning_node.textContent, "Test add-on is known to cause security or stability issues.", "Warning message should be correct");
   1.121 +    run_next_test();
   1.122 +  });
   1.123 +});

mercurial