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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // Tests the new add-on tab
michael@0 6
michael@0 7 var gProvider;
michael@0 8
michael@0 9 function loadPage(aURL, aCallback) {
michael@0 10 gBrowser.selectedTab = gBrowser.addTab();
michael@0 11 gBrowser.loadURI(aURL);
michael@0 12 gBrowser.addEventListener("AddonDisplayed", function(event) {
michael@0 13 gBrowser.removeEventListener("AddonDisplayed", arguments.callee, false);
michael@0 14
michael@0 15 aCallback(gBrowser.selectedTab);
michael@0 16 });
michael@0 17 }
michael@0 18
michael@0 19 function test() {
michael@0 20 waitForExplicitFinish();
michael@0 21
michael@0 22 gProvider = new MockProvider();
michael@0 23
michael@0 24 gProvider.createAddons([{
michael@0 25 id: "addon1@tests.mozilla.org",
michael@0 26 name: "Test 1",
michael@0 27 version: "5.3",
michael@0 28 userDisabled: true,
michael@0 29 operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
michael@0 30 }, {
michael@0 31 id: "addon2@tests.mozilla.org",
michael@0 32 name: "Test 2",
michael@0 33 version: "7.1",
michael@0 34 creator: "Dave Townsend",
michael@0 35 userDisabled: true
michael@0 36 }]);
michael@0 37
michael@0 38 run_next_test();
michael@0 39 }
michael@0 40
michael@0 41 function end_test() {
michael@0 42 finish();
michael@0 43 }
michael@0 44
michael@0 45 // Tests that ignoring a restartless add-on works
michael@0 46 add_test(function() {
michael@0 47 loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
michael@0 48 var doc = aTab.linkedBrowser.contentDocument;
michael@0 49 is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
michael@0 50
michael@0 51 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
michael@0 52 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
michael@0 53
michael@0 54 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
michael@0 55 "Should be showing the right buttons");
michael@0 56
michael@0 57 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
michael@0 58 {}, aTab.linkedBrowser.contentWindow);
michael@0 59
michael@0 60 is(gBrowser.tabs.length, 1, "Page should have been closed");
michael@0 61
michael@0 62 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 63 ok(aAddon.userDisabled, "Add-on should not have been enabled");
michael@0 64
michael@0 65 ok(!aAddon.isActive, "Add-on should not be running");
michael@0 66
michael@0 67 run_next_test();
michael@0 68 });
michael@0 69 });
michael@0 70 });
michael@0 71
michael@0 72 // Tests that enabling a restartless add-on works
michael@0 73 add_test(function() {
michael@0 74 loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) {
michael@0 75 var doc = aTab.linkedBrowser.contentDocument;
michael@0 76 is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name");
michael@0 77
michael@0 78 is_element_hidden(doc.getElementById("author"), "Should be no author displayed");
michael@0 79 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
michael@0 80
michael@0 81 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
michael@0 82 "Should be showing the right buttons");
michael@0 83
michael@0 84 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
michael@0 85 {}, aTab.linkedBrowser.contentWindow);
michael@0 86
michael@0 87 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
michael@0 88 {}, aTab.linkedBrowser.contentWindow);
michael@0 89
michael@0 90 is(gBrowser.tabs.length, 1, "Page should have been closed");
michael@0 91
michael@0 92 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
michael@0 93 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
michael@0 94
michael@0 95 ok(aAddon.isActive, "Add-on should now be running");
michael@0 96
michael@0 97 run_next_test();
michael@0 98 });
michael@0 99 });
michael@0 100 });
michael@0 101
michael@0 102 // Tests that ignoring a non-restartless add-on works
michael@0 103 add_test(function() {
michael@0 104 loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
michael@0 105 var doc = aTab.linkedBrowser.contentDocument;
michael@0 106 is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
michael@0 107
michael@0 108 is_element_visible(doc.getElementById("author"), "Should be an author displayed");
michael@0 109 is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
michael@0 110 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
michael@0 111
michael@0 112 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
michael@0 113 "Should be showing the right buttons");
michael@0 114
michael@0 115 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
michael@0 116 {}, aTab.linkedBrowser.contentWindow);
michael@0 117
michael@0 118 is(gBrowser.tabs.length, 1, "Page should have been closed");
michael@0 119
michael@0 120 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
michael@0 121 ok(aAddon.userDisabled, "Add-on should not have been enabled");
michael@0 122
michael@0 123 ok(!aAddon.isActive, "Add-on should not be running");
michael@0 124
michael@0 125 run_next_test();
michael@0 126 });
michael@0 127 });
michael@0 128 });
michael@0 129
michael@0 130 // Tests that enabling a non-restartless add-on works
michael@0 131 add_test(function() {
michael@0 132 loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) {
michael@0 133 var doc = aTab.linkedBrowser.contentDocument;
michael@0 134 is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name");
michael@0 135
michael@0 136 is_element_visible(doc.getElementById("author"), "Should be an author displayed");
michael@0 137 is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author");
michael@0 138 is_element_hidden(doc.getElementById("location"), "Should be no location displayed");
michael@0 139
michael@0 140 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
michael@0 141 "Should be showing the right buttons");
michael@0 142
michael@0 143 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
michael@0 144 {}, aTab.linkedBrowser.contentWindow);
michael@0 145
michael@0 146 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
michael@0 147 {}, aTab.linkedBrowser.contentWindow);
michael@0 148
michael@0 149 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("restartPanel"),
michael@0 150 "Should be showing the right buttons");
michael@0 151
michael@0 152 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
michael@0 153 ok(!aAddon.userDisabled, "Add-on should now have been enabled");
michael@0 154
michael@0 155 ok(!aAddon.isActive, "Add-on should not be running");
michael@0 156
michael@0 157 ok(doc.getElementById("allow").disabled, "Should have disabled checkbox");
michael@0 158
michael@0 159 EventUtils.synthesizeMouseAtCenter(doc.getElementById("cancel-button"),
michael@0 160 {}, aTab.linkedBrowser.contentWindow);
michael@0 161
michael@0 162 is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"),
michael@0 163 "Should be showing the right buttons");
michael@0 164
michael@0 165 ok(!doc.getElementById("allow").disabled, "Should have enabled checkbox");
michael@0 166
michael@0 167 ok(aAddon.userDisabled, "Add-on should not have been enabled");
michael@0 168
michael@0 169 ok(!aAddon.isActive, "Add-on should not be running");
michael@0 170
michael@0 171 EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"),
michael@0 172 {}, aTab.linkedBrowser.contentWindow);
michael@0 173
michael@0 174 EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"),
michael@0 175 {}, aTab.linkedBrowser.contentWindow);
michael@0 176
michael@0 177 ok(aAddon.userDisabled, "Add-on should not have been enabled");
michael@0 178
michael@0 179 ok(!aAddon.isActive, "Add-on should not be running");
michael@0 180
michael@0 181 is(gBrowser.tabs.length, 1, "Page should have been closed");
michael@0 182
michael@0 183 run_next_test();
michael@0 184 });
michael@0 185 });
michael@0 186 });

mercurial