#!/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 entry output using Firefox."""

from macaroon.playback import *
import utils

sequence = MacroSequence()

sequence.append(PauseAction(3000))
sequence.append(KeyComboAction("<Control><Shift>o"))


########################################################################
# Tab three times, then down arrow twice to Bookmarks Menu. (This is
# necessary to add a new item).  Then Press Alt+O for Organize and Return
# on "New Bookmark..."
sequence.append(KeyComboAction("Tab"))
sequence.append(KeyComboAction("Tab"))
sequence.append(KeyComboAction("Tab"))
sequence.append(PauseAction(3000))

sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("Down"))
sequence.append(KeyComboAction("<Alt>o"))
sequence.append(KeyComboAction("Return"))

# This is to deal with a timing issue
sequence.append(KeyComboAction("Tab"))
sequence.append(KeyComboAction("<Shift>Tab"))

sequence.append(KeyComboAction("<Control>a"))
sequence.append(KeyComboAction("BackSpace"))
sequence.append(TypeAction("this is a test"))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("BackSpace"))
sequence.append(utils.AssertPresentationAction(
    "1. Backspace",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a tes $l'",
     "     VISIBLE:  'Name: this is a tes $l', cursor=20",
     "BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a tes $l'",
     "     VISIBLE:  'Name: this is a tes $l', cursor=20",
     "SPEECH OUTPUT: 't'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("BackSpace"))
sequence.append(utils.AssertPresentationAction(
    "2. Backspace",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a te $l'",
     "     VISIBLE:  'Name: this is a te $l', cursor=19",
     "BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a te $l'",
     "     VISIBLE:  'Name: this is a te $l', cursor=19",
     "SPEECH OUTPUT: 's'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Control>BackSpace"))
sequence.append(utils.AssertPresentationAction(
    "3. Control Backspace",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a  $l'",
     "     VISIBLE:  'Name: this is a  $l', cursor=17",
     "BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is a  $l'",
     "     VISIBLE:  'Name: this is a  $l', cursor=17",
     "SPEECH OUTPUT: 'te'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Control>BackSpace"))
sequence.append(utils.AssertPresentationAction(
    "4. Control Backspace",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is  $l'",
     "     VISIBLE:  'Name: this is  $l', cursor=15",
     "BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is  $l'",
     "     VISIBLE:  'Name: this is  $l', cursor=15",
     "SPEECH OUTPUT: 'a '"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Left"))
sequence.append(utils.AssertPresentationAction(
    "5. Left",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is  $l'",
     "     VISIBLE:  'Name: this is  $l', cursor=14",
     "SPEECH OUTPUT: 'space'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Left"))
sequence.append(utils.AssertPresentationAction(
    "6. Left",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is  $l'",
     "     VISIBLE:  'Name: this is  $l', cursor=13",
     "SPEECH OUTPUT: 's'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Control>Left"))
sequence.append(utils.AssertPresentationAction(
    "7. Control Left",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this is  $l'",
     "     VISIBLE:  'Name: this is  $l', cursor=12",
     "SPEECH OUTPUT: 'is '"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("Delete"))
sequence.append(utils.AssertPresentationAction(
    "8. Delete",
    ["BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this s  $l'",
     "     VISIBLE:  'Name: this s  $l', cursor=12",
     "SPEECH OUTPUT: 's'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("KP_Enter"))
sequence.append(utils.AssertPresentationAction(
    "9. Basic Where Am I",
    ["KNOWN ISSUE: The mnemonic seems to have gone missing",
     "BRAILLE LINE:  'Firefox application New Bookmark dialog Name: this s  $l'",
     "     VISIBLE:  'Name: this s  $l', cursor=12",
     "SPEECH OUTPUT: 'Name: entry this s '"]))

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