зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1217129: Part 6 - [webext] Test browserAction popups in both the toolbar and in the menu panel. r=gijs r=billm
--HG-- extra : commitid : E032c8k3ujN extra : rebase_source : c4a991bc2d9dd9ec90de5c39d6fdf7ea3a4f9695 extra : source : 106365a3847c66c2122563abb423c29685ea059c
This commit is contained in:
Родитель
59c0ce29a5
Коммит
1338145ff4
|
@ -10,6 +10,9 @@
|
|||
"XPCOMUtils": true,
|
||||
"Task": true,
|
||||
|
||||
// Browser window globals.
|
||||
"PanelUI": false,
|
||||
|
||||
// Test harness globals
|
||||
"ExtensionTestUtils": false,
|
||||
|
||||
|
|
|
@ -2,21 +2,7 @@
|
|||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return new Promise(resolve => {
|
||||
if (popup.state == "open") {
|
||||
resolve();
|
||||
} else {
|
||||
let onPopupShown = event => {
|
||||
popup.removeEventListener("popupshown", onPopupShown);
|
||||
resolve();
|
||||
};
|
||||
popup.addEventListener("popupshown", onPopupShown);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add_task(function* testPageActionPopup() {
|
||||
function* testInArea(area) {
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
"background": {
|
||||
|
@ -116,30 +102,34 @@ add_task(function* testPageActionPopup() {
|
|||
},
|
||||
});
|
||||
|
||||
let viewId = `PanelUI-webext-${makeWidgetId(extension.id)}-browser-action-view`;
|
||||
|
||||
extension.onMessage("send-click", () => {
|
||||
clickBrowserAction(extension);
|
||||
});
|
||||
|
||||
let widget;
|
||||
extension.onMessage("next-test", Task.async(function* () {
|
||||
let panel = getBrowserActionPopup(extension);
|
||||
if (panel) {
|
||||
yield promisePopupShown(panel);
|
||||
panel.hidePopup();
|
||||
|
||||
panel = getBrowserActionPopup(extension);
|
||||
is(panel, null, "panel successfully removed from document after hiding");
|
||||
if (!widget) {
|
||||
widget = getBrowserActionWidget(extension);
|
||||
CustomizableUI.addWidgetToArea(widget.id, area);
|
||||
}
|
||||
|
||||
yield closeBrowserAction(extension);
|
||||
|
||||
extension.sendMessage("next-test");
|
||||
}));
|
||||
|
||||
|
||||
yield Promise.all([extension.startup(), extension.awaitFinish("browseraction-tests-done")]);
|
||||
|
||||
yield extension.unload();
|
||||
|
||||
let view = document.getElementById(viewId);
|
||||
let view = document.getElementById(widget.viewId);
|
||||
is(view, null, "browserAction view removed from document");
|
||||
}
|
||||
|
||||
add_task(function* testBrowserActionInToolbar() {
|
||||
yield testInArea(CustomizableUI.AREA_NAVBAR);
|
||||
});
|
||||
|
||||
add_task(function* testBrowserActionInPanel() {
|
||||
yield testInArea(CustomizableUI.AREA_PANEL);
|
||||
});
|
||||
|
|
|
@ -2,20 +2,6 @@
|
|||
/* vim: set sts=2 sw=2 et tw=80: */
|
||||
"use strict";
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return new Promise(resolve => {
|
||||
if (popup.popupOpen) {
|
||||
resolve();
|
||||
} else {
|
||||
let onPopupShown = event => {
|
||||
popup.removeEventListener("popupshown", onPopupShown);
|
||||
resolve();
|
||||
};
|
||||
popup.addEventListener("popupshown", onPopupShown);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add_task(function* testPageActionPopup() {
|
||||
let scriptPage = url => `<html><head><meta charset="utf-8"><script src="${url}"></script></head></html>`;
|
||||
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
"use strict";
|
||||
|
||||
/* exported CustomizableUI makeWidgetId focusWindow forceGC
|
||||
* getBrowserActionWidget
|
||||
* clickBrowserAction clickPageAction
|
||||
* getBrowserActionPopup getPageActionPopup
|
||||
* closeBrowserAction closePageAction
|
||||
* promisePopupShown
|
||||
*/
|
||||
|
||||
var {AppConstants} = Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
@ -43,23 +45,51 @@ var focusWindow = Task.async(function* focusWindow(win) {
|
|||
yield promise;
|
||||
});
|
||||
|
||||
function promisePopupShown(popup) {
|
||||
return new Promise(resolve => {
|
||||
if (popup.state == "open") {
|
||||
resolve();
|
||||
} else {
|
||||
let onPopupShown = event => {
|
||||
popup.removeEventListener("popupshown", onPopupShown);
|
||||
resolve();
|
||||
};
|
||||
popup.addEventListener("popupshown", onPopupShown);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getBrowserActionWidget(extension) {
|
||||
return CustomizableUI.getWidget(makeWidgetId(extension.id) + "-browser-action");
|
||||
}
|
||||
|
||||
function getBrowserActionPopup(extension, win = window) {
|
||||
return win.document.getElementById("customizationui-widget-panel");
|
||||
let group = getBrowserActionWidget(extension);
|
||||
|
||||
if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
|
||||
return win.document.getElementById("customizationui-widget-panel");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function clickBrowserAction(extension, win = window) {
|
||||
let browserActionId = makeWidgetId(extension.id) + "-browser-action";
|
||||
let elem = win.document.getElementById(browserActionId);
|
||||
var clickBrowserAction = Task.async(function* (extension, win = window) {
|
||||
let group = getBrowserActionWidget(extension);
|
||||
let widget = group.forWindow(win);
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(elem, {}, win);
|
||||
return new Promise(SimpleTest.executeSoon);
|
||||
}
|
||||
if (group.areaType == CustomizableUI.TYPE_TOOLBAR) {
|
||||
ok(!widget.overflowed, "Expect widget not to be overflowed");
|
||||
} else if (group.areaType == CustomizableUI.TYPE_MENU_PANEL) {
|
||||
yield win.PanelUI.show();
|
||||
}
|
||||
|
||||
EventUtils.synthesizeMouseAtCenter(widget.node, {}, win);
|
||||
});
|
||||
|
||||
function closeBrowserAction(extension, win = window) {
|
||||
let node = getBrowserActionPopup(extension, win);
|
||||
if (node) {
|
||||
node.hidePopup();
|
||||
}
|
||||
let group = getBrowserActionWidget(extension);
|
||||
|
||||
let node = win.document.getElementById(group.viewId);
|
||||
CustomizableUI.hidePanelForNode(node);
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче