in dev/WebView2/TestUI/WebView2BasicPage.xaml.cs [1166:1797]
async public void CompleteCurrentTest(object sender, RoutedEventArgs args)
{
var MyWebView2 = FindName("MyWebView2") as WebView2;
TestList selectedTest = (TestList)Enum.Parse(typeof(TestList), TestNameComboBox.GetSelectedText());
using (var logger = new ResultsLogger(selectedTest.ToString(), TestResult))
{
switch (selectedTest)
{
case TestList.BasicRenderingTest:
{
// BasicRenderingTest not working via RTB due to HWND-based rendering workaround.
// It is validated in TestRunner side via GDI.
// Color expectedColor = Color.FromArgb(0xFF, 0xFF, 0x80, 0x00); // orange
// await VerifySingleColorTest(selectedTest, expectedColor, logger);
}
break;
case TestList.NavigationErrorTest:
{
var task = MyWebView2.GetNavigationCompletedTask();
MyWebView2.Source = new Uri("http://www.test.invalid");
await task;
var testStatus = Status2.Text;
bool result = testStatus.Equals("HostNameNotResolved");
logger.Verify(result,
string.Format("Test {0}: Expected web error status {1} did not match with received error status {2}",
selectedTest, "HostNameNotResolved", testStatus));
}
break;
case TestList.ExecuteScriptTest:
{
string expectedResult = "1000";
string result = await MyWebView2.ExecuteScriptAsync("timer();"); // calling timer function which takes >1s to complete
logger.Verify(result == expectedResult,
string.Format("Test {0}: Expected result {1} did not match with returned result {2}",
selectedTest, expectedResult.ToString(), result));
}
break;
case TestList.MultipleWebviews_BasicRenderingTest:
{
// Clear any other message that may be there
Status2.Text = string.Empty;
// wait for the other webviews to complete navigation before testing
var tasks = new List<Task>();
foreach (var unit in WebView2Collection.Children)
{
var webviewStackPanel = unit as StackPanel;
Debug.Assert(webviewStackPanel != null);
string stackPanelName = webviewStackPanel.Name;
string webviewName = stackPanelName.Replace("StackPanel", ""); // as per convention, stackpanel name is foowebviewStackPanel
var webview = FindName(webviewName) as WebView2;
Debug.Assert(webview != null);
tasks.Add(webview.GetNavigationCompletedTask());
WebView2Common.LoadWebPage(webview, TestPageNames[0]);
var parentOfWebview = webview.Parent as Border;
parentOfWebview.Height = 100;
parentOfWebview.UpdateLayout();
}
await Task.WhenAll(tasks);
}
break;
case TestList.MultipleWebviews_LanguageTest:
{
var tasks = new List<Task>();
var wv1_name = "MyWebView2";
var wv1 = FindName(wv1_name) as WebView2;
tasks.Add(wv1.GetNavigationCompletedTask());
var wv2_name = "MyWebView2B";
var wv2 = FindName(wv2_name) as WebView2;
tasks.Add(wv2.GetNavigationCompletedTask());
wv1.Reload();
wv2.Reload();
await Task.WhenAll(tasks);
string wv1_expectedLanguage = "\"zh-CN\"";
string wv1_language = await wv1.ExecuteScriptAsync("getLanguage();");
logger.Verify((wv1_language == wv1_expectedLanguage),
string.Format("Test {0}: {1} Language {2} did not match expected value {3}",
selectedTest.ToString(), wv1_name, wv1_language, wv1_expectedLanguage));
// TODO_WebView2: When we expose API to set custom UserData, update the 2nd WebView to use a different language
// (same UserData implies same browser instance and therefore requires same Language)
string wv2_expectedLanguage = "\"zh-CN\"";
string wv2_language = await wv2.ExecuteScriptAsync("getLanguage();");
logger.Verify((wv2_language == wv2_expectedLanguage),
string.Format("Test {0}: {1} Language {2} did not match expected value {3}",
selectedTest.ToString(), wv2_name, wv2_language, wv2_expectedLanguage));
}
break;
case TestList.MouseCaptureTest:
{
string textResult = CopyPasteTextBox2.Text;
string expectedResult = "MouseCaptureResult";
logger.Verify((textResult == expectedResult),
string.Format("Test {0}: Expected text {1} did not match with sampled text {2}",
selectedTest.ToString(), expectedResult, textResult));
}
break;
case TestList.ReloadTest:
{
Uri prevUri = MyWebView2.Source;
await MyWebView2.ExecuteScriptAsync("document.getElementById(\"textInput1\").value='injectedText';");
var task = MyWebView2.GetNavigationCompletedTask();
MyWebView2.Reload();
await task;
string finalTextContent = await MyWebView2.ExecuteScriptAsync("document.getElementById(\"textInput1\").value;");
logger.Verify((finalTextContent == "\"\""),
string.Format("Test {0}: TextBox value was not cleared (\"\"), value: {1}",
selectedTest.ToString(), finalTextContent));
Uri newUri = MyWebView2.Source;
logger.Verify((prevUri.ToString() == newUri.ToString()),
string.Format("Test {0}: Previous Uri {1} did not match the post-reload Uri {2}",
selectedTest.ToString(), prevUri.ToString(), newUri.ToString()));
}
break;
case TestList.NavigateToStringTest:
{
var task = MyWebView2.GetNavigationCompletedTask();
WebView2Common.NavigateToStringMessage(MyWebView2);
await task;
string expectedText = "\"You've navigated to a string message.\"";
string textResult = await MyWebView2.ExecuteScriptAsync("document.body.textContent;");
logger.Verify((expectedText == textResult),
string.Format("Test {0}: Expected content: {1} did not match with sampled content: {2}",
selectedTest.ToString(), expectedText, textResult));
string expectedSourceUri = "about:blank";
string sourceUri = MyWebView2.Source.ToString();
logger.Verify((expectedText == textResult) && (expectedSourceUri == sourceUri),
string.Format("Test {0}: Expected Uri: {1} did not match with sampled Uri: {2}",
selectedTest.ToString(), expectedSourceUri, sourceUri));
}
break;
case TestList.SourceBindingTest:
{
string expectedInitialUri = WebView2Common.GetTestPageUri("SimplePage.html").ToString();
var ActualUriTextBlock = FindName("ActualUriTextBlock") as TextBlock;
string initialActualSourceUri = ActualUriTextBlock.Text;
logger.Verify(AreEqualIgnoringSpace(expectedInitialUri, initialActualSourceUri),
string.Format("Test {0}: Expected source bound text, {1}, did not match actual text binding {2}",
selectedTest.ToString(), expectedInitialUri, initialActualSourceUri));
var task = MyWebView2.GetNavigationCompletedTask();
_ = MyWebView2.ExecuteScriptAsync("navigateToTextPage();");
// Confirm that navigation to SimplePageWithText.html occurred,
// meaning SimplePage intermediate was correctly loaded from textbox.
string expectedFinalSourceUri = WebView2Common.GetTestPageUri("SimplePageWithText.html").ToString();
await task;
string finalActualSourceUri = ActualUriTextBlock.Text;
logger.Verify(AreEqualIgnoringSpace(finalActualSourceUri, expectedFinalSourceUri),
string.Format("Test {0}: Expected navigate to bound uri text {1} failed with current uri {2}",
selectedTest.ToString(), expectedFinalSourceUri, finalActualSourceUri));
}
break;
case TestList.GoBackAndForwardTest:
{
var goBackButton = FindName("GoBackButton") as Button;
var goForwardButton = FindName("GoForwardButton") as Button;
bool canGoBackBindingVerify = !goBackButton.IsEnabled; // Verify both buttons are initially disabled
bool canGoForwardBindingVerify = !goForwardButton.IsEnabled;
ActualUriTextBlock = FindName("ActualUriTextBlock") as TextBlock;
// Part 1: [SimplePage.html] calls navigateToTextPage() -> Navigates to [SimplePageWithText.html].
// Ensure we are at the right URI (via ActualUriTextBlock)
// Scope task to make sure we unsubscribe from NavigationStarting before starting Part 2.
{
var task = MyWebView2.GetNavigationCompletedTask();
_ = MyWebView2.ExecuteScriptAsync("navigateToTextPage();");
await task;
var expectedInitialUri = WebView2Common.GetTestPageUri("SimplePageWithText.html").ToString();
var initialActualSourceUri = ActualUriTextBlock.Text;
logger.Verify(AreEqualIgnoringSpace(expectedInitialUri, initialActualSourceUri),
string.Format("\nTest {0}: Failed, Expected initial Uri {1} did not match actual Uri {2}",
selectedTest, expectedInitialUri, initialActualSourceUri));
}
// Part 2: Use GoBack to navigate back. Ensure we are back at [SimplePage.html].
{
canGoBackBindingVerify = canGoBackBindingVerify && goBackButton.IsEnabled; // Should both be true now
logger.Verify(canGoBackBindingVerify,
string.Format("\nTest {0}: Failed, canGoBackBindingVerify failed {1}",
selectedTest, canGoBackBindingVerify));
var task = MyWebView2.GetNavigationCompletedTask();
MyWebView2.GoBack();
string expectedSecondSourceUri = WebView2Common.GetTestPageUri("SimplePage.html").ToString();
await task;
string actualSecondSourceUri = ActualUriTextBlock.Text;
logger.Verify(AreEqualIgnoringSpace(expectedSecondSourceUri, actualSecondSourceUri),
string.Format("\nTest {0}: Failed, Expected intermediate Uri {1} did not match actual Uri {2}",
selectedTest, expectedSecondSourceUri, actualSecondSourceUri));
}
// Part 3: Use GoForward to navigate forward. Ensure we are back at [SimplePageWithText.html"].
{
canGoForwardBindingVerify = canGoForwardBindingVerify && goForwardButton.IsEnabled; // Should both be true now
logger.Verify(canGoForwardBindingVerify,
string.Format("\nTest {0}: Failed, canGoForwardBindingVerify failed {1}",
selectedTest, canGoForwardBindingVerify));
var task = MyWebView2.GetNavigationCompletedTask();
MyWebView2.GoForward();
string expectedFinalSourceUri = WebView2Common.GetTestPageUri("SimplePageWithText.html").ToString();
await task;
string actualFinalSourceUri = ActualUriTextBlock.Text;
logger.Verify(AreEqualIgnoringSpace(expectedFinalSourceUri, actualFinalSourceUri),
string.Format("\nTest {0}: Failed, Expected final Uri {1} did not match actual Uri {2}",
selectedTest, expectedFinalSourceUri, actualFinalSourceUri));
}
}
break;
case TestList.NavigationStartingTest:
{
// Part 1: [SimplePage.html] calls navigateToTextPage() -> Navigates to [SimplePageWithText.html].
// Ensure we get expected NavigationStarting event/args.
// Scope startTask to make sure we unsubscribe from NavigationStarting before starting Part 2.
{
var startTask = MyWebView2.GetNavigationStartingTask();
_ = MyWebView2.ExecuteScriptAsync("navigateToTextPage();");
await startTask;
string startingStatus = Status1.Text;
string expectedStatus = "MyWebView2 navigation starting...";
logger.Verify((startingStatus == expectedStatus),
string.Format("Test {0}: Failed, Expected navigation status: {1} did not match actual navigation status: {2}",
selectedTest, expectedStatus, startingStatus));
string navigationStartingUri = Status3.Text;
string expectedUri = WebView2Common.GetTestPageUri("SimplePageWithText.html").ToString();
logger.Verify(AreEqualIgnoringSpace(navigationStartingUri, expectedUri),
string.Format("Test {0}: Failed, Expected NavigationStarting Uri {1} did not match actual NavigationStarting Uri {2}",
selectedTest, expectedUri, navigationStartingUri));
logger.Verify(_isUserInitiated,
string.Format("Test {0}: Failed, NavigationStartingArgs.IsUserInitiated value: {1}, did not match expected value: true",
selectedTest, _isUserInitiated.ToString()));
logger.Verify(!_isRedirected,
string.Format("Test {0}: Failed, NavigationStartingArgs.IsRedirected value: {1}, did not match expected value: false",
selectedTest, _isRedirected.ToString()));
}
// Part 2: [SimplePageWithText.html] navigates to http://www.blockedbynavigationstarting.invalid. -> navigation cancelled via OnNavigationStarting.
// Ensure we are still on [SimplePageWithText.html] at end.
{
var startTask2 = MyWebView2.GetNavigationStartingTask();
_ = MyWebView2.ExecuteScriptAsync("navigateToInvalidPage();");
await startTask2;
string navigationStartingUri = Status3.Text;
string expectedUri = WebView2Common.GetTestPageUri("SimplePageWithText.html").ToString();
logger.Verify(AreEqualIgnoringSpace(navigationStartingUri, expectedUri),
string.Format("Test {0}: Failed, Expected NavigationStarting Uri {1} did not match actual NavigationStarting Uri {2}",
selectedTest, expectedUri, navigationStartingUri));
}
}
break;
case TestList.ResizeTest:
{
// Clear any previous resize message from when we created the webview
Status2.Text = string.Empty;
MyWebView2.Width = MyWebView2.ActualWidth / 2;
MyWebView2.Height = MyWebView2.ActualHeight / 2;
MyWebView2.UpdateLayout();
}
break;
case TestList.MoveTest:
{
var yPos1 = await MyWebView2.ExecuteScriptAsync("getWindowYPosition();");
var tcs = new TaskCompletionSource<bool>();
Task renderedTask = tcs.Task;
EventHandler<RenderedEventArgs> renderedHandler = null;
renderedHandler += (sender, args) =>
{
CompositionTarget.Rendered -= renderedHandler;
tcs.SetResult(true);
};
CompositionTarget.Rendered += renderedHandler;
var panel = FindName("WebView2Collection") as StackPanel;
Thickness margin = panel.Margin;
margin.Top = margin.Top += 100;
panel.Margin = margin;
panel.UpdateLayout();
await renderedTask;
var yPos2 = await MyWebView2.ExecuteScriptAsync("getWindowYPosition();");
logger.Verify((yPos1 != yPos2),
string.Format("Test {0} Part 1: Failed, Expected MyWebView2 to move",
selectedTest));
var xPos = await MyWebView2.ExecuteScriptAsync("getWindowXPosition();");
// Get the point at the top-left of the TestPage panel, relative to the webview
// Expected screenPoint value: (-22, -400)
GeneralTransform gt = TransformToVisual(MyWebView2);
Point screenPoint = gt.TransformPoint(new Point(0,0));
double expectedX = screenPoint.X * -1;
// This offset accounts for the elements above the webview on the page--
// specifically TestPage panel, which has its top at 65px, and the title bar.
// This offset is also valid only when the MUXC test app window is in the top left corner of the main monitor display.
// Otherwise, the test will fail.
int offset = 65;
double expectedY = screenPoint.Y * -1 + offset;
logger.Verify((xPos == expectedX.ToString()),
string.Format("Test {0} Part 2: Failed, Expected MyWebView2 xPosition to be {1}, Actual: {2}",
selectedTest, expectedX.ToString(), xPos.ToString()));
logger.Verify((yPos2 == expectedY.ToString()),
string.Format("Test {0} Part 3: Failed, Expected MyWebView2 yPosition to be {1}, Actual: {2}",
selectedTest, expectedY.ToString(), yPos2.ToString()));
var width = await MyWebView2.ExecuteScriptAsync("getWindowWidth();");
var height = await MyWebView2.ExecuteScriptAsync("getWindowHeight();");
logger.Verify((width == MyWebView2.ActualWidth.ToString()),
string.Format("Test {0} Part 4: Failed, Expected MyWebView2 width to be {1}, Actual: {2}",
selectedTest, MyWebView2.ActualWidth.ToString(), width.ToString()));
logger.Verify((height == MyWebView2.ActualHeight.ToString()),
string.Format("Test {0} Part 5: Failed, Expected MyWebView2 height to be {1}, Actual: {2}",
selectedTest, MyWebView2.ActualHeight.ToString(), height.ToString()));
}
break;
case TestList.ReparentElementTest:
{
// Pull the webview out of its border
var parentOfWebview = MyWebView2.Parent as Border;
parentOfWebview.Child = null;
// Make the old location smaller so we can see the webview in its new
// position even on a small screen
parentOfWebview.Height = 10;
// Put the Webview inside a new border in WebView2Collection
MoveWebViewControl("MyWebView2", MyWebView2);
}
break;
case TestList.SourceBeforeLoadTest:
{
// TODO_WebView2: This test should validate rendering
logger.Verify((MyWebView2.Source != null),
string.Format("Test {0}: Failed, Expected MyWebView2.Source to be {1}",
selectedTest, WebView2Common.GetTestPageUri("SimplePageWithButton.html").ToString()));
}
break;
case TestList.VisibilityHiddenTest:
{
MyWebView2.Visibility = Visibility.Collapsed;
}
break;
case TestList.VisibilityTurnedOnTest:
{
// Show the ancestor that was previously hidden
MyWebView2.Visibility = Visibility.Visible;
}
break;
case TestList.ParentVisibilityHiddenTest:
{
// Hide the parent border
var testContentsBorder = FindName("TestContentsBorder") as Border;
testContentsBorder.Visibility = Visibility.Collapsed;
}
break;
case TestList.ParentVisibilityTurnedOnTest:
{
// Show the ancestor that was previously hidden
var testContentsBorder = FindName("TestContentsBorder") as Border;
testContentsBorder.Visibility = Visibility.Visible;
}
break;
case TestList.QueryCoreWebView2BasicTest:
{
// First load test's default webpage SimplePage.html
var navCompletedTask1 = MyWebView2.GetNavigationCompletedTask();
WebView2Common.LoadWebPage(MyWebView2, TestPageNames[TestInfoDictionary[selectedTest]]);
await navCompletedTask1;
// Validate CoreWebView2.DocumentTitle
string expectedTitle1 = "Simple Page";
string actualTitle1 = GetDocumentTitle(MyWebView2);
logger.Verify((expectedTitle1 == actualTitle1),
string.Format("Part 1: Expected WV2.CWV2.DocumentTitle: {0}, actual: {1}",
expectedTitle1, actualTitle1));
// Load a different page
var navCompletedTask2 = MyWebView2.GetNavigationCompletedTask();
WebView2Common.LoadWebPage(MyWebView2, TestPageNames[1]);
await navCompletedTask2;
string expectedTitle2 = "Simple Page With Button";
string actualTitle2 = GetDocumentTitle(MyWebView2);
logger.Verify((expectedTitle2 == actualTitle2),
string.Format("Part 2: Expected WV2.CWV2.DocumentTitle: {0}, actual: {1}",
expectedTitle2, actualTitle2));
// Close() WebView2 - CWV2 should be shutdown + reference cleared
MyWebView2.Close();
string expectedTitle3 = string.Empty;
string actualTitle3 = GetDocumentTitle(MyWebView2);
logger.Verify((expectedTitle3 == actualTitle3),
string.Format("Part 3: Expected WV2.CWV2.DocumentTitle: {0}, actual: {1}",
expectedTitle3, actualTitle3));
}
break;
case TestList.CursorUpdateTest:
{
WebView2WithCursor webviewWithCursor = MyWebView2 as WebView2WithCursor;
Windows.UI.Core.CoreCursor cursor = webviewWithCursor.WrappedProtectedCursor;
logger.Verify(cursor != null, "ProtectedCursor was null");
if (cursor == null) break;
var actualCursorType = cursor.Type;
var expectedCursorType = Windows.UI.Core.CoreCursorType.Hand;
logger.Verify((expectedCursorType == actualCursorType),
string.Format("Expected cursor type ({0}) did not match actual: {1}",
expectedCursorType, actualCursorType));
}
break;
case TestList.CoreWebView2InitializedTest:
{
// First load test's default webpage SimplePage.html
var tasks = new List<Task>();
var initializedTask = MyWebView2.GetCoreWebView2InitializedTask();
tasks.Add(MyWebView2.GetNavigationCompletedTask());
tasks.Add(initializedTask);
WebView2Common.LoadWebPage(MyWebView2, TestPageNames[TestInfoDictionary[selectedTest]]);
await Task.WhenAll(tasks);
CoreWebView2InitializedEventArgs eventArgs = initializedTask.Result;
bool isExceptionNull = (eventArgs.Exception == null);
logger.Verify(isExceptionNull,
string.Format("Expected CoreWV2InitializedEventArgs.Exception to be null, actual: {0}",
eventArgs.Exception));
}
break;
case TestList.CoreWebView2Initialized_FailedTest:
{
// Try to load test's default webpage SimplePage.html
// This should fail since we uninstalled WebView2Runtime
var tasks = new List<Task>();
var initializedTask = MyWebView2.GetCoreWebView2InitializedTask();
WebView2Common.LoadWebPage(MyWebView2, TestPageNames[TestInfoDictionary[selectedTest]]);
await initializedTask;
CoreWebView2InitializedEventArgs eventArgs = initializedTask.Result;
bool exceptionFired = (eventArgs.Exception != null);
logger.Verify(exceptionFired,
string.Format("Expected CoreWV2InitializedEventArgs.Exception to fire"));
}
break;
case TestList.WindowlessPopupTest:
{
var popWebView2 = FindName("popWebView2") as WebView2;
var navCompletedTask = popWebView2.GetNavigationCompletedTask();
WebView2Common.LoadWebPage(popWebView2, TestPageNames[TestInfoDictionary[selectedTest]]);
await navCompletedTask;
}
break;
case TestList.HostNameToFolderMappingTest:
{
var task = MyWebView2.GetNavigationCompletedTask();
var core_wv2 = MyWebView2.CoreWebView2;
if (core_wv2 != null)
{
core_wv2.SetVirtualHostNameToFolderMapping(
"testapp.example", "assets",
Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow);
}
string uriString = "https://testapp.example/SimplePageWithButton.html";
WebView2Common.NavigateToUri(MyWebView2, uriString);
await task;
}
break;
case TestList.NavigateToVideoTest:
{
var task = MyWebView2.GetNavigationCompletedTask();
NavigateToVideo(MyWebView2);
await task;
string expectedSourceUri = "https://appassets.example/CastingVideo.mp4";
string sourceUri = MyWebView2.Source.ToString(); // Actually expecting "https://appassets.example/CastingVideo.mp4 []"
logger.Verify(sourceUri.StartsWith(expectedSourceUri),
string.Format("Test {0}: Expected Uri: {1} did not match with sampled Uri: {2}",
selectedTest.ToString(), expectedSourceUri, sourceUri));
}
break;
case TestList.NavigateToLocalImageTest:
{
var task = MyWebView2.GetNavigationCompletedTask();
var core_wv2 = MyWebView2.CoreWebView2;
if (core_wv2 != null)
{
core_wv2.SetVirtualHostNameToFolderMapping(
"testapp.example", "assets",
Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow);
}
string uriString = "https://testapp.example/SimplePageWithImage.html";
WebView2Common.NavigateToUri(MyWebView2, uriString);
await task;
}
break;
case TestList.ScaledTouchTest:
{
MyWebView2.RenderTransformOrigin = new Windows.Foundation.Point(0, 0);
var scaleTransform = new ScaleTransform { ScaleX = 1.2, ScaleY = 1.2 };
TransformGroup transformGroup = new TransformGroup();
transformGroup.Children.Add(scaleTransform);
MyWebView2.RenderTransform = transformGroup;
}
break;
case TestList.CloseThenDPIChangeTest:
{
MyWebView2.Close();
}
break;
case TestList.AddHostObjectToScriptTest:
{
var core_wv2 = MyWebView2.CoreWebView2;
logger.Verify(core_wv2 != null, string.Format(
"Test {0}: CoreWebView2 was null.", selectedTest.ToString()));
bool winrtNotImpl = false;
try
{
core_wv2.AddHostObjectToScript("bridge", new Bridge());
core_wv2.RemoveHostObjectFromScript("bridge");
}
catch (NotImplementedException)
{
// WinRT version of AddHostObjectToScript is not implemented yet,
// expect a NotImplementedException for now
winrtNotImpl = true;
}
logger.Verify(winrtNotImpl == true, string.Format(
"Test {0}: Expected NotImplementedException but did not receive it.", selectedTest.ToString()));
// There is a interop we can use to access the method
var interop = (ICoreWebView2Interop)(object)core_wv2;//core_wv2.As<ICoreWebView2Interop>();
try
{
interop.AddHostObjectToScript("bridge", new Bridge());
// AddHostObjectToScript represents the host objects in JavaScript using JavaScript async proxies.
// Accessing any member off of the proxy gives back a promise for another async proxy. You need to
// await a proxy to get to an actual value. The async proxies have no knowledge of the members of
// the actual host object, so JSON.toString on an async proxy won’t tell you anything interesting
// because the async proxy doesn’t know it has a property named Property. When you do bridge.Property
// you immediately get back an async proxy representing the result of doing a property get on ‘Property’
// on that object and a message is sent off to the host process to find that value, but that async proxy
// may resolve to an exception if there isn’t actually a property named Property on the actual host object.
string result = await MyWebView2.ExecuteScriptAsync(
"(async function() { " +
"let result = await window.chrome.webview.hostObjects.bridge.AnotherObject.Prop; " +
"window.chrome.webview.postMessage(result); })();");
// Listen for WebMessageReceived
core_wv2.RemoveHostObjectFromScript("bridge");
}
catch (Exception e)
{
logger.Verify(false, string.Format("Test {0}: Unexpected exception: {1}",
selectedTest.ToString(), e.ToString()));
}
}
break;
case TestList.UserAgentTest:
{
var userAgent = string.Empty;
var core_wv2 = MyWebView2.CoreWebView2;
if (core_wv2 == null)
{
logger.LogError(string.Format("Test {0}: Couldn't get CoreWebView2 object", selectedTest.ToString()));
break;
}
var core_wv2_settings = core_wv2.Settings;
if (core_wv2_settings == null)
{
logger.LogError(string.Format("Test {0}: Couldn't get CoreWebView2Settings object", selectedTest.ToString()));
break;
}
userAgent = core_wv2_settings.UserAgent;
// The "Edg" token identifies the Chromium Edge browser
// For more information, see https://docs.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-guidance
logger.Verify(userAgent.Contains("Edg"),
string.Format("Test {0}: Expected a valid UserAgent, got {1}", selectedTest.ToString(), userAgent));
}
break;
default:
break;
}
}
}