提交记录修改internal/workbench/shared_clipboard_test.go+3 −1看文件
修改internal/workbench/windows_browser_client_test.go+24 −3看文件
| @@ -60,7 +60,9 @@ func TestClipboardCopyRejectsMissingRevisionAndInvalidPhaseBeforeGuestAccess(t * | ||
| 60 | 60 | `{"phase":"read","session":"","revision":1}`, |
| 61 | 61 | } { |
| 62 | 62 | response := httptest.NewRecorder() |
| 63 | 删除: s.clipboardCopy(response, httptest.NewRequest(http.MethodPost, "/api/clipboard/copy", strings.NewReader(body))) | |
| 63 | 新增: request := httptest.NewRequest(http.MethodPost, "/api/clipboard/copy", strings.NewReader(body)) | |
| 64 | 新增: request.Header.Set("Content-Type", "application/json") | |
| 65 | 新增: s.clipboardCopy(response, request) | |
| 64 | 66 | if response.Code != http.StatusBadRequest { |
| 65 | 67 | t.Fatalf("invalid copy request reached the guest: %d", response.Code) |
| 66 | 68 | } |
| @@ -9,6 +9,7 @@ import ( | ||
| 9 | 9 | "io" |
| 10 | 10 | "os" |
| 11 | 11 | "os/exec" |
| 12 | 新增: "strings" | |
| 12 | 13 | "testing" |
| 13 | 14 | "time" |
| 14 | 15 | ) |
| @@ -18,6 +19,7 @@ func TestWindowsBrowserRelayHelper(t *testing.T) { | ||
| 18 | 19 | return |
| 19 | 20 | } |
| 20 | 21 | var uploaded []byte |
| 22 | 新增: downloaded := bytes.Repeat([]byte{0xab}, 131089) | |
| 21 | 23 | direction := "" |
| 22 | 24 | const transfer = "0123456789abcdef0123456789abcdef" |
| 23 | 25 | read := bufio.NewScanner(os.Stdin) |
| @@ -26,6 +28,10 @@ func TestWindowsBrowserRelayHelper(t *testing.T) { | ||
| 26 | 28 | var request struct { |
| 27 | 29 | Path string `json:"path"` |
| 28 | 30 | Input struct { |
| 31 | 新增: ID string `json:"id"` | |
| 32 | 新增: Tab string `json:"tab"` | |
| 33 | 新增: Context string `json:"context"` | |
| 34 | 新增: Document string `json:"document"` | |
| 29 | 35 | Direction string `json:"direction"` |
| 30 | 36 | Data string `json:"data"` |
| 31 | 37 | Sequence int `json:"sequence"` |
| @@ -57,7 +63,22 @@ func TestWindowsBrowserRelayHelper(t *testing.T) { | ||
| 57 | 63 | result = map[string]any{"transfer": transfer} |
| 58 | 64 | } |
| 59 | 65 | if request.Input.Direction == "download" { |
| 60 | 删除: result = map[string]any{"transfer": transfer, "size": 131089, "name": "binary.bin"} | |
| 66 | 新增: downloaded = bytes.Repeat([]byte{0xab}, 131089) | |
| 67 | 新增: metadata := map[string]any{"transfer": transfer, "size": len(downloaded), "name": "binary.bin"} | |
| 68 | 新增: if request.Input.Tab != "" { | |
| 69 | 新增: if request.Input.Tab != strings.Repeat("a", 32) || request.Input.Context != strings.Repeat("b", 32) || request.Input.Document != strings.Repeat("c", 32) { | |
| 70 | 新增: result = map[string]any{"error": "copy_changed", "code": "copy_changed"} | |
| 71 | 新增: break | |
| 72 | 新增: } | |
| 73 | 新增: metadata["name"], metadata["mime"] = "clipboard.txt", "text/plain" | |
| 74 | 新增: downloaded = []byte(strings.Repeat("中", (2<<20)/3) + "ab") | |
| 75 | 新增: if strings.HasPrefix(request.Input.ID, "11111111") { | |
| 76 | 新增: metadata["name"], metadata["mime"] = "clipboard.png", "image/png" | |
| 77 | 新增: downloaded, _ = base64.StdEncoding.DecodeString(testPNG(t)) | |
| 78 | 新增: } | |
| 79 | 新增: metadata["size"] = len(downloaded) | |
| 80 | 新增: } | |
| 81 | 新增: result = metadata | |
| 61 | 82 | } |
| 62 | 83 | case "/file-chunk": |
| 63 | 84 | chunk, err := base64.StdEncoding.DecodeString(request.Input.Data) |
| @@ -88,11 +109,11 @@ func TestWindowsBrowserRelayHelper(t *testing.T) { | ||
| 88 | 109 | result = map[string]any{"ok": true, "size": len(uploaded), "clipboard": map[string]any{"revision": 1, "available": true}} |
| 89 | 110 | case "/file-read": |
| 90 | 111 | start := request.Input.Sequence * 65536 |
| 91 | 删除: remaining := 131089 - start | |
| 112 | 新增: remaining := len(downloaded) - start | |
| 92 | 113 | if remaining > 65536 { |
| 93 | 114 | remaining = 65536 |
| 94 | 115 | } |
| 95 | 删除: result = map[string]any{"data": base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{0xab}, remaining)), "sequence": request.Input.Sequence + 1, "eof": start+remaining == 131089} | |
| 116 | 新增: result = map[string]any{"data": base64.StdEncoding.EncodeToString(downloaded[start : start+remaining]), "sequence": request.Input.Sequence + 1, "eof": start+remaining == len(downloaded)} | |
| 96 | 117 | } |
| 97 | 118 | data, _ := json.Marshal(result) |
| 98 | 119 | _, _ = os.Stdout.Write(append(data, '\n')) |

