detached 731bbf7

test(idle): copy fake portal member name and cover failed inhibit rollback

commit
731bbf717f9d0994ab13cc0a0b0de5613d5d2b8a
author
brice · · 2026-10-14 09:40 UTC
parent
39fad31
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +26 -1
M internal/infrastructure/idle/portal_inhibitor_test.go +26 -1
@@ -30,6 +30,8 @@ type fakePortal struct {
3030 // endRequest makes the portal answer Close with an error, like a
3131 // portal that already ended the request with a Response signal.
3232 endRequest bool
33+ // failInhibit makes the portal reject Inhibit calls.
34+ failInhibit bool
3335 }
3436
3537 func (f *fakePortal) serve(t *testing.T, conn *zerobus.Conn) {
@@ -53,13 +55,17 @@ func (f *fakePortal) serve(t *testing.T, conn *zerobus.Conn) {
5355 }
5456
5557 func (f *fakePortal) answer(conn *zerobus.Conn, m *zerobus.Message) {
56- call := portalCall{member: m.Member, path: strings.Clone(m.Path)}
58+ call := portalCall{member: strings.Clone(m.Member), path: strings.Clone(m.Path)}
5759 switch m.Member {
5860 case "Get":
5961 e := conn.NewReply(m, "v")
6062 e.Variant("u")
6163 e.Uint32(3)
6264 case "Inhibit":
65+ if f.failInhibit {
66+ conn.NewError(m, "org.freedesktop.DBus.Error.AccessDenied", "s").Str("denied")
67+ break
68+ }
6369 body := m.Body()
6470 body.Str() // window
6571 call.flags = body.Uint32()
@@ -183,6 +189,25 @@ func TestPortalInhibitorToleratesEndedRequest(t *testing.T) {
183189 }
184190 }
185191
192+func TestPortalInhibitorRollsBackFailedInhibit(t *testing.T) {
193+ portal := &fakePortal{failInhibit: true}
194+ p := newTestInhibitor(t, portal)
195+
196+ if err := p.Inhibit(context.Background(), "video playing"); err == nil {
197+ t.Fatal("Inhibit succeeded although the portal rejected it")
198+ }
199+ portal.next(t)
200+ if p.IsInhibited() {
201+ t.Fatal("refcount kept after a failed Inhibit")
202+ }
203+
204+ // Nothing to release: Uninhibit must not call Close.
205+ if err := p.Uninhibit(context.Background()); err != nil {
206+ t.Fatal(err)
207+ }
208+ portal.none(t)
209+}
210+
186211 func TestPortalInhibitorCloseReleasesActiveRequest(t *testing.T) {
187212 portal := &fakePortal{}
188213 p := newTestInhibitor(t, portal)
@@ -30,6 +30,8 @@ type fakePortal struct {
30 // endRequest makes the portal answer Close with an error, like a30 // endRequest makes the portal answer Close with an error, like a
31 // portal that already ended the request with a Response signal.31 // portal that already ended the request with a Response signal.
32 endRequest bool32 endRequest bool
33+ // failInhibit makes the portal reject Inhibit calls.
34+ failInhibit bool
33 }35 }
34 36
35 func (f *fakePortal) serve(t *testing.T, conn *zerobus.Conn) {37 func (f *fakePortal) serve(t *testing.T, conn *zerobus.Conn) {
@@ -53,13 +55,17 @@ func (f *fakePortal) serve(t *testing.T, conn *zerobus.Conn) {
53 }55 }
54 56
55 func (f *fakePortal) answer(conn *zerobus.Conn, m *zerobus.Message) {57 func (f *fakePortal) answer(conn *zerobus.Conn, m *zerobus.Message) {
56- call := portalCall{member: m.Member, path: strings.Clone(m.Path)}58+ call := portalCall{member: strings.Clone(m.Member), path: strings.Clone(m.Path)}
57 switch m.Member {59 switch m.Member {
58 case "Get":60 case "Get":
59 e := conn.NewReply(m, "v")61 e := conn.NewReply(m, "v")
60 e.Variant("u")62 e.Variant("u")
61 e.Uint32(3)63 e.Uint32(3)
62 case "Inhibit":64 case "Inhibit":
65+ if f.failInhibit {
66+ conn.NewError(m, "org.freedesktop.DBus.Error.AccessDenied", "s").Str("denied")
67+ break
68+ }
63 body := m.Body()69 body := m.Body()
64 body.Str() // window70 body.Str() // window
65 call.flags = body.Uint32()71 call.flags = body.Uint32()
@@ -183,6 +189,25 @@ func TestPortalInhibitorToleratesEndedRequest(t *testing.T) {
183 }189 }
184 }190 }
185 191
192+func TestPortalInhibitorRollsBackFailedInhibit(t *testing.T) {
193+ portal := &fakePortal{failInhibit: true}
194+ p := newTestInhibitor(t, portal)
195+
196+ if err := p.Inhibit(context.Background(), "video playing"); err == nil {
197+ t.Fatal("Inhibit succeeded although the portal rejected it")
198+ }
199+ portal.next(t)
200+ if p.IsInhibited() {
201+ t.Fatal("refcount kept after a failed Inhibit")
202+ }
203+
204+ // Nothing to release: Uninhibit must not call Close.
205+ if err := p.Uninhibit(context.Background()); err != nil {
206+ t.Fatal(err)
207+ }
208+ portal.none(t)
209+}
210+
186 func TestPortalInhibitorCloseReleasesActiveRequest(t *testing.T) {211 func TestPortalInhibitorCloseReleasesActiveRequest(t *testing.T) {
187 portal := &fakePortal{}212 portal := &fakePortal{}
188 p := newTestInhibitor(t, portal)213 p := newTestInhibitor(t, portal)

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close