|
3 | 3 | // See the LICENSE file in the project root for more information. |
4 | 4 |
|
5 | 5 | using System; |
| 6 | +using System.Collections.Generic; |
6 | 7 | using System.Diagnostics; |
7 | 8 | using System.Drawing; |
8 | 9 | using System.Globalization; |
|
11 | 12 | using System.Runtime.InteropServices; |
12 | 13 | using System.Threading; |
13 | 14 | using System.Windows.Forms; |
14 | | - |
15 | 15 | using Microsoft.AdvancedPaste.UITests.Helper; |
16 | 16 | using Microsoft.CodeCoverage.Core.Reports.Coverage; |
17 | 17 | using Microsoft.PowerToys.UITest; |
@@ -55,7 +55,7 @@ static AdvancedPasteUITest() |
55 | 55 | } |
56 | 56 |
|
57 | 57 | public AdvancedPasteUITest() |
58 | | - : base(PowerToysModule.PowerToysSettings, size: WindowSize.Small) |
| 58 | + : base(PowerToysModule.PowerToysSettings, size: WindowSize.Large_Vertical) |
59 | 59 | { |
60 | 60 | Type currentTestType = typeof(AdvancedPasteUITest); |
61 | 61 | string? dirName = Path.GetDirectoryName(currentTestType.Assembly.Location); |
@@ -254,13 +254,250 @@ public void TestCasePasteAsJSONCase3() |
254 | 254 |
|
255 | 255 | /* |
256 | 256 | * Clipboard History |
257 | | - - [] Open Settings and Enable clipboard history (if not enabled already). Open Advanced Paste window with hotkey, click Clipboard history and try deleting some entry. Check OS clipboard history (Win+V), and confirm that the same entry no longer exist. |
258 | | - - [] Open Advanced Paste window with hotkey, click Clipboard history, and click any entry (but first). Observe that entry is put on top of clipboard history. Check OS clipboard history (Win+V), and confirm that the same entry is on top of the clipboard. |
259 | | - - [] Open Settings and Disable clipboard history. Open Advanced Paste window with hotkey and observe that Clipboard history button is disabled. |
| 257 | + - [x] Open Settings and Enable clipboard history (if not enabled already). Open Advanced Paste window with hotkey, click Clipboard history and try deleting some entry. Check OS clipboard history (Win+V), and confirm that the same entry no longer exist. |
| 258 | + - [x] Open Advanced Paste window with hotkey, click Clipboard history, and click any entry (but first). Observe that entry is put on top of clipboard history. Check OS clipboard history (Win+V), and confirm that the same entry is on top of the clipboard. |
| 259 | + - [x] Open Settings and Disable clipboard history. Open Advanced Paste window with hotkey and observe that Clipboard history button is disabled. |
260 | 260 | * Disable Advanced Paste, try different Advanced Paste hotkeys and confirm that it's disabled and nothing happens. |
261 | 261 | */ |
262 | | - private void TestCaseClipboardHistory() |
| 262 | + [TestMethod] |
| 263 | + [TestCategory("AdvancedPasteUITest")] |
| 264 | + [TestCategory("TestCaseClipboardHistoryDeleteTest")] |
| 265 | + public void TestCaseClipboardHistoryDeleteTest() |
263 | 266 | { |
| 267 | + RestartScopeExe(); |
| 268 | + Thread.Sleep(1500); |
| 269 | + |
| 270 | + // Find the PowerToys Settings window |
| 271 | + var settingsWindow = Find<Window>("PowerToys Settings", global: true); |
| 272 | + Assert.IsNotNull(settingsWindow, "Failed to open PowerToys Settings window"); |
| 273 | + |
| 274 | + if (FindAll<NavigationViewItem>("Advanced Paste").Count == 0) |
| 275 | + { |
| 276 | + // Expand Advanced list-group if needed |
| 277 | + Find<NavigationViewItem>("System Tools").Click(); |
| 278 | + } |
| 279 | + |
| 280 | + Find<NavigationViewItem>("Advanced Paste").Click(); |
| 281 | + |
| 282 | + Find<ToggleSwitch>("Clipboard history").Toggle(true); |
| 283 | + |
| 284 | + Session.CloseMainWindow(); |
| 285 | + |
| 286 | + // clear system clipboard |
| 287 | + ClearSystemClipboardHistory(); |
| 288 | + |
| 289 | + // set test content to clipboard |
| 290 | + const string textForTesting = "Test text"; |
| 291 | + SetClipboardTextInSTAMode(textForTesting); |
| 292 | + |
| 293 | + // Open Advanced Paste window with hotkey, click Clipboard history and try deleting some entry. |
| 294 | + this.SendKeys(Key.Win, Key.Shift, Key.V); |
| 295 | + Thread.Sleep(1500); |
| 296 | + |
| 297 | + var apWind = this.Find<Window>("Advanced Paste", global: true); |
| 298 | + apWind.Find<PowerToys.UITest.Button>("Clipboard history").Click(); |
| 299 | + |
| 300 | + var textGroup = apWind.Find<Group>(textForTesting); |
| 301 | + Assert.IsNotNull(textGroup, "Cannot find the test string from advanced paste clipboard history."); |
| 302 | + |
| 303 | + textGroup.Find<PowerToys.UITest.Button>("More options").Click(); |
| 304 | + apWind.Find<TextBlock>("Delete").Click(); |
| 305 | + |
| 306 | + // Check OS clipboard history (Win+V), and confirm that the same entry no longer exist. |
| 307 | + this.SendKeys(Key.Win, Key.V); |
| 308 | + |
| 309 | + Thread.Sleep(1500); |
| 310 | + |
| 311 | + var clipboardWindow = this.Find<Window>("Windows Input Experience", global: true); |
| 312 | + Assert.IsNotNull(clipboardWindow, "Cannot find system clipboard window."); |
| 313 | + |
| 314 | + var nothingText = clipboardWindow.Find<Group>("Nothing here, You'll see your clipboard history here once you've copied something."); |
| 315 | + Assert.IsNotNull(nothingText, "System clipboard is not empty, which should be yes."); |
| 316 | + } |
| 317 | + |
| 318 | + [TestMethod] |
| 319 | + [TestCategory("AdvancedPasteUITest")] |
| 320 | + [TestCategory("TestCaseClipboardHistorySelectTest")] |
| 321 | + public void TestCaseClipboardHistorySelectTest() |
| 322 | + { |
| 323 | + RestartScopeExe(); |
| 324 | + Thread.Sleep(1500); |
| 325 | + |
| 326 | + // Find the PowerToys Settings window |
| 327 | + var settingsWindow = Find<Window>("PowerToys Settings", global: true); |
| 328 | + Assert.IsNotNull(settingsWindow, "Failed to open PowerToys Settings window"); |
| 329 | + |
| 330 | + if (FindAll<NavigationViewItem>("Advanced Paste").Count == 0) |
| 331 | + { |
| 332 | + // Expand Advanced list-group if needed |
| 333 | + Find<NavigationViewItem>("System Tools").Click(); |
| 334 | + } |
| 335 | + |
| 336 | + Find<NavigationViewItem>("Advanced Paste").Click(); |
| 337 | + |
| 338 | + Find<ToggleSwitch>("Clipboard history").Toggle(true); |
| 339 | + |
| 340 | + Session.CloseMainWindow(); |
| 341 | + |
| 342 | + // clear system clipboard |
| 343 | + ClearSystemClipboardHistory(); |
| 344 | + |
| 345 | + // set test content to clipboard |
| 346 | + string[] textForTesting = { "Test text1", "Test text2", "Test text3", "Test text4", "Test text5", "Test text6", }; |
| 347 | + foreach (var str in textForTesting) |
| 348 | + { |
| 349 | + SetClipboardTextInSTAMode(str); |
| 350 | + Thread.Sleep(1000); |
| 351 | + } |
| 352 | + |
| 353 | + // Open Advanced Paste window with hotkey |
| 354 | + this.SendKeys(Key.Win, Key.Shift, Key.V); |
| 355 | + Thread.Sleep(1500); |
| 356 | + |
| 357 | + var apWind = this.Find<Window>("Advanced Paste", global: true); |
| 358 | + apWind.Find<PowerToys.UITest.Button>("Clipboard history").Click(); |
| 359 | + |
| 360 | + // click the 3rd item |
| 361 | + var textGroup = apWind.Find<Group>(textForTesting[0]); |
| 362 | + Assert.IsNotNull(textGroup, "Cannot find the test string from advanced paste clipboard history."); |
| 363 | + textGroup.Click(); |
| 364 | + |
| 365 | + // Check OS clipboard history (Win+V) |
| 366 | + this.SendKeys(Key.Win, Key.V); |
| 367 | + |
| 368 | + Thread.Sleep(1500); |
| 369 | + |
| 370 | + var clipboardWindow = this.Find<Window>("Windows Input Experience", global: true); |
| 371 | + Assert.IsNotNull(clipboardWindow, "Cannot find system clipboard window."); |
| 372 | + |
| 373 | + var txtFound = clipboardWindow.Find<Element>(textForTesting[0]); |
| 374 | + Assert.IsNotNull(txtFound, "Cannot find textblock"); |
| 375 | + } |
| 376 | + |
| 377 | + // [x] Open Settings and Disable clipboard history.Open Advanced Paste window with hotkey and observe that Clipboard history button is disabled. |
| 378 | + [TestMethod] |
| 379 | + [TestCategory("AdvancedPasteUITest")] |
| 380 | + [TestCategory("TestCaseClipboardHistoryDisableTest")] |
| 381 | + public void TestCaseClipboardHistoryDisableTest() |
| 382 | + { |
| 383 | + RestartScopeExe(); |
| 384 | + Thread.Sleep(1500); |
| 385 | + |
| 386 | + // Find the PowerToys Settings window |
| 387 | + var settingsWindow = Find<Window>("PowerToys Settings", global: true); |
| 388 | + Assert.IsNotNull(settingsWindow, "Failed to open PowerToys Settings window"); |
| 389 | + |
| 390 | + if (FindAll<NavigationViewItem>("Advanced Paste").Count == 0) |
| 391 | + { |
| 392 | + // Expand Advanced list-group if needed |
| 393 | + Find<NavigationViewItem>("System Tools").Click(); |
| 394 | + } |
| 395 | + |
| 396 | + Find<NavigationViewItem>("Advanced Paste").Click(); |
| 397 | + |
| 398 | + Find<ToggleSwitch>("Clipboard history").Toggle(false); |
| 399 | + |
| 400 | + Session.CloseMainWindow(); |
| 401 | + |
| 402 | + // set test content to clipboard |
| 403 | + const string textForTesting = "Test text"; |
| 404 | + SetClipboardTextInSTAMode(textForTesting); |
| 405 | + |
| 406 | + // Open Advanced Paste window with hotkey, click Clipboard history and try deleting some entry. |
| 407 | + this.SendKeys(Key.Win, Key.Shift, Key.V); |
| 408 | + Thread.Sleep(1500); |
| 409 | + |
| 410 | + var apWind = this.Find<Window>("Advanced Paste", global: true); |
| 411 | + |
| 412 | + // Click the button (which should still exist but be disabled) |
| 413 | + apWind.Find<PowerToys.UITest.Button>("Clipboard history").Click(); |
| 414 | + |
| 415 | + // Verify that the clipboard content doesn't appear |
| 416 | + // Use a short timeout to avoid a long wait when the element doesn't exist |
| 417 | + Assert.IsFalse( |
| 418 | + Has<Group>(textForTesting), |
| 419 | + "Clipboard content should not appear when clipboard history is disabled"); |
| 420 | + } |
| 421 | + |
| 422 | + // Disable Advanced Paste, try different Advanced Paste hotkeys and confirm that it's disabled and nothing happens. |
| 423 | + [TestMethod] |
| 424 | + [TestCategory("AdvancedPasteUITest")] |
| 425 | + [TestCategory("TestCaseDisableAdvancedPaste")] |
| 426 | + public void TestCaseDisableAdvancedPaste() |
| 427 | + { |
| 428 | + RestartScopeExe(); |
| 429 | + Thread.Sleep(1500); |
| 430 | + |
| 431 | + // Find the PowerToys Settings window |
| 432 | + var settingsWindow = Find<Window>("PowerToys Settings", global: true); |
| 433 | + Assert.IsNotNull(settingsWindow, "Failed to open PowerToys Settings window"); |
| 434 | + |
| 435 | + if (FindAll<NavigationViewItem>("Advanced Paste").Count == 0) |
| 436 | + { |
| 437 | + // Expand System Tools if needed |
| 438 | + Find<NavigationViewItem>("System Tools").Click(); |
| 439 | + } |
| 440 | + |
| 441 | + Find<NavigationViewItem>("Advanced Paste").Click(); |
| 442 | + |
| 443 | + // Disable Advanced Paste module |
| 444 | + var moduleToggle = Find<ToggleSwitch>("Enable Advanced Paste"); |
| 445 | + moduleToggle.Toggle(false); |
| 446 | + |
| 447 | + Session.CloseMainWindow(); |
| 448 | + |
| 449 | + // Prepare some text to test with |
| 450 | + const string textForTesting = "Test text for disabled module"; |
| 451 | + SetClipboardTextInSTAMode(textForTesting); |
| 452 | + |
| 453 | + // Try main Advanced Paste hotkey |
| 454 | + this.SendKeys(Key.Win, Key.Shift, Key.V); |
| 455 | + Thread.Sleep(500); |
| 456 | + |
| 457 | + // Verify Advanced Paste window does not appear |
| 458 | + Assert.IsFalse( |
| 459 | + Has<Window>("Advanced Paste", global: true), |
| 460 | + "Advanced Paste window should not appear when the module is disabled"); |
| 461 | + |
| 462 | + // Re-enable Advanced Paste for other tests |
| 463 | + RestartScopeExe(); |
| 464 | + Thread.Sleep(1500); |
| 465 | + |
| 466 | + settingsWindow = Find<Window>("PowerToys Settings", global: true); |
| 467 | + |
| 468 | + if (FindAll<NavigationViewItem>("Advanced Paste").Count == 0) |
| 469 | + { |
| 470 | + Find<NavigationViewItem>("System Tools").Click(); |
| 471 | + } |
| 472 | + |
| 473 | + Find<NavigationViewItem>("Advanced Paste").Click(); |
| 474 | + Find<ToggleSwitch>("Enable Advanced Paste").Toggle(true); |
| 475 | + |
| 476 | + Session.CloseMainWindow(); |
| 477 | + } |
| 478 | + |
| 479 | + private void ClearSystemClipboardHistory() |
| 480 | + { |
| 481 | + this.SendKeys(Key.Win, Key.V); |
| 482 | + |
| 483 | + Thread.Sleep(1500); |
| 484 | + |
| 485 | + var clipboardWindow = this.Find<Window>("Windows Input Experience", global: true); |
| 486 | + Assert.IsNotNull(clipboardWindow, "Cannot find system clipboard window."); |
| 487 | + |
| 488 | + clipboardWindow.Find<PowerToys.UITest.Button>("Clear all except pinned items").Click(); |
| 489 | + } |
| 490 | + |
| 491 | + private void SetClipboardTextInSTAMode(string text) |
| 492 | + { |
| 493 | + var thread = new Thread(() => |
| 494 | + { |
| 495 | + System.Windows.Forms.Clipboard.SetText(text); |
| 496 | + }); |
| 497 | + |
| 498 | + thread.SetApartmentState(ApartmentState.STA); |
| 499 | + thread.Start(); |
| 500 | + thread.Join(); |
264 | 501 | } |
265 | 502 |
|
266 | 503 | private void ContentCopyAndPasteDirectly(string fileName, bool isRTF = false) |
|
0 commit comments