-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_graphical_foreground_app.py
More file actions
69 lines (56 loc) · 2.39 KB
/
test_graphical_foreground_app.py
File metadata and controls
69 lines (56 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Graphical test to verify get_foreground_app returns the active app.
"""
import time
import unittest
from mpos import AppManager
from mpos.ui import back_screen, get_foreground_app
from mpos.ui.testing import wait_for_render
class TestForegroundApp(unittest.TestCase):
"""Ensure get_foreground_app tracks the top activity in the UI stack."""
def _wait_for_foreground(self, expected, timeout_ms=5000):
start = time.ticks_ms()
while time.ticks_diff(time.ticks_ms(), start) < timeout_ms:
fg = get_foreground_app()
if fg == expected:
return True
wait_for_render(iterations=10)
return False
def test_get_foreground_app_after_starting_apps(self):
launcher_fullname = "com.micropythonos.launcher"
about_fullname = "com.micropythonos.about"
AppManager.start_app(launcher_fullname)
self.assertTrue(
self._wait_for_foreground(launcher_fullname),
f"Expected foreground app to be {launcher_fullname}, got {get_foreground_app()}",
)
AppManager.start_app(about_fullname)
self.assertTrue(
self._wait_for_foreground(about_fullname),
f"Expected foreground app to be {about_fullname}, got {get_foreground_app()}",
)
fg = get_foreground_app()
self.assertIsNotNone(fg, "Foreground app should not be None after start_app")
self.assertEqual(
fg,
about_fullname,
f"Foreground app mismatch: expected {about_fullname}, got {fg}",
)
def test_get_foreground_app_after_back_screen(self):
launcher_fullname = "com.micropythonos.launcher"
about_fullname = "com.micropythonos.about"
AppManager.start_app(launcher_fullname)
self.assertTrue(
self._wait_for_foreground(launcher_fullname),
f"Expected foreground app to be {launcher_fullname}, got {get_foreground_app()}",
)
AppManager.start_app(about_fullname)
self.assertTrue(
self._wait_for_foreground(about_fullname),
f"Expected foreground app to be {about_fullname}, got {get_foreground_app()}",
)
back_screen()
self.assertTrue(
self._wait_for_foreground(launcher_fullname),
f"Expected foreground app to be {launcher_fullname} after back_screen, got {get_foreground_app()}",
)