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
|
/* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Test to ensure that on "mousedown" in Toolbar we set Speculative Connection
*/
const { sinon } = ChromeUtils.importESModule(
"resource://testing-common/Sinon.sys.mjs"
);
const sandbox = sinon.createSandbox();
let spy = sandbox
.stub(PlacesUIUtils, "setupSpeculativeConnection")
.returns(Promise.resolve());
add_setup(async function () {
await PlacesUtils.bookmarks.eraseEverything();
let toolbar = document.getElementById("PersonalToolbar");
ok(toolbar, "PersonalToolbar should not be null");
if (toolbar.collapsed) {
await promiseSetToolbarVisibility(toolbar, true);
registerCleanupFunction(function () {
return promiseSetToolbarVisibility(toolbar, false);
});
}
registerCleanupFunction(async () => {
await PlacesUtils.bookmarks.eraseEverything();
sandbox.restore();
});
});
add_task(async function checkToolbarSpeculativeConnection() {
let toolbarBookmark = await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
url: "https://example.com/",
title: "Bookmark 1",
});
let toolbarNode = getToolbarNodeForItemGuid(toolbarBookmark.guid);
info("Synthesize mousedown on selected bookmark");
EventUtils.synthesizeMouseAtCenter(toolbarNode, {
type: "mousedown",
});
EventUtils.synthesizeMouseAtCenter(toolbarNode, {
type: "mouseup",
});
Assert.ok(spy.called, "Speculative connection for Toolbar called");
sandbox.restore();
});
add_task(async function checkMenuSpeculativeConnection() {
await PlacesUtils.bookmarks.eraseEverything();
info("Placing a Menu widget");
let origBMBlocation = CustomizableUI.getPlacementOfWidget(
"bookmarks-menu-button"
);
// Ensure BMB is available in UI.
if (!origBMBlocation) {
CustomizableUI.addWidgetToArea(
"bookmarks-menu-button",
CustomizableUI.AREA_NAVBAR
);
}
registerCleanupFunction(async function () {
await PlacesUtils.bookmarks.eraseEverything();
// if BMB was not originally in UI, remove it.
if (!origBMBlocation) {
CustomizableUI.removeWidgetFromArea("bookmarks-menu-button");
}
});
await PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
url: "http://example.com/",
title: "Bookmark 2",
});
// Test Bookmarks Menu Button
let BMB = document.getElementById("bookmarks-menu-button");
let BMBpopup = document.getElementById("BMB_bookmarksPopup");
let promiseEvent = BrowserTestUtils.waitForEvent(BMBpopup, "popupshown");
EventUtils.synthesizeMouseAtCenter(BMB, {});
await promiseEvent;
info("Popupshown on Bookmarks-Menu-Button");
let menuBookmark = [...BMBpopup.children].find(
node => node.label == "Bookmark 2"
);
EventUtils.synthesizeMouseAtCenter(menuBookmark, {
type: "mousedown",
});
EventUtils.synthesizeMouseAtCenter(menuBookmark, {
type: "mouseup",
});
Assert.ok(spy.called, "Speculative connection for Menu Button called");
sandbox.restore();
});
|