@@ -298,6 +298,82 @@ await ShowString("<p>Hidden</p>"),
298298 }
299299 }
300300
301+ [ TestMethod ]
302+ [ PlatformCondition ( ConditionMode . Include , RuntimeTestPlatforms . SkiaWasm ) ]
303+ [ GitHubWorkItem ( "https://github.com/unoplatform/uno/issues/25735" ) ]
304+ public async Task When_Url_Read_Before_Cross_Origin_Content_Arrives_Then_Its_Url_Is_Reported ( )
305+ {
306+ const string DataUrl = "data:text/html,arriving" ;
307+
308+ var webView = new WebView2 { Width = 200 , Height = 200 } ;
309+ string loadedSource = null ;
310+ void OnNavigationCompleted ( WebView2 sender , CoreWebView2NavigationCompletedEventArgs args ) => loadedSource ??= sender . CoreWebView2 . Source ;
311+
312+ try
313+ {
314+ await UITestHelper . Load ( webView ) ;
315+ await webView . EnsureCoreWebView2Async ( ) ;
316+ var elementId = GetIframeElementId ( webView ) ;
317+ webView . NavigationCompleted += OnNavigationCompleted ;
318+
319+ // Start a navigation to a cross-origin document and, in the same task, read the frame's URL as Loaded does when the
320+ // WebView2 is added to the tree again before that document arrives.
321+ WasmSemanticDomHelper . InvokeBrowserJs (
322+ $ "(function(){{var w=Microsoft.UI.Xaml.Controls.WebView;w.navigate('{ elementId } ','{ DataUrl } ');w.getCurrentUrl('{ elementId } ');return '';}})()") ;
323+
324+ await TestServices . WindowHelper . WaitFor (
325+ ( ) => loadedSource is not null ,
326+ timeoutMS : 10000 ,
327+ message : "NavigationCompleted should be raised when the cross-origin document loads." ) ;
328+
329+ Assert . AreEqual ( DataUrl , loadedSource , "The cross-origin document should be reported with its own URL, not the previous page's." ) ;
330+ }
331+ finally
332+ {
333+ webView . NavigationCompleted -= OnNavigationCompleted ;
334+ TestServices . WindowHelper . WindowContent = null ;
335+ }
336+ }
337+
338+ [ TestMethod ]
339+ [ PlatformCondition ( ConditionMode . Include , RuntimeTestPlatforms . SkiaWasm ) ]
340+ [ GitHubWorkItem ( "https://github.com/unoplatform/uno/issues/25735" ) ]
341+ public async Task When_Loaded_Again_Then_Source_Is_Kept ( )
342+ {
343+ // A cross-origin document, whose location the browser hides.
344+ const string DataUrl = "data:text/html,kept" ;
345+
346+ var webView = new WebView2 { Width = 200 , Height = 200 } ;
347+ var documentLoaded = false ;
348+ void OnNavigationCompleted ( WebView2 sender , CoreWebView2NavigationCompletedEventArgs args )
349+ => documentLoaded |= sender . CoreWebView2 . Source == DataUrl ;
350+
351+ try
352+ {
353+ await UITestHelper . Load ( webView ) ;
354+ await webView . EnsureCoreWebView2Async ( ) ;
355+ webView . NavigationCompleted += OnNavigationCompleted ;
356+
357+ webView . CoreWebView2 . Navigate ( DataUrl ) ;
358+ await TestServices . WindowHelper . WaitFor (
359+ ( ) => documentLoaded ,
360+ timeoutMS : 10000 ,
361+ message : "NavigationCompleted should be raised for the document, with Source set to its URL." ) ;
362+
363+ // Unloading and loading the WebView2 again keeps its frame and the document it shows.
364+ TestServices . WindowHelper . WindowContent = null ;
365+ await TestServices . WindowHelper . WaitForIdle ( ) ;
366+ await UITestHelper . Load ( webView ) ;
367+
368+ Assert . AreEqual ( new Uri ( DataUrl ) , webView . Source , "Loading the WebView2 again should keep the Source of the document it shows." ) ;
369+ }
370+ finally
371+ {
372+ webView . NavigationCompleted -= OnNavigationCompleted ;
373+ TestServices . WindowHelper . WindowContent = null ;
374+ }
375+ }
376+
301377 [ MethodImpl ( MethodImplOptions . NoInlining ) ]
302378 private static async Task < ( WeakReference , string ) > LoadNavigateAndUnloadWebView2 ( )
303379 {
0 commit comments