Bug 1453589 - Select next item in list when removing items in Site Data Manager. r=johannh
authorMichael Kohler <me@michaelkohler.info>
Thu, 19 Apr 2018 13:36:11 -0400
changeset 468110 7c588027cbbb6274f47a2000bfe055a3163977c4
parent 468109 e3509035413ca6ea2360f3b9497d836d35d826e5
child 468111 99ec19154f8ae42c178030c0581551c7c46d230c
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1453589
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1453589 - Select next item in list when removing items in Site Data Manager. r=johannh Select next item in list when removing items in Site Data Manager. When there are multiple selected sites, it will select the next item after the last previously selected item. Differential Revision: https://phabricator.services.mozilla.com/D965
browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
browser/components/preferences/in-content/tests/siteData/browser_siteData_multi_select.js
browser/components/preferences/in-content/tests/siteData/head.js
browser/components/preferences/siteDataSettings.js
--- a/browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData2.js
@@ -205,24 +205,26 @@ add_task(async function() {
   assertSitesListed(doc, fakeHosts.slice(2));
 
   await mockSiteDataManager.unregister();
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
   function removeSelectedSite(hosts) {
     frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
     let removeBtn = frameDoc.getElementById("removeSelected");
+    is(removeBtn.disabled, true, "Should start with disabled removeSelected button");
     let sitesList = frameDoc.getElementById("sitesList");
     hosts.forEach(host => {
       let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
       if (site) {
         site.click();
+        let currentSelectedIndex = sitesList.selectedIndex;
         is(removeBtn.disabled, false, "Should enable the removeSelected button");
         removeBtn.doCommand();
-        is(removeBtn.disabled, true, "Should disable the removeSelected button");
+        is(sitesList.selectedIndex, currentSelectedIndex);
       } else {
         ok(false, `Should not select and remove inexistent site of ${host}`);
       }
     });
   }
 });
 
 // Test searching and then removing only visible sites
--- a/browser/components/preferences/in-content/tests/siteData/browser_siteData_multi_select.js
+++ b/browser/components/preferences/in-content/tests/siteData/browser_siteData_multi_select.js
@@ -45,34 +45,34 @@ add_task(async function() {
   await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
   await updatePromise;
   await openSiteDataSettingsDialog();
 
   let doc = gBrowser.selectedBrowser.contentDocument;
 
   // Test the initial state
   assertSitesListed(doc, fakeHosts);
+  let win = gBrowser.selectedBrowser.contentWindow;
+  let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
+  let removeBtn = frameDoc.getElementById("removeSelected");
+  is(removeBtn.disabled, true, "Should start with disabled removeSelected button");
 
   let removeDialogOpenPromise = BrowserTestUtils.promiseAlertDialogOpen("accept", REMOVE_DIALOG_URL);
   let settingsDialogClosePromise = promiseSettingsDialogClose();
 
-  let win = gBrowser.selectedBrowser.contentWindow;
-  let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
-
   // Select some sites to remove.
   let sitesList = frameDoc.getElementById("sitesList");
   fakeHosts.slice(0, 2).forEach(host => {
     let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     sitesList.addItemToSelection(site);
   });
 
-  let removeBtn = frameDoc.getElementById("removeSelected");
   is(removeBtn.disabled, false, "Should enable the removeSelected button");
   removeBtn.doCommand();
-  is(removeBtn.disabled, true, "Should disable the removeSelected button");
+  is(sitesList.selectedIndex, 0, "Should select next item");
 
   let saveBtn = frameDoc.getElementById("save");
   assertSitesListed(doc, fakeHosts.slice(2));
   saveBtn.doCommand();
 
   await removeDialogOpenPromise;
   await settingsDialogClosePromise;
   await openSiteDataSettingsDialog();
--- a/browser/components/preferences/in-content/tests/siteData/head.js
+++ b/browser/components/preferences/in-content/tests/siteData/head.js
@@ -126,26 +126,24 @@ function promiseSettingsDialogClose() {
         resolve();
       }
     }, { once: true });
   });
 }
 
 function assertSitesListed(doc, hosts) {
   let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
-  let removeBtn = frameDoc.getElementById("removeSelected");
   let removeAllBtn = frameDoc.getElementById("removeAll");
   let sitesList = frameDoc.getElementById("sitesList");
   let totalSitesNumber = sitesList.getElementsByTagName("richlistitem").length;
   is(totalSitesNumber, hosts.length, "Should list the right sites number");
   hosts.forEach(host => {
     let site = sitesList.querySelector(`richlistitem[host="${host}"]`);
     ok(site, `Should list the site of ${host}`);
   });
-  is(removeBtn.disabled, true, "Should disable the removeSelected button");
   is(removeAllBtn.disabled, false, "Should enable the removeAllBtn button");
 }
 
 const mockSiteDataManager = {
 
   _SiteDataManager: null,
   _originalQMS: null,
   _originalRemoveQuotaUsage: null,
--- a/browser/components/preferences/siteDataSettings.js
+++ b/browser/components/preferences/siteDataSettings.js
@@ -254,18 +254,29 @@ let gSiteDataSettings = {
   },
 
   onCommandSearch() {
     this._buildSitesList(this._sites);
     this._list.clearSelection();
   },
 
   onClickRemoveSelected() {
+    let lastIndex = this._list.selectedItems.length - 1;
+    let lastSelectedItem = this._list.selectedItems[lastIndex];
+    let lastSelectedItemPosition = this._list.getIndexOfItem(lastSelectedItem);
+    let nextSelectedItem = this._list.getItemAtIndex(lastSelectedItemPosition + 1);
+
     this._removeSiteItems(this._list.selectedItems);
     this._list.clearSelection();
+
+    if (nextSelectedItem) {
+      this._list.selectedItem = nextSelectedItem;
+    } else {
+      this._list.selectedIndex = this._list.itemCount - 1;
+    }
   },
 
   onClickRemoveAll() {
     let siteItems = this._list.getElementsByTagName("richlistitem");
     if (siteItems.length > 0) {
       this._removeSiteItems(siteItems);
     }
   },