Bug 1342427 - Setting Web Feeds in Application Preferences to "Add Live Bookmarks" then reselecting it appears to revert to "Preview in Nightly". r=jaws
authorMark Banner <standard8@mozilla.com>
Mon, 27 Feb 2017 13:37:30 +0000
changeset 345259 a88a6717a2b7830c24f1d14970309224a8db4f80
parent 345258 f32a30e626416f963ac3bd6a08d4a71d8ea084ea
child 345260 0d6ca3d14e5b4e0a6ace7e72f074e2b29e8400f6
push id87555
push usercbook@mozilla.com
push dateWed, 01 Mar 2017 15:40:32 +0000
treeherdermozilla-inbound@33c9d4c02376 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1342427
milestone54.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 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,79 @@
+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 - use the pdf item as that doesn't
+  // need to load any favicons.
+  let anotherItem = container.querySelector("richlistitem[type='application/pdf']");
+
+  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.");
+});