summaryrefslogtreecommitdiffstats
path: root/browser/components/enterprisepolicies/tests/browser/managedbookmarks/browser_policy_managedbookmarks.js
blob: 494f49978cabe88dd548b86999f4f6dccda40e12 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_policy_managedbookmarks() {
  let managedBookmarksMenu =
    window.document.getElementById("managed-bookmarks");

  is(
    managedBookmarksMenu.hidden,
    false,
    "Managed bookmarks button should be visible."
  );
  is(
    managedBookmarksMenu.label,
    "Folder 1",
    "Managed bookmarks buttons should have correct label"
  );

  let popupShownPromise = BrowserTestUtils.waitForEvent(
    managedBookmarksMenu.menupopup,
    "popupshown",
    false
  );
  let popupHiddenPromise = BrowserTestUtils.waitForEvent(
    managedBookmarksMenu.menupopup,
    "popuphidden",
    false
  );
  managedBookmarksMenu.open = true;
  await popupShownPromise;

  is(
    managedBookmarksMenu.menupopup.children[0].label,
    "Bookmark 1",
    "Bookmark should have correct label"
  );
  is(
    managedBookmarksMenu.menupopup.children[0].link,
    "https://example.com/",
    "Bookmark should have correct link"
  );
  is(
    managedBookmarksMenu.menupopup.children[1].label,
    "Bookmark 2",
    "Bookmark should have correct label"
  );
  is(
    managedBookmarksMenu.menupopup.children[1].link,
    "https://bookmark2.example.com/",
    "Bookmark should have correct link"
  );
  let subFolder = managedBookmarksMenu.menupopup.children[2];
  is(subFolder.label, "Folder 2", "Subfolder should have correct label");
  is(
    subFolder.menupopup.children[0].label,
    "Bookmark 3",
    "Bookmark should have correct label"
  );
  is(
    subFolder.menupopup.children[0].link,
    "https://bookmark3.example.com/",
    "Bookmark should have correct link"
  );
  is(
    subFolder.menupopup.children[1].label,
    "Bookmark 4",
    "Bookmark should have correct link"
  );
  is(
    subFolder.menupopup.children[1].link,
    "https://bookmark4.example.com/",
    "Bookmark should have correct label"
  );
  subFolder = managedBookmarksMenu.menupopup.children[3];
  await TestUtils.waitForCondition(() => {
    // Need to wait for Fluent to translate
    return subFolder.label == "Subfolder";
  }, "Subfolder should have correct label");
  is(
    subFolder.menupopup.children[0].label,
    "Bookmark 5",
    "Bookmark should have correct label"
  );
  is(
    subFolder.menupopup.children[0].link,
    "https://bookmark5.example.com/",
    "Bookmark should have correct link"
  );
  is(
    subFolder.menupopup.children[1].label,
    "Bookmark 6",
    "Bookmark should have correct link"
  );
  is(
    subFolder.menupopup.children[1].link,
    "https://bookmark6.example.com/",
    "Bookmark should have correct label"
  );

  managedBookmarksMenu.open = false;
  await popupHiddenPromise;
});

add_task(async function test_open_managedbookmark() {
  let managedBookmarksMenu =
    window.document.getElementById("managed-bookmarks");

  let promise = BrowserTestUtils.waitForEvent(
    managedBookmarksMenu.menupopup,
    "popupshown",
    false
  );
  managedBookmarksMenu.open = true;
  await promise;

  let context = document.getElementById("placesContext");
  let openContextMenuPromise = BrowserTestUtils.waitForEvent(
    context,
    "popupshown"
  );
  EventUtils.synthesizeMouseAtCenter(
    managedBookmarksMenu.menupopup.children[0],
    {
      button: 2,
      type: "contextmenu",
    }
  );
  await openContextMenuPromise;
  info("Opened context menu");

  ok(
    document.getElementById("placesContext_open:newprivatewindow").hidden,
    "Private Browsing menu should be hidden"
  );
  ok(
    document.getElementById("placesContext_openContainer:tabs").hidden,
    "Open in Tabs should be hidden"
  );
  ok(
    document.getElementById("placesContext_delete").hidden,
    "Delete should be hidden"
  );

  let tabCreatedPromise = BrowserTestUtils.waitForNewTab(gBrowser, null, true);

  let openInNewTabOption = document.getElementById("placesContext_open:newtab");
  context.activateItem(openInNewTabOption);
  info("Click open in new tab");

  let lastOpenedTab = await tabCreatedPromise;
  Assert.equal(
    lastOpenedTab.linkedBrowser.currentURI.spec,
    "https://example.com/",
    "Should have opened the correct URI"
  );
  await BrowserTestUtils.removeTab(lastOpenedTab);
});

add_task(async function test_copy_managedbookmark() {
  let managedBookmarksMenu =
    window.document.getElementById("managed-bookmarks");

  let promise = BrowserTestUtils.waitForEvent(
    managedBookmarksMenu.menupopup,
    "popupshown",
    false
  );
  managedBookmarksMenu.open = true;
  await promise;

  let context = document.getElementById("placesContext");
  let openContextMenuPromise = BrowserTestUtils.waitForEvent(
    context,
    "popupshown"
  );
  EventUtils.synthesizeMouseAtCenter(
    managedBookmarksMenu.menupopup.children[0],
    {
      button: 2,
      type: "contextmenu",
    }
  );
  await openContextMenuPromise;
  info("Opened context menu");

  let copyOption = document.getElementById("placesContext_copy");

  await new Promise((resolve, reject) => {
    SimpleTest.waitForClipboard(
      "https://example.com/",
      () => {
        context.activateItem(copyOption);
      },
      resolve,
      () => {
        ok(false, "Clipboard copy failed");
        reject();
      }
    );
  });

  let popupHidden = BrowserTestUtils.waitForEvent(
    managedBookmarksMenu.menupopup,
    "popuphidden"
  );
  managedBookmarksMenu.menupopup.hidePopup();
  await popupHidden;
});