michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests the new add-on tab michael@0: michael@0: var gProvider; michael@0: michael@0: function loadPage(aURL, aCallback) { michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gBrowser.loadURI(aURL); michael@0: gBrowser.addEventListener("AddonDisplayed", function(event) { michael@0: gBrowser.removeEventListener("AddonDisplayed", arguments.callee, false); michael@0: michael@0: aCallback(gBrowser.selectedTab); michael@0: }); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon1@tests.mozilla.org", michael@0: name: "Test 1", michael@0: version: "5.3", michael@0: userDisabled: true, michael@0: operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE michael@0: }, { michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "Test 2", michael@0: version: "7.1", michael@0: creator: "Dave Townsend", michael@0: userDisabled: true michael@0: }]); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: function end_test() { michael@0: finish(); michael@0: } michael@0: michael@0: // Tests that ignoring a restartless add-on works michael@0: add_test(function() { michael@0: loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) { michael@0: var doc = aTab.linkedBrowser.contentDocument; michael@0: is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name"); michael@0: michael@0: is_element_hidden(doc.getElementById("author"), "Should be no author displayed"); michael@0: is_element_hidden(doc.getElementById("location"), "Should be no location displayed"); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: is(gBrowser.tabs.length, 1, "Page should have been closed"); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: ok(aAddon.userDisabled, "Add-on should not have been enabled"); michael@0: michael@0: ok(!aAddon.isActive, "Add-on should not be running"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that enabling a restartless add-on works michael@0: add_test(function() { michael@0: loadPage("about:newaddon?id=addon1@tests.mozilla.org", function(aTab) { michael@0: var doc = aTab.linkedBrowser.contentDocument; michael@0: is(doc.getElementById("name").value, "Test 1 5.3", "Should say the right name"); michael@0: michael@0: is_element_hidden(doc.getElementById("author"), "Should be no author displayed"); michael@0: is_element_hidden(doc.getElementById("location"), "Should be no location displayed"); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: is(gBrowser.tabs.length, 1, "Page should have been closed"); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { michael@0: ok(!aAddon.userDisabled, "Add-on should now have been enabled"); michael@0: michael@0: ok(aAddon.isActive, "Add-on should now be running"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that ignoring a non-restartless add-on works michael@0: add_test(function() { michael@0: loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) { michael@0: var doc = aTab.linkedBrowser.contentDocument; michael@0: is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name"); michael@0: michael@0: is_element_visible(doc.getElementById("author"), "Should be an author displayed"); michael@0: is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author"); michael@0: is_element_hidden(doc.getElementById("location"), "Should be no location displayed"); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: is(gBrowser.tabs.length, 1, "Page should have been closed"); michael@0: michael@0: AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) { michael@0: ok(aAddon.userDisabled, "Add-on should not have been enabled"); michael@0: michael@0: ok(!aAddon.isActive, "Add-on should not be running"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that enabling a non-restartless add-on works michael@0: add_test(function() { michael@0: loadPage("about:newaddon?id=addon2@tests.mozilla.org", function(aTab) { michael@0: var doc = aTab.linkedBrowser.contentDocument; michael@0: is(doc.getElementById("name").value, "Test 2 7.1", "Should say the right name"); michael@0: michael@0: is_element_visible(doc.getElementById("author"), "Should be an author displayed"); michael@0: is(doc.getElementById("author").value, "By Dave Townsend", "Should have the right author"); michael@0: is_element_hidden(doc.getElementById("location"), "Should be no location displayed"); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("restartPanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) { michael@0: ok(!aAddon.userDisabled, "Add-on should now have been enabled"); michael@0: michael@0: ok(!aAddon.isActive, "Add-on should not be running"); michael@0: michael@0: ok(doc.getElementById("allow").disabled, "Should have disabled checkbox"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("cancel-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: is(doc.getElementById("buttonDeck").selectedPanel, doc.getElementById("continuePanel"), michael@0: "Should be showing the right buttons"); michael@0: michael@0: ok(!doc.getElementById("allow").disabled, "Should have enabled checkbox"); michael@0: michael@0: ok(aAddon.userDisabled, "Add-on should not have been enabled"); michael@0: michael@0: ok(!aAddon.isActive, "Add-on should not be running"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("allow"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(doc.getElementById("continue-button"), michael@0: {}, aTab.linkedBrowser.contentWindow); michael@0: michael@0: ok(aAddon.userDisabled, "Add-on should not have been enabled"); michael@0: michael@0: ok(!aAddon.isActive, "Add-on should not be running"); michael@0: michael@0: is(gBrowser.tabs.length, 1, "Page should have been closed"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: });