|
3 | 3 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
5 | 5 | using System; |
| 6 | +using System.Collections.Generic; |
6 | 7 | using System.Collections.ObjectModel; |
| 8 | +using System.Threading; |
| 9 | +using System.Threading.Tasks; |
7 | 10 | using System.Windows; |
8 | 11 | using System.Windows.Input; |
9 | 12 | using CefSharp.Example; |
@@ -140,6 +143,11 @@ private void CustomCommandBinding(object sender, ExecutedRoutedEventArgs e) |
140 | 143 | browserViewModel.ShowDownloadInfo = !browserViewModel.ShowDownloadInfo; |
141 | 144 | } |
142 | 145 |
|
| 146 | + if (param == "ResizeHackTests") |
| 147 | + { |
| 148 | + ReproduceWasResizedCrashAsync(); |
| 149 | + } |
| 150 | + |
143 | 151 | if (param == "AsyncJsbTaskTests") |
144 | 152 | { |
145 | 153 | //After this setting has changed all tests will run through the Concurrent MethodQueueRunner |
@@ -223,5 +231,76 @@ private void Exit(object sender, ExecutedRoutedEventArgs e) |
223 | 231 | { |
224 | 232 | Close(); |
225 | 233 | } |
| 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 | + |
226 | 305 | } |
227 | 306 | } |
0 commit comments