Bug 1513882 - [Return to AMO] Show add-on notification icon in urlbar (#4625)

This commit is contained in:
punamdahiya 2019-01-11 11:46:16 -08:00 коммит произвёл GitHub
Родитель 9651f993ee
Коммит f1dac9f2b7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 62 добавлений и 0 удалений

Просмотреть файл

@ -217,8 +217,30 @@ const MessageLoaderUtils = {
};
},
/**
* _loadAddonIconInURLBar - load addons-notification icon by displaying
* box containing addons icon in urlbar. See Bug 1513882
*
* @param {XULElement} Target browser element for showing addons icon
*/
_loadAddonIconInURLBar(browser) {
if (!browser) {
return;
}
const chromeDoc = browser.ownerDocument;
let notificationPopupBox = chromeDoc.getElementById("notification-popup-box");
if (!notificationPopupBox) {
return;
}
if (notificationPopupBox.style.display === "none" ||
notificationPopupBox.style.display === "") {
notificationPopupBox.style.display = "block";
}
},
async installAddonFromURL(browser, url) {
try {
MessageLoaderUtils._loadAddonIconInURLBar(browser);
const aUri = Services.io.newURI(url);
const systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();

Просмотреть файл

@ -233,6 +233,45 @@ describe("MessageLoaderUtils", () => {
});
});
describe("#_loadAddonIconInURLBar", () => {
let sandbox;
let notificationContainerEl;
let browser;
let getContainerStub;
beforeEach(() => {
sandbox = sinon.createSandbox();
notificationContainerEl = {style: {}};
browser = {ownerDocument: {getElementById() { return {}; }}};
getContainerStub = sandbox.stub(browser.ownerDocument, "getElementById");
});
afterEach(() => {
sandbox.restore();
});
it("should return for empty args", () => {
MessageLoaderUtils._loadAddonIconInURLBar();
assert.notCalled(getContainerStub);
});
it("should return if notification popup box not found", () => {
getContainerStub.returns(null);
MessageLoaderUtils._loadAddonIconInURLBar(browser);
assert.calledOnce(getContainerStub);
});
it("should unhide notification popup box with display style as none", () => {
getContainerStub.returns(notificationContainerEl);
notificationContainerEl.style.display = "none";
MessageLoaderUtils._loadAddonIconInURLBar(browser);
assert.calledWith(browser.ownerDocument.getElementById, "notification-popup-box");
assert.equal(notificationContainerEl.style.display, "block");
});
it("should unhide notification popup box with display style empty", () => {
getContainerStub.returns(notificationContainerEl);
notificationContainerEl.style.display = "";
MessageLoaderUtils._loadAddonIconInURLBar(browser);
assert.calledWith(browser.ownerDocument.getElementById, "notification-popup-box");
assert.equal(notificationContainerEl.style.display, "block");
});
});
describe("#installAddonFromURL", () => {
let globals;
let sandbox;
@ -243,6 +282,7 @@ describe("MessageLoaderUtils", () => {
sandbox = sinon.createSandbox();
getInstallStub = sandbox.stub();
installAddonStub = sandbox.stub();
sandbox.stub(MessageLoaderUtils, "_loadAddonIconInURLBar").returns(null);
globals.set("AddonManager", {
getInstallForURL: getInstallStub,
installAddonFromWebpage: installAddonStub,