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 that the visible delay in showing the "Language" category occurs michael@0: // very minimally michael@0: michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: var gProvider; michael@0: var gInstall; michael@0: var gInstallProperties = [{ michael@0: name: "Locale Category Test", michael@0: type: "locale" michael@0: }]; michael@0: michael@0: function test() { michael@0: try { michael@0: if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) { michael@0: requestLongerTimeout(2); michael@0: } michael@0: } catch(e) {} michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, finish); michael@0: } michael@0: michael@0: function install_locale(aCallback) { michael@0: gInstall = gProvider.createInstalls(gInstallProperties)[0]; michael@0: gInstall.addTestListener({ michael@0: onInstallEnded: function(aInstall) { michael@0: gInstall.removeTestListener(this); michael@0: aCallback(); michael@0: } michael@0: }); michael@0: gInstall.install(); michael@0: } michael@0: michael@0: function check_hidden(aExpectedHidden) { michael@0: var hidden = !gCategoryUtilities.isTypeVisible("locale"); michael@0: is(hidden, !!aExpectedHidden, "Should have correct hidden state"); michael@0: } michael@0: michael@0: function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) { michael@0: function loadCallback(aManagerWindow) { michael@0: gManagerWindow = aManagerWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: check_hidden(aLoadHidden); michael@0: } michael@0: michael@0: function run() { michael@0: open_manager(null, function() { michael@0: check_hidden(aInitializedHidden); michael@0: var selected = (gCategoryUtilities.selectedCategory == "locale"); michael@0: is(selected, !!aSelected, "Should have correct selected state"); michael@0: michael@0: run_next_test(); michael@0: }, loadCallback); michael@0: } michael@0: michael@0: close_manager(gManagerWindow, function() { michael@0: // Allow for asynchronous functions to run before the manager opens michael@0: aTestSetup ? aTestSetup(run) : run(); michael@0: }); michael@0: } michael@0: michael@0: michael@0: // Tests that the locale category is hidden when there are no locales installed michael@0: add_test(function() { michael@0: run_open_test(null, true, true); michael@0: }); michael@0: michael@0: // Tests that installing a locale while the Add-on Manager is open shows the michael@0: // locale category michael@0: add_test(function() { michael@0: check_hidden(true); michael@0: install_locale(function() { michael@0: check_hidden(false); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that the locale category is shown with no delay when restarting michael@0: // Add-on Manager michael@0: add_test(function() { michael@0: run_open_test(null, false, false); michael@0: }); michael@0: michael@0: // Tests that cancelling the locale install and restarting the Add-on Manager michael@0: // causes the locale category to be hidden with an acceptable delay michael@0: add_test(function() { michael@0: gInstall.cancel(); michael@0: run_open_test(null, false, true) michael@0: }); michael@0: michael@0: // Tests that the locale category is hidden with no delay when restarting michael@0: // Add-on Manager michael@0: add_test(function() { michael@0: run_open_test(null, true, true); michael@0: }); michael@0: michael@0: // Tests that installing a locale when the Add-on Manager is closed, and then michael@0: // opening the Add-on Manager causes the locale category to be shown with an michael@0: // acceptable delay michael@0: add_test(function() { michael@0: run_open_test(install_locale, true, false); michael@0: }); michael@0: michael@0: // Tests that selection of the locale category persists michael@0: add_test(function() { michael@0: gCategoryUtilities.openType("locale", function() { michael@0: run_open_test(null, false, false, true); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that cancelling the locale install and restarting the Add-on Manager michael@0: // causes the locale category to be hidden and not selected michael@0: add_test(function() { michael@0: gInstall.cancel(); michael@0: run_open_test(null, false, true); michael@0: }); michael@0: