42 lines
930 B
Go
42 lines
930 B
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package xorg
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNativeClipboardOwnerChange(t *testing.T) {
|
|
if os.Getenv("CTHULHU_NATIVE_X11") != "1" {
|
|
t.Skip("requires isolated X11 display")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
monitor := NewClipboardMonitor()
|
|
if err := monitor.Start(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer func() {
|
|
if err := monitor.Stop(context.Background()); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}()
|
|
command := exec.CommandContext(ctx, "xclip", "-selection", "clipboard", "-i")
|
|
command.Stdin = strings.NewReader("same text")
|
|
if err := command.Run(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
select {
|
|
case <-monitor.Changes():
|
|
case <-ctx.Done():
|
|
t.Fatal("clipboard owner change was not observed")
|
|
}
|
|
}
|