toolkit/content/tests/chrome/test_toolbar.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
     3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Toolbar" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     6         onload="startTest();">
     8   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    10   <toolbox id="toolbox">
    11     <toolbarpalette>
    12       <toolbarbutton id="p1" label="p1"/>
    13       <toolbarbutton id="p2" label="p2"/>
    14       <toolbarbutton id="p3" label="p3"/>
    15       <toolbarbutton id="p4" label="p4"/>
    16       <toolbarbutton id="p5" label="p5"/>
    17       <toolbarbutton id="p6" label="p6"/>
    18       <toolbarbutton id="p7" label="p7"/>
    19       <toolbarbutton id="p8" label="p8"/>
    20       <toolbarbutton id="p9" label="p9"/>
    21       <toolbarbutton id="p10" label="p10"/>
    22       <toolbarbutton id="p11" label="p11"/>
    23       <toolbarbutton id="p12" label="p12"/>
    24     </toolbarpalette>
    26     <toolbar id="tb1" defaultset="p1,p2"/>
    27     <toolbar id="tb2" defaultset="p4,p3"/>
    28     <toolbar id="tb3" defaultset="p5,p6,t31">
    29       <toolbarbutton id="t31" label="t31" removable="true"/>
    30     </toolbar>
    31     <toolbar id="tb4" defaultset="t41,p7,p8">
    32       <toolbarbutton id="t41" label="t41" removable="true"/>
    33     </toolbar>
    34     <toolbar id="tb5" defaultset="p9,t51,p10">
    35       <toolbarbutton id="t51" label="t51" removable="true"/>
    36     </toolbar>
    38     <toolbar id="tb-test" defaultset="p11,p12"/>
    39     <toolbar id="tb-test2" defaultset=""/>
    40     <!-- fixed toolbarbuttons always have 'fixed' in their id -->
    41     <toolbar id="tb-test3" defaultset="">
    42       <toolbarbutton id="tb-fixed-1" label="tb-test3-1"/>
    43       <toolbarbutton id="tb-fixed-2" label="tb-test3-2" removable="false"/>
    44       <toolbarbutton id="tb-fixed-3" label="tb-test3-3"/>
    45     </toolbar>
    46   </toolbox>
    48   <toolbar id="notoolbox"/>
    50   <!-- test resuls are displayed in the html:body -->
    51   <body xmlns="http://www.w3.org/1999/xhtml"
    52         style="height: 300px; overflow: auto;"/>
    54   <!-- test code goes here -->
    55   <script type="text/javascript"><![CDATA[
    56     const SPACER = /^spacer\d+/;
    57     const SEPARATOR = /^separator\d+/;
    58     const SPRING = /^spring\d+/;
    60     function testSet(aTb, aIDs, aResultIDs, aUseFixed) {
    61       // build a list of the fixed items in the order they appear on the toolbar
    62       var fixedSet = [];
    63       if (aUseFixed) {
    64         for (let i = 0; i < aTb.childNodes.length; i++) {
    65           var id = aTb.childNodes[i].id;
    66           if (id.indexOf("fixed") >= 0)
    67             fixedSet.push(id);
    68         }
    69       }
    71       var currentSet = aIDs.join(",");
    72       ok(currentSet, "setting currentSet: " + currentSet);
    73       aTb.currentSet = currentSet;
    74       var resultIDs = aResultIDs || aIDs;
    75       checkSet(aTb, resultIDs, fixedSet);
    76     }
    78     var checkSetCount = 0;
    79     function checkSet(aTb, aResultIDs, aFixedSet) {
    80       checkSetCount++;
    81       var testID = "checkSet(" + checkSetCount + ") ";
    83       for (let i = 0; i < aTb.childNodes.length; i++) {
    84         let id = aTb.childNodes[i].id;
    85         if (aResultIDs[i] instanceof RegExp) {
    86           ok(aResultIDs[i].test(id),
    87              testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + "; got: " + id);
    88         }
    89         else if (aResultIDs[i] == "*") {
    90           is(id, aFixedSet.shift(), testID + "is fixed with ID " + id + " for toolbar " + aTb.id);
    91         }
    92         else {
    93           is(id, aResultIDs[i],
    94              testID + "correct ID " + aResultIDs[i] + " for toolbar " + aTb.id + 
    95              "****" + aResultIDs + "," + i + ",");
    96           // remove the item from the fixed set once found
    97           if (aFixedSet && id.indexOf("fixed") >= 0)
    98             aFixedSet.splice(aFixedSet.indexOf(id), 1);
    99         }
   100       }
   102       if (aFixedSet)
   103         is(aFixedSet.length, 0, testID + "extra fixed items for " + aTb.id);
   104       is(aTb.childNodes.length, aResultIDs.length,
   105          testID + "correct number of children for " + aTb.id);
   106     }
   108     function test_defaultSet() {
   109       checkSet($("tb1"), ["p1", "p2"]);
   110       checkSet($("tb2"), ["p4", "p3"]);
   111       checkSet($("tb3"), ["p5", "p6", "t31"]);
   112       checkSet($("tb4"), ["t41", "p7", "p8"]);
   113       checkSet($("tb5"), ["p9", "t51", "p10"]);
   114     }
   116     function test_currentSet(aTb) {
   117       ok(aTb, "have toolbar");
   118       var defaultSet = aTb.getAttribute("defaultset");
   119       var setLength = (defaultSet && defaultSet.split(",").length) || 0;
   120       is(setLength, aTb.childNodes.length, "correct # of children initially");
   122       var emptySet = [["__empty"], []];
   123       var testSets = [
   124          emptySet,
   125          [["p11"]],
   126          [["p11","p12"]],
   127          [["p11","p12","bogus"], ["p11","p12"]],
   128          [["p11"]],
   129          emptySet,
   130          [["spacer"],    [SPACER]],
   131          [["spring"],    [SPRING]],
   132          [["separator"], [SEPARATOR]],
   133          [["p11", "p11", "p12", "spacer", "p11"], ["p11", "p12", SPACER]],
   134          [["separator", "separator", "p11", "spring", "spacer"],
   135           [SEPARATOR, SEPARATOR, "p11", SPRING, SPACER]],
   136          [["separator", "spacer", "separator", "p11", "spring", "spacer", "p12", "spring"],
   137           [SEPARATOR, SPACER, SEPARATOR, "p11", SPRING, SPACER, "p12", SPRING]],
   138          emptySet
   139       ];
   141       cycleSets(aTb, testSets, emptySet, false);
   142     }
   144     function test_currentSet_nonremovable() {
   145       var tb = $("tb-test3");
   146       ok(tb, "have tb-test-3");
   148       // the * used in the tests below means that any fixed item can appear in that position
   149       var emptySet = [["__empty"], ["*", "*", "*"]];
   150       var testSets = [
   151         [["p1", "tb-fixed-1", "p2"],
   152          ["p1", "tb-fixed-1", "p2", "*", "*"]],
   153         [["p1", "tb-fixed-2", "p2"],
   154          ["p1", "tb-fixed-2", "p2", "*", "*"]],
   155         [["p1", "tb-fixed-3", "p2"],
   156          ["p1", "tb-fixed-3", "p2", "*", "*"]],
   157         emptySet,
   159         [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"],
   160          ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3"]],
   161         [["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"],
   162          ["tb-fixed-3", "tb-fixed-2", "tb-fixed-1"]],
   164         [["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"],
   165          ["tb-fixed-1", "tb-fixed-2", "tb-fixed-3", "p1", "p2"]],
   167         [["tb-fixed-1", "p2", "p1"],
   168          ["tb-fixed-1", "p2", "p1", "*", "*"]],
   170         [["tb-fixed-1", "p2"],
   171          ["tb-fixed-1", "p2", "*", "*"]],
   173         [["p1", "p2"], ["p1", "p2", "*", "*", "*"]],
   174         [["p2", "p1"], ["p2", "p1", "*", "*", "*"]],
   176         [["tb-fixed-3", "spacer", "p1"],
   177          ["tb-fixed-3", SPACER, "p1", "*", "*"]]
   178       ];
   180       cycleSets(tb, testSets, emptySet, true);
   181     }
   183     function cycleSets(aTb, aSets, aEmptySet, aUseFixed) {
   184       // Since a lot of the tricky cases handled in the currentSet setter
   185       // depend on going from one state to another, run through the test set
   186       // multiple times in different orders.
   187       var length = aSets.length;
   189       for (var i = 0; i < length; i++) {
   190         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   191       }
   192       for (var i = length - 1; i >= 0; i--) {
   193         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   194       }
   195       for (var i = 0; i < length; i++) {
   196         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   197         testSet(aTb, aSets[length - i - 1][0], aSets[length - i - 1][1], aUseFixed);
   198         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   199         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   200       }
   201       for (var i = 0; i < length; i++) {
   202         testSet(aTb, aEmptySet[0], aEmptySet[1], aUseFixed);
   203         testSet(aTb, aSets[i][0], aSets[i][1], aUseFixed);
   204       }
   205     }
   207     SimpleTest.waitForExplicitFinish();
   208     function startTest() {
   209       test_defaultSet();
   210       test_currentSet($("tb-test"));
   211       test_currentSet($("tb-test2"));
   212       test_currentSet_nonremovable();
   214       var toolbox = $("toolbox");
   215       var toolbars = document.getElementsByTagName("toolbar");
   216       for (var t = 0; t < toolbars.length; t++) {
   217         var toolbar = toolbars[t];
   218         is(toolbar.toolbox, toolbar.id == "notoolbox" ? null : toolbox,
   219            "toolbar " + toolbar.id + " has correct toolbox");
   220       }
   222       $("tb1").toolbox = document.documentElement;
   223       is($("tb1").toolbox, toolbox, "toolbox still correct after set");
   224       SimpleTest.finish();
   225     }
   226   ]]></script>
   227 </window>

mercurial