toolkit/mozapps/extensions/test/browser/browser_newaddon.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_newaddon.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,186 @@
     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 +// Tests the new add-on tab
     1.9 +
    1.10 +var gProvider;
    1.11 +
    1.12 +function loadPage(aURL, aCallback) {
    1.13 +  gBrowser.selectedTab = gBrowser.addTab();
    1.14 +  gBrowser.loadURI(aURL);
    1.15 +  gBrowser.addEventListener("AddonDisplayed", function(event) {
    1.16 +    gBrowser.removeEventListener("AddonDisplayed", arguments.callee, false);
    1.17 +
    1.18 +    aCallback(gBrowser.selectedTab);
    1.19 +  });
    1.20 +}
    1.21 +
    1.22 +function test() {
    1.23 +  waitForExplicitFinish();
    1.24 +
    1.25 +  gProvider = new MockProvider();
    1.26 +
    1.27 +  gProvider.createAddons([{
    1.28 +    id: "addon1@tests.mozilla.org",
    1.29 +    name: "Test 1",
    1.30 +    version: "5.3",
    1.31 +    userDisabled: true,
    1.32 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.33 +  }, {
    1.34 +    id: "addon2@tests.mozilla.org",
    1.35 +    name: "Test 2",
    1.36 +    version: "7.1",
    1.37 +    creator: "Dave Townsend",
    1.38 +    userDisabled: true
    1.39 +  }]);
    1.40 +
    1.41 +  run_next_test();
    1.42 +}
    1.43 +
    1.44 +function end_test() {
    1.45 +  finish();
    1.46 +}
    1.47 +
    1.48 +// Tests that ignoring a restartless add-on works
    1.49 +add_test(function() {
    1.50 +  loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
    1.51 +    var doc = aTab.linkedBrowser.contentDocument;
    1.52 +    is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
    1.53 +
    1.54 +    is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
    1.55 +    is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
    1.56 +
    1.57 +    is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
    1.58 +       "Should be showing the right buttons");
    1.59 +
    1.60 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
    1.61 +                                       {}, aTab.linkedBrowser.contentWindow);
    1.62 +
    1.63 +    is(gBrowser.tabs.length, 1, "Page should have been closed");
    1.64 +
    1.65 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
    1.66 +      ok(aAddon.userDisabled, "Add-on should not have been enabled");
    1.67 +
    1.68 +      ok(!aAddon.isActive, "Add-on should not be running");
    1.69 +
    1.70 +      run_next_test();
    1.71 +    });
    1.72 +  });
    1.73 +});
    1.74 +
    1.75 +// Tests that enabling a restartless add-on works
    1.76 +add_test(function() {
    1.77 +  loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
    1.78 +    var doc = aTab.linkedBrowser.contentDocument;
    1.79 +    is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
    1.80 +
    1.81 +    is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
    1.82 +    is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
    1.83 +
    1.84 +    is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
    1.85 +       "Should be showing the right buttons");
    1.86 +
    1.87 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
    1.88 +                                       {}, aTab.linkedBrowser.contentWindow);
    1.89 +
    1.90 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
    1.91 +                                       {}, aTab.linkedBrowser.contentWindow);
    1.92 +
    1.93 +    is(gBrowser.tabs.length, 1, "Page should have been closed");
    1.94 +
    1.95 +    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
    1.96 +      ok(!aAddon.userDisabled, "Add-on should now have been enabled");
    1.97 +
    1.98 +      ok(aAddon.isActive, "Add-on should now be running");
    1.99 +
   1.100 +      run_next_test();
   1.101 +    });
   1.102 +  });
   1.103 +});
   1.104 +
   1.105 +// Tests that ignoring a non-restartless add-on works
   1.106 +add_test(function() {
   1.107 +  loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
   1.108 +    var doc = aTab.linkedBrowser.contentDocument;
   1.109 +    is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
   1.110 +
   1.111 +    is_element_visible(doc.getElementById("author"), "Should be an author displayed");
   1.112 +    is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
   1.113 +    is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
   1.114 +
   1.115 +    is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
   1.116 +       "Should be showing the right buttons");
   1.117 +
   1.118 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
   1.119 +                                       {}, aTab.linkedBrowser.contentWindow);
   1.120 +
   1.121 +    is(gBrowser.tabs.length, 1, "Page should have been closed");
   1.122 +
   1.123 +    AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
   1.124 +      ok(aAddon.userDisabled, "Add-on should not have been enabled");
   1.125 +
   1.126 +      ok(!aAddon.isActive, "Add-on should not be running");
   1.127 +
   1.128 +      run_next_test();
   1.129 +    });
   1.130 +  });
   1.131 +});
   1.132 +
   1.133 +// Tests that enabling a non-restartless add-on works
   1.134 +add_test(function() {
   1.135 +  loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
   1.136 +    var doc = aTab.linkedBrowser.contentDocument;
   1.137 +    is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
   1.138 +
   1.139 +    is_element_visible(doc.getElementById("author"), "Should be an author displayed");
   1.140 +    is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
   1.141 +    is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
   1.142 +
   1.143 +    is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
   1.144 +       "Should be showing the right buttons");
   1.145 +
   1.146 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
   1.147 +                                       {}, aTab.linkedBrowser.contentWindow);
   1.148 +
   1.149 +    EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
   1.150 +                                       {}, aTab.linkedBrowser.contentWindow);
   1.151 +
   1.152 +    is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("restartPanel"),
   1.153 +       "Should be showing the right buttons");
   1.154 +
   1.155 +    AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
   1.156 +      ok(!aAddon.userDisabled, "Add-on should now have been enabled");
   1.157 +
   1.158 +      ok(!aAddon.isActive, "Add-on should not be running");
   1.159 +
   1.160 +      ok(doc.getElementById("allow").disabled, "Should have disabled checkbox");
   1.161 +
   1.162 +      EventUtils.synthesizeMouseAtCenter(doc.getElementById("cancel-button"),
   1.163 +                                         {}, aTab.linkedBrowser.contentWindow);
   1.164 +
   1.165 +      is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
   1.166 +         "Should be showing the right buttons");
   1.167 +
   1.168 +      ok(!doc.getElementById("allow").disabled, "Should have enabled checkbox");
   1.169 +
   1.170 +      ok(aAddon.userDisabled, "Add-on should not have been enabled");
   1.171 +
   1.172 +      ok(!aAddon.isActive, "Add-on should not be running");
   1.173 +
   1.174 +      EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
   1.175 +                                         {}, aTab.linkedBrowser.contentWindow);
   1.176 +
   1.177 +      EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
   1.178 +                                         {}, aTab.linkedBrowser.contentWindow);
   1.179 +
   1.180 +      ok(aAddon.userDisabled, "Add-on should not have been enabled");
   1.181 +
   1.182 +      ok(!aAddon.isActive, "Add-on should not be running");
   1.183 +
   1.184 +      is(gBrowser.tabs.length, 1, "Page should have been closed");
   1.185 +
   1.186 +      run_next_test();
   1.187 +    });
   1.188 +  });
   1.189 +});

mercurial