From 438a598f61f50455c64dad7fab737df5d02f2168 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Wed, 9 Oct 2019 15:11:49 -0400 Subject: [PATCH] [tests] Import regression test for bug 29730 (#3748) Context: https://dev.azure.com/devdiv/DevDiv/_build/results?buildId=3107238&view=ms.vss-test-web.test-result-details Context: https://bugzilla.xamarin.com/show_bug.cgi?id=29730 This test has been failing with some frequency since it was imported in the new Integrated Regression test Azure Pipeline jobs. After some investigation, it appears that the failure is due to test environment limitations. Some of the Android devices attached to the machine pools being used for this test job have a lock screen enabled, and in some cases this is preventing ViewTreeObserver events from executing. Fixes the intermittent failure by moving this test into the MSBuildDeviceIntegration suite which runs on an x86 emulator in CI. This emulator is never locked and should always display activites for applications we're installing and launching. --- .../Tests/BugzillaTests.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/MSBuildDeviceIntegration/Tests/BugzillaTests.cs diff --git a/tests/MSBuildDeviceIntegration/Tests/BugzillaTests.cs b/tests/MSBuildDeviceIntegration/Tests/BugzillaTests.cs new file mode 100644 index 00000000000..9ca73150508 --- /dev/null +++ b/tests/MSBuildDeviceIntegration/Tests/BugzillaTests.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using Xamarin.ProjectTools; + +namespace Xamarin.Android.Build.Tests +{ + [SingleThreaded] + public class BugzillaTests : DeviceTest + { + static ProjectBuilder builder; + static XamarinAndroidApplicationProject proj; + + [TearDown] + public void Teardown () + { + if (HasDevices && proj != null) + RunAdbCommand ($"uninstall {proj.PackageName}"); + + if (TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Passed + && builder != null && Directory.Exists (builder.ProjectDirectory)) + Directory.Delete (builder.ProjectDirectory, recursive: true); + } + + [Test] + public void GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch ([Values (false, true)] bool isRelease) + { + if (!HasDevices) + Assert.Ignore ("Skipping Test. No devices available."); + + string expectedLogcatOutput = "Bug 29730: GlobalLayout event handler called!"; + + proj = new XamarinAndroidApplicationProject () { + IsRelease = isRelease, + }; + if (isRelease || !CommercialBuildAvailable) { + proj.SetProperty (KnownProperties.AndroidSupportedAbis, "armeabi-v7a;arm64-v8a;x86"); + } else { + proj.AndroidManifest = proj.AndroidManifest.Replace ("", ""); + } + proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", +$@"button.ViewTreeObserver.GlobalLayout += Button_ViewTreeObserver_GlobalLayout; + }} + void Button_ViewTreeObserver_GlobalLayout (object sender, EventArgs e) + {{ + Android.Util.Log.Debug (""BugzillaTests"", ""{expectedLogcatOutput}""); +"); + builder = CreateApkBuilder (Path.Combine ("temp", $"Bug29730-{isRelease}")); + Assert.IsTrue (builder.Install (proj), "Install should have succeeded."); + ClearAdbLogcat (); + AdbStartActivity ($"{proj.PackageName}/{proj.JavaPackageName}.MainActivity"); + Assert.IsTrue (MonitorAdbLogcat ((line) => { + return line.Contains (expectedLogcatOutput); + }, Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"), 45), $"Output did not contain {expectedLogcatOutput}!"); + } + + } +}