#!/usr/bin/python

"""Test of UIUC button presentation using Firefox.
"""

from macaroon.playback import *
import utils

sequence = MacroSequence()

########################################################################
# We wait for the focus to be on the Firefox window as well as for focus
# to move to the "text/html: Button Example 1" frame.
#
sequence.append(WaitForWindowActivate(utils.firefoxFrameNames, None))

########################################################################
# Load the UIUC button demo.
#
sequence.append(KeyComboAction("<Control>l"))
sequence.append(WaitForFocus(acc_role=pyatspi.ROLE_ENTRY))
sequence.append(TypeAction("http://test.cita.uiuc.edu/aria/alert/view_class.php?title=Alert%20Example%201:%20Number%20Guessing%20Game&ginc=includes/alert1_class.inc&gcss=css/alert1_class.css&gjs=../js/globals.js,../js/widgets_class.js,js/alert1_class.js"))
sequence.append(KeyComboAction("Return"))
sequence.append(WaitForDocLoad())
sequence.append(WaitForFocus("class: Alert Example 1: Number Guessing Game", acc_role=pyatspi.ROLE_DOCUMENT_FRAME))

sequence.append(PauseAction(10000))

########################################################################
# Tab to the text area, enter some text and press return.
#
sequence.append(KeyComboAction("Tab"))
sequence.append(WaitForFocus("Guess a number between 1 and 10", acc_role=pyatspi.ROLE_ENTRY))
sequence.append(PauseAction(10000))
sequence.append(TypeAction("12"))
#sequence.append(PauseAction(10000))
sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Return"))
sequence.append(PauseAction(10000))
sequence.append(utils.AssertPresentationAction(
    "Observe alert text", 
    ["SPEECH OUTPUT: '12 is not between 1 and 10'"]))

########################################################################
# Close the demo
#
sequence.append(KeyComboAction("<Control>l"))
sequence.append(WaitForFocus(acc_role=pyatspi.ROLE_ENTRY))
sequence.append(TypeAction("about:blank"))
sequence.append(KeyComboAction("Return"))
sequence.append(WaitForDocLoad())

# Just a little extra wait to let some events get through.
#
sequence.append(PauseAction(3000))

sequence.append(utils.AssertionSummaryAction())

sequence.start()
