summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_bookmarkProperties_editTagContainer.js
blob: f4e3b3e3fe11c971d047807a314fe7026f35497a (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
"use strict";

add_task(async function editTagContainer() {
  info("Bug 479348 - Properties on a root should be read-only.");
  let uri = Services.io.newURI("http://example.com/");
  let bm = await PlacesUtils.bookmarks.insert({
    url: uri.spec,
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
  });
  registerCleanupFunction(async function () {
    await PlacesUtils.bookmarks.remove(bm);
  });

  PlacesUtils.tagging.tagURI(uri, ["tag1"]);

  let library = await promiseLibrary();
  let PlacesOrganizer = library.PlacesOrganizer;
  registerCleanupFunction(async function () {
    await promiseLibraryClosed(library);
  });

  PlacesOrganizer.selectLeftPaneBuiltIn("Tags");
  let tree = PlacesOrganizer._places;
  let tagsContainer = tree.selectedNode;
  tagsContainer.containerOpen = true;
  let fooTag = tagsContainer.getChild(0);
  let tagNode = fooTag;
  tree.selectNode(fooTag);
  Assert.equal(tagNode.title, "tag1", "EditBookmark: tagNode title is correct");

  Assert.ok(
    tree.controller.isCommandEnabled("placesCmd_show:info"),
    "EditBookmark: 'placesCmd_show:info' on current selected node is enabled"
  );

  await withBookmarksDialog(
    true,
    function openDialog() {
      tree.controller.doCommand("placesCmd_show:info");
    },
    async function test(dialogWin) {
      // Check that the dialog is not read-only.
      Assert.ok(
        !dialogWin.gEditItemOverlay.readOnly,
        "EditBookmark: Dialog should not be read-only"
      );

      // Check that name picker is not read only
      let namepicker = dialogWin.document.getElementById(
        "editBMPanel_namePicker"
      );
      Assert.ok(
        !namepicker.readOnly,
        "EditBookmark: Name field should not be read-only"
      );
      Assert.equal(
        namepicker.value,
        "tag1",
        "EditBookmark: Node title is correct"
      );

      fillBookmarkTextField("editBMPanel_namePicker", "tag2", dialogWin);

      // Although we have received the expected notifications, we need
      // to let everything resolve to ensure the UI is updated.
      await new Promise(resolve => Services.tm.dispatchToMainThread(resolve));

      Assert.equal(
        namepicker.value,
        "tag2",
        "EditBookmark: The title field has been changed"
      );

      // Try to set an empty title, it should restore the previous one.
      fillBookmarkTextField("editBMPanel_namePicker", "", dialogWin);

      Assert.equal(
        namepicker.value,
        "tag1",
        "EditBookmark: The title field has been changed"
      );
    }
  );

  // Check the tag change hasn't changed
  let tags = PlacesUtils.tagging.getTagsForURI(uri);
  Assert.equal(tags.length, 1, "EditBookmark: Found the right number of tags");
  Assert.deepEqual(
    tags,
    ["tag1"],
    "EditBookmark: Found the expected unchanged tag"
  );

  await withBookmarksDialog(
    false,
    function openDialog() {
      tree.controller.doCommand("placesCmd_show:info");
    },
    async function test(dialogWin) {
      // Check that the dialog is not read-only.
      Assert.ok(
        !dialogWin.gEditItemOverlay.readOnly,
        "Dialog should not be read-only"
      );

      // Check that name picker is not read only
      let namepicker = dialogWin.document.getElementById(
        "editBMPanel_namePicker"
      );
      Assert.ok(
        !namepicker.readOnly,
        "EditBookmark: Name field should not be read-only"
      );
      Assert.equal(
        namepicker.value,
        "tag1",
        "EditBookmark: Node title is correct"
      );

      fillBookmarkTextField("editBMPanel_namePicker", "tag2", dialogWin);

      Assert.equal(
        namepicker.value,
        "tag2",
        "EditBookmark: The title field has been changed"
      );
      namepicker.blur();

      EventUtils.synthesizeKey("VK_RETURN", {}, dialogWin);
    }
  );

  tags = PlacesUtils.tagging.getTagsForURI(uri);
  Assert.equal(tags.length, 1, "EditBookmark: Found the right number of tags");
  Assert.deepEqual(
    tags,
    ["tag2"],
    "EditBookmark: Found the expected Y changed tag"
  );
});