Wed, 31 Dec 2014 06:09:35 +0100
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 that the visible delay in showing the "Language" category occurs |
michael@0 | 6 | // very minimally |
michael@0 | 7 | |
michael@0 | 8 | var gManagerWindow; |
michael@0 | 9 | var gCategoryUtilities; |
michael@0 | 10 | var gProvider; |
michael@0 | 11 | var gInstall; |
michael@0 | 12 | var gInstallProperties = [{ |
michael@0 | 13 | name: "Locale Category Test", |
michael@0 | 14 | type: "locale" |
michael@0 | 15 | }]; |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | try { |
michael@0 | 19 | if (Components.classes["@mozilla.org/gfx/info;1"].getService(Components.interfaces.nsIGfxInfo).D2DEnabled) { |
michael@0 | 20 | requestLongerTimeout(2); |
michael@0 | 21 | } |
michael@0 | 22 | } catch(e) {} |
michael@0 | 23 | waitForExplicitFinish(); |
michael@0 | 24 | |
michael@0 | 25 | gProvider = new MockProvider(); |
michael@0 | 26 | |
michael@0 | 27 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 28 | gManagerWindow = aWindow; |
michael@0 | 29 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 30 | run_next_test(); |
michael@0 | 31 | }); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function end_test() { |
michael@0 | 35 | close_manager(gManagerWindow, finish); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function install_locale(aCallback) { |
michael@0 | 39 | gInstall = gProvider.createInstalls(gInstallProperties)[0]; |
michael@0 | 40 | gInstall.addTestListener({ |
michael@0 | 41 | onInstallEnded: function(aInstall) { |
michael@0 | 42 | gInstall.removeTestListener(this); |
michael@0 | 43 | aCallback(); |
michael@0 | 44 | } |
michael@0 | 45 | }); |
michael@0 | 46 | gInstall.install(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function check_hidden(aExpectedHidden) { |
michael@0 | 50 | var hidden = !gCategoryUtilities.isTypeVisible("locale"); |
michael@0 | 51 | is(hidden, !!aExpectedHidden, "Should have correct hidden state"); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function run_open_test(aTestSetup, aLoadHidden, aInitializedHidden, aSelected) { |
michael@0 | 55 | function loadCallback(aManagerWindow) { |
michael@0 | 56 | gManagerWindow = aManagerWindow; |
michael@0 | 57 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 58 | check_hidden(aLoadHidden); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function run() { |
michael@0 | 62 | open_manager(null, function() { |
michael@0 | 63 | check_hidden(aInitializedHidden); |
michael@0 | 64 | var selected = (gCategoryUtilities.selectedCategory == "locale"); |
michael@0 | 65 | is(selected, !!aSelected, "Should have correct selected state"); |
michael@0 | 66 | |
michael@0 | 67 | run_next_test(); |
michael@0 | 68 | }, loadCallback); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | close_manager(gManagerWindow, function() { |
michael@0 | 72 | // Allow for asynchronous functions to run before the manager opens |
michael@0 | 73 | aTestSetup ? aTestSetup(run) : run(); |
michael@0 | 74 | }); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | |
michael@0 | 78 | // Tests that the locale category is hidden when there are no locales installed |
michael@0 | 79 | add_test(function() { |
michael@0 | 80 | run_open_test(null, true, true); |
michael@0 | 81 | }); |
michael@0 | 82 | |
michael@0 | 83 | // Tests that installing a locale while the Add-on Manager is open shows the |
michael@0 | 84 | // locale category |
michael@0 | 85 | add_test(function() { |
michael@0 | 86 | check_hidden(true); |
michael@0 | 87 | install_locale(function() { |
michael@0 | 88 | check_hidden(false); |
michael@0 | 89 | run_next_test(); |
michael@0 | 90 | }); |
michael@0 | 91 | }); |
michael@0 | 92 | |
michael@0 | 93 | // Tests that the locale category is shown with no delay when restarting |
michael@0 | 94 | // Add-on Manager |
michael@0 | 95 | add_test(function() { |
michael@0 | 96 | run_open_test(null, false, false); |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | // Tests that cancelling the locale install and restarting the Add-on Manager |
michael@0 | 100 | // causes the locale category to be hidden with an acceptable delay |
michael@0 | 101 | add_test(function() { |
michael@0 | 102 | gInstall.cancel(); |
michael@0 | 103 | run_open_test(null, false, true) |
michael@0 | 104 | }); |
michael@0 | 105 | |
michael@0 | 106 | // Tests that the locale category is hidden with no delay when restarting |
michael@0 | 107 | // Add-on Manager |
michael@0 | 108 | add_test(function() { |
michael@0 | 109 | run_open_test(null, true, true); |
michael@0 | 110 | }); |
michael@0 | 111 | |
michael@0 | 112 | // Tests that installing a locale when the Add-on Manager is closed, and then |
michael@0 | 113 | // opening the Add-on Manager causes the locale category to be shown with an |
michael@0 | 114 | // acceptable delay |
michael@0 | 115 | add_test(function() { |
michael@0 | 116 | run_open_test(install_locale, true, false); |
michael@0 | 117 | }); |
michael@0 | 118 | |
michael@0 | 119 | // Tests that selection of the locale category persists |
michael@0 | 120 | add_test(function() { |
michael@0 | 121 | gCategoryUtilities.openType("locale", function() { |
michael@0 | 122 | run_open_test(null, false, false, true); |
michael@0 | 123 | }); |
michael@0 | 124 | }); |
michael@0 | 125 | |
michael@0 | 126 | // Tests that cancelling the locale install and restarting the Add-on Manager |
michael@0 | 127 | // causes the locale category to be hidden and not selected |
michael@0 | 128 | add_test(function() { |
michael@0 | 129 | gInstall.cancel(); |
michael@0 | 130 | run_open_test(null, false, true); |
michael@0 | 131 | }); |
michael@0 | 132 |