summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_bug485100-change-case-loses-tag.js
blob: e11ae1cfc2bd478cf45358d2d7db2abaf93f7388 (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
"use strict";

const TEST_URL = "http://www.example.com/";
const testTag = "foo";
const testTagUpper = "Foo";
const testURI = Services.io.newURI(TEST_URL);

add_task(async function test() {
  // Add a bookmark.
  let bm = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    index: PlacesUtils.bookmarks.DEFAULT_INDEX,
    type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
    title: "mozilla",
    url: testURI,
  });

  const win = await BrowserTestUtils.openNewBrowserWindow();
  registerCleanupFunction(async () => {
    await BrowserTestUtils.closeWindow(win);
  });
  win.StarUI._createPanelIfNeeded();

  await BrowserTestUtils.withNewTab(
    {
      gBrowser: win.gBrowser,
      url: TEST_URL,
    },
    async () => {
      // Init panel
      await TestUtils.waitForCondition(
        () => BookmarkingUI.status !== BookmarkingUI.STATUS_UPDATING
      );
      await clickBookmarkStar(win);

      // add a tag
      await fillBookmarkTextField("editBMPanel_tagsField", testTag, win);
      let promiseNotification = PlacesTestUtils.waitForNotification(
        "bookmark-tags-changed"
      );
      await hideBookmarksPanel(win);
      await promiseNotification;

      // test that the tag has been added in the backend
      is(PlacesUtils.tagging.getTagsForURI(testURI)[0], testTag, "tags match");

      // change the tag
      await TestUtils.waitForCondition(
        () => BookmarkingUI.status !== BookmarkingUI.STATUS_UPDATING
      );
      await clickBookmarkStar(win);
      await fillBookmarkTextField("editBMPanel_tagsField", testTagUpper, win);
      // The old sync API doesn't notify a tags change, and fixing it would be
      // quite complex, so we just wait for a title change until tags are
      // refactored.
      promiseNotification = PlacesTestUtils.waitForNotification(
        "bookmark-title-changed"
      );
      await hideBookmarksPanel(win);
      await promiseNotification;

      // test that the tag has been added in the backend
      is(
        PlacesUtils.tagging.getTagsForURI(testURI)[0],
        testTagUpper,
        "tags match"
      );

      // Cleanup.
      PlacesUtils.tagging.untagURI(testURI, [testTag]);
      await PlacesUtils.bookmarks.remove(bm.guid);
    }
  );
});