async function openAddressBookWindow() {
// Set up a watcher for "domwindowopened". When DOM windows are opened the
// function supplied as a second argument is called. When it returns true the
// promise is resolved as the nsIDOMWindow object for the window.
let addressBookWindowPromise = BrowserTestUtils.domWindowOpened(
// win is the nsIDOMWindow object for a window that is opening.
// Wait until the "load" event has happened for the window.
await BrowserTestUtils.waitForEvent(win, "load");
// Return true when we have the right window.
win.document.documentURI ==
"chrome://messenger/content/addressbook/addressbook.xul"
// Open the address book window.
const addressBookButton = document.getElementById("button-address");
EventUtils.synthesizeMouseAtCenter(addressBookButton, { clickCount: 1 });
// Wait for the promise to resolve. abWindow is a nsIDOMWindow object.
let abWindow = await addressBookWindowPromise;
// There is no event that fires when the JavaScript that is initially loaded
// in the window has finished running, so let it finish by using a setTimeout.
await new Promise(resolve => abWindow.setTimeout(resolve));
// Assert that the window was opened successfully.
ok(abWindow && abWindow instanceof Window, "address book window was opened");