#!/usr/bin/env python3
#
# Copyright (c) 2024 Stormux
# Copyright (c) 2010-2012 The Orca Team
# Copyright (c) 2012 Igalia, S.L.
# Copyright (c) 2005-2010 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
# Boston MA  02110-1301 USA.
#
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca

"""Test of object navigation."""

from macaroon.playback import *
import utils

sequence = MacroSequence()

#sequence.append(WaitForDocLoad())
sequence.append(PauseAction(5000))

# Work around some new quirk in Gecko that causes this test to fail if
# run via the test harness rather than manually.
sequence.append(KeyComboAction("<Control>r"))
sequence.append(PauseAction(5000))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Control>Home"))
sequence.append(utils.AssertPresentationAction(
    "1. Top of file",
    ["BRAILLE LINE:  'Home'",
     "     VISIBLE:  'Home', cursor=1",
     "SPEECH OUTPUT: 'Home link.' voice=hyperlink"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("H"))
sequence.append(utils.AssertPresentationAction(
    "2. H for heading",
    ["BRAILLE LINE:  'Enter Bug: cthulhu \u2013 This page lets you enter a new bug into Bugzilla. h1'",
     "     VISIBLE:  'Enter Bug: cthulhu \u2013 This page lets', cursor=1",
     "SPEECH OUTPUT: 'Enter Bug: cthulhu \u2013 This page lets you enter a new bug into Bugzilla. heading level 1'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "3. line Down",
    ["BRAILLE LINE:  'into Bugzilla. h1'",
     "     VISIBLE:  'into Bugzilla. h1', cursor=1",
     "SPEECH OUTPUT: 'into Bugzilla. heading level 1'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "4. line Down",
    ["BRAILLE LINE:  'Before reporting a bug, please read the'",
     "     VISIBLE:  'Before reporting a bug, please r', cursor=1",
     "SPEECH OUTPUT: 'Before reporting a bug, please read the.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "5. line Down",
    ["BRAILLE LINE:  'bug writing guidelines'",
     "     VISIBLE:  'bug writing guidelines', cursor=1",
     "SPEECH OUTPUT: 'bug writing guidelines link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "6. line Down",
    ["BRAILLE LINE:  ', please look at the list of'",
     "     VISIBLE:  ', please look at the list of', cursor=1",
     "SPEECH OUTPUT: ', please look at the list of.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "7. line Down",
    ["BRAILLE LINE:  'most'",
     "     VISIBLE:  'most', cursor=1",
     "SPEECH OUTPUT: 'most link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "8. line Down",
    ["BRAILLE LINE:  'frequently reported bugs'",
     "     VISIBLE:  'frequently reported bugs', cursor=1",
     "SPEECH OUTPUT: 'frequently reported bugs link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "9. line Down",
    ["BRAILLE LINE:  ', and please'",
     "     VISIBLE:  ', and please', cursor=1",
     "SPEECH OUTPUT: ', and please.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "10. line Down",
    ["BRAILLE LINE:  'search'",
     "     VISIBLE:  'search', cursor=1",
     "SPEECH OUTPUT: 'search link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "11. line Down",
    ["BRAILLE LINE:  ' or'",
     "     VISIBLE:  ' or', cursor=1",
     "SPEECH OUTPUT: 'or.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "12. line Down",
    ["BRAILLE LINE:  'browse'",
     "     VISIBLE:  'browse', cursor=1",
     "SPEECH OUTPUT: 'browse link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Down"))
sequence.append(utils.AssertPresentationAction(
    "13. line Down",
    ["BRAILLE LINE:  ' for the bug.'",
     "     VISIBLE:  ' for the bug.', cursor=1",
     "SPEECH OUTPUT: 'for the bug.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "14. line Up",
    ["BRAILLE LINE:  'browse'",
     "     VISIBLE:  'browse', cursor=1",
     "SPEECH OUTPUT: 'browse link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "15. line Up",
    ["BRAILLE LINE:  ' or'",
     "     VISIBLE:  ' or', cursor=1",
     "SPEECH OUTPUT: 'or.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "16. line Up",
    ["BRAILLE LINE:  'search'",
     "     VISIBLE:  'search', cursor=1",
     "SPEECH OUTPUT: 'search link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "17. line Up",
    ["BRAILLE LINE:  ', and please'",
     "     VISIBLE:  ', and please', cursor=1",
     "SPEECH OUTPUT: ', and please.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "18. line Up",
    ["BRAILLE LINE:  'frequently reported bugs'",
     "     VISIBLE:  'frequently reported bugs', cursor=1",
     "SPEECH OUTPUT: 'frequently reported bugs link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "19. line Up",
    ["BRAILLE LINE:  'most'",
     "     VISIBLE:  'most', cursor=1",
     "SPEECH OUTPUT: 'most link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "20. line Up",
    ["BRAILLE LINE:  ', please look at the list of'",
     "     VISIBLE:  ', please look at the list of', cursor=1",
     "SPEECH OUTPUT: ', please look at the list of.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "21. line Up",
    ["BRAILLE LINE:  'bug writing guidelines'",
     "     VISIBLE:  'bug writing guidelines', cursor=1",
     "SPEECH OUTPUT: 'bug writing guidelines link.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "22. line Up",
    ["BRAILLE LINE:  'Before reporting a bug, please read the'",
     "     VISIBLE:  'Before reporting a bug, please r', cursor=1",
     "SPEECH OUTPUT: 'Before reporting a bug, please read the.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "23. line Up",
    ["BRAILLE LINE:  'into Bugzilla. h1'",
     "     VISIBLE:  'into Bugzilla. h1', cursor=1",
     "SPEECH OUTPUT: 'into Bugzilla. heading level 1'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Up"))
sequence.append(utils.AssertPresentationAction(
    "24. line Up",
    ["BRAILLE LINE:  'Enter Bug: cthulhu \u2013 This page lets you enter a new bug  h1'",
     "     VISIBLE:  'Enter Bug: cthulhu \u2013 This page lets', cursor=1",
     "SPEECH OUTPUT: 'Enter Bug: cthulhu \u2013 This page lets you enter a new bug heading level 1'"]))

sequence.append(utils.AssertionSummaryAction())
sequence.start()