toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
author Brian Nicholson <bnicholson@mozilla.com>
Mon, 02 Jul 2012 12:42:11 -0700
changeset 98127 4a5f794edd2d03d83a9836f749665ac874b7320c
parent 95245 7c3cd4824f94609d4ad714bea9c687227c641e63
child 143070 3831481da4ce2527f13f379e0225a765130718c7
permissions -rw-r--r--
Bug 769097 - Remember desktop mode preference after OOM. r=mfinkle

<?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/.  -->
<!--
 * The unknownContentType popup can have two different layouts depending on
 * whether a helper application can be selected or not.
 * This tests that both layouts have correct collapsed elements.
-->

<window title="Unknown Content Type Dialog Test"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="init()">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript"
          src="utils.js"/>

  <script type="application/javascript">
  <![CDATA[

const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";

let testIndex = -1;
let tests = [
  { // This URL will trigger the simple UI, where only the Save an Cancel buttons are available
    url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif",
    elements: {
      basicBox: { collapsed: false },
      normalBox: { collapsed: true }
    }
  },
  { // This URL will trigger the full UI
    url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt",
    elements: {
      basicBox: { collapsed: true },
      normalBox: { collapsed: false }
    }
  }
];

let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
         getService(Ci.nsIWindowWatcher);

SimpleTest.waitForExplicitFinish();

let windowObserver = {
  observe: function(aSubject, aTopic, aData) {
    let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);

    if (aTopic == "domwindowclosed") {
      if (win.location == UCT_URI)
        loadNextTest();
      return;
    }

    // domwindowopened
    win.addEventListener("load", function onLoad(event) {
      win.removeEventListener("load", onLoad, false);

      // Let the dialog initialize
      SimpleTest.executeSoon(function() {
        checkWindow(win);
      });
    }, false);
  }
};

function init() {
  ww.registerNotification(windowObserver);
  loadNextTest();
}

function loadNextTest() {
  if (!tests[++testIndex]) {
    ww.unregisterNotification(windowObserver);
    SimpleTest.finish();
    return;
  }
  let frame = document.getElementById("testframe");
  frame.setAttribute("src", tests[testIndex].url);
}

function checkWindow(win) {
  for (let [id, props] in Iterator(tests[testIndex].elements)) {
    let elem = win.dialog.dialogElement(id);
    for (let [prop, value] in Iterator(props)) {
      is(elem[prop], value,
         "Element with id " + id + " has property " +
         prop + " set to " + value);
    }
  }
  win.document.documentElement.cancelDialog();
}

  ]]>
  </script>

  <body xmlns="http://www.w3.org/1999/xhtml">
    <p id="display"></p>
    <div id="content" style="display:none;"></div>
    <pre id="test"></pre>
  </body>

  <iframe xmlns="http://www.w3.org/1999/xhtml"
          id="testframe">
  </iframe>
</window>