From f253d7e5916196bd730be73799d2fdd25625bc7d Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Thu, 11 Aug 2022 11:47:30 +0200 Subject: [PATCH] feat(tests): Add test for busy screen. --- tests/device_tests/test_busy_state.py | 68 +++++++++++++++++++++++++++ tests/ui_tests/fixtures.json | 2 + 2 files changed, 70 insertions(+) create mode 100644 tests/device_tests/test_busy_state.py diff --git a/tests/device_tests/test_busy_state.py b/tests/device_tests/test_busy_state.py new file mode 100644 index 0000000000..c4ce368f88 --- /dev/null +++ b/tests/device_tests/test_busy_state.py @@ -0,0 +1,68 @@ +# This file is part of the Trezor project. +# +# Copyright (C) 2022 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 . + +import time + +import pytest + +from trezorlib import btc, device +from trezorlib.debuglink import TrezorClientDebugLink as Client +from trezorlib.tools import parse_path + +PIN = "1234" + +pytestmark = pytest.mark.skip_t1 + + +@pytest.mark.setup_client(pin=PIN) +def test_busy_state(client: Client): + assert client.features.unlocked is False + assert client.features.busy is False + + # Show busy dialog for 1 minute. + device.set_busy(client, expiry_ms=60 * 1000) + assert client.features.unlocked is False + assert client.features.busy is True + + with client: + client.use_pin_sequence([PIN]) + btc.get_address( + client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"), show_display=True + ) + + client.refresh_features() + assert client.features.unlocked is True + assert client.features.busy is True + + # Hide the busy dialog. + device.set_busy(client, None) + + assert client.features.unlocked is True + assert client.features.busy is False + + +def test_busy_expiry(client: Client): + expiry_ms = 100 # 100 milliseconds + + # Show the busy dialog. + device.set_busy(client, expiry_ms=expiry_ms) + + # Wait for it to expire. + time.sleep(expiry_ms / 1000) + + # Check that the device is no longer busy. + client.refresh_features() + assert client.features.busy is False diff --git a/tests/ui_tests/fixtures.json b/tests/ui_tests/fixtures.json index 986b666f7d..1abb3f1d73 100644 --- a/tests/ui_tests/fixtures.json +++ b/tests/ui_tests/fixtures.json @@ -1535,6 +1535,8 @@ "TT_test_basic.py::test_device_id_same": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "TT_test_basic.py::test_features": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "TT_test_basic.py::test_ping": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", +"TT_test_busy_state.py::test_busy_expiry": "84cbf08ffe52f79e63d32ed2298dbdc60c74059bcf59eaa69c01f13acf61c8ae", +"TT_test_busy_state.py::test_busy_state": "0517aa3301d4f55068766dfc130139e45449d8f90213d4a51c49776e3bbb7c98", "TT_test_cancel.py::test_cancel_message_via_cancel[message0]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc", "TT_test_cancel.py::test_cancel_message_via_cancel[message1]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc", "TT_test_cancel.py::test_cancel_message_via_initialize[message0]": "b014449cbf1a45739d64a370b30af75df2228f48c090a02227bac8ed20c7b2dc",