Commit fc881130 authored by Daisuke Akatsuka's avatar Daisuke Akatsuka
Browse files

Bug 1678623: Apply bookmark-title-changed event. r=mak

Depends on D103147

Differential Revision: https://phabricator.services.mozilla.com/D103148
parent d246521e
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -177,6 +177,16 @@ let observer = new (class extends EventEmitter {
            },
          });
          break;
        case "bookmark-title-changed":
          if (event.isTagging) {
            continue;
          }

          this.emit("changed", {
            guid: event.guid,
            info: { title: event.title },
          });
          break;
      }
    }
  }
@@ -194,17 +204,9 @@ let observer = new (class extends EventEmitter {
    oldVal,
    source
  ) {
    let info = {};
    if (prop == "title") {
      info.title = val;
    } else if (prop == "uri") {
      info.url = val;
    } else {
      // Not defined yet.
      return;
    if (prop === "uri") {
      this.emit("changed", { guid, info: { url: val } });
    }

    this.emit("changed", { guid, info });
  }
})();

@@ -213,7 +215,12 @@ const decrementListeners = () => {
  if (!listenerCount) {
    PlacesUtils.bookmarks.removeObserver(observer);
    PlacesUtils.observers.removeListener(
      ["bookmark-added", "bookmark-removed", "bookmark-moved"],
      [
        "bookmark-added",
        "bookmark-removed",
        "bookmark-moved",
        "bookmark-title-changed",
      ],
      observer.handlePlacesEvents
    );
  }
@@ -224,7 +231,12 @@ const incrementListeners = () => {
  if (listenerCount == 1) {
    PlacesUtils.bookmarks.addObserver(observer);
    PlacesUtils.observers.addListener(
      ["bookmark-added", "bookmark-removed", "bookmark-moved"],
      [
        "bookmark-added",
        "bookmark-removed",
        "bookmark-moved",
        "bookmark-title-changed",
      ],
      observer.handlePlacesEvents
    );
  }
+8 −8
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ add_task(async function test_bookmarks() {
    }

    function checkOnChanged(id, url, title) {
      // If both url and title are changed, then url is fired last.
      // If both url and title are changed, then title (PlacesEvent) is fired last.
      let changedData = collectedEvents.pop();
      browser.test.assertEq(
        "onChanged",
@@ -166,11 +166,11 @@ add_task(async function test_bookmarks() {
        "onChanged event received the expected id"
      );
      browser.test.assertEq(
        url,
        changedData.info.url,
        "onChanged event received the expected url"
        title,
        changedData.info.title,
        "onChanged event received the expected title"
      );
      // title is fired first.
      // url is fired first.
      changedData = collectedEvents.pop();
      browser.test.assertEq(
        "onChanged",
@@ -183,9 +183,9 @@ add_task(async function test_bookmarks() {
        "onChanged event received the expected id"
      );
      browser.test.assertEq(
        title,
        changedData.info.title,
        "onChanged event received the expected title"
        url,
        changedData.info.url,
        "onChanged event received the expected url"
      );
    }

+8 −10
Original line number Diff line number Diff line
@@ -343,7 +343,7 @@ var gEditItemOverlay = {
      PlacesUtils.bookmarks.addObserver(this);
      this.handlePlacesEvents = this.handlePlacesEvents.bind(this);
      PlacesUtils.observers.addListener(
        ["bookmark-moved"],
        ["bookmark-moved", "bookmark-title-changed"],
        this.handlePlacesEvents
      );
      window.addEventListener("unload", this);
@@ -561,7 +561,7 @@ var gEditItemOverlay = {
    if (this._observersAdded) {
      PlacesUtils.bookmarks.removeObserver(this);
      PlacesUtils.observers.removeListener(
        ["bookmark-moved"],
        ["bookmark-moved", "bookmark-title-changed"],
        this.handlePlacesEvents
      );
      window.removeEventListener("unload", this);
@@ -1154,6 +1154,12 @@ var gEditItemOverlay = {
            bm.title
          );
          break;
        case "bookmark-title-changed":
          if (this._paneInfo.isItem || this._paneInfo.isTag) {
            // This also updates titles of folders in the folder menu list.
            this._onItemTitleChange(event.id, event.title, event.guid);
          }
          break;
      }
    }
  },
@@ -1271,14 +1277,6 @@ var gEditItemOverlay = {
      this._onTagsChange(aGuid).catch(Cu.reportError);
      return;
    }
    if (
      aProperty == "title" &&
      (this._paneInfo.isItem || this._paneInfo.isTag)
    ) {
      // This also updates titles of folders in the folder menu list.
      this._onItemTitleChange(aItemId, aValue, aGuid);
      return;
    }

    if (!this._paneInfo.isItem || this._paneInfo.itemId != aItemId) {
      return;
+3 −2
Original line number Diff line number Diff line
@@ -34,8 +34,9 @@ add_task(async function() {
      },
      async function test(dialogWin) {
        let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
          "onItemChanged",
          (itemId, prop, isAnno, val) => prop == "title" && val == "n"
          "bookmark-title-changed",
          events => events.some(e => e.title === "n"),
          "places"
        );

        fillBookmarkTextField("editBMPanel_namePicker", "n", dialogWin, false);
+4 −2
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@ add_task(async function() {
      Assert.equal(namepicker.value, folderName, "Name field is correct.");

      let promiseTitleChange = PlacesTestUtils.waitForNotification(
        "onItemChanged",
        (id, prop, isAnno, val) => prop == "title" && val == "folder"
        "bookmark-title-changed",
        events => events.some(e => e.title === "folder"),
        "places"
      );

      fillBookmarkTextField("editBMPanel_namePicker", "folder", dialog);
      await promiseTitleChange;

Loading