2023-05-12 09:19:35 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2023 SatoshiLabs and contributors
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# 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 License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
from contextlib import contextmanager
|
|
|
|
from typing import TYPE_CHECKING, Generator
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from trezorlib import device
|
2023-08-09 07:44:33 +00:00
|
|
|
from trezorlib.exceptions import Cancelled
|
2023-05-12 09:19:35 +00:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
from trezorlib.debuglink import DebugLink
|
|
|
|
|
|
|
|
|
|
|
|
# TR-only
|
|
|
|
pytestmark = [pytest.mark.skip_t1, pytest.mark.skip_t2]
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def prepare_tutorial_and_cancel_after_it(
|
2023-08-09 07:44:33 +00:00
|
|
|
device_handler: "BackgroundDeviceHandler", cancelled: bool = False
|
2023-05-12 09:19:35 +00:00
|
|
|
) -> Generator["DebugLink", None, None]:
|
|
|
|
debug = device_handler.debuglink()
|
|
|
|
device_handler.run(device.show_device_tutorial)
|
|
|
|
|
|
|
|
yield debug
|
|
|
|
|
2023-08-09 07:44:33 +00:00
|
|
|
try:
|
|
|
|
device_handler.result()
|
|
|
|
except Cancelled:
|
|
|
|
if not cancelled:
|
|
|
|
raise
|
2023-05-12 09:19:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
def go_through_tutorial(debug: "DebugLink") -> None:
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
debug.press_right_htc(hold_ms=1000)
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
layout = debug.press_middle(wait=True)
|
2023-06-16 09:37:17 +00:00
|
|
|
assert layout.title() == "TUTORIAL COMPLETE"
|
2023-05-12 09:19:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
def test_tutorial_finish(device_handler: "BackgroundDeviceHandler"):
|
|
|
|
with prepare_tutorial_and_cancel_after_it(device_handler) as debug:
|
|
|
|
# CLICK THROUGH
|
|
|
|
go_through_tutorial(debug)
|
|
|
|
|
|
|
|
# FINISH
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
def test_tutorial_skip(device_handler: "BackgroundDeviceHandler"):
|
2023-08-09 07:44:33 +00:00
|
|
|
with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug:
|
2023-05-12 09:19:35 +00:00
|
|
|
# SKIP
|
|
|
|
debug.press_left(wait=True)
|
|
|
|
debug.press_right(wait=True)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(uninitialized=True)
|
|
|
|
def test_tutorial_again_and_skip(device_handler: "BackgroundDeviceHandler"):
|
2023-08-09 07:44:33 +00:00
|
|
|
with prepare_tutorial_and_cancel_after_it(device_handler, cancelled=True) as debug:
|
2023-05-12 09:19:35 +00:00
|
|
|
# CLICK THROUGH
|
|
|
|
go_through_tutorial(debug)
|
|
|
|
|
|
|
|
# AGAIN
|
|
|
|
debug.press_left(wait=True)
|
|
|
|
|
|
|
|
# SKIP
|
|
|
|
debug.press_left(wait=True)
|
|
|
|
debug.press_right(wait=True)
|