aboutsummaryrefslogtreecommitdiff
path: root/src/TestBA
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-02-17 15:47:46 -0600
committerSean Hall <r.sean.hall@gmail.com>2021-02-17 16:20:10 -0600
commit0b5290319a13c8f73315ea0e0407d88bfd79c944 (patch)
tree52638f81d37958c66c602cc1c57a93dfa487d7b4 /src/TestBA
parent15b1946325bf1cfd1794b997f2cbbbcfeb648e92 (diff)
downloadwix-0b5290319a13c8f73315ea0e0407d88bfd79c944.tar.gz
wix-0b5290319a13c8f73315ea0e0407d88bfd79c944.tar.bz2
wix-0b5290319a13c8f73315ea0e0407d88bfd79c944.zip
Add test for explicitly elevating between detect and plan.
Diffstat (limited to 'src/TestBA')
-rw-r--r--src/TestBA/MessagePump.cs39
-rw-r--r--src/TestBA/TestBA.cs22
2 files changed, 61 insertions, 0 deletions
diff --git a/src/TestBA/MessagePump.cs b/src/TestBA/MessagePump.cs
new file mode 100644
index 00000000..21a00349
--- /dev/null
+++ b/src/TestBA/MessagePump.cs
@@ -0,0 +1,39 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Test.BA
4{
5 using System;
6 using System.Runtime.InteropServices;
7 using System.Windows.Forms;
8
9 public class MessagePump
10 {
11 const uint PM_REMOVE = 1;
12
13 [DllImport("user32.dll", ExactSpelling = true)]
14 [return: MarshalAs(UnmanagedType.Bool)]
15 public static extern bool PeekMessageW(ref Message pMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
16
17 [DllImport("user32.dll", ExactSpelling = true)]
18 [return: MarshalAs(UnmanagedType.Bool)]
19 public static extern bool TranslateMessage(ref Message pMsg);
20
21 [DllImport("user32.dll", ExactSpelling = true)]
22 public static extern IntPtr DispatchMessageW(ref Message pMsg);
23
24 public static void ProcessMessages(int maxMessages)
25 {
26 for (int i = 0; i < maxMessages; i++)
27 {
28 Message message = new Message();
29 if (!PeekMessageW(ref message, IntPtr.Zero, 0, 0, PM_REMOVE))
30 {
31 break;
32 }
33
34 TranslateMessage(ref message);
35 DispatchMessageW(ref message);
36 }
37 }
38 }
39}
diff --git a/src/TestBA/TestBA.cs b/src/TestBA/TestBA.cs
index 1348ce98..b9f869a6 100644
--- a/src/TestBA/TestBA.cs
+++ b/src/TestBA/TestBA.cs
@@ -28,6 +28,7 @@ namespace WixToolset.Test.BA
28 28
29 private bool immediatelyQuit; 29 private bool immediatelyQuit;
30 private bool quitAfterDetect; 30 private bool quitAfterDetect;
31 private bool explicitlyElevateAndPlanFromOnElevateBegin;
31 private int redetectRemaining; 32 private int redetectRemaining;
32 private int sleepDuringCache; 33 private int sleepDuringCache;
33 private int cancelCacheAtProgress; 34 private int cancelCacheAtProgress;
@@ -122,6 +123,12 @@ namespace WixToolset.Test.BA
122 redetectCount = 0; 123 redetectCount = 0;
123 } 124 }
124 125
126 string explicitlyElevateAndPlanFromOnElevateBegin = this.ReadPackageAction(null, "ExplicitlyElevateAndPlanFromOnElevateBegin");
127 if (String.IsNullOrEmpty(explicitlyElevateAndPlanFromOnElevateBegin) || !Boolean.TryParse(explicitlyElevateAndPlanFromOnElevateBegin, out this.explicitlyElevateAndPlanFromOnElevateBegin))
128 {
129 this.explicitlyElevateAndPlanFromOnElevateBegin = false;
130 }
131
125 string quitAfterDetect = this.ReadPackageAction(null, "QuitAfterDetect"); 132 string quitAfterDetect = this.ReadPackageAction(null, "QuitAfterDetect");
126 if (String.IsNullOrEmpty(quitAfterDetect) || !Boolean.TryParse(quitAfterDetect, out this.quitAfterDetect)) 133 if (String.IsNullOrEmpty(quitAfterDetect) || !Boolean.TryParse(quitAfterDetect, out this.quitAfterDetect))
127 { 134 {
@@ -214,6 +221,10 @@ namespace WixToolset.Test.BA
214 { 221 {
215 this.ShutdownUiThread(); 222 this.ShutdownUiThread();
216 } 223 }
224 else if (this.explicitlyElevateAndPlanFromOnElevateBegin)
225 {
226 this.Engine.Elevate(this.windowHandle);
227 }
217 else 228 else
218 { 229 {
219 this.Engine.Plan(this.action); 230 this.Engine.Plan(this.action);
@@ -225,6 +236,17 @@ namespace WixToolset.Test.BA
225 } 236 }
226 } 237 }
227 238
239 protected override void OnElevateBegin(ElevateBeginEventArgs args)
240 {
241 if (this.explicitlyElevateAndPlanFromOnElevateBegin)
242 {
243 this.Engine.Plan(this.action);
244
245 // Simulate showing some UI since these tests won't actually show the UAC prompt.
246 MessagePump.ProcessMessages(10);
247 }
248 }
249
228 protected override void OnPlanPackageBegin(PlanPackageBeginEventArgs args) 250 protected override void OnPlanPackageBegin(PlanPackageBeginEventArgs args)
229 { 251 {
230 RequestState state; 252 RequestState state;