Skip to content
This repository was archived by the owner on Feb 29, 2020. It is now read-only.

Commit 0b7dba2

Browse files
committed
Merge open bookmark panel PR
1 parent 441ab72 commit 0b7dba2

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

lib/BookmarkPanelHub.jsm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,13 @@ class _BookmarkPanelHub {
281281
const win = target.browser.ownerGlobal.window;
282282
// Bookmark the page to force the panel to show and
283283
// remove the bookmark when the panel is hidden
284-
win.StarUI.panel.addEventListener("popupshown", () => {
285-
win.StarUI._removeBookmarksOnPopupHidden = true;
286-
}, {once: true});
284+
win.StarUI.panel.addEventListener(
285+
"popupshown",
286+
() => {
287+
win.StarUI._removeBookmarksOnPopupHidden = true;
288+
},
289+
{ once: true }
290+
);
287291
await win.PlacesCommandHook.bookmarkPage();
288292

289293
const doc = target.browser.ownerGlobal.gBrowser.ownerDocument;

test/unit/lib/BookmarkPanelHub.test.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ describe("BookmarkPanelHub", () => {
6767
MozXULElement: { insertFTLIfNeeded: sandbox.stub() },
6868
document,
6969
requestAnimationFrame: x => x(),
70+
StarUI: {
71+
panel: {
72+
addEventListener: sandbox.stub(),
73+
},
74+
_removeBookmarksOnPopupHidden: false,
75+
},
76+
PlacesCommandHook: { bookmarkPage: sandbox.stub().resolves() },
7077
};
7178
fakeTarget = {
7279
document,
@@ -432,11 +439,11 @@ describe("BookmarkPanelHub", () => {
432439
});
433440
});
434441
describe("#_forceShowMessage", () => {
435-
it("should call showMessage with the correct args", () => {
442+
it("should call showMessage with the correct args", async () => {
436443
sandbox.spy(instance, "showMessage");
437444
sandbox.stub(instance, "removeMessage");
438445

439-
instance._forceShowMessage(fakeTarget, { content: fakeMessage });
446+
await instance._forceShowMessage(fakeTarget, { content: fakeMessage });
440447

441448
assert.calledOnce(instance.showMessage);
442449
assert.calledOnce(instance.removeMessage);
@@ -447,14 +454,14 @@ describe("BookmarkPanelHub", () => {
447454
fakeMessage
448455
);
449456
});
450-
it("should insert required fluent files", () => {
457+
it("should insert required fluent files", async () => {
451458
sandbox.stub(instance, "showMessage");
452459

453-
instance._forceShowMessage(fakeTarget, { content: fakeMessage });
460+
await instance._forceShowMessage(fakeTarget, { content: fakeMessage });
454461

455462
assert.calledTwice(fakeWindow.MozXULElement.insertFTLIfNeeded);
456463
});
457-
it("should insert a message you can collapse", () => {
464+
it("should insert a message you can collapse", async () => {
458465
sandbox.spy(instance, "showMessage");
459466
sandbox.stub(instance, "toggleRecommendation");
460467
sandbox.stub(instance, "sendUserEventTelemetry");
@@ -464,7 +471,7 @@ describe("BookmarkPanelHub", () => {
464471
.withArgs("editBookmarkPanelRecommendation")
465472
.returns(fakeContainer);
466473

467-
instance._forceShowMessage(fakeTarget, { content: fakeMessage });
474+
await instance._forceShowMessage(fakeTarget, { content: fakeMessage });
468475

469476
assert.calledTwice(fakeContainer.addEventListener);
470477

@@ -479,6 +486,22 @@ describe("BookmarkPanelHub", () => {
479486

480487
assert.calledWithExactly(instance.toggleRecommendation, target, false);
481488
});
489+
it("should open the bookmark panel when force showing the message", async () => {
490+
sandbox.stub(instance, "showMessage");
491+
sandbox.stub(instance, "removeMessage");
492+
493+
await instance._forceShowMessage(fakeTarget, { content: fakeMessage });
494+
const [
495+
,
496+
popupshownCb,
497+
] = fakeWindow.StarUI.panel.addEventListener.firstCall.args;
498+
499+
assert.isFalse(fakeWindow.StarUI._removeBookmarksOnPopupHidden);
500+
// call the event listener
501+
popupshownCb();
502+
503+
assert.isTrue(fakeWindow.StarUI._removeBookmarksOnPopupHidden);
504+
});
482505
});
483506
describe("#sendImpression", () => {
484507
beforeEach(() => {

0 commit comments

Comments
 (0)