Bug 1585482 - Necessary test fixes following the change to stop using xul:dialog as a root element. r=marionette-reviewers,ato,bgrins
authorKirk Steuber <ksteuber@mozilla.com>
Tue, 10 Dec 2019 18:14:10 +0000
changeset 506296 e183cbb4983cfb3aecf97ab18fad916b91f89e7e
parent 506295 9ed1b123250d4c9f616532a80f54b00099cf34b6
child 506297 b7ef124e4519ff8433b01056a4db60601ddd7377
push id36902
push useraciure@mozilla.com
push dateWed, 11 Dec 2019 03:34:51 +0000
treeherdermozilla-central@7635669b8d72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarionette-reviewers, ato, bgrins
bugs1585482
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1585482 - Necessary test fixes following the change to stop using xul:dialog as a root element. r=marionette-reviewers,ato,bgrins Most of these fixes involve fixing test XUL to not use <dialog> as a top level element or replacing calls to document.documentElement that expect it to return the dialog, now that the dialog is not the top level element anymore. Differential Revision: https://phabricator.services.mozilla.com/D53722
browser/base/content/test/general/browser_homeDrop.js
browser/base/content/test/general/browser_save_link_when_window_navigates.js
browser/base/content/test/sanitize/browser_sanitizeDialog.js
browser/components/places/tests/browser/browser.ini
browser/components/places/tests/browser/browser_bookmarkProperties_addKeywordForThisSearch.js
browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
browser/components/places/tests/browser/browser_bookmarkProperties_readOnlyRoot.js
browser/components/places/tests/browser/browser_bookmarksProperties.js
browser/components/places/tests/browser/head.js
browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
browser/components/preferences/in-content/tests/browser_change_app_handler.js
browser/components/preferences/in-content/tests/browser_connection.js
browser/components/preferences/in-content/tests/browser_connection_bug388287.js
browser/components/preferences/in-content/tests/browser_connection_dnsoverhttps.js
browser/components/preferences/in-content/tests/browser_extension_controlled.js
browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
browser/components/preferences/in-content/tests/browser_proxy_backup.js
browser/components/preferences/in-content/tests/browser_subdialogs.js
browser/components/preferences/in-content/tests/subdialog.xhtml
browser/components/preferences/in-content/tests/subdialog2.xhtml
browser/components/search/test/browser/browser_webapi.js
dom/serviceworkers/test/browser_download.js
dom/serviceworkers/test/browser_download_canceled.js
dom/tests/mochitest/chrome/file_bug1224790-1_modal.xhtml
dom/tests/mochitest/chrome/file_bug1224790-2_modal.xhtml
dom/xul/test/398289-resource.xhtml
security/manager/ssl/tests/mochitest/browser/browser_exportP12_passwordUI.js
testing/marionette/chrome/test2.xhtml
testing/marionette/chrome/test_dialog.xhtml
testing/marionette/components/marionette.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
toolkit/components/extensions/test/mochitest/test_ext_protocolHandlers.html
toolkit/components/passwordmgr/test/browser/browser_basicAuth_rateLimit.js
toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js
toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
toolkit/content/tests/browser/browser_f7_caret_browsing.js
toolkit/content/tests/chrome/dialog_dialogfocus.xhtml
toolkit/content/tests/chrome/dialog_dialogfocus2.xhtml
toolkit/content/tests/chrome/test_dialogfocus.xhtml
toolkit/content/tests/chrome/test_preferences_beforeaccept.xhtml
toolkit/content/tests/chrome/window_cursorsnap_dialog.xhtml
toolkit/content/tests/chrome/window_preferences.xhtml
toolkit/content/tests/chrome/window_preferences2.xhtml
toolkit/content/tests/chrome/window_preferences3.xhtml
toolkit/content/tests/chrome/window_preferences_beforeaccept.xhtml
toolkit/content/tests/chrome/window_preferences_commandretarget.xhtml
toolkit/content/tests/chrome/window_preferences_onsyncfrompreference.xhtml
toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_delayedbutton.js
toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_dialog_layout.js
toolkit/mozapps/extensions/test/browser/browser_bug523784.js
toolkit/mozapps/extensions/test/xpinstall/head.js
uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js
uriloader/exthandler/tests/mochitest/browser_remember_download_option.js
--- a/browser/base/content/test/general/browser_homeDrop.js
+++ b/browser/base/content/test/general/browser_homeDrop.js
@@ -49,17 +49,17 @@ add_task(async function() {
           Services.prefs.setStringPref(HOMEPAGE_PREF, "about:mozilla;");
 
           resolve();
         },
       };
       Services.prefs.addObserver(HOMEPAGE_PREF, observer);
     });
 
-    setHomepageDialog.document.documentElement.acceptDialog();
+    setHomepageDialog.document.getElementById("commonDialog").acceptDialog();
 
     await setHomepagePromise;
   }
 
   function dropInvalidURI() {
     return new Promise(resolve => {
       let consoleListener = {
         observe(m) {
--- a/browser/base/content/test/general/browser_save_link_when_window_navigates.js
+++ b/browser/base/content/test/general/browser_save_link_when_window_navigates.js
@@ -71,17 +71,19 @@ function triggerSave(aWindow, aCallback)
       false
     );
     executeSoon(continueDownloading);
   }
 
   function continueDownloading() {
     for (let win of Services.wm.getEnumerator("")) {
       if (win.location && win.location.href == UCT_URI) {
-        win.document.documentElement._fireButtonEvent("accept");
+        win.document
+          .getElementById("unknownContentType")
+          ._fireButtonEvent("accept");
         win.close();
         return;
       }
     }
     ok(false, "No Unknown Content Type dialog yet?");
   }
 
   function onTransferComplete(aWindow2, downloadSuccess) {
--- a/browser/base/content/test/sanitize/browser_sanitizeDialog.js
+++ b/browser/base/content/test/sanitize/browser_sanitizeDialog.js
@@ -622,29 +622,30 @@ function WindowHelper(aWin) {
   });
 }
 
 WindowHelper.prototype = {
   /**
    * "Presses" the dialog's OK button.
    */
   acceptDialog() {
+    let dialog = this.win.document.getElementById("SanitizeDialog");
     is(
-      this.win.document.documentElement.getButton("accept").disabled,
+      dialog.getButton("accept").disabled,
       false,
       "Dialog's OK button should not be disabled"
     );
-    this.win.document.documentElement.acceptDialog();
+    dialog.acceptDialog();
   },
 
   /**
    * "Presses" the dialog's Cancel button.
    */
   cancelDialog() {
-    this.win.document.documentElement.cancelDialog();
+    this.win.document.getElementById("SanitizeDialog").cancelDialog();
   },
 
   /**
    * (Un)checks a history scope checkbox (browser & download history,
    * form history, etc.).
    *
    * @param aPrefName
    *        The final portion of the checkbox's privacy.cpd.* preference name
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -32,17 +32,17 @@ skip-if = os != 'mac' # Mac-only functio
 [browser_bookmarks_change_title.js]
 [browser_bookmarks_sidebar_search.js]
 support-files =
   pageopeningwindow.html
 [browser_bookmarkProperties_addFolderDefaultButton.js]
 [browser_bookmarkProperties_addKeywordForThisSearch.js]
 skip-if = (verify && debug)
 [browser_bookmarkProperties_bookmarkAllTabs.js]
-skip-if = (verify && debug && (os == 'win' || os == 'mac'))
+skip-if = (verify && debug)
 [browser_bookmarkProperties_cancel.js]
 [browser_bookmarkProperties_editFolder.js]
 [browser_bookmarkProperties_editTagContainer.js]
 [browser_bookmarkProperties_folderSelection.js]
 [browser_bookmarkProperties_no_user_actions.js]
 [browser_bookmarkProperties_newFolder.js]
 [browser_bookmarkProperties_readOnlyRoot.js]
 [browser_bookmarkProperties_remember_folders.js]
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_addKeywordForThisSearch.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_addKeywordForThisSearch.js
@@ -23,19 +23,19 @@ add_task(async function() {
         browser,
         '#form1 > input[name="search"]'
       );
 
       await withBookmarksDialog(
         true,
         AddKeywordForSearchField,
         async function(dialogWin) {
-          let acceptBtn = dialogWin.document.documentElement.getButton(
-            "accept"
-          );
+          let acceptBtn = dialogWin.document
+            .getElementById("bookmarkproperties")
+            .getButton("accept");
           Assert.ok(acceptBtn.disabled, "Accept button is disabled");
 
           let promiseKeywordNotification = PlacesTestUtils.waitForNotification(
             "onItemChanged",
             (itemId, prop, isAnno, val) => prop == "keyword" && val == "kw"
           );
 
           fillBookmarkTextField("editBMPanel_keywordField", "kw", dialogWin);
@@ -106,19 +106,19 @@ add_task(async function reopen_same_fiel
         browser,
         '#form1 > input[name="search"]'
       );
 
       await withBookmarksDialog(
         true,
         AddKeywordForSearchField,
         async function(dialogWin) {
-          let acceptBtn = dialogWin.document.documentElement.getButton(
-            "accept"
-          );
+          let acceptBtn = dialogWin.document
+            .getElementById("bookmarkproperties")
+            .getButton("accept");
           ok(acceptBtn.disabled, "Accept button is disabled");
 
           let elt = dialogWin.document.getElementById(
             "editBMPanel_keywordField"
           );
           await BrowserTestUtils.waitForCondition(
             () => elt.value == "kw",
             "Keyword should be the previous value"
@@ -152,19 +152,19 @@ add_task(async function open_other_field
         browser,
         '#form2 > input[name="search"]'
       );
 
       await withBookmarksDialog(
         true,
         AddKeywordForSearchField,
         function(dialogWin) {
-          let acceptBtn = dialogWin.document.documentElement.getButton(
-            "accept"
-          );
+          let acceptBtn = dialogWin.document
+            .getElementById("bookmarkproperties")
+            .getButton("accept");
           ok(acceptBtn.disabled, "Accept button is disabled");
 
           let elt = dialogWin.document.getElementById(
             "editBMPanel_keywordField"
           );
           is(elt.value, "");
         },
         closeHandler
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_bookmarkAllTabs.js
@@ -14,17 +14,19 @@ add_task(async function() {
   });
 
   await withBookmarksDialog(
     true,
     function open() {
       document.getElementById("Browser:BookmarkAllTabs").doCommand();
     },
     async dialog => {
-      let acceptBtn = dialog.document.documentElement.getButton("accept");
+      let acceptBtn = dialog.document
+        .getElementById("bookmarkproperties")
+        .getButton("accept");
       Assert.ok(!acceptBtn.disabled, "Accept button is enabled");
 
       let namepicker = dialog.document.getElementById("editBMPanel_namePicker");
       Assert.ok(!namepicker.readOnly, "Name field is writable");
       let folderName = dialog.document
         .getElementById("stringBundle")
         .getString("bookmarkAllTabsDefault");
       Assert.equal(namepicker.value, folderName, "Name field is correct.");
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_cancel.js
@@ -48,19 +48,19 @@ add_task(async function test_cancel_with
 
     // Now open the bookmarks dialog and cancel it.
     await withBookmarksDialog(
       true,
       function openDialog() {
         tree.controller.doCommand("placesCmd_show:info");
       },
       async function test(dialogWin) {
-        let acceptButton = dialogWin.document.documentElement.getButton(
-          "accept"
-        );
+        let acceptButton = dialogWin.document
+          .getElementById("bookmarkproperties")
+          .getButton("accept");
         await BrowserTestUtils.waitForCondition(
           () => !acceptButton.disabled,
           "The accept button should be enabled"
         );
       }
     );
 
     // Check the bookmark is still removed.
@@ -87,19 +87,19 @@ add_task(async function test_cancel_with
 
     // Now open the bookmarks dialog and cancel it.
     await withBookmarksDialog(
       true,
       function openDialog() {
         tree.controller.doCommand("placesCmd_show:info");
       },
       async function test(dialogWin) {
-        let acceptButton = dialogWin.document.documentElement.getButton(
-          "accept"
-        );
+        let acceptButton = dialogWin.document
+          .getElementById("bookmarkproperties")
+          .getButton("accept");
         await BrowserTestUtils.waitForCondition(
           () => !acceptButton.disabled,
           "The accept button should be enabled"
         );
 
         let promiseTitleChangeNotification = PlacesTestUtils.waitForNotification(
           "onItemChanged",
           (itemId, prop, isAnno, val) => prop == "title" && val == "n"
--- a/browser/components/places/tests/browser/browser_bookmarkProperties_readOnlyRoot.js
+++ b/browser/components/places/tests/browser/browser_bookmarkProperties_readOnlyRoot.js
@@ -14,19 +14,19 @@ add_task(async function test_dialog() {
       function openDialog() {
         // Even if the cmd is disabled, we can execute it regardless.
         tree.controller.doCommand("placesCmd_show:info");
       },
       async function test(dialogWin) {
         // Check that the dialog is read-only.
         Assert.ok(dialogWin.gEditItemOverlay.readOnly, "Dialog is read-only");
         // Check that accept button is disabled
-        let acceptButton = dialogWin.document.documentElement.getButton(
-          "accept"
-        );
+        let acceptButton = dialogWin.document
+          .getElementById("bookmarkproperties")
+          .getButton("accept");
         Assert.ok(acceptButton.disabled, "Accept button is disabled");
 
         // Check that name picker is read only
         let namepicker = dialogWin.document.getElementById(
           "editBMPanel_namePicker"
         );
         Assert.ok(namepicker.readOnly, "Name field is read-only");
         Assert.equal(
--- a/browser/components/places/tests/browser/browser_bookmarksProperties.js
+++ b/browser/components/places/tests/browser/browser_bookmarksProperties.js
@@ -115,17 +115,19 @@ gTests.push({
     });
 
     var popupListener = {
       handleEvent(aEvent) {
         switch (aEvent.type) {
           case "popuphidden":
             // Everything worked fine, we can stop observing the window.
             self._cleanShutdown = true;
-            self.window.document.documentElement.cancelDialog();
+            self.window.document
+              .getElementById("bookmarkproperties")
+              .cancelDialog();
             break;
           case "popupshown":
             tagsField.popup.removeEventListener("popupshown", this, true);
             // In case this test fails the window will close, the test will fail
             // since we didn't set _cleanShutdown.
             let richlistbox = tagsField.popup.richlistbox;
             // Focus and select first result.
             Assert.equal(
@@ -242,17 +244,19 @@ gTests.push({
     });
 
     var popupListener = {
       handleEvent(aEvent) {
         switch (aEvent.type) {
           case "popuphidden":
             // Everything worked fine.
             self._cleanShutdown = true;
-            self.window.document.documentElement.cancelDialog();
+            self.window.document
+              .getElementById("bookmarkproperties")
+              .cancelDialog();
             break;
           case "popupshown":
             tagsField.popup.removeEventListener("popupshown", this, true);
             // In case this test fails the window will close, the test will fail
             // since we didn't set _cleanShutdown.
             let richlistbox = tagsField.popup.richlistbox;
             // Focus and select first result.
             Assert.equal(
@@ -397,17 +401,19 @@ gTests.push({
 
         self._cleanShutdown = true;
         self._removeObserver = PlacesTestUtils.waitForNotification(
           "onItemRemoved",
           (itemId, parentId, index, type, uri, guid) =>
             guid == self._bookmarkGuid
         );
 
-        self.window.document.documentElement.cancelDialog();
+        self.window.document
+          .getElementById("bookmarkproperties")
+          .cancelDialog();
       });
     });
     foldersExpander.doCommand();
     await unloadPromise;
   },
 
   finish() {
     SidebarUI.hide();
--- a/browser/components/places/tests/browser/head.js
+++ b/browser/components/places/tests/browser/head.js
@@ -261,17 +261,17 @@ var withBookmarksDialog = async function
     closePromise = closeFn(dialogWin);
   }
 
   try {
     await taskFn(dialogWin);
   } finally {
     if (!closed && autoCancel) {
       info("withBookmarksDialog: canceling the dialog");
-      doc.documentElement.cancelDialog();
+      doc.getElementById("bookmarkproperties").cancelDialog();
       await closePromise;
     }
     // Give the dialog a little time to close itself.
     await BrowserTestUtils.waitForCondition(
       () => closed,
       "The dialog should be closed!"
     );
   }
--- a/browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
+++ b/browser/components/preferences/in-content/tests/browser_browser_languages_subdialog.js
@@ -360,20 +360,17 @@ add_task(async function testReorderingBr
   assertLocaleOrder(selected, "en-US,pl,he");
 
   // Moving pl down changes the order.
   selected.selectedItem = selected.querySelector("[value='pl']");
   dialogDoc.getElementById("down").doCommand();
   assertLocaleOrder(selected, "en-US,he,pl");
 
   // Accepting the change shows the confirm message bar.
-  let dialogClosed = BrowserTestUtils.waitForEvent(
-    dialogDoc.documentElement,
-    "dialogclosing"
-  );
+  let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "dialogclosing");
   dialog.acceptDialog();
   await dialogClosed;
   is(messageBar.hidden, false, "The message bar is now visible");
   is(
     messageBar.querySelector("button").getAttribute("locales"),
     "en-US,he,pl",
     "The locales are set on the message bar button"
   );
@@ -390,20 +387,17 @@ add_task(async function testReorderingBr
 
   // Select pl in the list.
   selected.selectedItem = selected.querySelector("[value='pl']");
   // Move pl back up.
   dialogDoc.getElementById("up").doCommand();
   assertLocaleOrder(selected, "en-US,pl,he");
 
   // Accepting the change hides the confirm message bar.
-  dialogClosed = BrowserTestUtils.waitForEvent(
-    dialogDoc.documentElement,
-    "dialogclosing"
-  );
+  dialogClosed = BrowserTestUtils.waitForEvent(dialog, "dialogclosing");
   dialog.acceptDialog();
   await dialogClosed;
   is(messageBar.hidden, true, "The message bar is hidden again");
 
   ok(firstDialogId, "There was an id on the first dialog");
   ok(secondDialogId, "There was an id on the second dialog");
   ok(firstDialogId != secondDialogId, "The dialog ids are different");
   ok(
@@ -472,20 +466,17 @@ add_task(async function testAddAndRemove
   assertAvailableLocales(available, ["fr", "pl", "he"]);
 
   // Add he to selected.
   await selectLocale("he", available, selected, dialogDoc);
   assertLocaleOrder(selected, "he,en-US");
   assertAvailableLocales(available, ["pl", "fr"]);
 
   // Accepting the change shows the confirm message bar.
-  let dialogClosed = BrowserTestUtils.waitForEvent(
-    dialogDoc.documentElement,
-    "dialogclosing"
-  );
+  let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "dialogclosing");
   dialog.acceptDialog();
   await dialogClosed;
 
   await waitForMutation(
     messageBar,
     { attributes: true, attributeFilter: ["hidden"] },
     target => !target.hidden
   );
@@ -616,20 +607,17 @@ add_task(async function testInstallFromA
     return done;
   });
 
   // Move pl down the list, which prevents an error since it isn't valid.
   dialogDoc.getElementById("down").doCommand();
   assertLocaleOrder(selected, "en-US,pl");
 
   // Test that disabling the langpack removes it from the list.
-  let dialogClosed = BrowserTestUtils.waitForEvent(
-    dialogDoc.documentElement,
-    "dialogclosing"
-  );
+  let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "dialogclosing");
   dialog.acceptDialog();
   await dialogClosed;
 
   // Disable the Polish langpack.
   langpack = await AddonManager.getAddonByID("langpack-pl@firefox.mozilla.org");
   await langpack.disable();
 
   ({ dialogDoc, available, selected } = await openDialog(doc, true));
--- a/browser/components/preferences/in-content/tests/browser_change_app_handler.js
+++ b/browser/components/preferences/in-content/tests/browser_change_app_handler.js
@@ -64,20 +64,21 @@ add_task(async function() {
     0
   );
   chooseItem.dispatchEvent(cmdEvent);
 
   let dialog = await dialogLoadedPromise;
   info("Dialog loaded");
 
   let dialogDoc = dialog.document;
+  let dialogElement = dialogDoc.getElementById("app-picker");
   let dialogList = dialogDoc.getElementById("app-picker-listbox");
   dialogList.selectItem(dialogList.firstElementChild);
   let selectedApp = dialogList.firstElementChild.handlerApp;
-  dialogDoc.documentElement.acceptDialog();
+  dialogElement.acceptDialog();
 
   // Verify results are correct in mime service:
   let mimeInfo = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null);
   ok(
     mimeInfo.preferredApplicationHandler.equals(selectedApp),
     "App should be set as preferred."
   );
 
@@ -109,26 +110,27 @@ add_task(async function() {
     0
   );
   manageItem.dispatchEvent(cmdEvent);
 
   dialog = await dialogLoadedPromise;
   info("Dialog loaded the second time");
 
   dialogDoc = dialog.document;
+  dialogElement = dialogDoc.getElementById("appManager");
   dialogList = dialogDoc.getElementById("appList");
   let itemToRemove = dialogList.querySelector(
     'richlistitem > label[value="' + selectedApp.name + '"]'
   ).parentNode;
   dialogList.selectItem(itemToRemove);
   let itemsBefore = dialogList.children.length;
   dialogDoc.getElementById("remove").click();
   ok(!itemToRemove.parentNode, "Item got removed from DOM");
   is(dialogList.children.length, itemsBefore - 1, "Item got removed");
-  dialogDoc.documentElement.acceptDialog();
+  dialogElement.acceptDialog();
 
   // Verify results are correct in mime service:
   mimeInfo = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null);
   ok(
     !mimeInfo.preferredApplicationHandler,
     "App should no longer be set as preferred."
   );
 
--- a/browser/components/preferences/in-content/tests/browser_connection.js
+++ b/browser/components/preferences/in-content/tests/browser_connection.js
@@ -26,24 +26,25 @@ function test() {
   */
   open_preferences(async function tabOpened(aContentWindow) {
     is(
       gBrowser.currentURI.spec,
       "about:preferences",
       "about:preferences loaded"
     );
     let dialog = await openAndLoadSubDialog(connectionURL);
+    let dialogElement = dialog.document.getElementById("ConnectionsDialog");
     let dialogClosingPromise = BrowserTestUtils.waitForEvent(
-      dialog.document.documentElement,
+      dialogElement,
       "dialogclosing"
     );
 
     ok(dialog, "connection window opened");
     runConnectionTests(dialog);
-    dialog.document.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     let dialogClosingEvent = await dialogClosingPromise;
     ok(dialogClosingEvent, "connection window closed");
     // runConnectionTests will have changed this pref - make sure it was
     // sanitized correctly when the dialog was accepted
     is(
       Services.prefs.getCharPref("network.proxy.no_proxies_on"),
       ".a.com,.b.com,.c.com",
--- a/browser/components/preferences/in-content/tests/browser_connection_bug388287.js
+++ b/browser/components/preferences/in-content/tests/browser_connection_bug388287.js
@@ -30,106 +30,100 @@ function test() {
   });
 
   /*
    The connection dialog alone won't save onaccept since it uses type="child",
    so it has to be opened as a sub dialog of the main pref tab.
    Open the main tab here.
    */
   open_preferences(async function tabOpened(aContentWindow) {
-    let dialog, dialogClosingPromise;
-    let doc,
-      proxyTypePref,
-      sharePref,
-      httpPref,
-      httpPortPref,
-      ftpPref,
-      ftpPortPref;
+    let dialog, dialogClosingPromise, dialogElement;
+    let proxyTypePref, sharePref, httpPref, httpPortPref, ftpPref, ftpPortPref;
 
     // Convenient function to reset the variables for the new window
     async function setDoc() {
       if (closeable) {
         let dialogClosingEvent = await dialogClosingPromise;
         ok(dialogClosingEvent, "Connection dialog closed");
       }
 
       if (finalTest) {
         gBrowser.removeCurrentTab();
         finish();
         return;
       }
 
       dialog = await openAndLoadSubDialog(connectionURL);
+      dialogElement = dialog.document.getElementById("ConnectionsDialog");
       dialogClosingPromise = BrowserTestUtils.waitForEvent(
-        dialog.document.documentElement,
+        dialogElement,
         "dialogclosing"
       );
 
-      doc = dialog.document;
       proxyTypePref = dialog.Preferences.get("network.proxy.type");
       sharePref = dialog.Preferences.get("network.proxy.share_proxy_settings");
       httpPref = dialog.Preferences.get("network.proxy.http");
       httpPortPref = dialog.Preferences.get("network.proxy.http_port");
       ftpPref = dialog.Preferences.get("network.proxy.ftp");
       ftpPortPref = dialog.Preferences.get("network.proxy.ftp_port");
     }
 
     // This batch of tests should not close the dialog
     await setDoc();
 
     // Testing HTTP port 0 with share on
     proxyTypePref.value = 1;
     sharePref.value = true;
     httpPref.value = "localhost";
     httpPortPref.value = 0;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // Testing HTTP port 0 + FTP port 80 with share off
     sharePref.value = false;
     ftpPref.value = "localhost";
     ftpPortPref.value = 80;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // Testing HTTP port 80 + FTP port 0 with share off
     httpPortPref.value = 80;
     ftpPortPref.value = 0;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // From now on, the dialog should close since we are giving it legitimate inputs.
     // The test will timeout if the onbeforeaccept kicks in erroneously.
     closeable = true;
 
     // Both ports 80, share on
     httpPortPref.value = 80;
     ftpPortPref.value = 80;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // HTTP 80, FTP 0, with share on
     await setDoc();
     proxyTypePref.value = 1;
     sharePref.value = true;
     ftpPref.value = "localhost";
     httpPref.value = "localhost";
     httpPortPref.value = 80;
     ftpPortPref.value = 0;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // HTTP host empty, port 0 with share on
     await setDoc();
     proxyTypePref.value = 1;
     sharePref.value = true;
     httpPref.value = "";
     httpPortPref.value = 0;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     // HTTP 0, but in no proxy mode
     await setDoc();
     proxyTypePref.value = 0;
     sharePref.value = true;
     httpPref.value = "localhost";
     httpPortPref.value = 0;
 
     // This is the final test, don't spawn another connection window
     finalTest = true;
-    doc.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
     await setDoc();
   });
 }
--- a/browser/components/preferences/in-content/tests/browser_connection_dnsoverhttps.js
+++ b/browser/components/preferences/in-content/tests/browser_connection_dnsoverhttps.js
@@ -84,18 +84,19 @@ async function testWithProperties(props,
 
   let dialog = await openConnectionsSubDialog();
   await dialog.uiReady;
   info(
     Date.now() - startTime + ": testWithProperties: connections dialog now open"
   );
   let doc = dialog.document;
   let win = doc.ownerGlobal;
+  let dialogElement = doc.getElementById("ConnectionsDialog");
   let dialogClosingPromise = BrowserTestUtils.waitForEvent(
-    doc.documentElement,
+    dialogElement,
     "dialogclosing"
   );
   let modeCheckbox = doc.querySelector(modeCheckboxSelector);
   let uriTextbox = doc.querySelector(uriTextboxSelector);
   let resolverMenulist = doc.querySelector(resolverMenulistSelector);
   let uriPrefChangedPromise;
   let modePrefChangedPromise;
 
@@ -174,17 +175,17 @@ async function testWithProperties(props,
     info(
       Date.now() -
         startTime +
         ": testWithProperties: inputUriKeys, input and change events dispatched"
     );
   }
 
   info(Date.now() - startTime + ": testWithProperties: calling acceptDialog");
-  doc.documentElement.acceptDialog();
+  dialogElement.acceptDialog();
 
   info(
     Date.now() -
       startTime +
       ": testWithProperties: waiting for the dialogClosingPromise"
   );
   let dialogClosingEvent = await dialogClosingPromise;
   ok(dialogClosingEvent, "connection window closed");
--- a/browser/components/preferences/in-content/tests/browser_extension_controlled.js
+++ b/browser/components/preferences/in-content/tests/browser_extension_controlled.js
@@ -1117,25 +1117,26 @@ add_task(async function testExtensionCon
     let messageChanged = connectionSettingsMessagePromise(mainDoc, true);
     await addon.enable();
     await messageChanged;
   }
 
   async function openProxyPanel() {
     let panel = await openAndLoadSubDialog(PANEL_URL);
     let closingPromise = waitForEvent(
-      panel.document.documentElement,
+      panel.document.getElementById("ConnectionsDialog"),
       "dialogclosing"
     );
     ok(panel, "Proxy panel opened.");
     return { panel, closingPromise };
   }
 
   async function closeProxyPanel(panelObj) {
-    panelObj.panel.document.documentElement.cancelDialog();
+    let dialog = panelObj.panel.document.getElementById("ConnectionsDialog");
+    dialog.cancelDialog();
     let panelClosingEvent = await panelObj.closingPromise;
     ok(panelClosingEvent, "Proxy panel closed.");
   }
 
   await openPreferencesViaOpenPreferencesAPI("paneGeneral", {
     leaveOpen: true,
   });
   let mainDoc = gBrowser.contentDocument;
--- a/browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
+++ b/browser/components/preferences/in-content/tests/browser_homepages_use_bookmark.js
@@ -37,17 +37,20 @@ add_task(async function testSetHomepageF
 
   let promiseSubDialogLoaded = promiseLoadSubDialog(
     "chrome://browser/content/preferences/selectBookmark.xhtml"
   );
   doc.getElementById("useBookmarkBtn").click();
 
   let dialog = await promiseSubDialogLoaded;
   dialog.document.getElementById("bookmarks").selectItems([bm.guid]);
-  dialog.document.documentElement.getButton("accept").click();
+  dialog.document
+    .getElementById("selectBookmarkDialog")
+    .getButton("accept")
+    .click();
 
   await TestUtils.waitForCondition(() => HomePage.get() == TEST_URL1);
 
   Assert.equal(
     HomePage.get(),
     TEST_URL1,
     "Should have set the homepage to the same as the bookmark."
   );
@@ -69,17 +72,20 @@ add_task(async function testSetHomepageF
     "chrome://browser/content/preferences/selectBookmark.xhtml"
   );
   doc.getElementById("useBookmarkBtn").click();
 
   let dialog = await promiseSubDialogLoaded;
   dialog.document
     .getElementById("bookmarks")
     .selectItems([PlacesUtils.bookmarks.menuGuid]);
-  dialog.document.documentElement.getButton("accept").click();
+  dialog.document
+    .getElementById("selectBookmarkDialog")
+    .getButton("accept")
+    .click();
 
   await TestUtils.waitForCondition(
     () => HomePage.get() == `${TEST_URL1}|${TEST_URL2}`
   );
 
   Assert.equal(
     HomePage.get(),
     `${TEST_URL1}|${TEST_URL2}`,
--- a/browser/components/preferences/in-content/tests/browser_proxy_backup.js
+++ b/browser/components/preferences/in-content/tests/browser_proxy_backup.js
@@ -47,23 +47,24 @@ function test() {
   */
   open_preferences(async function tabOpened(aContentWindow) {
     is(
       gBrowser.currentURI.spec,
       "about:preferences",
       "about:preferences loaded"
     );
     let dialog = await openAndLoadSubDialog(connectionURL);
+    let dialogElement = dialog.document.getElementById("ConnectionsDialog");
     let dialogClosingPromise = BrowserTestUtils.waitForEvent(
-      dialog.document.documentElement,
+      dialogElement,
       "dialogclosing"
     );
 
     ok(dialog, "connection window opened");
-    dialog.document.documentElement.acceptDialog();
+    dialogElement.acceptDialog();
 
     let dialogClosingEvent = await dialogClosingPromise;
     ok(dialogClosingEvent, "connection window closed");
 
     // The SOCKS backup should not be replaced by the shared value
     is(
       Services.prefs.getCharPref("network.proxy.backup.socks"),
       "127.0.0.1",
--- a/browser/components/preferences/in-content/tests/browser_subdialogs.js
+++ b/browser/components/preferences/in-content/tests/browser_subdialogs.js
@@ -234,32 +234,36 @@ add_task(
         "subdialog should have updated title"
       );
     });
 
     // Accept the dialog
     await close_subdialog_and_test_generic_end_state(
       tab.linkedBrowser,
       function() {
-        content.window.gSubDialog._topDialog._frame.contentDocument.documentElement.acceptDialog();
+        content.window.gSubDialog._topDialog._frame.contentDocument
+          .getElementById("subDialog")
+          .acceptDialog();
       },
       "accept",
       1
     );
   }
 );
 
 add_task(async function check_canceling_dialog() {
   await open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
 
   info("canceling the dialog");
   await close_subdialog_and_test_generic_end_state(
     tab.linkedBrowser,
     function() {
-      content.window.gSubDialog._topDialog._frame.contentDocument.documentElement.cancelDialog();
+      content.window.gSubDialog._topDialog._frame.contentDocument
+        .getElementById("subDialog")
+        .cancelDialog();
     },
     "cancel",
     0
   );
 });
 
 add_task(async function check_reopening_dialog() {
   await open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
@@ -297,41 +301,47 @@ add_task(async function check_reopening_
       "The lower dialog should not have an overlay"
     );
   });
 
   info("closing two dialogs");
   await close_subdialog_and_test_generic_end_state(
     tab.linkedBrowser,
     function() {
-      content.window.gSubDialog._topDialog._frame.contentDocument.documentElement.acceptDialog();
+      content.window.gSubDialog._topDialog._frame.contentDocument
+        .getElementById("subDialog")
+        .acceptDialog();
     },
     "accept",
     1
   );
   await close_subdialog_and_test_generic_end_state(
     tab.linkedBrowser,
     function() {
-      content.window.gSubDialog._topDialog._frame.contentDocument.documentElement.acceptDialog();
+      content.window.gSubDialog._topDialog._frame.contentDocument
+        .getElementById("subDialog")
+        .acceptDialog();
     },
     "accept",
     1
   );
 });
 
 add_task(async function check_opening_while_closing() {
   await open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
   info("closing");
   content.window.gSubDialog._topDialog.close();
   info("reopening immediately after calling .close()");
   await open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
   await close_subdialog_and_test_generic_end_state(
     tab.linkedBrowser,
     function() {
-      content.window.gSubDialog._topDialog._frame.contentDocument.documentElement.acceptDialog();
+      content.window.gSubDialog._topDialog._frame.contentDocument
+        .getElementById("subDialog")
+        .acceptDialog();
     },
     "accept",
     1
   );
 });
 
 add_task(async function window_close_on_dialog() {
   await open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
--- a/browser/components/preferences/in-content/tests/subdialog.xhtml
+++ b/browser/components/preferences/in-content/tests/subdialog.xhtml
@@ -1,28 +1,29 @@
 <?xml version="1.0"?>
 
 <!-- Any copyright is dedicated to the Public Domain.
    - http://creativecommons.org/publicdomain/zero/1.0/ -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog id="subDialog"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="Sample sub-dialog" style="width: 32em; height: 5em;"
         onload="document.getElementById('textbox').focus();">
+<dialog id="subDialog">
   <script>
     document.addEventListener("dialogaccept", acceptSubdialog);
     function acceptSubdialog() {
       window.arguments[0].acceptCount++;
     }
   </script>
 
   <description id="desc">A sample sub-dialog for testing</description>
 
   <html:input id="textbox" value="Default text" />
 
   <separator class="thin"/>
 
   <button oncommand="window.close();" icon="close" label="Close" />
 
 </dialog>
+</window>
--- a/browser/components/preferences/in-content/tests/subdialog2.xhtml
+++ b/browser/components/preferences/in-content/tests/subdialog2.xhtml
@@ -1,28 +1,29 @@
 <?xml version="1.0"?>
 
 <!-- Any copyright is dedicated to the Public Domain.
    - http://creativecommons.org/publicdomain/zero/1.0/ -->
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog id="subDialog"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         title="Sample sub-dialog #2" style="width: 32em; height: 5em;"
         onload="document.getElementById('textbox').focus();">
+<dialog id="subDialog">
   <script>
     document.addEventListener("dialogaccept", acceptSubdialog);
     function acceptSubdialog() {
       window.arguments[0].acceptCount++;
     }
   </script>
 
   <description id="desc">A sample sub-dialog for testing</description>
 
   <html:input id="textbox" value="Default text" />
 
   <separator class="thin"/>
 
   <button oncommand="window.close();" icon="close" label="Close" />
 
 </dialog>
+</window>
--- a/browser/components/search/test/browser/browser_webapi.js
+++ b/browser/components/search/test/browser/browser_webapi.js
@@ -49,17 +49,17 @@ add_task(async function test_working() {
     "confirmEx",
     "Should see the confirmation dialog."
   );
   is(
     dialog.args.text,
     getString("addEngineConfirmation", "Foo", "example.com"),
     "Should have seen the right install message"
   );
-  dialog.document.documentElement.cancelDialog();
+  dialog.document.getElementById("commonDialog").cancelDialog();
 
   gBrowser.removeCurrentTab();
 });
 
 add_task(async function test_HTTP() {
   gBrowser.selectedTab = AddSearchProvider(
     ROOT.replace("http:", "HTTP:") + "testEngine.xml"
   );
@@ -70,17 +70,17 @@ add_task(async function test_HTTP() {
     "confirmEx",
     "Should see the confirmation dialog."
   );
   is(
     dialog.args.text,
     getString("addEngineConfirmation", "Foo", "example.com"),
     "Should have seen the right install message"
   );
-  dialog.document.documentElement.cancelDialog();
+  dialog.document.getElementById("commonDialog").cancelDialog();
 
   gBrowser.removeCurrentTab();
 });
 
 add_task(async function test_relative() {
   gBrowser.selectedTab = AddSearchProvider("testEngine.xml");
 
   let dialog = await promiseDialogOpened();
@@ -89,60 +89,60 @@ add_task(async function test_relative() 
     "confirmEx",
     "Should see the confirmation dialog."
   );
   is(
     dialog.args.text,
     getString("addEngineConfirmation", "Foo", "example.com"),
     "Should have seen the right install message"
   );
-  dialog.document.documentElement.cancelDialog();
+  dialog.document.getElementById("commonDialog").cancelDialog();
 
   gBrowser.removeCurrentTab();
 });
 
 add_task(async function test_invalid() {
   let url = "z://foobar";
   gBrowser.selectedTab = AddSearchProvider(url);
 
   let dialog = await promiseDialogOpened();
   is(dialog.args.promptType, "alert", "Should see the alert dialog.");
   is(
     dialog.args.text,
     getString("error_invalid_engine_msg2", brandName, url),
     "Should have seen the right error message"
   );
-  dialog.document.documentElement.acceptDialog();
+  dialog.document.getElementById("commonDialog").acceptDialog();
 
   gBrowser.removeCurrentTab();
 });
 
 add_task(async function test_missing() {
   let url = ROOT + "foobar.xml";
   gBrowser.selectedTab = AddSearchProvider(url);
 
   let dialog = await promiseDialogOpened();
   is(dialog.args.promptType, "alert", "Should see the alert dialog.");
   is(
     dialog.args.text,
     getString("error_loading_engine_msg2", brandName, url),
     "Should have seen the right error message"
   );
-  dialog.document.documentElement.acceptDialog();
+  dialog.document.getElementById("commonDialog").acceptDialog();
 
   gBrowser.removeCurrentTab();
 });
 
 add_task(async function test_missing_namespace() {
   let url = ROOT + "testEngine_missing_namespace.xml";
   gBrowser.selectedTab = AddSearchProvider(url);
 
   let dialog = await promiseDialogOpened();
   is(dialog.args.promptType, "alert", "Should see the alert dialog.");
   is(
     dialog.args.text,
     getString("error_invalid_engine_msg2", brandName, url),
     "Should have seen the right error message"
   );
-  dialog.document.documentElement.acceptDialog();
+  dialog.document.getElementById("commonDialog").acceptDialog();
 
   gBrowser.removeCurrentTab();
 });
--- a/dom/serviceworkers/test/browser_download.js
+++ b/dom/serviceworkers/test/browser_download.js
@@ -28,19 +28,20 @@ function windowObserver(win, topic) {
   win.addEventListener(
     "load",
     function() {
       if (
         win.document.documentURI ===
         "chrome://mozapps/content/downloads/unknownContentType.xul"
       ) {
         executeSoon(function() {
-          var button = win.document.documentElement.getButton("accept");
+          let dialog = win.document.getElementById("unknownContentType");
+          let button = dialog.getButton("accept");
           button.disabled = false;
-          win.document.documentElement.acceptDialog();
+          dialog.acceptDialog();
         });
       }
     },
     { once: true }
   );
 }
 
 function test() {
--- a/dom/serviceworkers/test/browser_download_canceled.js
+++ b/dom/serviceworkers/test/browser_download_canceled.js
@@ -48,17 +48,19 @@ function promiseClickDownloadDialogButto
       // setTimeout is not sufficient because it appears we get our "load"
       // listener before the document's, so we use TestUtils.waitForTick() to
       // defer until after its load handler runs, then use setTimeout(0) to end
       // up after its eval.
       await TestUtils.waitForTick();
 
       await new Promise(resolve => setTimeout(resolve, 0));
 
-      const button = win.document.documentElement.getButton(buttonAction);
+      const button = win.document
+        .getElementById("unknownContentType")
+        .getButton(buttonAction);
       button.disabled = false;
       info(`clicking ${buttonAction} button`);
       button.click();
     }
   );
 }
 
 async function performCanceledDownload(tab, path) {
--- a/dom/tests/mochitest/chrome/file_bug1224790-1_modal.xhtml
+++ b/dom/tests/mochitest/chrome/file_bug1224790-1_modal.xhtml
@@ -1,17 +1,17 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1224790
 -->
-<dialog title="Mozilla Bug 1224790"
-        buttons="accept"
+<window title="Mozilla Bug 1224790"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog buttons="accept">
   <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   </body>
 
   <!-- test code goes here -->
   <script type="application/javascript">
@@ -26,8 +26,9 @@ https://bugzilla.mozilla.org/show_bug.cg
     window.close();
     window.arguments[0].modalClosed();
   }
 
   SimpleTest.waitForFocus(runTests);
   ]]>
   </script>
 </dialog>
+</window>
--- a/dom/tests/mochitest/chrome/file_bug1224790-2_modal.xhtml
+++ b/dom/tests/mochitest/chrome/file_bug1224790-2_modal.xhtml
@@ -1,17 +1,17 @@
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=1224790
 -->
-<dialog title="Mozilla Bug 1224790"
-        buttons="accept"
+<window title="Mozilla Bug 1224790"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog buttons="accept">
   <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   </body>
 
   <!-- test code goes here -->
   <script type="application/javascript">
@@ -28,8 +28,9 @@ https://bugzilla.mozilla.org/show_bug.cg
     window.close();
     nonModal.modalClosed(window.arguments[0]);
   }
 
   SimpleTest.waitForFocus(runTests);
   ]]>
   </script>
 </dialog>
+</window>
--- a/dom/xul/test/398289-resource.xhtml
+++ b/dom/xul/test/398289-resource.xhtml
@@ -1,14 +1,14 @@
 <?xml version="1.0"?>
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        buttonlabelaccept="OK"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog buttonlabelaccept="OK"
         buttonlabelcancel="Cancel">
 
   <script>
     document.addEventListener("dialogaccept", function() { alert('OK') });
     document.addEventListener("dialogcancel", function() { alert('Cancel') });
   </script>
 
   <tabbox id="test" flex="1" persist="selectedIndex">
@@ -38,8 +38,9 @@
 
     </tabpanels>
 
   </tabbox>
 
   <box height="1000"/> <!-- Push dialog buttons out of sight so that the animated default button isn't part of the snapshot -->
 
 </dialog>
+</window>
--- a/security/manager/ssl/tests/mochitest/browser/browser_exportP12_passwordUI.js
+++ b/security/manager/ssl/tests/mochitest/browser/browser_exportP12_passwordUI.js
@@ -107,17 +107,18 @@ add_task(async function testPasswordStre
     password1Textbox.value = testCase.password1;
     password2Textbox.value = testCase.password2;
     // Setting the value of the password textboxes via |.value| apparently
     // doesn't cause the oninput handlers to be called, so we do it here.
     password1Textbox.oninput();
     password2Textbox.oninput();
 
     Assert.equal(
-      win.document.documentElement.getButton("accept").disabled,
+      win.document.getElementById("setp12password").getButton("accept")
+        .disabled,
       password1Textbox.value != password2Textbox.value,
       "Actual and expected accept button disable state should " +
         `match for ${testCase.name}`
     );
     Assert.equal(
       strengthProgressBar.value,
       testCase.strength,
       `Actual and expected strength value should match for ${testCase.name}`
--- a/testing/marionette/chrome/test2.xhtml
+++ b/testing/marionette/chrome/test2.xhtml
@@ -1,19 +1,20 @@
 <?xml version="1.0"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <!DOCTYPE window [
 ]>
 
-<dialog id="dia"
-            xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog id="dia">
 
   <vbox id="things">
     <checkbox id="testBox"  label="box" />
     <input xmlns="http://www.w3.org/1999/xhtml" id="textInput"  size="6" value="test" label="input" />
     <input xmlns="http://www.w3.org/1999/xhtml" id="textInput2"  size="6" value="test" label="input" />
     <input xmlns="http://www.w3.org/1999/xhtml" id="textInput3" class="asdf" size="6" value="test" label="input" />
   </vbox>
      
 </dialog>
+</window>
--- a/testing/marionette/chrome/test_dialog.xhtml
+++ b/testing/marionette/chrome/test_dialog.xhtml
@@ -6,19 +6,19 @@
 <!DOCTYPE testdialog [
 <!ENTITY % dialogDTD SYSTEM "chrome://marionette/content/test_dialog.dtd" >
 %dialogDTD;
 ]>
 
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 
 
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="&testDialog.title;">
 <dialog id="testDialog"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        title="&testDialog.title;"
         buttons="accept,cancel">
 
   <vbox flex="1" style="min-width: 300px; min-height: 500px;">
     <label>&settings.label;</label>
     <separator class="thin"/>
     <richlistbox id="test-list" flex="1">
         <richlistitem id="item-choose" orient="horizontal" selected="true">
             <label id="choose-label" value="First Entry" flex="1"/>
@@ -29,8 +29,9 @@
     <checkbox id="check-box" label="Test Mode 2" />
     <hbox align="center">
       <label id="text-box-label" control="text-box">Name:</label>
       <input xmlns="http://www.w3.org/1999/xhtml" id="text-box" style="-moz-box-flex: 1;" />
     </hbox>
   </vbox>
 
 </dialog>
+</window>
--- a/testing/marionette/components/marionette.js
+++ b/testing/marionette/components/marionette.js
@@ -445,21 +445,22 @@ class MarionetteParentProcess {
         break;
     }
   }
 
   suppressSafeModeDialog(win) {
     win.addEventListener(
       "load",
       () => {
-        if (win.document.getElementById("safeModeDialog")) {
+        let dialog = win.document.getElementById("safeModeDialog");
+        if (dialog) {
           // accept the dialog to start in safe-mode
           log.trace("Safe mode detected, supressing dialog");
           win.setTimeout(() => {
-            win.document.documentElement.getButton("accept").click();
+            dialog.getButton("accept").click();
           });
         }
       },
       { once: true }
     );
   }
 
   init(quit = true) {
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -2065,18 +2065,18 @@ var BrowserTestUtils = {
       return win.document.documentURI === uri;
     });
 
     if (func) {
       await func(win);
       return win;
     }
 
-    let doc = win.document.documentElement;
-    doc.getButton(buttonAction).click();
+    let dialog = win.document.querySelector("dialog");
+    dialog.getButton(buttonAction).click();
 
     return win;
   },
 
   /**
    * Waits for the dialog to open, and clicks the specified button, and waits
    * for the dialog to close.
    *
--- a/toolkit/components/extensions/test/mochitest/test_ext_protocolHandlers.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_protocolHandlers.html
@@ -134,17 +134,17 @@ add_task(async function test_protocolHan
 
   // Expect the chooser window to be open, close it.
   chromeScript = SpecialPowers.loadChromeScript(async () => {
     const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
 
     let window = await BrowserTestUtils.domWindowOpened(undefined, win => {
       return BrowserTestUtils.waitForEvent(win, "load", false, event => {
         let win = event.target.defaultView;
-        return win.document.documentElement.getAttribute("id") === "handling";
+        return !!win.document.querySelector("dialog#handling");
       });
     });
     let entry =  window.document.getElementById("items").firstChild;
     sendAsyncMessage("handling", {name: entry.getAttribute("name"), disabled: entry.disabled});
     window.close();
   });
 
   let testData = chromeScript.promiseOneMessage("handling");
--- a/toolkit/components/passwordmgr/test/browser/browser_basicAuth_rateLimit.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_basicAuth_rateLimit.js
@@ -17,17 +17,17 @@ function promiseAuthWindowShown() {
             PROMPT_URL,
             "Should have seen a prompt window"
           );
           is(
             domwindow.args.promptType,
             "promptUserAndPass",
             "Should be an authenticate prompt"
           );
-          domwindow.document.documentElement.cancelDialog();
+          domwindow.document.getElementById("commonDialog").cancelDialog();
           Services.wm.removeListener(listener);
           resolve();
         }, domwindow);
       },
 
       onCloseWindow() {},
     };
 
--- a/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js
@@ -21,17 +21,17 @@ add_task(async function test() {
           is(
             domwindow.args.promptType,
             "promptUserAndPass",
             "Should be an authenticate prompt"
           );
 
           is(gBrowser.selectedTab, tab, "Should have selected the new tab");
 
-          domwindow.document.documentElement.cancelDialog();
+          domwindow.document.getElementById("commonDialog").cancelDialog();
         }, domwindow);
       },
 
       onCloseWindow() {},
     };
 
     Services.wm.addListener(listener);
     registerCleanupFunction(() => {
--- a/toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
@@ -117,17 +117,19 @@
           getService(parentCi.nsIHttpAuthManager).
           clearAll();
         sendAsyncMessage("prepareForNextTestDone");
       });
 
       let dialogObserverTopic = "common-dialog-loaded";
 
       function dialogObserver(subj, topic, data) {
-        subj.Dialog.ui.prompt.document.documentElement.acceptDialog();
+        subj.Dialog.ui.prompt.document
+          .getElementById("commonDialog")
+          .acceptDialog();
         sendAsyncMessage("promptAccepted");
       }
 
       Services.obs.addObserver(dialogObserver, dialogObserverTopic);
 
       addMessageListener("cleanup", message => {
         Services.obs.removeObserver(dialogObserver, dialogObserverTopic);
         sendAsyncMessage("cleanupDone");
--- a/toolkit/content/tests/browser/browser_f7_caret_browsing.js
+++ b/toolkit/content/tests/browser/browser_f7_caret_browsing.js
@@ -108,80 +108,71 @@ function focusInput(browser) {
 add_task(async function checkTogglingCaretBrowsing() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kURL);
   await focusInput(tab.linkedBrowser);
 
   let promiseGotKey = promiseCaretPromptOpened();
   hitF7();
   let prompt = await promiseGotKey;
   let doc = prompt.document;
-  is(
-    doc.documentElement.defaultButton,
-    "cancel",
-    "No button should be the default"
-  );
+  let dialog = doc.getElementById("commonDialog");
+  is(dialog.defaultButton, "cancel", "No button should be the default");
   ok(
     !doc.getElementById("checkbox").checked,
     "Checkbox shouldn't be checked by default."
   );
   let promiseDialogUnloaded = BrowserTestUtils.waitForEvent(prompt, "unload");
 
-  doc.documentElement.cancelDialog();
+  dialog.cancelDialog();
   await promiseDialogUnloaded;
   info("Dialog unloaded");
   await waitForFocusOnInput(tab.linkedBrowser);
   ok(
     !Services.prefs.getBoolPref(kPrefCaretBrowsingOn),
     "Caret browsing should still be off after cancelling the dialog."
   );
 
   promiseGotKey = promiseCaretPromptOpened();
   hitF7();
   prompt = await promiseGotKey;
 
   doc = prompt.document;
-  is(
-    doc.documentElement.defaultButton,
-    "cancel",
-    "No button should be the default"
-  );
+  dialog = doc.getElementById("commonDialog");
+  is(dialog.defaultButton, "cancel", "No button should be the default");
   ok(
     !doc.getElementById("checkbox").checked,
     "Checkbox shouldn't be checked by default."
   );
   promiseDialogUnloaded = BrowserTestUtils.waitForEvent(prompt, "unload");
 
-  doc.documentElement.acceptDialog();
+  dialog.acceptDialog();
   await promiseDialogUnloaded;
   info("Dialog unloaded");
   await waitForFocusOnInput(tab.linkedBrowser);
   ok(
     Services.prefs.getBoolPref(kPrefCaretBrowsingOn),
     "Caret browsing should be on after accepting the dialog."
   );
 
   syncToggleCaretNoDialog(false);
 
   promiseGotKey = promiseCaretPromptOpened();
   hitF7();
   prompt = await promiseGotKey;
   doc = prompt.document;
+  dialog = doc.getElementById("commonDialog");
 
-  is(
-    doc.documentElement.defaultButton,
-    "cancel",
-    "No button should be the default"
-  );
+  is(dialog.defaultButton, "cancel", "No button should be the default");
   ok(
     !doc.getElementById("checkbox").checked,
     "Checkbox shouldn't be checked by default."
   );
 
   promiseDialogUnloaded = BrowserTestUtils.waitForEvent(prompt, "unload");
-  doc.documentElement.cancelDialog();
+  dialog.cancelDialog();
   await promiseDialogUnloaded;
   info("Dialog unloaded");
   await waitForFocusOnInput(tab.linkedBrowser);
 
   ok(
     !Services.prefs.getBoolPref(kPrefCaretBrowsingOn),
     "Caret browsing should still be off after cancelling the dialog."
   );
@@ -196,31 +187,28 @@ add_task(async function checkTogglingCar
 add_task(async function toggleCheckboxNoCaretBrowsing() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kURL);
   await focusInput(tab.linkedBrowser);
 
   let promiseGotKey = promiseCaretPromptOpened();
   hitF7();
   let prompt = await promiseGotKey;
   let doc = prompt.document;
-  is(
-    doc.documentElement.defaultButton,
-    "cancel",
-    "No button should be the default"
-  );
+  let dialog = doc.getElementById("commonDialog");
+  is(dialog.defaultButton, "cancel", "No button should be the default");
   let checkbox = doc.getElementById("checkbox");
   ok(!checkbox.checked, "Checkbox shouldn't be checked by default.");
 
   // Check the box:
   checkbox.click();
 
   let promiseDialogUnloaded = BrowserTestUtils.waitForEvent(prompt, "unload");
 
   // Say no:
-  doc.documentElement.getButton("cancel").click();
+  dialog.getButton("cancel").click();
 
   await promiseDialogUnloaded;
   info("Dialog unloaded");
   await waitForFocusOnInput(tab.linkedBrowser);
   ok(
     !Services.prefs.getBoolPref(kPrefCaretBrowsingOn),
     "Caret browsing should still be off."
   );
@@ -245,31 +233,28 @@ add_task(async function toggleCheckboxNo
 add_task(async function toggleCheckboxWantCaretBrowsing() {
   let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kURL);
   await focusInput(tab.linkedBrowser);
 
   let promiseGotKey = promiseCaretPromptOpened();
   hitF7();
   let prompt = await promiseGotKey;
   let doc = prompt.document;
-  is(
-    doc.documentElement.defaultButton,
-    "cancel",
-    "No button should be the default"
-  );
+  let dialog = doc.getElementById("commonDialog");
+  is(dialog.defaultButton, "cancel", "No button should be the default");
   let checkbox = doc.getElementById("checkbox");
   ok(!checkbox.checked, "Checkbox shouldn't be checked by default.");
 
   // Check the box:
   checkbox.click();
 
   let promiseDialogUnloaded = BrowserTestUtils.waitForEvent(prompt, "unload");
 
   // Say yes:
-  doc.documentElement.acceptDialog();
+  dialog.acceptDialog();
   await promiseDialogUnloaded;
   info("Dialog unloaded");
   await waitForFocusOnInput(tab.linkedBrowser);
   ok(
     Services.prefs.getBoolPref(kPrefCaretBrowsingOn),
     "Caret browsing should now be on."
   );
   ok(
--- a/toolkit/content/tests/chrome/dialog_dialogfocus.xhtml
+++ b/toolkit/content/tests/chrome/dialog_dialogfocus.xhtml
@@ -1,13 +1,15 @@
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 
-<dialog buttons="extra2,accept,cancel" onload="loaded()"
+<window onload="loaded()"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml">
+<dialog id="dialog-focus"
+        buttons="extra2,accept,cancel">
 
 <tabbox id="tabbox" hidden="true">
   <tabs>
     <tab id="tab" label="Tab"/>
   </tabs>
   <tabpanels>
     <tabpanel>
       <button id="tabbutton" label="Tab Button"/>
@@ -51,8 +53,9 @@ function loaded()
         document.getElementById("textbox-no").hidden = false;
         break;
     }
   }
 }
 </script>
 
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/dialog_dialogfocus2.xhtml
+++ b/toolkit/content/tests/chrome/dialog_dialogfocus2.xhtml
@@ -1,6 +1,8 @@
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 
-<dialog id="root" buttons="none" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<window id="root" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog id="dialog-focus"
+        buttons="none">
   <button id="nonbutton" noinitialfocus="true"/>
 </dialog>
-
+</window>
--- a/toolkit/content/tests/chrome/test_dialogfocus.xhtml
+++ b/toolkit/content/tests/chrome/test_dialogfocus.xhtml
@@ -25,19 +25,20 @@ SimpleTest.waitForExplicitFinish();
 SimpleTest.requestCompleteLog();
 
 var expected = [ "one", "_extra2", "tab", "one", "tabbutton2", "tabbutton", "two", "textbox-yes", "one", "root" ];
 // non-Mac will always focus the default button if any of the dialog buttons
 // would be focused
 if (!navigator.platform.includes("Mac"))
   expected[1] = "_accept";
 
-let extraDialog = "data:application/vnd.mozilla.xul+xml,<dialog id='root' buttons='none' " +
+let extraDialog = "data:application/vnd.mozilla.xul+xml,<window id='root'><dialog " +
+                  "buttons='none' " +
                   "xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" +
-                  "<button id='nonbutton' noinitialfocus='true'/></dialog>";
+                  "<button id='nonbutton' noinitialfocus='true'/></dialog></window>";
 
 var step = 0;
 var fullKeyboardAccess = false;
 
 function startTest()
 {
   var testButton = document.getElementById("test");
   synthesizeKey("KEY_Tab");
@@ -60,20 +61,21 @@ function runTest()
   let filename = expectedFocus == "root" ? "dialog_dialogfocus2.xhtml" : "dialog_dialogfocus.xhtml";
   var win = docShell.rootTreeItem.domWindow.openDialog(filename, "_new", "chrome,dialog", step);
 
   function checkDialogFocus(event)
   {
     info(`checkDialogFocus()`);
     let match = false;
     let activeElement = win.document.activeElement;
+    let dialog = win.document.getElementById("dialog-focus");
 
-    if (activeElement == win.document.documentElement) {
+    if (activeElement == dialog) {
       let shadowActiveElement =
-        win.document.documentElement.shadowRoot.activeElement;
+        dialog.shadowRoot.activeElement;
       if (shadowActiveElement) {
         activeElement = shadowActiveElement;
       }
     }
     // if full keyboard access is not on, just skip the tests
     if (fullKeyboardAccess) {
       if (!(event.target instanceof Element)) {
         info("target not an Element");
@@ -89,17 +91,17 @@ function runTest()
         return;
     }
     else {
       match = (activeElement == win.document.documentElement);
       info("match = " + match);
     }
 
     win.removeEventListener("focus", checkDialogFocusEvent, true);
-    win.document.documentElement.shadowRoot.removeEventListener(
+    dialog.shadowRoot.removeEventListener(
       "focus", checkDialogFocusEvent, true);
     ok(match, "focus step " + step);
 
     win.close();
     SimpleTest.waitForFocus(runTest, window);
   }
 
   let finalCheckInitiated = false;
@@ -116,17 +118,17 @@ function runTest()
         finalCheckInitiated = true;
       }
     } else {
       checkDialogFocus(event);
     }
   }
   win.addEventListener("focus", checkDialogFocusEvent, true);
   win.addEventListener("load", () => {
-    win.document.documentElement.shadowRoot.addEventListener(
+    win.document.getElementById("dialog-focus").shadowRoot.addEventListener(
       "focus", checkDialogFocusEvent, true);
   });
 }
 
 SimpleTest.waitForFocus(startTest, window);
 
 ]]>
 
--- a/toolkit/content/tests/chrome/test_preferences_beforeaccept.xhtml
+++ b/toolkit/content/tests/chrome/test_preferences_beforeaccept.xhtml
@@ -24,25 +24,25 @@
       var dialogShown = prefWindow.Preferences.get("tests.beforeaccept.dialogShown");
       var called = prefWindow.Preferences.get("tests.beforeaccept.called");
       is(dialogShown.value, true, "dialog opened, shown pref set");
       is(dialogShown.valueFromPreferences, null, "shown pref not committed");
       is(called.value, null, "beforeaccept not yet called");
       is(called.valueFromPreferences, null, "beforeaccept not yet called, pref not committed");
 
       // try to accept the dialog, should fail the first time
-      prefWindow.document.documentElement.acceptDialog();
+      prefWindow.document.getElementById("beforeaccept_dialog").acceptDialog();
       is(prefWindow.closed, false, "window not closed");
       is(dialogShown.value, true, "shown pref still set");
       is(dialogShown.valueFromPreferences, null, "shown pref still not committed");
       is(called.value, true, "beforeaccept called");
       is(called.valueFromPreferences, null, "called pref not committed");
 
       // try again, this one should succeed
-      prefWindow.document.documentElement.acceptDialog();
+      prefWindow.document.getElementById("beforeaccept_dialog").acceptDialog();
       is(prefWindow.closed, true, "window now closed");
       is(dialogShown.valueFromPreferences, true, "shown pref committed");
       is(called.valueFromPreferences, true, "called pref committed");
 
       SimpleTest.finish();
     }
 });
   ]]>
--- a/toolkit/content/tests/chrome/window_cursorsnap_dialog.xhtml
+++ b/toolkit/content/tests/chrome/window_cursorsnap_dialog.xhtml
@@ -1,16 +1,17 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<dialog title="Cursor snapping test" id="dialog"
+<window title="Cursor snapping test"
   width="600" height="600"
   onload="onload();"
   onunload="onunload();"
-  buttons="accept,cancel"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+<dialog id="dialog"
+  buttons="accept,cancel">
 
 <script class="testbody" type="application/javascript">
 <![CDATA[
 
 function ok(aCondition, aMessage)
 {
   window.arguments[0].SimpleTest.ok(aCondition, aMessage);
 }
@@ -97,8 +98,9 @@ function onunload()
     window.arguments[0].runNextTest();
   }
 }
 
 ]]>
 </script>
 
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences.xhtml
@@ -1,30 +1,31 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <!--
   XUL Widget Test for preferences window
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         class="prefwindow"
         title="preferences window"
         windowtype="test:preferences"
-        buttons="accept,cancel"
-        onload="RunTest(window.arguments)"
->
+        onload="RunTest(window.arguments)">
+<dialog id="window_preferences_dialog"
+        buttons="accept,cancel">
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     function RunTest(aArgs)
     {
       // run test
       aArgs[0](this);
       // close dialog
-      document.documentElement[aArgs[1] ? "acceptDialog" : "cancelDialog"]();
+      let dialog = document.getElementById("window_preferences_dialog");
+      dialog[aArgs[1] ? "acceptDialog" : "cancelDialog"]();
     }
 
     Preferences.addAll([
       // one of each type known to Preference.valueFromPreferences
       { id: "tests.static_preference_int", type: "int" },
       { id: "tests.static_preference_bool", type: "bool" },
       { id: "tests.static_preference_string", type: "string" },
       { id: "tests.static_preference_wstring", type: "wstring" },
@@ -58,8 +59,9 @@
       <html:input id="static_element_unichar" preference="tests.static_preference_unichar"/>
     </hbox>
     <hbox>
       <label flex="1" value="file"/>
       <html:input id="static_element_file"    preference="tests.static_preference_file"/>
     </hbox>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences2.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences2.xhtml
@@ -1,27 +1,29 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <!--
   XUL Widget Test for preferences window
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         class="prefwindow"
         title="preferences window"
         windowtype="test:preferences2"
-        buttons="accept,cancel"
-        onload="RunTest(window.arguments)"
->
+        onload="RunTest(window.arguments)">
+<dialog id="window_preferences2_dialog"
+        buttons="accept,cancel">
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     function RunTest(aArgs)
     {
       // open child
       openDialog("window_preferences3.xhtml", "", "modal,centerscreen,resizable=no", {test: aArgs[0], accept: aArgs[1]});
       // close dialog
-      document.documentElement[aArgs[1] ? "acceptDialog" : "cancelDialog"]();
+      let dialog = document.getElementById("window_preferences2_dialog");
+      dialog[aArgs[1] ? "acceptDialog" : "cancelDialog"]();
     }
   ]]>
   </script>
 
   <vbox id="sample_pane" class="prefpane" label="Sample Prefpane"/>
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences3.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences3.xhtml
@@ -1,31 +1,32 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <!--
   XUL Widget Test for preferences window
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         xmlns:html="http://www.w3.org/1999/xhtml"
         class="prefwindow"
         title="preferences window"
         windowtype="test:preferences3"
-        buttons="accept,cancel"
         onload="RunTest(window.arguments)"
-        type="child"
->
+        type="child">
+<dialog id="window_preferences3_dialog"
+        buttons="accept,cancel">
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     function RunTest(aArgs)
     {
       // run test
       aArgs[0].test(this);
       // close dialog
-      document.documentElement[aArgs[0].accept ? "acceptDialog" : "cancelDialog"]();
+      let dialog = document.getElementById("window_preferences3_dialog");
+      dialog[aArgs[0].accept ? "acceptDialog" : "cancelDialog"]();
     }
 
     Preferences.addAll([
       // one of each type known to Preference.valueFromPreferences
       { id: "tests.static_preference_int", type: "int" },
       { id: "tests.static_preference_bool", type: "bool" },
       { id: "tests.static_preference_string", type: "string" },
       { id: "tests.static_preference_wstring", type: "wstring" },
@@ -58,8 +59,9 @@
       <html:input id="static_element_unichar" preference="tests.static_preference_unichar"/>
     </hbox>
     <hbox>
       <label flex="1" value="file"/>
       <html:input id="static_element_file"    preference="tests.static_preference_file"/>
     </hbox>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences_beforeaccept.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences_beforeaccept.xhtml
@@ -1,21 +1,21 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <!--
   XUL Widget Test for preferences window with beforeaccept
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         class="prefwindow"
         title="preferences window"
         width="300" height="300"
         windowtype="test:preferences"
-        buttons="accept,cancel"
-        onload="onDialogLoad();"
->
+        onload="onDialogLoad();">
+<dialog id="beforeaccept_dialog"
+        buttons="accept,cancel">
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     function onDialogLoad() {
       document.addEventListener("beforeaccept", beforeAccept);
       var pref = Preferences.get("tests.beforeaccept.dialogShown");
       pref.value = true;
 
@@ -39,8 +39,9 @@
     ]);
   ]]>
   </script>
 
   <vbox id="sample_pane" class="prefpane" label="Sample Prefpane">
   </vbox>
   <label>Test Prefpane</label>
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences_commandretarget.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences_commandretarget.xhtml
@@ -1,36 +1,39 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 <!--
   XUL Widget Test for preferences window. This particular test ensures that
   a checkbox with a command attribute properly updates even though the command
   event gets retargeted.
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         class="prefwindow"
         title="preferences window"
         windowtype="test:preferences"
-        buttons="accept,cancel"
         onload="RunTest(window.arguments)">
+<dialog id="commandretarget_dialog"
+        buttons="accept,cancel">
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     function RunTest(aArgs)
     {
       aArgs[0](this);
-      document.documentElement.cancelDialog();
+      let dialog = document.getElementById("commandretarget_dialog");
+      dialog.cancelDialog();
     }
 
     Preferences.addAll([
       { id: "tests.static_preference_bool", type: "bool" },
     ]);
   ]]>
   </script>
 
   <vbox id="sample_pane" class="prefpane" label="Sample Prefpane">
     <commandset>
       <command id="cmd_test" preference="tests.static_preference_bool"/>
     </commandset>
 
     <checkbox id="checkbox" label="Enable Option" preference="tests.static_preference_bool" command="cmd_test"/>
   </vbox>
 </dialog>
+</window>
--- a/toolkit/content/tests/chrome/window_preferences_onsyncfrompreference.xhtml
+++ b/toolkit/content/tests/chrome/window_preferences_onsyncfrompreference.xhtml
@@ -3,22 +3,23 @@
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this file,
    - You can obtain one at http://mozilla.org/MPL/2.0/.  -->
 <!--
   XUL Widget Test for preferences window with onsyncfrompreference
   This test ensures that onsyncfrompreference handlers are called after all the
   values of the corresponding preference element have been set correctly
 -->
-<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         class="prefwindow"
         title="preferences window"
         width="300" height="300"
         windowtype="test:preferences"
         onload="onLoad()">
+<dialog>
 
   <script type="application/javascript" src="chrome://global/content/preferencesBindings.js"/>
   <script type="application/javascript">
   <![CDATA[
     Preferences.addAll([
       { id: "tests.onsyncfrompreference.pref1", type: "int" },
       { id: "tests.onsyncfrompreference.pref2", type: "int" },
       { id: "tests.onsyncfrompreference.pref3", type: "int" },
@@ -45,8 +46,9 @@
   <label>Test Prefpane</label>
         <checkbox id="check1" label="Label1"
                 preference="tests.onsyncfrompreference.pref1"/>
         <checkbox id="check2" label="Label2"
                 preference="tests.onsyncfrompreference.pref2"/>
         <checkbox id="check3" label="Label3"
                 preference="tests.onsyncfrompreference.pref3"/>
 </dialog>
+</window>
--- a/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_delayedbutton.js
+++ b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_delayedbutton.js
@@ -53,17 +53,18 @@ add_task(async function test_unknownCont
 
   await BrowserTestUtils.withNewTab(
     {
       gBrowser,
       url: LOAD_URI,
     },
     async function() {
       let uctWindow = await UCTObserver.opened.promise;
-      let ok = uctWindow.document.documentElement.getButton("accept");
+      let dialog = uctWindow.document.getElementById("unknownContentType");
+      let ok = dialog.getButton("accept");
 
       SimpleTest.is(ok.disabled, true, "button started disabled");
 
       await waitDelay(DIALOG_DELAY);
 
       SimpleTest.is(ok.disabled, false, "button was enabled");
 
       let focusOutOfDialog = SimpleTest.promiseFocus(window);
@@ -76,17 +77,17 @@ add_task(async function test_unknownCont
       uctWindow.focus();
       await focusOnDialog;
 
       SimpleTest.is(ok.disabled, true, "button remained disabled");
 
       await waitDelay(DIALOG_DELAY);
       SimpleTest.is(ok.disabled, false, "button re-enabled after delay");
 
-      uctWindow.document.documentElement.cancelDialog();
+      dialog.cancelDialog();
       await UCTObserver.closed.promise;
 
       Services.ww.unregisterNotification(UCTObserver);
       uctWindow = null;
       UCTObserver = null;
     }
   );
 });
--- a/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_dialog_layout.js
+++ b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_dialog_layout.js
@@ -86,15 +86,15 @@ add_task(async function test_unknownCont
                 value
             );
           }
         }
         let focusOnDialog = SimpleTest.promiseFocus(uctWindow);
         uctWindow.focus();
         await focusOnDialog;
 
-        uctWindow.document.documentElement.cancelDialog();
+        uctWindow.document.getElementById("unknownContentType").cancelDialog();
         uctWindow = null;
         Services.ww.unregisterNotification(UCTObserver);
       }
     );
   }
 });
--- a/toolkit/mozapps/extensions/test/browser/browser_bug523784.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug523784.js
@@ -50,17 +50,19 @@ function test() {
     args
   );
 }
 
 function bug523784_test1(win) {
   let bundle = Services.strings.createBundle(
     "chrome://mozapps/locale/update/updates.properties"
   );
-  let cancelButton = win.document.documentElement.getButton("cancel");
+  let cancelButton = win.document
+    .getElementById("BlocklistDialog")
+    .getButton("cancel");
   let moreInfoLink = win.document.getElementById("moreInfo");
 
   is(
     cancelButton.getAttribute("label"),
     bundle.GetStringFromName("restartLaterButton"),
     "Text should be changed on Cancel button"
   );
   is(
@@ -97,17 +99,19 @@ function bug523784_test2(win) {
     }
 
     Services.ww.unregisterNotification(windowObserver);
     win.addEventListener(
       "load",
       function() {
         executeSoon(function() {
           let moreInfoLink = win.document.getElementById("moreInfo");
-          let cancelButton = win.document.documentElement.getButton("cancel");
+          let cancelButton = win.document
+            .getElementById("BlocklistDialog")
+            .getButton("cancel");
           is(
             moreInfoLink.getAttribute("href"),
             Services.urlFormatter.formatURLPref(
               "extensions.blocklist.detailsURL"
             ),
             "More Info link should link to the general blocklist page."
           );
           cancelButton.doCommand();
--- a/toolkit/mozapps/extensions/test/xpinstall/head.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/head.js
@@ -214,39 +214,40 @@ var Harness = {
       executeSoon(() => callback(count));
     }
   },
 
   // Window open handling
   windowReady(window) {
     if (window.document.location.href == PROMPT_URL) {
       var promptType = window.args.promptType;
+      let dialog = window.document.getElementById("commonDialog");
       switch (promptType) {
         case "alert":
         case "alertCheck":
         case "confirmCheck":
         case "confirm":
         case "confirmEx":
-          window.document.documentElement.acceptDialog();
+          dialog.acceptDialog();
           break;
         case "promptUserAndPass":
           // This is a login dialog, hopefully an authentication prompt
           // for the xpi.
           if (this.authenticationCallback) {
             var auth = this.authenticationCallback();
             if (auth && auth.length == 2) {
               window.document.getElementById("loginTextbox").value = auth[0];
               window.document.getElementById("password1Textbox").value =
                 auth[1];
-              window.document.documentElement.acceptDialog();
+              dialog.acceptDialog();
             } else {
-              window.document.documentElement.cancelDialog();
+              dialog.cancelDialog();
             }
           } else {
-            window.document.documentElement.cancelDialog();
+            dialog.cancelDialog();
           }
           break;
         default:
           ok(false, "prompt type " + promptType + " not handled in test.");
           break;
       }
     }
   },
--- a/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js
+++ b/uriloader/exthandler/tests/mochitest/browser_download_always_ask_preferred_app.js
@@ -15,11 +15,11 @@ add_task(async function() {
     "open",
     "Should be opening the file."
   );
   ok(
     !dlg.document.getElementById("openHandler").selectedItem.hidden,
     "Should not have selected a hidden item."
   );
   let helperAppDialogHiddenPromise = BrowserTestUtils.windowClosed(dlg);
-  doc.documentElement.cancelDialog();
+  doc.getElementById("unknownContentType").cancelDialog();
   await helperAppDialogHiddenPromise;
 });
--- a/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js
+++ b/uriloader/exthandler/tests/mochitest/browser_remember_download_option.js
@@ -1,16 +1,17 @@
 add_task(async function() {
   // create mocked objects
   let launcher = createMockedObjects(true);
 
   // open helper app dialog with mocked launcher
   let dlg = await openHelperAppDialog(launcher);
 
   let doc = dlg.document;
+  let dialogElement = doc.getElementById("unknownContentType");
 
   // Set remember choice
   ok(
     !doc.getElementById("rememberChoice").checked,
     "Remember choice checkbox should be not checked."
   );
   doc.getElementById("rememberChoice").checked = true;
 
@@ -20,18 +21,18 @@ add_task(async function() {
     "Should not be in nsIHandlerService."
   );
 
   // close the dialog by pushing the ok button.
   let dialogClosedPromise = BrowserTestUtils.windowClosed(dlg);
   // Make sure the ok button is enabled, since the ok button might be disabled by
   // EnableDelayHelper mechanism. Please refer the detailed
   // https://dxr.mozilla.org/mozilla-central/source/toolkit/components/prompts/src/SharedPromptUtils.jsm#53
-  doc.documentElement.getButton("accept").disabled = false;
-  doc.documentElement.acceptDialog();
+  dialogElement.getButton("accept").disabled = false;
+  dialogElement.acceptDialog();
   await dialogClosedPromise;
 
   // check the mocked handler information is saved in nsIHandlerService
   ok(gHandlerSvc.exists(launcher.MIMEInfo), "Should be in nsIHandlerService.");
   // check the extension.
   var mimeType = gHandlerSvc.getTypeFromExtension("abc");
   is(mimeType, launcher.MIMEInfo.type, "Got correct mime type.");
   for (let handlerInfo of gHandlerSvc.enumerate()) {