#!/usr/bin/python

"""Tests to verify bug #517048 - Orca does not always speak the correct
   information when navigating and/or selecting text across object
   boundaries in OOo Writer.
"""

from macaroon.playback import *
import utils

sequence = MacroSequence()

###########################################################################
# Wait for oowriter to startup.
#
sequence.append(WaitForWindowActivate("Untitled1 - OpenOffice.org Writer",None))

###########################################################################
# Create a document containing:
#
# This is a test.
# So is this.
#
sequence.append(TypeAction("This is a test."))
sequence.append(KeyComboAction("Return"))
sequence.append(WaitForFocus("", acc_role=pyatspi.ROLE_PARAGRAPH))
sequence.append(TypeAction("So is this."))
sequence.append(WaitForFocus("", acc_role=pyatspi.ROLE_PARAGRAPH))

###########################################################################
# Test 9. Press Control-Home to start from the beginning of the document.
#         Press Shift-Down Arrow to select the current line.
#
sequence.append(KeyComboAction("<Control>Home"))
sequence.append(PauseAction(3000))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>Down"))
sequence.append(PauseAction(3000))
sequence.append(utils.AssertPresentationAction(
    "Select the current line from start of document",
    ["BRAILLE LINE:  'This is a test. $l'",
     "     VISIBLE:  'This is a test. $l', cursor=1",
     "BRAILLE LINE:  'soffice Application Untitled1 - OpenOffice.org Writer Frame Untitled1 - OpenOffice.org Writer RootPane ScrollPane Document view So is this. $l'",
     "     VISIBLE:  'So is this. $l', cursor=1",
     "SPEECH OUTPUT: 'This is a test.'",
     "SPEECH OUTPUT: 'selected'"]))

###########################################################################
# Test 10. Start from the end of the document (by pressing Control+End).
#          Press Shift-Up Arrow to select a line's worth (thus "So is this."
#          on the last line is selected, along with "est." at the end of the
#          previous line).
#
sequence.append(KeyComboAction("<Control>End"))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>Up"))
sequence.append(PauseAction(3000))
sequence.append(utils.AssertPresentationAction(
    "Select the current line from end of document",
    ["BUG - should say 'est. so is this. selected'",
     "BRAILLE LINE:  'So is this. $l'",
     "     VISIBLE:  'So is this. $l', cursor=1",
     "BRAILLE LINE:  'soffice Application Untitled1 - OpenOffice.org Writer Frame Untitled1 - OpenOffice.org Writer RootPane ScrollPane Document view This is a test. $l'",
     "     VISIBLE:  'This is a test. $l', cursor=12",
     "SPEECH OUTPUT: 'est.'",
     "SPEECH OUTPUT: 'selected'"]))

sequence.append(utils.AssertionSummaryAction())

sequence.start()
