Bug 1087114 - Run browser_subdialogs.js in e10s. r=gijs
authorJared Wein <jwein@mozilla.com>
Fri, 08 Jan 2016 13:08:34 -0500
changeset 320165 ea01aa74be131267e98f034d115df035bd86cd9d
parent 320164 2ec18a7b734917ef8743a0cfcacb86ba37ab32fb
child 320166 b58f40911311a1b74bc650dccdd973b7ba23acaa
child 320169 895e44661a5fcfd826d95c560990ecea25228b25
child 320171 eb0a8df76807252de86a57c40490a0250b8b375c
child 320172 3667d70d6d4a37f5089016f8a9150b2cbe3e43fa
child 320559 ac2fd5836f67c4013a5b078426d36d8120e9f9ca
child 320637 42bc352092a0eacb22d62c0d9b8fbfc3f1f487d9
child 320675 70eef69c59406fa097436812682c7b4c33d7f2bc
child 320679 4455378fadfe9eef63a00b10eeed8475497c7dc4
child 320680 9d81700bf0920064a2cb0cf0923a570da439f62c
child 321180 5374a5998e3f7ba014d200a500d3ec42085444b5
child 321181 12ab58b9fe8daf44863906c7ac26c7cc629d6636
child 321182 7c3155f69a0862b1a8a25936d3e08b01a52b9c9f
child 321188 26df22dab4e31b086cb7613891b7b0597027a28b
child 321508 b53826a1f9dfb46730be1a4a6f9be0511dd33b66
push id9143
push userahunt@mozilla.com
push dateFri, 08 Jan 2016 21:30:53 +0000
reviewersgijs
bugs1087114
milestone46.0a1
Bug 1087114 - Run browser_subdialogs.js in e10s. r=gijs
browser/components/preferences/in-content/subdialogs.js
browser/components/preferences/in-content/tests/browser.ini
browser/components/preferences/in-content/tests/browser_subdialogs.js
--- a/browser/components/preferences/in-content/subdialogs.js
+++ b/browser/components/preferences/in-content/subdialogs.js
@@ -92,17 +92,17 @@ var gSubDialog = {
       // cancelled by the ESC <key>.
       this._frame.loadURI("about:blank");
     }, 0);
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "command":
-        this.close(aEvent);
+        this._frame.contentWindow.close();
         break;
       case "dialogclosing":
         this._onDialogClosing(aEvent);
         break;
       case "DOMTitleChanged":
         this.updateTitle(aEvent);
         break;
       case "DOMFrameContentLoaded":
@@ -122,17 +122,17 @@ var gSubDialog = {
         break;
     }
   },
 
   /* Private methods */
 
   _onUnload: function(aEvent) {
     if (aEvent.target.location.href == this._openedURL) {
-      this.close(this._closingEvent);
+      this._frame.contentWindow.close();
     }
   },
 
   _onContentLoaded: function(aEvent) {
     if (aEvent.target != this._frame || aEvent.target.contentWindow.location == "about:blank")
       return;
 
     for (let styleSheetURL of this._injectedStyleSheets) {
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -27,13 +27,12 @@ skip-if = true || !healthreport # Bug 11
 [browser_privacypane_3.js]
 [browser_privacypane_4.js]
 [browser_privacypane_5.js]
 [browser_privacypane_8.js]
 skip-if = e10s # Bug ?????? -  "leaked until shutdown [nsGlobalWindow #99 about:preferences]"
 [browser_sanitizeOnShutdown_prefLocked.js]
 [browser_searchsuggestions.js]
 [browser_subdialogs.js]
-skip-if = e10s # Bug 1087114
 support-files = subdialog.xul
 [browser_telemetry.js]
 # Skip this test on Android and B2G as FHR and Telemetry are separate systems there.
 skip-if = !healthreport || !telemetry || (os == 'linux' && debug) || (os == 'android') || (os == 'b2g')
--- a/browser/components/preferences/in-content/tests/browser_subdialogs.js
+++ b/browser/components/preferences/in-content/tests/browser_subdialogs.js
@@ -2,273 +2,270 @@
 * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 /**
  * Tests for the sub-dialog infrastructure, not for actual sub-dialog functionality.
  */
 
-var gTeardownAfterClose = false;
 const gDialogURL = getRootDirectory(gTestPath) + "subdialog.xul";
 
-function test() {
-  waitForExplicitFinish();
-  open_preferences((win) => {
-    Task.spawn(function () {
-      for (let test of gTests) {
-        info("STARTING TEST: " + test.desc);
-        try {
-          yield test.run();
-        } finally {
-          if (test.teardown) {
-            yield test.teardown();
-          }
-        }
+function* open_subdialog_and_test_generic_start_state(browser, domcontentloadedFn) {
+  let domcontentloadedFnStr = domcontentloadedFn ?
+    "(" + domcontentloadedFn.toString() + ")()" :
+    "";
+  return ContentTask.spawn(browser, {gDialogURL, domcontentloadedFnStr}, function*(args) {
+    let {gDialogURL, domcontentloadedFnStr} = args;
+    let rv = { acceptCount: 0 };
+    let win = content.window;
+    let subdialog = win.gSubDialog;
+    subdialog.open(gDialogURL, null, rv);
+
+    info("waiting for subdialog DOMFrameContentLoaded");
+    yield ContentTaskUtils.waitForEvent(win, "DOMFrameContentLoaded", true);
+    let result;
+    if (domcontentloadedFnStr) {
+      result = eval(domcontentloadedFnStr);
+    }
+
+    info("waiting for subdialog load");
+    yield ContentTaskUtils.waitForEvent(subdialog._frame, "load");
+    info("subdialog window is loaded");
+
+    let expectedStyleSheetURLs = subdialog._injectedStyleSheets.slice(0);
+    for (let styleSheet of subdialog._frame.contentDocument.styleSheets) {
+      let index = expectedStyleSheetURLs.indexOf(styleSheet.href);
+      if (index >= 0) {
+        expectedStyleSheetURLs.splice(index, 1);
       }
-    });
+    }
+
+    ok(!!subdialog._frame.contentWindow, "The dialog should be non-null");
+    isnot(subdialog._frame.contentWindow.location.toString(), "about:blank",
+      "Subdialog URL should not be about:blank");
+    is(win.getComputedStyle(subdialog._overlay, "").visibility, "visible",
+      "Overlay should be visible");
+    is(expectedStyleSheetURLs.length, 0,
+      "No stylesheets that were expected are missing");
+    return result;
   });
 }
 
-var gTests = [{
-  desc: "Check titlebar, focus, return value, title changes, and accepting",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    // Check focus is in the textbox
-    is(dialog.document.activeElement.value, "Default text", "Textbox with correct text is focused");
-
-    // Titlebar
-    is(content.document.getElementById("dialogTitle").textContent, "Sample sub-dialog",
-      "Dialog title should be correct initially");
-    let receivedEvent = waitForEvent(gBrowser.selectedBrowser, "DOMTitleChanged");
-    dialog.document.title = "Updated title";
-    // Wait for the title change listener
-    yield receivedEvent;
-    is(content.document.getElementById("dialogTitle").textContent, "Updated title",
-      "Dialog title should be updated with changes");
-
-    let closingPromise = promiseDialogClosing(dialog);
-
-    // Accept the dialog
-    dialog.document.documentElement.acceptDialog();
-    let closingEvent = yield closingPromise;
-    is(closingEvent.detail.button, "accept", "closing event should indicate button was 'accept'");
-
-    yield deferredClose.promise;
-    is(rv.acceptCount, 1, "return value should have been updated");
-  },
-},
-{
-  desc: "Check canceling the dialog",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    let closingPromise = promiseDialogClosing(dialog);
-
-    info("cancelling the dialog");
-    dialog.document.documentElement.cancelDialog();
-
-    let closingEvent = yield closingPromise;
-    is(closingEvent.detail.button, "cancel", "closing event should indicate button was 'cancel'");
+function* close_subdialog_and_test_generic_end_state(browser, closingFn, closingButton, acceptCount, options) {
+  let dialogclosingPromise = ContentTask.spawn(browser, {closingButton, acceptCount}, function*(expectations) {
+    let win = content.window;
+    let subdialog = win.gSubDialog;
+    let frame = subdialog._frame;
+    info("waiting for dialogclosing");
+    let closingEvent =
+      yield ContentTaskUtils.waitForEvent(frame.contentWindow, "dialogclosing");
+    let actualAcceptCount = frame.contentWindow.arguments &&
+                            frame.contentWindow.arguments[0].acceptCount;
 
-    yield deferredClose.promise;
-    is(rv.acceptCount, 0, "return value should NOT have been updated");
-  },
-},
-{
-  desc: "Check window.close on the dialog",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    let closingPromise = promiseDialogClosing(dialog);
-    info("window.close called on the dialog");
-    dialog.window.close();
-
-    let closingEvent = yield closingPromise;
-    is(closingEvent.detail.button, null, "closing event should indicate no button was clicked");
-
-    yield deferredClose.promise;
-    is(rv.acceptCount, 0, "return value should NOT have been updated");
-  },
-},
-{
-  desc: "Check clicking the close button on the dialog",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    yield EventUtils.synthesizeMouseAtCenter(content.document.getElementById("dialogClose"), {},
-                                             content.window);
-
-    yield deferredClose.promise;
-    is(rv.acceptCount, 0, "return value should NOT have been updated");
-  },
-},
-{
-  desc: "Check that 'back' navigation will close the dialog",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    info("cancelling the dialog");
-    content.gSubDialog._frame.goBack();
+    info("waiting for about:blank load");
+    yield ContentTaskUtils.waitForEvent(frame, "load");
 
-    yield deferredClose.promise;
-    is(rv.acceptCount, 0, "return value should NOT have been updated");
-  },
-},
-{
-  desc: "Hitting escape in the dialog",
-  run: function* () {
-    let rv = { acceptCount: 0 };
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, rv,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    EventUtils.synthesizeKey("VK_ESCAPE", {}, content.window);
-
-    yield deferredClose.promise;
-    is(rv.acceptCount, 0, "return value should NOT have been updated");
-  },
-},
-{
-  desc: "Check that width and height from the sub-dialog are used to size the <browser>",
-  run: function* () {
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, null,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-    let dialog = yield dialogPromise;
-
-    is(content.gSubDialog._frame.style.width, "32em", "Width should be set on the frame from the dialog");
-    is(content.gSubDialog._frame.style.height, "5em", "Height should be set on the frame from the dialog");
-
-    content.gSubDialog.close();
-    yield deferredClose.promise;
-  },
-},
-{
-  desc: "Check that a set width and content causing wrapping still lead to correct scrollHeight-implied height",
-  run: function* () {
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, null,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-
-    let oldHeight;
-    content.addEventListener("DOMFrameContentLoaded", function frame2Loaded() {
-      content.removeEventListener("DOMFrameContentLoaded", frame2Loaded);
-      let doc = content.gSubDialog._frame.contentDocument;
-      oldHeight = doc.documentElement.scrollHeight;
-      doc.documentElement.style.removeProperty("height");
-      doc.getElementById("desc").textContent = `
-        Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
-        laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
-        architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
-        sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
-        laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
-        architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
-        sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
-        laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
-        architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
-        sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
-        voluptatem sequi nesciunt.`
-      doc = null;
-    });
+    isnot(win.getComputedStyle(subdialog._overlay, "").visibility, "visible",
+      "overlay is not visible");
+    is(frame.getAttribute("style"), "", "inline styles should be cleared");
+    is(frame.contentWindow.location.href.toString(), "about:blank",
+      "sub-dialog should be unloaded");
+    is(closingEvent.detail.button, expectations.closingButton,
+      "closing event should indicate button was '" + expectations.closingButton + "'");
+    is(actualAcceptCount, expectations.acceptCount,
+      "should be 1 if accepted, 0 if canceled, undefined if closed w/out button");
+  });
 
-    let dialog = yield dialogPromise;
-
-    is(content.gSubDialog._frame.style.width, "32em", "Width should be set on the frame from the dialog");
-    let docEl = content.gSubDialog._frame.contentDocument.documentElement;
-    ok(docEl.scrollHeight > oldHeight, "Content height increased (from " + oldHeight + " to " + docEl.scrollHeight + ").");
-    is(content.gSubDialog._frame.style.height, docEl.scrollHeight + "px", "Height on the frame should be higher now");
-
-    content.gSubDialog.close();
-    yield deferredClose.promise;
-  },
-},
-{
-  desc: "Check that a dialog that is too high gets cut down to size",
-  run: function* () {
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, null,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-
-    content.addEventListener("DOMFrameContentLoaded", function frame3Loaded() {
-      content.removeEventListener("DOMFrameContentLoaded", frame3Loaded);
-      content.gSubDialog._frame.contentDocument.documentElement.style.height = '100000px';
-    });
-
-    let dialog = yield dialogPromise;
-
-    is(content.gSubDialog._frame.style.width, "32em", "Width should be set on the frame from the dialog");
-    let newHeight = content.gSubDialog._frame.contentDocument.documentElement.scrollHeight;
-    ok(parseInt(content.gSubDialog._frame.style.height) < window.innerHeight,
-       "Height on the frame should be smaller than window's innerHeight");
+  if (options && options.runClosingFnOutsideOfContentTask) {
+    yield closingFn();
+  } else {
+    ContentTask.spawn(browser, null, closingFn);
+  }
 
-    content.gSubDialog.close();
-    yield deferredClose.promise;
-  }
-},
-{
-  desc: "Check that scrollWidth and scrollHeight from the sub-dialog are used to size the <browser>",
-  run: function* () {
-    let deferredClose = Promise.defer();
-    let dialogPromise = openAndLoadSubDialog(gDialogURL, null, null,
-                                             (aEvent) => dialogClosingCallback(deferredClose, aEvent));
-
-    content.addEventListener("DOMFrameContentLoaded", function frameLoaded() {
-      content.removeEventListener("DOMFrameContentLoaded", frameLoaded);
-      content.gSubDialog._frame.contentDocument.documentElement.style.removeProperty("height");
-      content.gSubDialog._frame.contentDocument.documentElement.style.removeProperty("width");
-    });
-
-    let dialog = yield dialogPromise;
-
-    ok(content.gSubDialog._frame.style.width.endsWith("px"),
-       "Width (" + content.gSubDialog._frame.style.width + ") should be set to a px value of the scrollWidth from the dialog");
-    ok(content.gSubDialog._frame.style.height.endsWith("px"),
-       "Height (" + content.gSubDialog._frame.style.height + ") should be set to a px value of the scrollHeight from the dialog");
-
-    gTeardownAfterClose = true;
-    content.gSubDialog.close();
-    yield deferredClose.promise;
-  },
-}];
-
-function promiseDialogClosing(dialog) {
-  return waitForEvent(dialog, "dialogclosing");
+  yield dialogclosingPromise;
 }
 
-function dialogClosingCallback(aPromise, aEvent) {
-  // Wait for the close handler to unload the page
-  waitForEvent(content.gSubDialog._frame, "load", 4000).then((aEvt) => {
-    info("Load event happened: " + !(aEvt instanceof Error));
-    is_element_hidden(content.gSubDialog._overlay, "Overlay is not visible");
-    is(content.gSubDialog._frame.getAttribute("style"), "",
-       "Check that inline styles were cleared");
-    is(content.gSubDialog._frame.contentWindow.location.toString(), "about:blank",
-      "Check the sub-dialog was unloaded");
-    if (gTeardownAfterClose) {
-      content.close();
-      finish();
-    }
-    aPromise.resolve();
-  }, Cu.reportError);
-}
+let tab;
+
+add_task(function* test_initialize() {
+  tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
+});
+
+add_task(function* check_titlebar_focus_returnval_titlechanges_accepting() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  let domtitlechangedPromise = BrowserTestUtils.waitForEvent(tab.linkedBrowser, "DOMTitleChanged");
+  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let dialog = content.window.gSubDialog._frame.contentWindow;
+    let dialogTitleElement = content.document.getElementById("dialogTitle");
+    is(dialogTitleElement.textContent, "Sample sub-dialog",
+       "Title should be correct initially");
+    is(dialog.document.activeElement.value, "Default text",
+       "Textbox with correct text is focused");
+    dialog.document.title = "Updated title";
+  });
+
+  info("waiting for DOMTitleChanged event");
+  yield domtitlechangedPromise;
+
+  ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let dialogTitleElement = content.document.getElementById("dialogTitle");
+    is(dialogTitleElement.textContent, "Updated title", "subdialog should have updated title");
+  });
+
+  // Accept the dialog
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentDocument.documentElement.acceptDialog(); },
+    "accept", 1);
+});
+
+add_task(function* check_canceling_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentDocument.documentElement.cancelDialog(); },
+    "cancel", 0);
+});
+
+add_task(function* window_close_on_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentWindow.window.close(); },
+    null, 0);
+});
+
+add_task(function* click_close_button_on_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { return BrowserTestUtils.synthesizeMouseAtCenter("#dialogClose", {}, tab.linkedBrowser); },
+    null, 0, {runClosingFnOutsideOfContentTask: true});
+});
+
+add_task(function* back_navigation_on_subdialog_should_close_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.goBack(); },
+    null, undefined);
+});
+
+add_task(function* back_navigation_on_browser_tab_should_close_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { tab.linkedBrowser.goBack(); },
+    null, undefined, {runClosingFnOutsideOfContentTask: true});
+});
+
+add_task(function* escape_should_close_dialog() {
+  todo(false, "BrowserTestUtils.sendChar('VK_ESCAPE') triggers " +
+              "'can't access dead object' on `navigator` in this test. " +
+              "See bug 1238065.")
+  return;
+
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  info("canceling the dialog");
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { return BrowserTestUtils.sendChar("VK_ESCAPE", tab.linkedBrowser); },
+    null, undefined, {runClosingFnOutsideOfContentTask: true});
+});
+
+add_task(function* correct_width_and_height_should_be_used_for_dialog() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser);
+
+  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let frameStyle = content.window.gSubDialog._frame.style;
+    is(frameStyle.width, "32em", "Width should be set on the frame from the dialog");
+    is(frameStyle.height, "5em", "Height should be set on the frame from the dialog");
+  });
+
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentWindow.window.close(); },
+    null, 0);
+});
+
+add_task(function* wrapped_text_in_dialog_should_have_expected_scrollHeight() {
+  let oldHeight = yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser, function domcontentloadedFn() {
+    let frame = content.window.gSubDialog._frame;
+    let doc = frame.contentDocument;
+    let oldHeight = doc.documentElement.scrollHeight;
+    doc.documentElement.style.removeProperty("height");
+    doc.getElementById("desc").textContent = `
+      Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque
+      laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
+      architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
+      sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
+      laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
+      architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
+      sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
+      laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi
+      architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
+      sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione
+      voluptatem sequi nesciunt.`
+    return oldHeight;
+  });
+
+  yield ContentTask.spawn(tab.linkedBrowser, oldHeight, function*(oldHeight) {
+    let frame = content.window.gSubDialog._frame;
+    let docEl = frame.contentDocument.documentElement;
+    is(frame.style.width, "32em",
+      "Width should be set on the frame from the dialog");
+    ok(docEl.scrollHeight > oldHeight,
+      "Content height increased (from " + oldHeight + " to " + docEl.scrollHeight + ").");
+    is(frame.style.height, docEl.scrollHeight + "px",
+      "Height on the frame should be higher now");
+  });
+
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentWindow.window.close(); },
+    null, 0);
+});
+
+add_task(function* dialog_too_tall_should_get_reduced_in_height() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser, function domcontentloadedFn() {
+    let frame = content.window.gSubDialog._frame;
+    frame.contentDocument.documentElement.style.height = '100000px';
+  });
+
+  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let frame = content.window.gSubDialog._frame;
+    is(frame.style.width, "32em", "Width should be set on the frame from the dialog");
+    ok(parseInt(frame.style.height) < content.window.innerHeight,
+       "Height on the frame should be smaller than window's innerHeight");
+  });
+
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentWindow.window.close(); },
+    null, 0);
+});
+
+add_task(function* scrollWidth_and_scrollHeight_from_subdialog_should_size_the_browser() {
+  yield open_subdialog_and_test_generic_start_state(tab.linkedBrowser, function domcontentloadedFn() {
+    let frame = content.window.gSubDialog._frame;
+    frame.contentDocument.documentElement.style.removeProperty("height");
+    frame.contentDocument.documentElement.style.removeProperty("width");
+  });
+
+  yield ContentTask.spawn(tab.linkedBrowser, null, function*() {
+    let frame = content.window.gSubDialog._frame;
+    ok(frame.style.width.endsWith("px"),
+       "Width (" + frame.style.width + ") should be set to a px value of the scrollWidth from the dialog");
+    ok(frame.style.height.endsWith("px"),
+       "Height (" + frame.style.height + ") should be set to a px value of the scrollHeight from the dialog");
+  });
+
+  yield close_subdialog_and_test_generic_end_state(tab.linkedBrowser,
+    function() { content.window.gSubDialog._frame.contentWindow.window.close(); },
+    null, 0);
+});
+
+add_task(function* test_shutdown() {
+  gBrowser.removeTab(tab);
+});