Bug 876277 - Make widgets always return labels and values in the displayed order, to avoid tests failing because of the async way in which items could be added, r=past

This commit is contained in:
Victor Porof 2013-09-13 16:23:14 +03:00
Родитель 2ce3425857
Коммит 1160234392
9 изменённых файлов: 33 добавлений и 76 удалений

Просмотреть файл

@ -686,7 +686,7 @@ RequestsMenuView.prototype = Heritage.extend(WidgetMethods, {
* Adds odd/even attributes to all the visible items in this container.
*/
refreshZebra: function() {
let visibleItems = this.orderedVisibleItems;
let visibleItems = this.visibleItems;
for (let i = 0, len = visibleItems.length; i < len; i++) {
let requestItem = visibleItems[i];

Просмотреть файл

@ -101,7 +101,7 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.orderedItems.length, aVisibility.length,
is(RequestsMenu.items.length, aVisibility.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisibility.filter(e => e).length,
"There should be a specific amount of visbile items in the requests menu.");

Просмотреть файл

@ -82,7 +82,7 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.orderedItems.length, aVisibility.length,
is(RequestsMenu.items.length, aVisibility.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisibility.filter(e => e).length,
"There should be a specific amount of visbile items in the requests menu.");

Просмотреть файл

@ -96,13 +96,13 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after filtering.");
is(RequestsMenu.orderedItems.length, aOrder.length,
is(RequestsMenu.items.length, aOrder.length,
"There should be a specific amount of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aVisible,
"There should be a specific amount of visbile items in the requests menu.");
for (let i = 0; i < aOrder.length; i++) {
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.orderedItems[i],
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.items[i],
"The requests menu items aren't ordered correctly. Misplaced item " + i + ".");
}

Просмотреть файл

@ -178,20 +178,20 @@ function test() {
});
function testContents([a, b, c, d, e]) {
is(RequestsMenu.orderedItems.length, 5,
is(RequestsMenu.items.length, 5,
"There should be a total of 5 items in the requests menu.");
is(RequestsMenu.visibleItems.length, 5,
"There should be a total of 5 visbile items in the requests menu.");
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.orderedItems[0],
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0],
"The requests menu items aren't ordered correctly. First item is misplaced.");
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.orderedItems[1],
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1],
"The requests menu items aren't ordered correctly. Second item is misplaced.");
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.orderedItems[2],
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2],
"The requests menu items aren't ordered correctly. Third item is misplaced.");
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.orderedItems[3],
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3],
"The requests menu items aren't ordered correctly. Fourth item is misplaced.");
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.orderedItems[4],
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4],
"The requests menu items aren't ordered correctly. Fifth item is misplaced.");
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),

Просмотреть файл

@ -174,20 +174,20 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after sorting.");
is(RequestsMenu.orderedItems.length, 5,
is(RequestsMenu.items.length, 5,
"There should be a total of 5 items in the requests menu.");
is(RequestsMenu.visibleItems.length, 5,
"There should be a total of 5 visbile items in the requests menu.");
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.orderedItems[0],
is(RequestsMenu.getItemAtIndex(0), RequestsMenu.items[0],
"The requests menu items aren't ordered correctly. First item is misplaced.");
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.orderedItems[1],
is(RequestsMenu.getItemAtIndex(1), RequestsMenu.items[1],
"The requests menu items aren't ordered correctly. Second item is misplaced.");
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.orderedItems[2],
is(RequestsMenu.getItemAtIndex(2), RequestsMenu.items[2],
"The requests menu items aren't ordered correctly. Third item is misplaced.");
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.orderedItems[3],
is(RequestsMenu.getItemAtIndex(3), RequestsMenu.items[3],
"The requests menu items aren't ordered correctly. Fourth item is misplaced.");
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.orderedItems[4],
is(RequestsMenu.getItemAtIndex(4), RequestsMenu.items[4],
"The requests menu items aren't ordered correctly. Fifth item is misplaced.");
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(a),

Просмотреть файл

@ -110,13 +110,13 @@ function test() {
is(NetMonitorView.detailsPaneHidden, false,
"The details pane should still be visible after sorting.");
is(RequestsMenu.orderedItems.length, aOrder.length,
is(RequestsMenu.items.length, aOrder.length,
"There should be a specific number of items in the requests menu.");
is(RequestsMenu.visibleItems.length, aOrder.length,
"There should be a specific number of visbile items in the requests menu.");
for (let i = 0; i < aOrder.length; i++) {
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.orderedItems[i],
is(RequestsMenu.getItemAtIndex(i), RequestsMenu.items[i],
"The requests menu items aren't ordered correctly. Misplaced item " + i + ".");
}

Просмотреть файл

@ -193,7 +193,7 @@ function verifyRequestItemTarget(aRequestItem, aMethod, aUrl, aData = {}) {
let requestsMenu = aRequestItem.ownerView;
let widgetIndex = requestsMenu.indexOfItem(aRequestItem);
let visibleIndex = requestsMenu.orderedVisibleItems.indexOf(aRequestItem);
let visibleIndex = requestsMenu.visibleItems.indexOf(aRequestItem);
info("Widget index of item: " + widgetIndex);
info("Visible index of item: " + visibleIndex);

Просмотреть файл

@ -812,7 +812,7 @@ this.WidgetMethods = {
* If unspecified, all items will be sorted by their label.
*/
sortContents: function(aPredicate = this._currentSortPredicate) {
let sortedItems = this.orderedItems.sort(this._currentSortPredicate = aPredicate);
let sortedItems = this.items.sort(this._currentSortPredicate = aPredicate);
for (let i = 0, len = sortedItems.length; i < len; i++) {
this.swapItems(this.getItemAtIndex(i), sortedItems[i]);
@ -1314,67 +1314,32 @@ this.WidgetMethods = {
get itemCount() this._itemsByElement.size,
/**
* Returns a list of items in this container, in no particular order.
* Returns a list of items in this container, in the displayed order.
* @return array
*/
get items() {
let items = [];
for (let [, item] of this._itemsByElement) {
items.push(item);
let store = [];
let itemCount = this.itemCount;
for (let i = 0; i < itemCount; i++) {
store.push(this.getItemAtIndex(i));
}
return items;
return store;
},
/**
* Returns a list of labels in this container, in no particular order.
* Returns a list of labels in this container, in the displayed order.
* @return array
*/
get labels() {
let labels = [];
for (let [label] of this._itemsByLabel) {
labels.push(label);
}
return labels;
return this.items.map(e => e._label);
},
/**
* Returns a list of values in this container, in no particular order.
* Returns a list of values in this container, in the displayed order.
* @return array
*/
get values() {
let values = [];
for (let [value] of this._itemsByValue) {
values.push(value);
}
return values;
},
/**
* Returns a list of all the visible (non-hidden) items in this container,
* in no particular order.
* @return array
*/
get visibleItems() {
let items = [];
for (let [element, item] of this._itemsByElement) {
if (!element.hidden) {
items.push(item);
}
}
return items;
},
/**
* Returns a list of all items in this container, in the displayed order.
* @return array
*/
get orderedItems() {
let items = [];
let itemCount = this.itemCount;
for (let i = 0; i < itemCount; i++) {
items.push(this.getItemAtIndex(i));
}
return items;
return this.items.map(e => e._value);
},
/**
@ -1382,16 +1347,8 @@ this.WidgetMethods = {
* in the displayed order
* @return array
*/
get orderedVisibleItems() {
let items = [];
let itemCount = this.itemCount;
for (let i = 0; i < itemCount; i++) {
let item = this.getItemAtIndex(i);
if (!item._target.hidden) {
items.push(item);
}
}
return items;
get visibleItems() {
return this.items.filter(e => !e._target.hidden);
},
/**