Bug 1327947 - Remove id's from about:preferences#containers as it breaks sorting for applications. r?jaws
MozReview-Commit-ID: H39D5kT4lc5
--- a/browser/components/preferences/in-content-new/containers.xul
+++ b/browser/components/preferences/in-content-new/containers.xul
@@ -30,24 +30,16 @@
<!-- Containers -->
<groupbox id="browserContainersGroupPane" data-category="paneContainers" hidden="true"
data-hidden-from-search="true" data-subpanel="true">
<vbox id="browserContainersbox">
<richlistbox id="containersView" orient="vertical" persist="lastSelectedType"
flex="1">
- <listheader equalsize="always">
- <treecol id="typeColumn" value="type"
- persist="sortDirection"
- flex="1" sortDirection="ascending"/>
- <treecol id="actionColumn" value="action"
- persist="sortDirection"
- flex="1"/>
- </listheader>
</richlistbox>
</vbox>
<vbox>
<hbox flex="1">
<button onclick="gContainersPane.onAddButtonClick();" accesskey="&addButton.accesskey;" label="&addButton.label;"/>
</hbox>
</vbox>
</groupbox>
--- a/browser/components/preferences/in-content-new/tests/browser_applications_selection.js
+++ b/browser/components/preferences/in-content-new/tests/browser_applications_selection.js
@@ -14,17 +14,17 @@ add_task(async function setup() {
});
add_task(async function getFeedItem() {
win = gBrowser.selectedBrowser.contentWindow;
container = win.document.getElementById("handlersView");
feedItem = container.querySelector("richlistitem[type='application/vnd.mozilla.maybe.feed']");
Assert.ok(feedItem, "feedItem is present in handlersView.");
-})
+});
add_task(async function selectInternalOptionForFeed() {
// Select the item.
feedItem.scrollIntoView();
container.selectItem(feedItem);
Assert.ok(feedItem.selected, "Should be able to select our item.");
// Wait for the menu.
@@ -72,8 +72,90 @@ add_task(async function reselectInternal
info("Got list after item was selected");
Assert.ok(list.selectedItem,
"Should have a selected item");
Assert.equal(list.selectedItem.getAttribute("action"),
Ci.nsIHandlerInfo.handleInternally,
"Selected item should still be the same as the previously selected item.");
});
+
+add_task(async function sortingCheck() {
+ win = gBrowser.selectedBrowser.contentWindow;
+
+ const handlerView = win.document.getElementById("handlersView");
+ const typeColumn = win.document.getElementById("typeColumn");
+ Assert.ok(typeColumn, "typeColumn is present in handlersView.");
+
+ // Test default sorting
+ assertSortByType("ascending");
+
+ const oldDir = typeColumn.getAttribute("sortDirection");
+
+
+ // Test sorting on the type column
+ typeColumn.click();
+ assertSortByType("descending");
+ Assert.notEqual(oldDir,
+ typeColumn.getAttribute("sortDirection"),
+ "Sort direction should change");
+
+ typeColumn.click();
+ assertSortByType("ascending");
+
+ const actionColumn = win.document.getElementById("actionColumn");
+ Assert.ok(actionColumn, "actionColumn is present in handlersView.");
+
+ // Test sorting on the action column
+ const oldActionDir = actionColumn.getAttribute("sortDirection");
+ actionColumn.click();
+ assertSortByAction("ascending");
+ Assert.notEqual(oldActionDir,
+ actionColumn.getAttribute("sortDirection"),
+ "Sort direction should change");
+
+ actionColumn.click();
+ assertSortByAction("descending");
+
+ function assertSortByAction(order) {
+ Assert.equal(actionColumn.getAttribute("sortDirection"),
+ order,
+ `Sort direction should be ${order}`);
+ let siteItems = handlerView.getElementsByTagName("richlistitem");
+ for (let i = 0; i < siteItems.length - 1; ++i) {
+ let aType = siteItems[i].getAttribute("actionDescription").toLowerCase();
+ let bType = siteItems[i + 1].getAttribute("actionDescription").toLowerCase();
+ let result = 0;
+ if (aType > bType) {
+ result = 1;
+ } else if (bType > aType) {
+ result = -1;
+ }
+ if (order == "ascending") {
+ Assert.lessOrEqual(result, 0, "Should sort applications in the ascending order by action");
+ } else {
+ Assert.greaterOrEqual(result, 0, "Should sort applications in the descending order by action");
+ }
+ }
+ }
+
+ function assertSortByType(order) {
+ Assert.equal(typeColumn.getAttribute("sortDirection"),
+ order,
+ `Sort direction should be ${order}`);
+ let siteItems = handlerView.getElementsByTagName("richlistitem");
+ for (let i = 0; i < siteItems.length - 1; ++i) {
+ let aType = siteItems[i].getAttribute("typeDescription").toLowerCase();
+ let bType = siteItems[i + 1].getAttribute("typeDescription").toLowerCase();
+ let result = 0;
+ if (aType > bType) {
+ result = 1;
+ } else if (bType > aType) {
+ result = -1;
+ }
+ if (order == "ascending") {
+ Assert.lessOrEqual(result, 0, "Should sort applications in the ascending order by type");
+ } else {
+ Assert.greaterOrEqual(result, 0, "Should sort applications in the descending order by type");
+ }
+ }
+ }
+});
--- a/browser/components/preferences/in-content/containers.xul
+++ b/browser/components/preferences/in-content/containers.xul
@@ -31,24 +31,16 @@
</hbox>
<!-- Containers -->
<groupbox id="browserContainersGroup" data-category="paneContainers" hidden="true">
<vbox id="browserContainersbox">
<richlistbox id="containersView" orient="vertical" persist="lastSelectedType"
flex="1">
- <listheader equalsize="always">
- <treecol id="typeColumn" value="type"
- persist="sortDirection"
- flex="1" sortDirection="ascending"/>
- <treecol id="actionColumn" value="action"
- persist="sortDirection"
- flex="1"/>
- </listheader>
</richlistbox>
</vbox>
<vbox>
<hbox flex="1">
<button onclick="gContainersPane.onAddButtonClick();" accesskey="&addButton.accesskey;" label="&addButton.label;"/>
</hbox>
</vbox>
</groupbox>
--- a/browser/components/preferences/in-content/tests/browser_applications_selection.js
+++ b/browser/components/preferences/in-content/tests/browser_applications_selection.js
@@ -72,8 +72,90 @@ add_task(async function reselectInternal
info("Got list after item was selected");
Assert.ok(list.selectedItem,
"Should have a selected item");
Assert.equal(list.selectedItem.getAttribute("action"),
Ci.nsIHandlerInfo.handleInternally,
"Selected item should still be the same as the previously selected item.");
});
+
+add_task(async function sortingCheck() {
+ win = gBrowser.selectedBrowser.contentWindow;
+
+ const handlerView = win.document.getElementById("handlersView");
+ const typeColumn = win.document.getElementById("typeColumn");
+ Assert.ok(typeColumn, "typeColumn is present in handlersView.");
+
+ // Test default sorting
+ assertSortByType("ascending");
+
+ const oldDir = typeColumn.getAttribute("sortDirection");
+
+
+ // Test sorting on the type column
+ typeColumn.click();
+ assertSortByType("descending");
+ Assert.notEqual(oldDir,
+ typeColumn.getAttribute("sortDirection"),
+ "Sort direction should change");
+
+ typeColumn.click();
+ assertSortByType("ascending");
+
+ const actionColumn = win.document.getElementById("actionColumn");
+ Assert.ok(actionColumn, "actionColumn is present in handlersView.");
+
+ // Test sorting on the action column
+ const oldActionDir = actionColumn.getAttribute("sortDirection");
+ actionColumn.click();
+ assertSortByAction("ascending");
+ Assert.notEqual(oldActionDir,
+ actionColumn.getAttribute("sortDirection"),
+ "Sort direction should change");
+
+ actionColumn.click();
+ assertSortByAction("descending");
+
+ function assertSortByAction(order) {
+ Assert.equal(actionColumn.getAttribute("sortDirection"),
+ order,
+ `Sort direction should be ${order}`);
+ let siteItems = handlerView.getElementsByTagName("richlistitem");
+ for (let i = 0; i < siteItems.length - 1; ++i) {
+ let aType = siteItems[i].getAttribute("actionDescription").toLowerCase();
+ let bType = siteItems[i + 1].getAttribute("actionDescription").toLowerCase();
+ let result = 0;
+ if (aType > bType) {
+ result = 1;
+ } else if (bType > aType) {
+ result = -1;
+ }
+ if (order == "ascending") {
+ Assert.lessOrEqual(result, 0, "Should sort applications in the ascending order by action");
+ } else {
+ Assert.greaterOrEqual(result, 0, "Should sort applications in the descending order by action");
+ }
+ }
+ }
+
+ function assertSortByType(order) {
+ Assert.equal(typeColumn.getAttribute("sortDirection"),
+ order,
+ `Sort direction should be ${order}`);
+ let siteItems = handlerView.getElementsByTagName("richlistitem");
+ for (let i = 0; i < siteItems.length - 1; ++i) {
+ let aType = siteItems[i].getAttribute("typeDescription").toLowerCase();
+ let bType = siteItems[i + 1].getAttribute("typeDescription").toLowerCase();
+ let result = 0;
+ if (aType > bType) {
+ result = 1;
+ } else if (bType > aType) {
+ result = -1;
+ }
+ if (order == "ascending") {
+ Assert.lessOrEqual(result, 0, "Should sort applications in the ascending order by type");
+ } else {
+ Assert.greaterOrEqual(result, 0, "Should sort applications in the descending order by type");
+ }
+ }
+ }
+});