Ensure Process.MainWindowTitle and Process.Responding is refreshed (#38385)
authorJeroen Oortwijn <51476918+JeroenOortwijn@users.noreply.github.com>
Wed, 12 Aug 2020 13:48:12 +0000 (15:48 +0200)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 13:48:12 +0000 (14:48 +0100)
* Add test for process.MainWindowTitle refresh bug

See #36768.

* Add test for Process.Responding refresh bug

See dotnet#36768.

* Ensure Process.MainWindowTitle is refreshed

See dotnet#36768.

* Ensure Process.Responding is refreshed

See dotnet#36768.

* Made dummyFilePath const

* Fix glaring bugs

* remove Process.Responding test

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs

index af02b8a..b0ab947 100644 (file)
@@ -119,6 +119,8 @@ namespace System.Diagnostics
         {
             _signaled = false;
             _haveMainWindow = false;
+            _mainWindowTitle = null;
+            _haveResponding = false;
         }
 
         /// <summary>Additional logic invoked when the Process is closed.</summary>
index fa6503b..badc169 100644 (file)
@@ -1595,6 +1595,42 @@ namespace System.Diagnostics.Tests
             }
         }
 
+        [Fact]
+        [OuterLoop]
+        [Trait(XunitConstants.Category, XunitConstants.IgnoreForCI)] // Pops UI
+        [PlatformSpecific(TestPlatforms.Windows)]
+        public void MainWindowTitle_GetWithGui_ShouldRefresh_Windows()
+        {
+            const string ExePath = "notepad.exe";
+            Assert.True(IsProgramInstalled(ExePath));
+
+            using (Process process = Process.Start(ExePath))
+            {
+                try
+                {
+                    Assert.Equal(string.Empty, process.MainWindowTitle);
+
+                    for (int attempt = 0; attempt < 50; ++attempt)
+                    {
+                        process.Refresh();
+                        if (process.MainWindowTitle != string.Empty)
+                        {
+                            break;
+                        }
+
+                        Thread.Sleep(100);
+                    }
+
+                    Assert.NotEqual(string.Empty, process.MainWindowTitle);
+                }
+                finally
+                {
+                    process.Kill();
+                    Assert.True(process.WaitForExit(WaitInMS));
+                }
+            }
+        }
+
         [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
         public void MainWindowTitle_NoWindow_ReturnsEmpty()
         {