/**
   * Exercise IHTMLAnchorElement functionality.
   *
   * @throws Exception
   */
  public void testAnchors() 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 the simple anchor and click
    //
    IHTMLAnchorElement anchor = (IHTMLAnchorElement) document.getElementByName("anchor1");
    anchor.click(true);
    assertEquals("Anchor Target", document.getTitle());
    anchor.release();
    anchor = null;

    //
    // Navigate back and try the anchor that has an onclick handler
    //
    m_explorer.goBack(true);
    assertEquals("Anchor Test", document.getTitle());
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor2");
    anchor.click(true);
    assertEquals("Anchor Target", document.getTitle());
    anchor.release();
    anchor = null;

    //
    // Navigate back and try the anchor that blocks on an alert dialog
    //
    m_explorer.goBack(true);
    assertEquals("Anchor Test", document.getTitle());
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor3");

    // start a new thread to perform the click, the call to the
    // click method will block when the alert dialog is shown
    // but we can continue in the main thread and send key presses
    // to the dialog to dismiss it
    BlockingClickThread thread = new BlockingClickThread(anchor);
    thread.start();

    // send a space to the dialog to press the button
    JiffieUtility.sendKeys("Internet Explorer", " ", document);
    assertEquals("Anchor Target", document.getTitle());
    anchor.release();
    anchor = null;

    //
    // Navigate back and try the anchor that blocks on a confirm dialog
    // First time through we will press the OK button
    //
    m_explorer.goBack(true);
    assertEquals("Anchor Test", document.getTitle());
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor4");

    // start a new thread to perform the click, the call to the
    // click method will block when the alert dialog is shown
    // but we can continue in the main thread and send key presses
    // to the dialog to dismiss it
    thread = new BlockingClickThread(anchor);
    thread.start();

    //
    // Send a space to the dialog to press the ok button
    //
    JiffieUtility.sendKeys("Internet Explorer", " ");
    document.waitWhileIncomplete();
    assertEquals("Anchor Target", document.getTitle());
    anchor.release();
    anchor = null;

    //
    // Navigate back and try the anchor that blocks on a confirm dialog
    // Second time through, we will press the cancel button
    // to stop the navigation.
    //
    m_explorer.goBack(true);
    assertEquals("Anchor Test", document.getTitle());
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor4");

    // start a new thread to perform the click, the call to the
    // click method will block when the alert dialog is shown
    // but we can continue in the main thread and send key presses
    // to the dialog to dismiss it
    thread = new BlockingClickThread(anchor);
    thread.start();

    // send a tab to change to the cancel button, then send a space
    // to press the button
    JiffieUtility.sendKeys("Internet Explorer", "{TAB} ", document);
    assertEquals("Anchor Test", document.getTitle());
    anchor.release();
    anchor = null;

    //
    // Try the anchor that navigates to a new window via a target attribute
    //
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor5");
    anchor.click(true);

    // our main window document should not have changed
    assertEquals("Anchor Test", document.getTitle());
    anchor.release();
    anchor = null;

    // we should have a single new window
    assertEquals(1, m_explorer.getNewWindowCount());

    InternetExplorer newWindow = m_explorer.getLastNewWindow(true);
    IHTMLDocument2 newDocument = newWindow.getDocument(true);
    assertEquals("Anchor Target", newDocument.getTitle());
    newDocument.release();
    newDocument = null;
    newWindow.quit();
    newWindow.release();
    newWindow = null;

    //
    // Try the anchor that navigates to a new window via an on click handler
    //
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor6");
    anchor.click(true);

    //
    // our main window document should not have changed
    //
    assertEquals("Anchor Test", document.getTitle());
    anchor.release();
    anchor = null;

    // we should have a single new window, however
    // under Windows XP SP2, this test will fail due to the new popup
    // protection which IE6 implements
    assertEquals(1, m_explorer.getNewWindowCount());
    newWindow = m_explorer.getLastNewWindow(true);
    newDocument = newWindow.getDocument(true);
    assertEquals("Anchor Target", newDocument.getTitle());
    newDocument.release();
    newDocument = null;
    newWindow.quit();
    newWindow.release();
    newWindow = null;

    //
    // Try the anchor that blocks on a prompt dialog. Enter some
    // text at the prompt and check that we get the expected result.
    // Note that you should be able to use the same technique as shown
    // to complete authentication dialogs etc.
    //
    anchor = (IHTMLAnchorElement) document.getElementByName("anchor7");

    // start a new thread to perform the click, the call to the
    // click method will block when the dialog is shown
    // but we can continue in the main thread and send key presses
    // to the dialog to dismiss it
    thread = new BlockingClickThread(anchor);
    thread.start();

    // send some text to populate the prompt field,
    // a tab to change to the ok button, then send a space
    // to press the button
    JiffieUtility.sendKeys("Explorer User Prompt", "test text{TAB} ", document);

    IHTMLInputElement input = (IHTMLInputElement) document.getElementByName("input1");
    assertEquals("test text", input.getValue());
    anchor.release();
    anchor = null;
    input.release();
    input = null;

    document.release();
    document = null;
  }