browser/components/tabview/test/browser_tabview_bug616729.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/ */
     4 function test() {
     5   let cw;
     7   let createGroupItem = function () {
     8     return createGroupItemWithBlankTabs(window, 400, 200, 0, 5);
     9   }
    11   let assertCorrectItemOrder = function (items) {
    12     for (let i=1; i<items.length; i++) {
    13       if (items[i-1].tab._tPos > items[i].tab._tPos) {
    14         ok(false, 'tabs were correctly reordered');
    15         return;
    16       }
    17     }
    18     ok(true, 'tabs were correctly reordered');
    19   }
    21   let testVariousTabOrders = function () {
    22     let groupItem = createGroupItem();
    23     let [tab1, tab2, tab3, tab4, tab5] = groupItem.getChildren();
    25     // prepare tests
    26     let tests = [];
    27     tests.push([tab1, tab2, tab3, tab4, tab5]);
    28     tests.push([tab5, tab4, tab3, tab2, tab1]);
    29     tests.push([tab1, tab2, tab3, tab4]);
    30     tests.push([tab4, tab3, tab2, tab1]);
    31     tests.push([tab1, tab2, tab3]);
    32     tests.push([tab1, tab2, tab3]);
    33     tests.push([tab1, tab3, tab2]);
    34     tests.push([tab2, tab1, tab3]);
    35     tests.push([tab2, tab3, tab1]);
    36     tests.push([tab3, tab1, tab2]);
    37     tests.push([tab3, tab2, tab1]);
    38     tests.push([tab1, tab2]);
    39     tests.push([tab2, tab1]);
    40     tests.push([tab1]);
    42     // test reordering of empty groups - removes the last tab and causes
    43     // the groupItem to close
    44     tests.push([]);
    46     while (tests.length) {
    47       let test = tests.shift();
    49       // prepare
    50       let items = groupItem.getChildren();
    51       while (test.length < items.length)
    52         items[items.length-1].close();
    54       let orig = cw.Utils.copy(items);
    55       items.sort(function (a, b) test.indexOf(a) - test.indexOf(b));
    57       // order and check
    58       groupItem.reorderTabsBasedOnTabItemOrder();
    59       assertCorrectItemOrder(items);
    61       // revert to original item order
    62       items.sort(function (a, b) orig.indexOf(a) - orig.indexOf(b));
    63       groupItem.reorderTabsBasedOnTabItemOrder();
    64     }
    66     testMoveBetweenGroups();
    67   }
    69   let testMoveBetweenGroups = function () {
    70     let groupItem = createGroupItem();
    71     let groupItem2 = createGroupItem();
    73     afterAllTabsLoaded(function () {
    74       // move item from group1 to group2
    75       let child = groupItem.getChild(2);
    76       groupItem.remove(child);
    78       groupItem2.add(child, {index: 3});
    79       groupItem2.reorderTabsBasedOnTabItemOrder();
    81       assertCorrectItemOrder(groupItem.getChildren());
    82       assertCorrectItemOrder(groupItem2.getChildren());
    84       // move item from group2 to group1
    85       child = groupItem2.getChild(1);
    86       groupItem2.remove(child);
    88       groupItem.add(child, {index: 1});
    89       groupItem.reorderTabsBasedOnTabItemOrder();
    91       assertCorrectItemOrder(groupItem.getChildren());
    92       assertCorrectItemOrder(groupItem2.getChildren());
    94       // cleanup
    95       closeGroupItem(groupItem, function () {
    96         closeGroupItem(groupItem2, function () {
    97           hideTabView(finish);
    98         });
    99       });
   100     });
   101   }
   103   waitForExplicitFinish();
   105   showTabView(function () {
   106     cw = TabView.getContentWindow();
   107     afterAllTabsLoaded(testVariousTabOrders);
   108   });
   109 }

mercurial