(nobug): Fix Admin page CFR
This commit is contained in:
Родитель
c7254f9ecd
Коммит
139d2924ad
|
@ -495,7 +495,11 @@ class _ASRouter {
|
|||
|
||||
// CFR doorhanger
|
||||
} else if (message.template === "cfr_doorhanger") {
|
||||
CFRPageActions.addRecommendation(target, trigger.param, message, this.dispatch, force);
|
||||
if (force) {
|
||||
CFRPageActions.forceRecommendation(target, message, this.dispatch);
|
||||
} else {
|
||||
CFRPageActions.addRecommendation(target, trigger.param, message, this.dispatch);
|
||||
}
|
||||
|
||||
// New tab single messages
|
||||
} else {
|
||||
|
@ -621,7 +625,7 @@ class _ASRouter {
|
|||
await this.setState({lastMessageId: id});
|
||||
const newMessage = this.getMessageById(id);
|
||||
|
||||
await this._sendMessageToTarget(newMessage, target, force, action.data);
|
||||
await this._sendMessageToTarget(newMessage, target, action.data, force);
|
||||
}
|
||||
|
||||
async blockMessageById(idOrIds) {
|
||||
|
|
|
@ -220,18 +220,36 @@ const CFRPageActions = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Force a recommendation to be shown. Should only happen via the Admin page.
|
||||
* @param browser The browser for the recommendation
|
||||
* @param recommendation The recommendation to show
|
||||
* @param dispatchToASRouter A function to dispatch resulting actions to
|
||||
* @return Did adding the recommendation succeed?
|
||||
*/
|
||||
async forceRecommendation(browser, recommendation, dispatchToASRouter) {
|
||||
// If we are forcing via the Admin page, the browser comes in a different format
|
||||
const win = browser.browser.ownerGlobal;
|
||||
const {id, content} = recommendation;
|
||||
RecommendationMap.set(browser.browser, {id, content});
|
||||
if (!PageActionMap.has(win)) {
|
||||
PageActionMap.set(win, new PageAction(win, dispatchToASRouter));
|
||||
}
|
||||
await PageActionMap.get(win).show(recommendation.content.notification_text, true);
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a recommendation specific to the given browser and host.
|
||||
* @param browser The browser for the recommendation
|
||||
* @param host The host for the recommendation
|
||||
* @param recommendation The recommendation to show
|
||||
* @param dispatchToASRouter A function to dispatch resulting actions to
|
||||
* @param force Force the recommendation to appear if the host doesn't match
|
||||
* @return Did adding the recommendation succeed?
|
||||
*/
|
||||
async addRecommendation(browser, host, recommendation, dispatchToASRouter, force = false) {
|
||||
async addRecommendation(browser, host, recommendation, dispatchToASRouter) {
|
||||
const win = browser.ownerGlobal;
|
||||
if (browser !== win.gBrowser.selectedBrowser || !(force || isHostMatch(browser, host))) {
|
||||
if (browser !== win.gBrowser.selectedBrowser || !isHostMatch(browser, host)) {
|
||||
return false;
|
||||
}
|
||||
const {id, content} = recommendation;
|
||||
|
|
|
@ -641,14 +641,23 @@ describe("ASRouter", () => {
|
|||
assert.calledWith(msg.target.sendAsyncMessage, PARENT_TO_CHILD_MESSAGE_NAME, {type: "SET_MESSAGE", data: testMessage});
|
||||
});
|
||||
|
||||
it("should call CFRPageActions.addRecommendation if the template is cfr_action", async () => {
|
||||
sandbox.stub(CFRPageActions, "addRecommendation");
|
||||
it("should call CFRPageActions.forceRecommendation if the template is cfr_action and force is true", async () => {
|
||||
sandbox.stub(CFRPageActions, "forceRecommendation");
|
||||
const testMessage = {id: "foo", template: "cfr_doorhanger"};
|
||||
await Router.setState({messages: [testMessage]});
|
||||
const msg = fakeAsyncMessage({type: "OVERRIDE_MESSAGE", data: {id: testMessage.id}});
|
||||
await Router.onMessage(msg);
|
||||
|
||||
assert.notCalled(msg.target.sendAsyncMessage);
|
||||
assert.calledOnce(CFRPageActions.forceRecommendation);
|
||||
});
|
||||
|
||||
it("should call CFRPageActions.addRecommendation if the template is cfr_action and force is false", async () => {
|
||||
sandbox.stub(CFRPageActions, "addRecommendation");
|
||||
const testMessage = {id: "foo", template: "cfr_doorhanger"};
|
||||
await Router.setState({messages: [testMessage]});
|
||||
await Router._sendMessageToTarget(testMessage, {}, {}, false);
|
||||
|
||||
assert.calledOnce(CFRPageActions.addRecommendation);
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче