Bug 1327947 - Remove id's from about:preferences#containers as it breaks sorting for applications. r=jaws, a=jcristau
authorJonathan Kingston <jkt@mozilla.com>
Wed, 05 Jul 2017 17:45:27 -0700
changeset 414361 64f34d964fa3924d976793e1490e2f554d5840a4
parent 414360 fe847bf98f6ad35e96f98a218741a7bdcffe0ebd
child 414362 20b0f0b4a61218a67893f2252f378f8ad35b2876
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, jcristau
bugs1327947
milestone55.0
Bug 1327947 - Remove id's from about:preferences#containers as it breaks sorting for applications. r=jaws, a=jcristau MozReview-Commit-ID: H39D5kT4lc5
browser/components/preferences/in-content-new/containers.xul
browser/components/preferences/in-content-new/tests/browser_applications_selection.js
browser/components/preferences/in-content/containers.xul
browser/components/preferences/in-content/tests/browser_applications_selection.js
--- a/browser/components/preferences/in-content-new/containers.xul
+++ b/browser/components/preferences/in-content-new/containers.xul
@@ -29,24 +29,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-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");
+      }
+    }
+  }
+});