Bug 1340987 - (Part 4) Fix browser-chrome-mochitest for other tests related to gSubDialog. r=MattN

MozReview-Commit-ID: FsJwyKvssni

--HG--
extra : rebase_source : f4a4eb620733831ab0fe5489a8897b2699d7f37e
This commit is contained in:
Scott Wu 2017-04-13 23:26:57 +08:00
Родитель aaedd72242
Коммит 4f4df688b8
6 изменённых файлов: 46 добавлений и 38 удалений

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

@ -114,7 +114,7 @@ add_task(async function() {
let doc = gBrowser.selectedBrowser.contentDocument;
let showBtn = doc.getElementById("showUpdateHistory");
let dialogOverlay = doc.getElementById("dialogOverlay");
let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
// XXX: For unknown reasons, this mock cannot be loaded by
// XPCOMUtils.defineLazyServiceGetter() called in aboutDialog-appUpdater.js.
@ -125,11 +125,12 @@ add_task(async function() {
// Test the dialog window opens
is(dialogOverlay.style.visibility, "", "The dialog should be invisible");
let promiseSubDialogLoaded = promiseLoadSubDialog("chrome://mozapps/content/update/history.xul");
showBtn.doCommand();
await promiseLoadSubDialog("chrome://mozapps/content/update/history.xul");
await promiseSubDialogLoaded;
is(dialogOverlay.style.visibility, "visible", "The dialog should be visible");
let dialogFrame = doc.getElementById("dialogFrame");
let dialogFrame = dialogOverlay.querySelector(".dialogFrame");
let frameDoc = dialogFrame.contentDocument;
let updates = frameDoc.querySelectorAll("update");
@ -151,7 +152,7 @@ add_task(async function() {
}
// Test the dialog window closes
let closeBtn = doc.getElementById("dialogClose");
let closeBtn = dialogOverlay.querySelector(".dialogClose");
closeBtn.doCommand();
is(dialogOverlay.style.visibility, "", "The dialog should be invisible");

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

@ -20,8 +20,9 @@ add_task(async function() {
let fontSizeField = doc.getElementById("defaultFontSize");
is(fontSizeField.value, defaultFontSize, "Font size should be set correctly.");
let promiseSubDialogLoaded = promiseLoadSubDialog("chrome://browser/content/preferences/fonts.xul");
doc.getElementById("advancedFonts").click();
let win = await promiseLoadSubDialog("chrome://browser/content/preferences/fonts.xul");
let win = await promiseSubDialogLoaded;
doc = win.document;
// Simulate a dumb font backend.

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

@ -339,10 +339,12 @@ var testRunner = {
let historyMode = doc.getElementById("historyMode");
historyMode.value = "custom";
historyMode.doCommand();
let promiseSubDialogLoaded =
promiseLoadSubDialog("chrome://browser/content/preferences/permissions.xul");
doc.getElementById("cookieExceptions").doCommand();
let subDialogURL = "chrome://browser/content/preferences/permissions.xul";
promiseLoadSubDialog(subDialogURL).then(function(win) {
promiseSubDialogLoaded.then(function(win) {
helperFunctions.windowLoad(win);
});
});

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

@ -111,8 +111,8 @@ add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
await updatedPromise;
await openSiteDataSettingsDialog();
let doc = gBrowser.selectedBrowser.contentDocument;
let dialogFrame = doc.getElementById("dialogFrame");
let dialog = content.gSubDialog._topDialog;
let dialogFrame = dialog._frame;
let frameDoc = dialogFrame.contentDocument;
let siteItems = frameDoc.getElementsByTagName("richlistitem");
@ -280,8 +280,8 @@ add_task(async function() {
await updatePromise;
await openSiteDataSettingsDialog();
let doc = gBrowser.selectedBrowser.contentDocument;
let dialogFrame = doc.getElementById("dialogFrame");
let dialog = content.gSubDialog._topDialog;
let dialogFrame = dialog._frame;
let frameDoc = dialogFrame.contentDocument;
let hostCol = frameDoc.getElementById("hostCol");
let usageCol = frameDoc.getElementById("usageCol");
@ -406,7 +406,7 @@ add_task(async function() {
await openSiteDataSettingsDialog();
let doc = gBrowser.selectedBrowser.contentDocument;
let frameDoc = doc.getElementById("dialogFrame").contentDocument;
let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
let searchBox = frameDoc.getElementById("searchBox");
searchBox.value = "xyz";

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

@ -6,11 +6,11 @@ const { DownloadUtils } = Cu.import("resource://gre/modules/DownloadUtils.jsm",
function promiseSettingsDialogClose() {
return new Promise(resolve => {
let doc = gBrowser.selectedBrowser.contentDocument;
let dialogOverlay = doc.getElementById("dialogOverlay");
let win = content.gSubDialog._frame.contentWindow;
win.addEventListener("unload", function unload() {
if (win.document.documentURI === "chrome://browser/content/preferences/siteDataSettings.xul") {
let win = gBrowser.selectedBrowser.contentWindow;
let dialogOverlay = win.gSubDialog._topDialog._overlay;
let dialogWin = win.gSubDialog._topDialog._frame.contentWindow;
dialogWin.addEventListener("unload", function unload() {
if (dialogWin.document.documentURI === "chrome://browser/content/preferences/siteDataSettings.xul") {
isnot(dialogOverlay.style.visibility, "visible", "The Settings dialog should be hidden");
resolve();
}
@ -55,6 +55,7 @@ add_task(async function() {
await updatePromise;
await openSiteDataSettingsDialog();
let win = gBrowser.selectedBrowser.contentWindow;
let doc = gBrowser.selectedBrowser.contentDocument;
let frameDoc = null;
let saveBtn = null;
@ -66,7 +67,7 @@ add_task(async function() {
// Test the "Cancel" button
settingsDialogClosePromise = promiseSettingsDialogClose();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
cancelBtn = frameDoc.getElementById("cancel");
removeAllSitesOneByOne();
assertAllSitesNotListed();
@ -78,7 +79,7 @@ add_task(async function() {
// Test the "Save Changes" button but cancelling save
let cancelPromise = promiseAlertDialogOpen("cancel");
settingsDialogClosePromise = promiseSettingsDialogClose();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
saveBtn = frameDoc.getElementById("save");
removeAllSitesOneByOne();
assertAllSitesNotListed();
@ -92,7 +93,7 @@ add_task(async function() {
let acceptPromise = promiseAlertDialogOpen("accept");
settingsDialogClosePromise = promiseSettingsDialogClose();
updatePromise = promiseSiteDataManagerSitesUpdated();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
saveBtn = frameDoc.getElementById("save");
removeAllSitesOneByOne();
assertAllSitesNotListed();
@ -107,7 +108,7 @@ add_task(async function() {
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
function removeAllSitesOneByOne() {
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
let sitesList = frameDoc.getElementById("sitesList");
let sites = sitesList.getElementsByTagName("richlistitem");
@ -118,7 +119,7 @@ add_task(async function() {
}
function assertAllSitesNotListed() {
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
let removeAllBtn = frameDoc.getElementById("removeAll");
let sitesList = frameDoc.getElementById("sitesList");
@ -184,6 +185,7 @@ add_task(async function() {
await updatePromise;
await openSiteDataSettingsDialog();
let win = gBrowser.selectedBrowser.contentWindow;
let doc = gBrowser.selectedBrowser.contentDocument;
let frameDoc = null;
let saveBtn = null;
@ -196,7 +198,7 @@ add_task(async function() {
// Test the "Cancel" button
settingsDialogClosePromise = promiseSettingsDialogClose();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
cancelBtn = frameDoc.getElementById("cancel");
removeSelectedSite(fakeHosts.slice(0, 2));
assertSitesListed(doc, fakeHosts.slice(2));
@ -208,7 +210,7 @@ add_task(async function() {
// Test the "Save Changes" button but canceling save
removeDialogOpenPromise = promiseWindowDialogOpen("cancel", REMOVE_DIALOG_URL);
settingsDialogClosePromise = promiseSettingsDialogClose();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
saveBtn = frameDoc.getElementById("save");
removeSelectedSite(fakeHosts.slice(0, 2));
assertSitesListed(doc, fakeHosts.slice(2));
@ -221,7 +223,7 @@ add_task(async function() {
// Test the "Save Changes" button and accepting save
removeDialogOpenPromise = promiseWindowDialogOpen("accept", REMOVE_DIALOG_URL);
settingsDialogClosePromise = promiseSettingsDialogClose();
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
saveBtn = frameDoc.getElementById("save");
removeSelectedSite(fakeHosts.slice(0, 2));
assertSitesListed(doc, fakeHosts.slice(2));
@ -235,7 +237,7 @@ add_task(async function() {
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
function removeSelectedSite(hosts) {
frameDoc = doc.getElementById("dialogFrame").contentDocument;
frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
let sitesList = frameDoc.getElementById("sitesList");
hosts.forEach(host => {
@ -288,8 +290,9 @@ add_task(async function() {
await openSiteDataSettingsDialog();
// Search "foo" to only list foo.com sites
let win = gBrowser.selectedBrowser.contentWindow;
let doc = gBrowser.selectedBrowser.contentDocument;
let frameDoc = doc.getElementById("dialogFrame").contentDocument;
let frameDoc = win.gSubDialog._topDialog._frame.contentDocument;
let searchBox = frameDoc.getElementById("searchBox");
searchBox.value = "xyz";
searchBox.doCommand();
@ -349,7 +352,8 @@ add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
await updatedPromise;
await openSiteDataSettingsDialog();
let dialogFrame = gBrowser.selectedBrowser.contentDocument.getElementById("dialogFrame");
let win = gBrowser.selectedBrowser.contentWindow;
let dialogFrame = win.gSubDialog._topDialog._frame;
let frameDoc = dialogFrame.contentDocument;
let siteItems = frameDoc.getElementsByTagName("richlistitem");

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

@ -45,20 +45,20 @@ function openAndLoadSubDialog(aURL, aFeatures = null, aParams = null, aClosingCa
function promiseLoadSubDialog(aURL) {
return new Promise((resolve, reject) => {
content.gSubDialog._frame.addEventListener("load", function load(aEvent) {
if (aEvent.target.contentWindow.location == "about:blank")
content.gSubDialog._dialogStack.addEventListener("dialogopen", function dialogopen(aEvent) {
if (aEvent.detail.dialog._frame.contentWindow.location == "about:blank")
return;
content.gSubDialog._frame.removeEventListener("load", load);
content.gSubDialog._dialogStack.removeEventListener("dialogopen", dialogopen);
is(content.gSubDialog._frame.contentWindow.location.toString(), aURL,
is(aEvent.detail.dialog._frame.contentWindow.location.toString(), aURL,
"Check the proper URL is loaded");
// Check visibility
is_element_visible(content.gSubDialog._overlay, "Overlay is visible");
is_element_visible(aEvent.detail.dialog._overlay, "Overlay is visible");
// Check that stylesheets were injected
let expectedStyleSheetURLs = content.gSubDialog._injectedStyleSheets.slice(0);
for (let styleSheet of content.gSubDialog._frame.contentDocument.styleSheets) {
let expectedStyleSheetURLs = aEvent.detail.dialog._injectedStyleSheets.slice(0);
for (let styleSheet of aEvent.detail.dialog._frame.contentDocument.styleSheets) {
let i = expectedStyleSheetURLs.indexOf(styleSheet.href);
if (i >= 0) {
info("found " + styleSheet.href);
@ -67,7 +67,7 @@ function promiseLoadSubDialog(aURL) {
}
is(expectedStyleSheetURLs.length, 0, "All expectedStyleSheetURLs should have been found");
resolve(content.gSubDialog._frame.contentWindow);
resolve(aEvent.detail.dialog._frame.contentWindow);
});
});
}
@ -193,7 +193,7 @@ function promiseSiteDataManagerSitesUpdated() {
function openSiteDataSettingsDialog() {
let doc = gBrowser.selectedBrowser.contentDocument;
let settingsBtn = doc.getElementById("siteDataSettings");
let dialogOverlay = doc.getElementById("dialogOverlay");
let dialogOverlay = content.gSubDialog._preloadDialog._overlay;
let dialogLoadPromise = promiseLoadSubDialog("chrome://browser/content/preferences/siteDataSettings.xul");
let dialogInitPromise = TestUtils.topicObserved("sitedata-settings-init", () => true);
let fullyLoadPromise = Promise.all([ dialogLoadPromise, dialogInitPromise ]).then(() => {
@ -204,7 +204,7 @@ function openSiteDataSettingsDialog() {
}
function assertSitesListed(doc, hosts) {
let frameDoc = doc.getElementById("dialogFrame").contentDocument;
let frameDoc = content.gSubDialog._topDialog._frame.contentDocument;
let removeBtn = frameDoc.getElementById("removeSelected");
let removeAllBtn = frameDoc.getElementById("removeAll");
let sitesList = frameDoc.getElementById("sitesList");