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 certain types of addons do not have their version number |
michael@0 | 6 | // displayed. This currently only includes lightweight themes. |
michael@0 | 7 | |
michael@0 | 8 | var gManagerWindow; |
michael@0 | 9 | var gCategoryUtilities; |
michael@0 | 10 | var gProvider; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | gProvider = new MockProvider(); |
michael@0 | 16 | |
michael@0 | 17 | gProvider.createAddons([{ |
michael@0 | 18 | id: "extension@tests.mozilla.org", |
michael@0 | 19 | name: "Extension 1", |
michael@0 | 20 | type: "extension", |
michael@0 | 21 | version: "123" |
michael@0 | 22 | }, { |
michael@0 | 23 | id: "theme@tests.mozilla.org", |
michael@0 | 24 | name: "Theme 2", |
michael@0 | 25 | type: "theme", |
michael@0 | 26 | version: "456" |
michael@0 | 27 | }, { |
michael@0 | 28 | id: "lwtheme@personas.mozilla.org", |
michael@0 | 29 | name: "Persona 3", |
michael@0 | 30 | type: "theme", |
michael@0 | 31 | version: "789" |
michael@0 | 32 | }]); |
michael@0 | 33 | |
michael@0 | 34 | open_manager(null, function(aWindow) { |
michael@0 | 35 | gManagerWindow = aWindow; |
michael@0 | 36 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 37 | run_next_test(); |
michael@0 | 38 | }); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function end_test() { |
michael@0 | 42 | close_manager(gManagerWindow, finish); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function get(aId) { |
michael@0 | 46 | return gManagerWindow.document.getElementById(aId); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function get_node(parent, anonid) { |
michael@0 | 50 | return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function open_details(aList, aItem, aCallback) { |
michael@0 | 54 | aList.ensureElementIsVisible(aItem); |
michael@0 | 55 | EventUtils.synthesizeMouseAtCenter(aItem, { clickCount: 1 }, gManagerWindow); |
michael@0 | 56 | EventUtils.synthesizeMouseAtCenter(aItem, { clickCount: 2 }, gManagerWindow); |
michael@0 | 57 | wait_for_view_load(gManagerWindow, aCallback); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function check_addon_has_version(aList, aName, aVersion) { |
michael@0 | 61 | for (let i = 0; i < aList.itemCount; i++) { |
michael@0 | 62 | let item = aList.getItemAtIndex(i); |
michael@0 | 63 | if (get_node(item, "name").value === aName) { |
michael@0 | 64 | ok(true, "Item with correct name found"); |
michael@0 | 65 | is(get_node(item, "version").value, aVersion, "Item has correct version"); |
michael@0 | 66 | return item; |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | ok(false, "Item with correct name was not found"); |
michael@0 | 70 | return null; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | add_test(function() { |
michael@0 | 74 | gCategoryUtilities.openType("extension", function() { |
michael@0 | 75 | info("Extension"); |
michael@0 | 76 | let list = gManagerWindow.document.getElementById("addon-list"); |
michael@0 | 77 | let item = check_addon_has_version(list, "Extension 1", "123"); |
michael@0 | 78 | open_details(list, item, function() { |
michael@0 | 79 | is_element_visible(get("detail-version"), "Details view has version visible"); |
michael@0 | 80 | is(get("detail-version").value, "123", "Details view has correct version"); |
michael@0 | 81 | run_next_test(); |
michael@0 | 82 | }); |
michael@0 | 83 | }); |
michael@0 | 84 | }); |
michael@0 | 85 | |
michael@0 | 86 | add_test(function() { |
michael@0 | 87 | gCategoryUtilities.openType("theme", function() { |
michael@0 | 88 | info("Normal theme"); |
michael@0 | 89 | let list = gManagerWindow.document.getElementById("addon-list"); |
michael@0 | 90 | let item = check_addon_has_version(list, "Theme 2", "456"); |
michael@0 | 91 | open_details(list, item, function() { |
michael@0 | 92 | is_element_visible(get("detail-version"), "Details view has version visible"); |
michael@0 | 93 | is(get("detail-version").value, "456", "Details view has correct version"); |
michael@0 | 94 | run_next_test(); |
michael@0 | 95 | }); |
michael@0 | 96 | }); |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | add_test(function() { |
michael@0 | 100 | gCategoryUtilities.openType("theme", function() { |
michael@0 | 101 | info("Lightweight theme"); |
michael@0 | 102 | let list = gManagerWindow.document.getElementById("addon-list"); |
michael@0 | 103 | // See that the version isn't displayed |
michael@0 | 104 | let item = check_addon_has_version(list, "Persona 3", ""); |
michael@0 | 105 | open_details(list, item, function() { |
michael@0 | 106 | is_element_hidden(get("detail-version"), "Details view has version hidden"); |
michael@0 | 107 | // If the version element is hidden then we don't care about its value |
michael@0 | 108 | run_next_test(); |
michael@0 | 109 | }); |
michael@0 | 110 | }); |
michael@0 | 111 | }); |