summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_bookmark_remove_tags.js
blob: ece5fdbce05c8e7c59e781dc55d33f7ab075c581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/**
 * Tests that the bookmark tags can be removed from the bookmark star, toolbar and sidebar.
 */
"use strict";

const TEST_URL = "about:buildconfig";
const TEST_URI = Services.io.newURI(TEST_URL);
const TEST_TAG = "tag";

// Setup.
add_setup(async function () {
  let toolbar = document.getElementById("PersonalToolbar");
  let wasCollapsed = toolbar.collapsed;

  // Uncollapse the personal toolbar if needed.
  if (wasCollapsed) {
    await promiseSetToolbarVisibility(toolbar, true);
  }

  // Cleanup.
  registerCleanupFunction(async () => {
    // Collapse the personal toolbar if needed.
    if (wasCollapsed) {
      await promiseSetToolbarVisibility(toolbar, false);
    }
    await PlacesUtils.bookmarks.eraseEverything();
  });
});

add_task(async function test_remove_tags_from_BookmarkStar() {
  await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
    url: TEST_URL,
    title: TEST_URL,
  });
  PlacesUtils.tagging.tagURI(TEST_URI, ["tag1", "tag2", "tag3", "tag4"]);

  let tab = await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    opening: TEST_URL,
    waitForStateStop: true,
  });

  registerCleanupFunction(async () => {
    BrowserTestUtils.removeTab(tab);
  });

  StarUI._createPanelIfNeeded();
  await clickBookmarkStar();

  // Check if the "Edit This Bookmark" panel is open.
  let bookmarkPanelTitle = document.getElementById("editBookmarkPanelTitle");
  Assert.equal(
    document.l10n.getAttributes(bookmarkPanelTitle).id,
    "bookmarks-edit-bookmark",
    "Bookmark panel title is correct."
  );

  let promiseTagsChange = PlacesTestUtils.waitForNotification(
    "bookmark-tags-changed"
  );

  // Update the "tags" field.
  fillBookmarkTextField("editBMPanel_tagsField", "tag1, tag2, tag3", window);
  let tagspicker = document.getElementById("editBMPanel_tagsField");
  await TestUtils.waitForCondition(
    () => tagspicker.value === "tag1, tag2, tag3",
    "Tags are correct after update."
  );

  let doneButton = document.getElementById("editBookmarkPanelDoneButton");
  doneButton.click();
  await promiseTagsChange;

  let tags = PlacesUtils.tagging.getTagsForURI(TEST_URI);
  Assert.deepEqual(
    tags,
    ["tag1", "tag2", "tag3"],
    "Should have updated the bookmark tags in the database."
  );
});

add_task(async function test_remove_tags_from_Toolbar() {
  let toolbarBookmark = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    title: TEST_URL,
    url: TEST_URL,
  });

  let toolbarNode = getToolbarNodeForItemGuid(toolbarBookmark.guid);

  await withBookmarksDialog(
    false,
    async function openPropertiesDialog() {
      let placesContext = document.getElementById("placesContext");
      let promisePopup = BrowserTestUtils.waitForEvent(
        placesContext,
        "popupshown"
      );
      EventUtils.synthesizeMouseAtCenter(toolbarNode, {
        button: 2,
        type: "contextmenu",
      });
      await promisePopup;

      let properties = document.getElementById(
        "placesContext_show_bookmark:info"
      );
      placesContext.activateItem(properties, {});
    },
    async function test(dialogWin) {
      let tagspicker = dialogWin.document.getElementById(
        "editBMPanel_tagsField"
      );
      Assert.equal(
        tagspicker.value,
        "tag1, tag2, tag3",
        "Tags are correct before update."
      );

      let promiseTagsChange = PlacesTestUtils.waitForNotification(
        "bookmark-tags-changed"
      );

      // Update the "tags" field.
      fillBookmarkTextField(
        "editBMPanel_tagsField",
        "tag1, tag2",
        dialogWin,
        false
      );
      await TestUtils.waitForCondition(
        () => tagspicker.value === "tag1, tag2",
        "Tags are correct after update."
      );

      // Confirm and close the dialog.
      EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
      await promiseTagsChange;

      let tags = PlacesUtils.tagging.getTagsForURI(TEST_URI);
      Assert.deepEqual(
        tags,
        ["tag1", "tag2"],
        "Should have updated the bookmark tags in the database."
      );
    }
  );
});

add_task(async function test_remove_tags_from_Sidebar() {
  let bookmarks = [];
  await PlacesUtils.bookmarks.fetch({ url: TEST_URL }, bm =>
    bookmarks.push(bm)
  );

  await withSidebarTree("bookmarks", async function (tree) {
    tree.selectItems([bookmarks[0].guid]);

    await withBookmarksDialog(
      false,
      function openPropertiesDialog() {
        tree.controller.doCommand("placesCmd_show:info");
      },
      async function test(dialogWin) {
        let tagspicker = dialogWin.document.getElementById(
          "editBMPanel_tagsField"
        );
        Assert.equal(
          tagspicker.value,
          "tag1, tag2",
          "Tags are correct before update."
        );

        let promiseTagsChange = PlacesTestUtils.waitForNotification(
          "bookmark-tags-changed"
        );

        // Update the "tags" field.
        fillBookmarkTextField(
          "editBMPanel_tagsField",
          "tag1",
          dialogWin,
          false
        );
        await TestUtils.waitForCondition(
          () => tagspicker.value === "tag1",
          "Tags are correct after update."
        );

        // Confirm and close the dialog.
        EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
        await promiseTagsChange;

        let tags = PlacesUtils.tagging.getTagsForURI(TEST_URI);
        Assert.deepEqual(
          tags,
          ["tag1"],
          "Should have updated the bookmark tags in the database."
        );
      }
    );
  });
});

add_task(async function test_remove_tags_from_Library() {
  await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
    url: TEST_URL,
    title: TEST_URL,
  });
  PlacesUtils.tagging.tagURI(TEST_URI, [TEST_TAG]);
  const getTags = () => PlacesUtils.tagging.getTagsForURI(TEST_URI);

  // Open the Library and select the tag.
  const library = await promiseLibrary("place:tag=" + TEST_TAG);

  registerCleanupFunction(async function () {
    await promiseLibraryClosed(library);
  });

  const contextMenu = library.document.getElementById("placesContext");
  const contextMenuDeleteTag = library.document.getElementById(
    "placesContext_removeTag"
  );

  let firstColumn = library.ContentTree.view.columns[0];
  let firstBookmarkRect = library.ContentTree.view.getCoordsForCellItem(
    0,
    firstColumn,
    "bm0"
  );

  EventUtils.synthesizeMouse(
    library.ContentTree.view.body,
    firstBookmarkRect.x,
    firstBookmarkRect.y,
    { type: "contextmenu", button: 2 },
    library
  );

  await BrowserTestUtils.waitForEvent(contextMenu, "popupshown");

  ok(getTags().includes(TEST_TAG), "Test tag exists before delete.");

  contextMenu.activateItem(contextMenuDeleteTag, {});

  await PlacesTestUtils.waitForNotification("bookmark-tags-changed");
  await promiseLibraryClosed(library);

  ok(
    await PlacesUtils.bookmarks.fetch({ url: TEST_URL }),
    "Bookmark still exists after removing tag."
  );
  ok(!getTags().includes(TEST_TAG), "Test tag is removed after delete.");
});