toolkit/mozapps/extensions/test/browser/browser_bug580298.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.

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

mercurial