Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Import upstream commit that fixes pageAction-related test
Browse files Browse the repository at this point in the history
This imports commit 9e1691779afd5943e4a12ff95e69722b41f5c185 from mozilla-central
Bug 1221539 - Add search engine discovery to the page action menu. Part 1: Page action changes.
  • Loading branch information
0c0w3 authored and ianb committed Apr 19, 2018
1 parent b3e4a95 commit 7e245df
Showing 1 changed file with 71 additions and 4 deletions.
75 changes: 71 additions & 4 deletions test/addon/browser_screenshots_ui_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,84 @@ function checkElements(expectPresent, l) {
}
}

async function togglePageActionPanel() {
await promiseOpenPageActionPanel();
EventUtils.synthesizeMouseAtCenter(BrowserPageActions.mainButtonNode, {});
await promisePageActionPanelEvent("popuphidden");
}

function promiseOpenPageActionPanel() {
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
return BrowserTestUtils.waitForCondition(() => {
// Wait for the main page action button to become visible. It's hidden for
// some URIs, so depending on when this is called, it may not yet be quite
// visible. It's up to the caller to make sure it will be visible.
info("Waiting for main page action button to have non-0 size");
let bounds = dwu.getBoundsWithoutFlushing(BrowserPageActions.mainButtonNode);
return bounds.width > 0 && bounds.height > 0;
}).then(() => {
// Wait for the panel to become open, by clicking the button if necessary.
info("Waiting for main page action panel to be open");
if (BrowserPageActions.panelNode.state == "open") {
return Promise.resolve();
}
let shownPromise = promisePageActionPanelEvent("popupshown");
EventUtils.synthesizeMouseAtCenter(BrowserPageActions.mainButtonNode, {});
return shownPromise;
}).then(() => {
// Wait for items in the panel to become visible.
return promisePageActionViewChildrenVisible(BrowserPageActions.mainViewNode);
});
}

function promisePageActionPanelEvent(eventType) {
return new Promise(resolve => {
let panel = BrowserPageActions.panelNode;
if ((eventType == "popupshown" && panel.state == "open") ||
(eventType == "popuphidden" && panel.state == "closed")) {
executeSoon(resolve);
return;
}
panel.addEventListener(eventType, () => {
executeSoon(resolve);
}, { once: true });
});
}

function promisePageActionViewChildrenVisible(panelViewNode) {
info("promisePageActionViewChildrenVisible waiting for a child node to be visible");
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
return BrowserTestUtils.waitForCondition(() => {
let bodyNode = panelViewNode.firstChild;
for (let childNode of bodyNode.childNodes) {
let bounds = dwu.getBoundsWithoutFlushing(childNode);
if (bounds.width > 0 && bounds.height > 0) {
return true;
}
}
return false;
});
}

add_task(async function() {
await promiseScreenshotsEnabled();

registerCleanupFunction(async function() {
await promiseScreenshotsReset();
});

// Toggle the page action panel to get it to rebuild itself. An actionable
// page must be opened first.
let url = "http://example.com/browser_screenshots_ui_check";
await BrowserTestUtils.withNewTab(url, async () => {
await togglePageActionPanel();

await BrowserTestUtils.waitForCondition(
() => document.getElementById(BUTTON_ID),
"Screenshots button should be present", 100, 100);
await BrowserTestUtils.waitForCondition(
() => document.getElementById(BUTTON_ID),
"Screenshots button should be present", 100, 100);

checkElements(true, [BUTTON_ID]);
checkElements(true, [BUTTON_ID]);
});
});

0 comments on commit 7e245df

Please sign in to comment.