diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2021-02-17 15:47:46 -0600 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2021-02-17 16:20:10 -0600 |
| commit | 0b5290319a13c8f73315ea0e0407d88bfd79c944 (patch) | |
| tree | 52638f81d37958c66c602cc1c57a93dfa487d7b4 /src | |
| parent | 15b1946325bf1cfd1794b997f2cbbbcfeb648e92 (diff) | |
| download | wix-0b5290319a13c8f73315ea0e0407d88bfd79c944.tar.gz wix-0b5290319a13c8f73315ea0e0407d88bfd79c944.tar.bz2 wix-0b5290319a13c8f73315ea0e0407d88bfd79c944.zip | |
Add test for explicitly elevating between detect and plan.
Diffstat (limited to 'src')
| -rw-r--r-- | src/TestBA/MessagePump.cs | 39 | ||||
| -rw-r--r-- | src/TestBA/TestBA.cs | 22 | ||||
| -rw-r--r-- | src/TestData/ElevationTests/BundleA/BundleA.wixproj | 18 | ||||
| -rw-r--r-- | src/TestData/ElevationTests/BundleA/BundleA.wxs | 10 | ||||
| -rw-r--r-- | src/TestData/ElevationTests/PackageA/PackageA.wixproj | 9 | ||||
| -rw-r--r-- | src/WixToolsetTest.BurnE2E/ElevationTests.cs | 30 | ||||
| -rw-r--r-- | src/WixToolsetTest.BurnE2E/TestBAController.cs | 5 |
7 files changed, 133 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 | |||
| 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 | } | ||
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; |
diff --git a/src/TestData/ElevationTests/BundleA/BundleA.wixproj b/src/TestData/ElevationTests/BundleA/BundleA.wixproj new file mode 100644 index 00000000..414535b1 --- /dev/null +++ b/src/TestData/ElevationTests/BundleA/BundleA.wixproj | |||
| @@ -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 | ||
diff --git a/src/TestData/ElevationTests/BundleA/BundleA.wxs b/src/TestData/ElevationTests/BundleA/BundleA.wxs new file mode 100644 index 00000000..bd164a29 --- /dev/null +++ b/src/TestData/ElevationTests/BundleA/BundleA.wxs | |||
| @@ -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> | ||
diff --git a/src/TestData/ElevationTests/PackageA/PackageA.wixproj b/src/TestData/ElevationTests/PackageA/PackageA.wixproj new file mode 100644 index 00000000..87f99513 --- /dev/null +++ b/src/TestData/ElevationTests/PackageA/PackageA.wixproj | |||
| @@ -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 | ||
diff --git a/src/WixToolsetTest.BurnE2E/ElevationTests.cs b/src/WixToolsetTest.BurnE2E/ElevationTests.cs new file mode 100644 index 00000000..54a89469 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/ElevationTests.cs | |||
| @@ -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 | } | ||
diff --git a/src/WixToolsetTest.BurnE2E/TestBAController.cs b/src/WixToolsetTest.BurnE2E/TestBAController.cs index 1b254656..8e3053b3 100644 --- a/src/WixToolsetTest.BurnE2E/TestBAController.cs +++ b/src/WixToolsetTest.BurnE2E/TestBAController.cs | |||
| @@ -41,6 +41,11 @@ namespace WixToolsetTest.BurnE2E | |||
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | public void SetExplicitlyElevateAndPlanFromOnElevateBegin(string value = "true") | ||
| 45 | { | ||
| 46 | this.SetBurnTestValue("ExplicitlyElevateAndPlanFromOnElevateBegin", value); | ||
| 47 | } | ||
| 48 | |||
| 44 | public void SetImmediatelyQuit(string value = "true") | 49 | public void SetImmediatelyQuit(string value = "true") |
| 45 | { | 50 | { |
| 46 | this.SetBurnTestValue("ImmediatelyQuit", value); | 51 | this.SetBurnTestValue("ImmediatelyQuit", value); |
