71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
// Fenrir console screen reader.
|
|
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify it
|
|
// under the terms of the GNU General Public License as published by the Free
|
|
// Software Foundation, either version 3 of the License, or (at your option)
|
|
// any later version.
|
|
//
|
|
// This program 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 General Public License for
|
|
// more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
|
|
|
package clipboard
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.stormux.org/storm/fenrir/internal/command"
|
|
)
|
|
|
|
func TestQueuedPasteCannotStartAfterTargetRetirement(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
called := false
|
|
worker := &Worker{jobs: make(chan queuedRequest, 1), results: make(chan Result, 1), ctx: ctx, cancel: cancel, done: make(chan struct{}), paste: func(context.Context, string, int) error { called = true; return nil }}
|
|
worker.Submit(Request{Command: command.PasteClipboard, Text: "old target", Terminal: 2})
|
|
worker.Cancel()
|
|
go worker.run()
|
|
defer worker.Close()
|
|
select {
|
|
case result := <-worker.Results():
|
|
if called || !errors.Is(result.Err, context.Canceled) {
|
|
t.Fatal(called, result.Err)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("canceled paste did not finish")
|
|
}
|
|
}
|
|
|
|
func TestActivePasteCancellationDoesNotBlockShutdown(t *testing.T) {
|
|
started := make(chan struct{})
|
|
worker := New_worker(context.Background(), func(ctx context.Context, text string, terminal int) error {
|
|
close(started)
|
|
<-ctx.Done()
|
|
return ctx.Err()
|
|
})
|
|
worker.Submit(Request{Command: command.PasteClipboard, Text: "target", Terminal: 2})
|
|
select {
|
|
case <-started:
|
|
case <-time.After(time.Second):
|
|
t.Fatal("paste did not start")
|
|
}
|
|
worker.Cancel()
|
|
select {
|
|
case result := <-worker.Results():
|
|
if !errors.Is(result.Err, context.Canceled) {
|
|
t.Fatal(result.Err)
|
|
}
|
|
case <-time.After(time.Second):
|
|
t.Fatal("paste did not cancel")
|
|
}
|
|
worker.Close()
|
|
}
|