Bug 1342427 - Setting Web Feeds in Application Preferences to "Add Live Bookmarks" then reselecting it appears to revert to "Preview in Nightly". r?jaws draft
authorMark Banner <standard8@mozilla.com>
Mon, 27 Feb 2017 13:37:30 +0000
changeset 490132 9513c0d1ea1782222a6f09de2bccd85a6f69d398
parent 490032 106a96755d3bcebe64bbbc3b521d65d262ba9c02
child 547176 cb6520bf9a4dc408b8786e19d8e48b144a009f84
push id47006
push userbmo:standard8@mozilla.com
push dateMon, 27 Feb 2017 18:04:58 +0000
reviewersjaws
bugs1342427
milestone54.0a1
Bug 1342427 - Setting Web Feeds in Application Preferences to "Add Live Bookmarks" then reselecting it appears to revert to "Preview in Nightly". r?jaws MozReview-Commit-ID: KedE9gfOyp0
browser/components/preferences/in-content/applications.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_applications_selection.js
--- a/browser/components/preferences/in-content/applications.js
+++ b/browser/components/preferences/in-content/applications.js
@@ -1343,19 +1343,20 @@ var gApplicationsPane = {
     var menu =
       document.getAnonymousElementByAttribute(typeItem, "class", "actionsMenu");
     var menuPopup = menu.menupopup;
 
     // Clear out existing items.
     while (menuPopup.hasChildNodes())
       menuPopup.removeChild(menuPopup.lastChild);
 
+    let internalMenuItem;
     // Add the "Preview in Firefox" option for optional internal handlers.
     if (handlerInfo instanceof InternalHandlerInfoWrapper) {
-      let internalMenuItem = document.createElement("menuitem");
+      internalMenuItem = document.createElement("menuitem");
       internalMenuItem.setAttribute("action", Ci.nsIHandlerInfo.handleInternally);
       let label = this._prefsBundle.getFormattedString("previewInApp",
                                                        [this._brandShortName]);
       internalMenuItem.setAttribute("label", label);
       internalMenuItem.setAttribute("tooltiptext", label);
       internalMenuItem.setAttribute(APP_ICON_ATTR_NAME, "ask");
       menuPopup.appendChild(internalMenuItem);
     }
@@ -1387,17 +1388,17 @@ var gApplicationsPane = {
       saveMenuItem.setAttribute("label", label);
       saveMenuItem.setAttribute("tooltiptext", label);
       saveMenuItem.setAttribute(APP_ICON_ATTR_NAME, "save");
       menuPopup.appendChild(saveMenuItem);
     }
 
     // If this is the feed type, add a Live Bookmarks item.
     if (isFeedType(handlerInfo.type)) {
-      let internalMenuItem = document.createElement("menuitem");
+      internalMenuItem = document.createElement("menuitem");
       internalMenuItem.setAttribute("action", Ci.nsIHandlerInfo.handleInternally);
       let label = this._prefsBundle.getFormattedString("addLiveBookmarksInApp",
                                                        [this._brandShortName]);
       internalMenuItem.setAttribute("label", label);
       internalMenuItem.setAttribute("tooltiptext", label);
       internalMenuItem.setAttribute(APP_ICON_ATTR_NAME, "feed");
       menuPopup.appendChild(internalMenuItem);
     }
@@ -1499,17 +1500,21 @@ var gApplicationsPane = {
     // Select the item corresponding to the preferred action.  If the always
     // ask flag is set, it overrides the preferred action.  Otherwise we pick
     // the item identified by the preferred action (when the preferred action
     // is to use a helper app, we have to pick the specific helper app item).
     if (handlerInfo.alwaysAskBeforeHandling)
       menu.selectedItem = askMenuItem;
     else switch (handlerInfo.preferredAction) {
       case Ci.nsIHandlerInfo.handleInternally:
-        menu.selectedItem = internalMenuItem;
+        if (internalMenuItem) {
+          menu.selectedItem = internalMenuItem;
+        } else {
+          Cu.reportError("No menu item defined to set!")
+        }
         break;
       case Ci.nsIHandlerInfo.useSystemDefault:
         menu.selectedItem = defaultMenuItem;
         break;
       case Ci.nsIHandlerInfo.useHelperApp:
         if (preferredApp)
           menu.selectedItem =
             possibleAppMenuItems.filter(v => v.handlerApp.equals(preferredApp))[0];
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -1,14 +1,15 @@
 [DEFAULT]
 support-files =
   head.js
   privacypane_tests_perwindow.js
   site_data_test.html
 
+[browser_applications_selection.js]
 [browser_advanced_siteData.js]
 [browser_advanced_update.js]
 skip-if = !updater
 [browser_basic_rebuild_fonts_test.js]
 [browser_bug410900.js]
 [browser_bug705422.js]
 [browser_bug731866.js]
 [browser_bug795764_cachedisabled.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_applications_selection.js
@@ -0,0 +1,81 @@
+var win;
+var feedItem;
+var container;
+
+SimpleTest.requestCompleteLog();
+
+add_task(function* setup() {
+  yield openPreferencesViaOpenPreferencesAPI("applications", null, {leaveOpen: true});
+  info("Preferences page opened on the applications pane.");
+
+  registerCleanupFunction(() => {
+    gBrowser.removeCurrentTab();
+  });
+});
+
+add_task(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(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.
+  let list = yield waitForCondition(() =>
+    win.document.getAnonymousElementByAttribute(feedItem, "class", "actionsMenu"));
+  info("Got list after item was selected");
+
+  // Find the "Add Live bookmarks option".
+  let chooseItems = list.getElementsByAttribute("action", Ci.nsIHandlerInfo.handleInternally);
+  Assert.equal(chooseItems.length, 1, "Should only be one action to handle internally");
+
+  // Select the option.
+  let cmdEvent = win.document.createEvent("xulcommandevent");
+  cmdEvent.initCommandEvent("command", true, true, win, 0, false, false, false, false, null);
+  chooseItems[0].dispatchEvent(cmdEvent);
+
+  // Check that we display the correct result.
+  list = yield waitForCondition(() =>
+    win.document.getAnonymousElementByAttribute(feedItem, "class", "actionsMenu"));
+  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,
+               "Newly selected item should be the expected one.");
+});
+
+// This builds on the previous selectInternalOptionForFeed task.
+add_task(function* reselectInternalOptionForFeed() {
+  // Now select a different option in the list.
+  let anotherItem = container.getItemAtIndex(0);
+
+  Assert.notEqual(anotherItem, feedItem,
+                  "This test doesn't expect the feed item to be first.");
+
+  container.selectItem(anotherItem);
+
+  // Wait for the menu so that we don't hit race conditions.
+  yield waitForCondition(() =>
+    win.document.getAnonymousElementByAttribute(anotherItem, "class", "actionsMenu"));
+  info("Got list after item was selected");
+
+  // Now select the feed item again, and check what it is displaying.
+  container.selectItem(feedItem);
+
+  let list = yield waitForCondition(() =>
+    win.document.getAnonymousElementByAttribute(feedItem, "class", "actionsMenu"));
+  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.");
+});