|
| 1 | +/* SPDX-FileCopyrightText: 2026 Core Devices LLC */ |
| 2 | +/* SPDX-License-Identifier: Apache-2.0 */ |
| 3 | + |
| 4 | +#include "clar.h" |
| 5 | + |
| 6 | +#include "shell/normal/app_idle_timeout.h" |
| 7 | + |
| 8 | +#include "kernel/event_loop.h" |
| 9 | +#include "shell/normal/watchface.h" |
| 10 | +#include "shell/shell.h" |
| 11 | + |
| 12 | +// Stubs |
| 13 | +///////////////////////////////////////////////////////////////////////// |
| 14 | +#include "stubs_logging.h" |
| 15 | +#include "stubs_passert.h" |
| 16 | + |
| 17 | +#include "fake_new_timer.h" |
| 18 | + |
| 19 | +static int s_watchface_launch_count; |
| 20 | + |
| 21 | +void launcher_task_add_callback(CallbackEventCallback callback, void *data) { |
| 22 | + callback(data); |
| 23 | +} |
| 24 | + |
| 25 | +const CompositorTransition *shell_get_watchface_compositor_animation(bool watchface_is_destination) { |
| 26 | + return NULL; |
| 27 | +} |
| 28 | + |
| 29 | +void watchface_launch_default(const CompositorTransition *animation) { |
| 30 | + s_watchface_launch_count++; |
| 31 | +} |
| 32 | + |
| 33 | +// Module state under test |
| 34 | +///////////////////////////////////////////////////////////////////////// |
| 35 | +extern TimerID s_timer; |
| 36 | +extern bool s_app_paused; |
| 37 | +extern bool s_touch_held; |
| 38 | + |
| 39 | +static bool prv_is_scheduled(void) { |
| 40 | + return stub_new_timer_is_scheduled(s_timer); |
| 41 | +} |
| 42 | + |
| 43 | +// Tests |
| 44 | +///////////////////////////////////////////////////////////////////////// |
| 45 | + |
| 46 | +void test_app_idle_timeout__initialize(void) { |
| 47 | + s_watchface_launch_count = 0; |
| 48 | + app_idle_timeout_stop(); |
| 49 | + s_app_paused = false; |
| 50 | + s_touch_held = false; |
| 51 | +} |
| 52 | + |
| 53 | +void test_app_idle_timeout__cleanup(void) { |
| 54 | + app_idle_timeout_stop(); |
| 55 | + stub_new_timer_cleanup(); |
| 56 | +} |
| 57 | + |
| 58 | +void test_app_idle_timeout__start_schedules(void) { |
| 59 | + app_idle_timeout_start(); |
| 60 | + cl_assert(prv_is_scheduled()); |
| 61 | +} |
| 62 | + |
| 63 | +void test_app_idle_timeout__touch_hold_halts_until_liftoff(void) { |
| 64 | + app_idle_timeout_start(); |
| 65 | + |
| 66 | + app_idle_timeout_touch_down(); |
| 67 | + cl_assert(!prv_is_scheduled()); |
| 68 | + |
| 69 | + app_idle_timeout_touch_up(); |
| 70 | + cl_assert(prv_is_scheduled()); |
| 71 | +} |
| 72 | + |
| 73 | +void test_app_idle_timeout__refresh_during_hold_stays_halted(void) { |
| 74 | + app_idle_timeout_start(); |
| 75 | + app_idle_timeout_touch_down(); |
| 76 | + |
| 77 | + app_idle_timeout_refresh(); |
| 78 | + cl_assert(!prv_is_scheduled()); |
| 79 | + |
| 80 | + app_idle_timeout_touch_up(); |
| 81 | + cl_assert(prv_is_scheduled()); |
| 82 | +} |
| 83 | + |
| 84 | +void test_app_idle_timeout__hold_composes_with_focus_pause(void) { |
| 85 | + app_idle_timeout_start(); |
| 86 | + |
| 87 | + // Focus lost mid-hold: liftoff must not restart the timer while paused. |
| 88 | + app_idle_timeout_touch_down(); |
| 89 | + app_idle_timeout_pause(); |
| 90 | + app_idle_timeout_touch_up(); |
| 91 | + cl_assert(!prv_is_scheduled()); |
| 92 | + app_idle_timeout_resume(); |
| 93 | + cl_assert(prv_is_scheduled()); |
| 94 | + |
| 95 | + // Focus regained mid-hold: resume must not restart the timer while held. |
| 96 | + app_idle_timeout_pause(); |
| 97 | + app_idle_timeout_touch_down(); |
| 98 | + app_idle_timeout_resume(); |
| 99 | + cl_assert(!prv_is_scheduled()); |
| 100 | + app_idle_timeout_touch_up(); |
| 101 | + cl_assert(prv_is_scheduled()); |
| 102 | +} |
| 103 | + |
| 104 | +void test_app_idle_timeout__liftoff_without_touchdown_is_harmless(void) { |
| 105 | + app_idle_timeout_start(); |
| 106 | + app_idle_timeout_touch_up(); |
| 107 | + cl_assert(prv_is_scheduled()); |
| 108 | +} |
| 109 | + |
| 110 | +void test_app_idle_timeout__start_during_hold_waits_for_liftoff(void) { |
| 111 | + app_idle_timeout_touch_down(); |
| 112 | + app_idle_timeout_start(); |
| 113 | + cl_assert(!prv_is_scheduled()); |
| 114 | + |
| 115 | + app_idle_timeout_touch_up(); |
| 116 | + cl_assert(prv_is_scheduled()); |
| 117 | +} |
| 118 | + |
| 119 | +void test_app_idle_timeout__expiry_launches_watchface(void) { |
| 120 | + app_idle_timeout_start(); |
| 121 | + cl_assert(stub_new_timer_fire(s_timer)); |
| 122 | + cl_assert_equal_i(s_watchface_launch_count, 1); |
| 123 | +} |
0 commit comments