-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homepage tests refactor #15078
base: master
Are you sure you want to change the base?
Homepage tests refactor #15078
Changes from 5 commits
cf6971c
aef2603
fb3bcec
732394e
915bf96
dbe49f9
6cd83a1
84d10cd
3168b22
24ca262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ public partial class HomePage : UserControl, IDisposable | |
/// </summary> | ||
internal static Action<string> TestHook { get; set; } | ||
|
||
internal AsyncMethodState initState = AsyncMethodState.NotStarted; | ||
|
||
public HomePage() | ||
{ | ||
InitializeComponent(); | ||
|
@@ -143,14 +145,17 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA | |
PathHelper.CreateFolderIfNotExist(userDataDir.ToString()); | ||
var webBrowserUserDataFolder = userDataDir.Exists ? userDataDir : null; | ||
|
||
var userDataFolder = CreateUniqueUserDataFolder(webBrowserUserDataFolder.FullName); | ||
|
||
dynWebView.CreationProperties = new CoreWebView2CreationProperties | ||
{ | ||
UserDataFolder = webBrowserUserDataFolder.FullName | ||
UserDataFolder = userDataFolder.FullName | ||
}; | ||
|
||
//ContentRendered ensures that the webview2 component is visible. | ||
try | ||
{ | ||
initState = AsyncMethodState.Started; | ||
await dynWebView.Initialize(); | ||
|
||
// Set WebView2 settings | ||
|
@@ -194,6 +199,8 @@ private async void UserControl_Loaded(object sender, System.Windows.RoutedEventA | |
RequestShowSampleFilesInFolder, | ||
RequestShowBackupFilesInFolder, | ||
RequestShowTemplate)); | ||
|
||
initState = AsyncMethodState.Done; | ||
} | ||
catch (ObjectDisposedException ex) | ||
{ | ||
|
@@ -471,14 +478,51 @@ internal void ApplicationLoaded() | |
|
||
#endregion | ||
|
||
#region Helper Functions | ||
/// <summary> | ||
/// Create unique subfolder to allocate webView2 resources | ||
/// </summary> | ||
/// <param name="baseDir"></param> | ||
/// <returns></returns> | ||
private DirectoryInfo CreateUniqueUserDataFolder(string baseDir) | ||
{ | ||
Directory.CreateDirectory(baseDir); | ||
|
||
var uniqueSubfolderName = Guid.NewGuid().ToString(); | ||
var uniquePath = Path.Combine(baseDir, uniqueSubfolderName); | ||
Directory.CreateDirectory(uniquePath); | ||
|
||
return new DirectoryInfo(uniquePath); | ||
} | ||
#endregion | ||
|
||
#region Dispose | ||
public void Dispose() | ||
{ | ||
DataContextChanged -= OnDataContextChanged; | ||
if(startPage != null) startPage.DynamoViewModel.PropertyChanged -= DynamoViewModel_PropertyChanged; | ||
|
||
this.dynWebView.CoreWebView2.NewWindowRequested -= CoreWebView2_NewWindowRequested; | ||
if(startPage != null) startPage.DynamoViewModel.PropertyChanged -= DynamoViewModel_PropertyChanged; | ||
if (this.dynWebView != null) | ||
{ | ||
var userDataFolder = this.dynWebView.CoreWebView2.Environment.UserDataFolder; | ||
if (userDataFolder != null && Directory.Exists(userDataFolder)) | ||
{ | ||
// Try shutting down the browser with Dispose, and wait for process to exit | ||
try | ||
{ | ||
var webViewProcessId = Convert.ToInt32(this.dynWebView.CoreWebView2.BrowserProcessId); | ||
var webViewProcess = Process.GetProcessById(webViewProcessId); | ||
|
||
this.dynWebView.Dispose(); | ||
webViewProcess.WaitForExit(3000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might be able to use this event There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, great, I can definitely do that. Thank you for the suggestion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably have to clean it up too.. |
||
|
||
Directory.Delete(userDataFolder, true); | ||
} | ||
catch { | ||
} | ||
} | ||
|
||
} | ||
if (File.Exists(fontFilePath)) | ||
{ | ||
File.Delete(fontFilePath); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has not been a problem with other vebview2 tests...
Are you certain this solves your test issues ?
Also maybe we should just create and cleanup these unique folders only during testing ? either use the testing flag...or make these APIs accessible to the test project and call them directly from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time being, testing things locally, I didn't run on any sporadic test failures as before.
I was also thinking that maybe this is only necessary under test environment, so if the build completes correctly, I can make the necessary changes.