/**
   * This test demonstrates how a modal dialog can be managed. In order for this to work, the dialog
   * needs to pass a reference to the document it contains back to the document in the browser that
   * opened the dialog. Jiffie can then retrieve this reference and work with the document in the
   * dialog window.
   *
   * <p>Unfortunately this means that if you don't have the ability to change the web pages you want
   * to test to add this kind of code, modal dialogs will remain out of bounds for Jiffie.
   *
   * <p>The files anchor.htm and dialogtarget.htm show how this technique works using an onload
   * function on the dialog document, and a div in anchor.htm which receives a reference to the
   * dialog's document as an attribute.
   *
   * @throws Exception
   */
  public void testModalDialog() throws Exception {
    //
    // Open the browser
    //
    m_explorer.navigate(m_datadir + "/anchor.htm", true);

    //
    // Retrieve the document
    //
    IHTMLDocument2 document = m_explorer.getDocument(true);
    assertEquals("Anchor Test", document.getTitle());

    //
    // Find and click the anchor which launches the modal dialog
    //
    IHTMLAnchorElement anchor = (IHTMLAnchorElement) document.getElementByName("anchor8");
    BlockingClickThread thread = new BlockingClickThread(anchor);
    thread.start();
    anchor = null;

    //
    // Find the div to which the dialog window has attached a reference
    // to its document, and create an IHTMLDocument2 instance from it.
    //
    IHTMLElement div = (IHTMLElement) document.getElementById("dialogDocumentDiv");
    IHTMLDocument2 dialogDocument =
        new IHTMLDocument2(m_explorer, div.getVariantProperty("dialogDocument").toDispatch());
    assertEquals("Dialog Target", dialogDocument.getTitle());

    //
    // Click the anchor which closes the dialog and clean up
    //
    anchor = (IHTMLAnchorElement) dialogDocument.getElementByName("closeAnchor");
    anchor.click(true);
    anchor.release();
    anchor = null;

    dialogDocument.release();
    dialogDocument = null;

    document.release();
    document = null;
  }