summaryrefslogtreecommitdiff
path: root/browser/base/content/test/browser_allTabsPanel.js
blob: eb82c0d1ae00cab76045926668a7b0e3f20838ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function test() {
  waitForExplicitFinish();

  Services.prefs.setBoolPref(allTabs.prefName, true);
  registerCleanupFunction(function () {
    Services.prefs.clearUserPref(allTabs.prefName);
  });

  allTabs.init();
  nextSequence();
}

var sequences = 3;
var chars = "ABCDEFGHI";
var closedTabs;
var history;
var steps;
var whenOpen = [
  startSearch,
  clearSearch, clearSearch,
  closeTab,
  moveTab,
  closePanel,
];
var whenClosed = [
  openPanel, openPanel, openPanel, openPanel, openPanel, openPanel,
  closeTab, closeTab, closeTab,
  moveTab, moveTab, moveTab,
  selectTab, selectTab,
  undoCloseTab,
  openTab,
];

function rand(min, max) {
  return min + Math.floor(Math.random() * (max - min + 1));
}
function pickOne(array) {
  return array[rand(0, array.length - 1)];
}
function pickOneTab() {
  var tab = pickOne(gBrowser.tabs);
  return [tab, Array.indexOf(gBrowser.tabs, tab)];
}
function nextSequence() {
  while (gBrowser.browsers.length > 1)
    gBrowser.removeCurrentTab();
  if (sequences-- <= 0) {
    allTabs.close();
    gBrowser.addTab();
    gBrowser.removeCurrentTab();
    finish();
    return;
  }
  closedTabs = 0;
  steps = rand(10, 20);
  var initialTabs = "";
  while (gBrowser.browsers.length < rand(3, 20)) {
    let tabChar = pickOne(chars);
    initialTabs += tabChar;
    gBrowser.addTab("data:text/plain," + tabChar);
  }
  history = [initialTabs];
  gBrowser.removeCurrentTab();
  next();
}
function next() {
  executeSoon(function () {
    is(allTabs.previews.length, gBrowser.browsers.length,
       history.join(", "));
    if (steps-- <= 0) {
      nextSequence();
      return;
    }
    var step;
    var rv;
    do {
      step = pickOne(allTabs.isOpen ? whenOpen : whenClosed);
      info(step.name);
      rv = step();
    } while (rv === false);
    history.push(step.name + (rv !== true && rv !== undefined ? " " + rv : ""));
  });
}

function openPanel() {
  if (allTabs.isOpen)
    return false;
  allTabs.panel.addEventListener("popupshown", function () {
    allTabs.panel.removeEventListener("popupshown", arguments.callee, false);
    next();
  }, false);
  allTabs.open();
  return true;
}

function closePanel() {
  allTabs.panel.addEventListener("popuphidden", function () {
    allTabs.panel.removeEventListener("popuphidden", arguments.callee, false);
    next();
  }, false);
  allTabs.close();
}

function closeTab() {
  if (gBrowser.browsers.length == 1)
    return false;
  var [tab, index] = pickOneTab();
  gBrowser.removeTab(tab);
  closedTabs++;
  next();
  return index;
}

function startSearch() {
  allTabs.filterField.value = pickOne(chars);
  info(allTabs.filterField.value);
  allTabs.filter();
  next();
  return allTabs.filterField.value;
}

function clearSearch() {
  if (!allTabs.filterField.value)
    return false;
  allTabs.filterField.value = "";
  allTabs.filter();
  next();
  return true;
}

function undoCloseTab() {
  if (!closedTabs)
    return false;
  window.undoCloseTab(0);
  closedTabs--;
  next();
  return true;
}

function selectTab() {
  var [tab, index] = pickOneTab();
  gBrowser.selectedTab = tab;
  next();
  return index;
}

function openTab() {
  BrowserOpenTab();
  next();
}

function moveTab() {
  if (gBrowser.browsers.length == 1)
    return false;
  var [tab, currentIndex] = pickOneTab();
  do {
    var [, newIndex] = pickOneTab();
  } while (newIndex == currentIndex);
  gBrowser.moveTabTo(tab, newIndex);
  next();
  return currentIndex + "->" + newIndex;
}