Add test for explicitly elevating between detect and plan.
Sean Hall committed
Feb 17, 2021 at 15:47 UTC
0b5290319a13c8f73315ea0e0407d88bfd79c944
7 files changed
+133
src/TestBA/MessagePump.cs
new
+39
@@ -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
+
3
+namespace 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
+}
src/TestBA/TestBA.cs
+22
@@ -28,6 +28,7 @@ namespace WixToolset.Test.BA
28
29
private bool immediatelyQuit;
30
private bool quitAfterDetect;
31
+ private bool explicitlyElevateAndPlanFromOnElevateBegin;
32
private int redetectRemaining;
33
private int sleepDuringCache;
34
private int cancelCacheAtProgress;
@@ -122,6 +123,12 @@ namespace WixToolset.Test.BA
123
redetectCount = 0;
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
+
132
string quitAfterDetect = this.ReadPackageAction(null, "QuitAfterDetect");
133
if (String.IsNullOrEmpty(quitAfterDetect) || !Boolean.TryParse(quitAfterDetect, out this.quitAfterDetect))
134
{
@@ -214,6 +221,10 @@ namespace WixToolset.Test.BA
221
{
222
this.ShutdownUiThread();
223
}
224
+ else if (this.explicitlyElevateAndPlanFromOnElevateBegin)
225
+ {
226
+ this.Engine.Elevate(this.windowHandle);
227
+ }
228
else
229
{
230
this.Engine.Plan(this.action);
@@ -225,6 +236,17 @@ namespace WixToolset.Test.BA
236
}
237
}
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
+
250
protected override void OnPlanPackageBegin(PlanPackageBeginEventArgs args)
251
{
252
RequestState state;
src/TestData/ElevationTests/BundleA/BundleA.wixproj
new
+18
@@ -0,0 +1,18 @@
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
+<Project Sdk="WixToolset.Sdk">
3
+ <PropertyGroup>
4
+ <OutputType>Bundle</OutputType>
5
+ <UpgradeCode>{5DDF6D9F-FF04-40E8-919C-8DD1DCE4B592}</UpgradeCode>
6
+ </PropertyGroup>
7
+ <ItemGroup>
8
+ <Compile Include="..\..\Templates\Bundle.wxs" Link="Bundle.wxs" />
9
+ </ItemGroup>
10
+ <ItemGroup>
11
+ <ProjectReference Include="..\PackageA\PackageA.wixproj" />
12
+ <ProjectReference Include="..\..\TestBA\TestBAWixlib\testbawixlib.wixproj" />
13
+ </ItemGroup>
14
+ <ItemGroup>
15
+ <PackageReference Include="WixToolset.Bal.wixext" Version="4.0.83" />
16
+ <PackageReference Include="WixToolset.NetFx.wixext" Version="4.0.61" />
17
+ </ItemGroup>
18
+</Project>
\ No newline at end of file
src/TestData/ElevationTests/BundleA/BundleA.wxs
new
+10
@@ -0,0 +1,10 @@
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
+
3
+
4
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
5
+ <Fragment>
6
+ <PackageGroup Id="BundlePackages">
7
+ <MsiPackage Id="PackageA" SourceFile="$(var.PackageA.TargetPath)" />
8
+ </PackageGroup>
9
+ </Fragment>
10
+</Wix>
src/TestData/ElevationTests/PackageA/PackageA.wixproj
new
+9
@@ -0,0 +1,9 @@
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
+<Project Sdk="WixToolset.Sdk">
3
+ <PropertyGroup>
4
+ <UpgradeCode>{D803BB11-5B94-42EA-8289-7A17E55699A3}</UpgradeCode>
5
+ </PropertyGroup>
6
+ <ItemGroup>
7
+ <Compile Include="..\..\Templates\Package.wxs" Link="Package.wxs" />
8
+ </ItemGroup>
9
+</Project>
\ No newline at end of file
src/WixToolsetTest.BurnE2E/ElevationTests.cs
new
+30
@@ -0,0 +1,30 @@
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
+
3
+namespace WixToolsetTest.BurnE2E
4
+{
5
+ using Xunit;
6
+ using Xunit.Abstractions;
7
+
8
+ public class ElevationTests : BurnE2ETests
9
+ {
10
+ public ElevationTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { }
11
+
12
+ /// <summary>
13
+ /// This test calls Elevate after Detect, and then calls Plan in OnElevateBegin.
14
+ /// After calling Plan, it pumps some messages to simulate UI like the UAC callback.
15
+ /// </summary>
16
+ [Fact(Skip = "https://github.com/wixtoolset/issues/issues/6349")] // CAUTION: this test currently hangs because the Plan request gets dropped.
17
+ public void CanExplicitlyElevateAndPlanFromOnElevateBegin()
18
+ {
19
+ var packageA = this.CreatePackageInstaller("PackageA");
20
+ var bundleA = this.CreateBundleInstaller("BundleA");
21
+ var testBAController = this.CreateTestBAController();
22
+
23
+ testBAController.SetExplicitlyElevateAndPlanFromOnElevateBegin();
24
+
25
+ bundleA.Install();
26
+ bundleA.VerifyRegisteredAndInPackageCache();
27
+ packageA.VerifyInstalled(true);
28
+ }
29
+ }
30
+}
src/WixToolsetTest.BurnE2E/TestBAController.cs
+5
@@ -41,6 +41,11 @@ namespace WixToolsetTest.BurnE2E
41
}
42
}
43
44
+ public void SetExplicitlyElevateAndPlanFromOnElevateBegin(string value = "true")
45
+ {
46
+ this.SetBurnTestValue("ExplicitlyElevateAndPlanFromOnElevateBegin", value);
47
+ }
48
+
49
public void SetImmediatelyQuit(string value = "true")
50
{
51
this.SetBurnTestValue("ImmediatelyQuit", value);