Skip to content

Commit 3c708df

Browse files
committed
1 parent 79008ae commit 3c708df

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

CefSharp.Wpf.Example/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<MenuItem Header="_Load Custom Request" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="CustomRequest" />
4646
<MenuItem Header="_CDM/DRM Support Test" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="{Binding Source={x:Static ex:CefExample.CdmSupportTestUrl}}"/>
4747
<MenuItem Header="_Async JSB Task Tests" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="AsyncJsbTaskTests" />
48+
<MenuItem Header="_Resize Hack Tests" Command="controls:CefSharpCommands.CustomCommand" CommandParameter="ResizeHackTests" />
4849
<MenuItem Header="_Google Service Worker Demo" Command="controls:CefSharpCommands.OpenTabCommand" CommandParameter="https://googlechrome.github.io/samples/service-worker/basic/"/>
4950
</MenuItem>
5051
</Menu>

CefSharp.Wpf.Example/MainWindow.xaml.cs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

55
using System;
6+
using System.Collections.Generic;
67
using System.Collections.ObjectModel;
8+
using System.Threading;
9+
using System.Threading.Tasks;
710
using System.Windows;
811
using System.Windows.Input;
912
using CefSharp.Example;
@@ -140,6 +143,11 @@ private void CustomCommandBinding(object sender, ExecutedRoutedEventArgs e)
140143
browserViewModel.ShowDownloadInfo = !browserViewModel.ShowDownloadInfo;
141144
}
142145

146+
if (param == "ResizeHackTests")
147+
{
148+
ReproduceWasResizedCrashAsync();
149+
}
150+
143151
if (param == "AsyncJsbTaskTests")
144152
{
145153
//After this setting has changed all tests will run through the Concurrent MethodQueueRunner
@@ -223,5 +231,76 @@ private void Exit(object sender, ExecutedRoutedEventArgs e)
223231
{
224232
Close();
225233
}
234+
235+
private void CloseTab(BrowserTabViewModel browserViewModel)
236+
{
237+
if (BrowserTabs.Remove(browserViewModel))
238+
{
239+
browserViewModel.WebBrowser?.Dispose();
240+
}
241+
}
242+
243+
private void ReproduceWasResizedCrashAsync()
244+
{
245+
CreateNewTab();
246+
CreateNewTab();
247+
248+
WindowState = WindowState.Normal;
249+
250+
Task.Run(() =>
251+
{
252+
try
253+
{
254+
var random = new Random();
255+
256+
for (int i = 0; i < 20; i++)
257+
{
258+
for (int j = 0; j < 150; j++)
259+
{
260+
Dispatcher.Invoke(new Action(() =>
261+
{
262+
var newWidth = Width + (i % 2 == 0 ? -5 : 5);
263+
var newHeight = Height + (i % 2 == 0 ? -5 : 5);
264+
if (newWidth < 500 || newWidth > 1500)
265+
{
266+
newWidth = 1000;
267+
}
268+
if (newHeight < 500 || newHeight > 1500)
269+
{
270+
newHeight = 1000;
271+
}
272+
Width = newWidth;
273+
Height = newHeight;
274+
275+
// Get all indexes but the selected one
276+
var indexes = new List<int>();
277+
for (int k = 0; k < TabControl.Items.Count; k++)
278+
{
279+
if (TabControl.SelectedIndex != k)
280+
{
281+
indexes.Add(k);
282+
}
283+
}
284+
285+
// Select a random unselected tab
286+
TabControl.SelectedIndex = indexes[random.Next(0, indexes.Count)];
287+
288+
// Close a tab and create a tab once in a while
289+
if (random.Next(0, 5) == 0)
290+
{
291+
CloseTab(BrowserTabs[Math.Max(1, TabControl.SelectedIndex)]); // Don't close the first tab
292+
CreateNewTab();
293+
}
294+
}));
295+
296+
// Sleep random amount of time
297+
Thread.Sleep(random.Next(1, 11));
298+
}
299+
}
300+
}
301+
catch (TaskCanceledException) { } // So it doesn't break on VS stop
302+
});
303+
}
304+
226305
}
227306
}

0 commit comments

Comments
 (0)