icedwright 0.0.1

The icedwright test harness: run an iced 0.14 program headlessly on virtual time
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
//! Windows: what the harness knows of each, the pure state machine window actions drive, and
//! [`WindowRef`], a test's handle on one window.

use std::collections::BTreeMap;
use std::path::PathBuf;

use iced_core::{Point as IcedPoint, Size as IcedSize, theme, window};
use icedwright_locator::{AnyRole, IntoLocator, IntoTestId, RoleKind, RoleType, TextMatch, role};
use icedwright_types::units::{Logical, Physical, ScaleFactor};
use icedwright_types::{Point, Size};

use crate::error::{HarnessError, Result};
use crate::fakes::WindowRequest;
use crate::harness::{Handle, Harness, TestProgram};

/// What the harness knows of one window.
#[derive(Debug, Clone)]
pub struct WindowInfo {
    /// The window.
    pub id: window::Id,
    /// Its title, from `Program::title`.
    pub title: String,
    /// Its size in logical pixels at the system scale factor.
    pub logical_size: Logical<Size>,
    /// Its size in physical pixels.
    pub physical_size: Physical<Size<u32>>,
    /// The system scale factor times `Program::scale_factor`.
    pub scale_factor: ScaleFactor,
    /// Its position, when it has one.
    pub position: Option<Logical<Point>>,
    /// Windowed, fullscreen or hidden.
    pub mode: window::Mode,
    /// Maximised.
    pub maximized: bool,
    /// Minimised.
    pub minimized: bool,
    /// Focused.
    pub focused: bool,
    /// The mode of its theme.
    pub theme_mode: theme::Mode,
    /// The settings it was opened with, as changed since.
    pub settings: window::Settings,
    /// A request for the user's attention, if one is outstanding.
    pub attention: Option<window::UserAttention>,
}

impl WindowInfo {
    /// The logical size the interface is laid out in: the physical size over the full scale
    /// factor.
    pub(crate) fn layout_size(&self) -> IcedSize {
        let physical = self.physical_size.get();
        let factor = self.scale_factor.get();
        IcedSize::new(
            physical.width as f32 / factor,
            physical.height as f32 / factor,
        )
    }
}

/// What a change to the window set asks the harness to do.
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum Effect {
    /// Deliver this event to the window's interface and subscriptions.
    Event(window::Id, window::Event),
    /// Broadcast this event; the window is gone.
    Broadcast(window::Id, window::Event),
    /// The app exits.
    Exit,
}

/// One window's state, apart from its interface and renderer.
#[derive(Debug, Clone)]
pub(crate) struct WindowState {
    pub(crate) info: WindowInfo,
    pub(crate) requests: Vec<WindowRequest>,
    pub(crate) ordinal: u64,
    pub(crate) system_scale: ScaleFactor,
}

/// Every open window, in `window::Id` order.
#[derive(Debug, Clone)]
pub(crate) struct WindowSet {
    pub(crate) windows: BTreeMap<window::Id, WindowState>,
    pub(crate) focused: Option<window::Id>,
    daemon: bool,
    next_ordinal: u64,
    pub(crate) monitor: Logical<Size>,
}

/// `size` clamped to the window's minimum and maximum.
fn clamp(size: Size, settings: &window::Settings) -> Size {
    let min = settings.min_size.unwrap_or(IcedSize::ZERO);
    let max = settings
        .max_size
        .unwrap_or(IcedSize::new(f32::INFINITY, f32::INFINITY));
    Size::new(
        size.width.clamp(min.width, max.width.max(min.width)),
        size.height.clamp(min.height, max.height.max(min.height)),
    )
}

impl WindowSet {
    pub(crate) fn new(daemon: bool, monitor: Logical<Size>) -> Self {
        Self {
            windows: BTreeMap::new(),
            focused: None,
            daemon,
            next_ordinal: 0,
            monitor,
        }
    }

    pub(crate) fn get(&self, id: window::Id) -> Result<&WindowState, HarnessError> {
        self.windows.get(&id).ok_or(HarnessError::NoSuchWindow(id))
    }

    fn get_mut(&mut self, id: window::Id) -> Result<&mut WindowState, HarnessError> {
        self.windows
            .get_mut(&id)
            .ok_or(HarnessError::NoSuchWindow(id))
    }

    /// Opens a window, which takes focus, and asks for `Opened`, then the focus events.
    pub(crate) fn open(
        &mut self,
        id: window::Id,
        settings: window::Settings,
        size: Logical<Size>,
        system_scale: ScaleFactor,
    ) -> Vec<Effect> {
        self.next_ordinal += 1;
        let size = Logical(clamp(size.0, &settings));
        let position = match settings.position {
            window::Position::Specific(point) => Some(Logical(Point::from(point))),
            _ => None,
        };
        let info = WindowInfo {
            id,
            title: String::new(),
            logical_size: size,
            physical_size: size.to_physical_pixels(system_scale),
            scale_factor: system_scale,
            position,
            mode: if settings.visible {
                window::Mode::Windowed
            } else {
                window::Mode::Hidden
            },
            maximized: settings.maximized,
            minimized: false,
            focused: false,
            theme_mode: theme::Mode::None,
            settings,
            attention: None,
        };
        self.windows.insert(
            id,
            WindowState {
                info,
                requests: Vec::new(),
                ordinal: self.next_ordinal,
                system_scale,
            },
        );
        let mut effects = vec![Effect::Event(
            id,
            window::Event::Opened {
                position: position.map(|p| IcedPoint::from(p.0)),
                size: IcedSize::from(size.0),
            },
        )];
        effects.extend(self.focus(id));
        effects
    }

    /// Moves focus to `id`, with `Unfocused` to the window that had it.
    pub(crate) fn focus(&mut self, id: window::Id) -> Vec<Effect> {
        if self.focused == Some(id) || !self.windows.contains_key(&id) {
            return Vec::new();
        }
        let mut effects = Vec::new();
        if let Some(old) = self.focused.take()
            && let Some(state) = self.windows.get_mut(&old)
        {
            state.info.focused = false;
            effects.push(Effect::Event(old, window::Event::Unfocused));
        }
        if let Some(state) = self.windows.get_mut(&id) {
            state.info.focused = true;
        }
        self.focused = Some(id);
        effects.push(Effect::Event(id, window::Event::Focused));
        effects
    }

    /// Closes a window. Focus goes to the most recently opened window left; an application
    /// whose last window closes exits, a daemon does not.
    pub(crate) fn close(&mut self, id: window::Id) -> Result<Vec<Effect>, HarnessError> {
        let state = self
            .windows
            .remove(&id)
            .ok_or(HarnessError::NoSuchWindow(id))?;
        let mut effects = vec![Effect::Broadcast(id, window::Event::Closed)];
        if state.info.focused {
            self.focused = None;
            let latest = self
                .windows
                .values()
                .max_by_key(|state| state.ordinal)
                .map(|state| state.info.id);
            if let Some(next) = latest {
                effects.extend(self.focus(next));
            }
        }
        if self.windows.is_empty() && !self.daemon {
            effects.push(Effect::Exit);
        }
        Ok(effects)
    }

    /// Resizes as a user drag would: refused for a window that is not resizable, clamped to
    /// its limits. `force` skips both, as a tiling window manager would.
    pub(crate) fn resize(
        &mut self,
        id: window::Id,
        size: Logical<Size>,
        force: bool,
    ) -> Result<Vec<Effect>, HarnessError> {
        let state = self.get_mut(id)?;
        if !force && !state.info.settings.resizable {
            return Err(HarnessError::NotResizable(id));
        }
        let size = if force {
            size.0
        } else {
            clamp(size.0, &state.info.settings)
        };
        state.info.logical_size = Logical(size);
        state.info.physical_size = Logical(size).to_physical_pixels(state.system_scale);
        Ok(vec![Effect::Event(
            id,
            window::Event::Resized(IcedSize::from(size)),
        )])
    }

    /// Changes the system scale factor of a window.
    pub(crate) fn rescale(
        &mut self,
        id: window::Id,
        factor: ScaleFactor,
        program_scale: f32,
    ) -> Result<Vec<Effect>, HarnessError> {
        let state = self.get_mut(id)?;
        state.system_scale = factor;
        state.info.physical_size = state.info.logical_size.to_physical_pixels(factor);
        state.info.scale_factor = ScaleFactor::new(factor.get() * program_scale).unwrap_or(factor);
        Ok(vec![Effect::Event(
            id,
            window::Event::Rescaled(state.info.scale_factor.get()),
        )])
    }

    /// Applies an action that needs nothing but window state, answering its channel if it
    /// has one. Returns `None` for actions the harness performs itself.
    pub(crate) fn apply(&mut self, action: iced_runtime::window::Action) -> Option<Vec<Effect>> {
        use iced_runtime::window::Action;
        let effects = match action {
            Action::Close(id) => self.close(id).unwrap_or_default(),
            Action::GetOldest(sender) => {
                let oldest = self
                    .windows
                    .values()
                    .min_by_key(|s| s.ordinal)
                    .map(|s| s.info.id);
                let _ = sender.send(oldest);
                Vec::new()
            }
            Action::GetLatest(sender) => {
                let latest = self
                    .windows
                    .values()
                    .max_by_key(|s| s.ordinal)
                    .map(|s| s.info.id);
                let _ = sender.send(latest);
                Vec::new()
            }
            Action::Drag(id) => self.request(id, WindowRequest::Drag),
            Action::DragResize(id, direction) => {
                self.request(id, WindowRequest::DragResize(direction))
            }
            Action::ShowSystemMenu(id) => self.request(id, WindowRequest::ShowSystemMenu),
            Action::SetIcon(id, _) => self.request(id, WindowRequest::SetIcon),
            Action::EnableMousePassthrough(id) => {
                self.request(id, WindowRequest::MousePassthrough(true))
            }
            Action::DisableMousePassthrough(id) => {
                self.request(id, WindowRequest::MousePassthrough(false))
            }
            Action::SetAllowAutomaticTabbing(on) => {
                if let Some(id) = self.focused {
                    let _ = self.request(id, WindowRequest::AutomaticTabbing(on));
                }
                Vec::new()
            }
            Action::RequestUserAttention(id, attention) => {
                if let Some(state) = self.windows.get_mut(&id) {
                    state.info.attention = attention;
                }
                self.request(id, WindowRequest::RequestUserAttention(attention))
            }
            Action::Resize(id, size) => self
                .resize(id, Logical(Size::from(size)), true)
                .unwrap_or_default(),
            Action::GetSize(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(IcedSize::from(state.info.logical_size.0));
                }
                Vec::new()
            }
            Action::GetMaximized(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(state.info.maximized);
                }
                Vec::new()
            }
            Action::Maximize(id, on) => self.update(id, |info| info.maximized = on),
            Action::ToggleMaximize(id) => self.update(id, |info| info.maximized = !info.maximized),
            Action::GetMinimized(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(Some(state.info.minimized));
                }
                Vec::new()
            }
            Action::Minimize(id, on) => self.update(id, |info| info.minimized = on),
            Action::GetPosition(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(state.info.position.map(|p| IcedPoint::from(p.0)));
                }
                Vec::new()
            }
            Action::GetScaleFactor(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(state.info.scale_factor.get());
                }
                Vec::new()
            }
            Action::Move(id, point) => {
                let _ = self.update(id, |info| info.position = Some(Logical(Point::from(point))));
                vec![Effect::Event(id, window::Event::Moved(point))]
            }
            Action::SetMode(id, mode) => self.update(id, |info| info.mode = mode),
            Action::GetMode(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(state.info.mode);
                }
                Vec::new()
            }
            Action::ToggleDecorations(id) => self.update(id, |info| {
                info.settings.decorations = !info.settings.decorations;
            }),
            Action::GainFocus(id) => self.focus(id),
            Action::SetLevel(id, level) => self.update(id, |info| info.settings.level = level),
            Action::GetRawId(id, sender) => {
                if let Ok(state) = self.get(id) {
                    let _ = sender.send(state.ordinal);
                }
                Vec::new()
            }
            Action::SetMinSize(id, size) => self.update(id, |info| info.settings.min_size = size),
            Action::SetMaxSize(id, size) => self.update(id, |info| info.settings.max_size = size),
            Action::SetResizable(id, on) => self.update(id, |info| info.settings.resizable = on),
            Action::SetResizeIncrements(_, _) => Vec::new(),
            Action::GetMonitorSize(_, sender) => {
                let _ = sender.send(Some(IcedSize::from(self.monitor.0)));
                Vec::new()
            }
            Action::Open(..)
            | Action::Run(..)
            | Action::Screenshot(..)
            | Action::RedrawAll
            | Action::RelayoutAll => return None,
        };
        Some(effects)
    }

    fn request(&mut self, id: window::Id, request: WindowRequest) -> Vec<Effect> {
        if let Some(state) = self.windows.get_mut(&id) {
            state.requests.push(request);
        }
        Vec::new()
    }

    fn update(&mut self, id: window::Id, change: impl FnOnce(&mut WindowInfo)) -> Vec<Effect> {
        if let Some(state) = self.windows.get_mut(&id) {
            change(&mut state.info);
        }
        Vec::new()
    }
}

/// A test's handle on one window.
#[must_use]
pub struct WindowRef<'h, P: TestProgram> {
    harness: &'h mut Harness<P>,
    id: window::Id,
}

impl<P: TestProgram> std::fmt::Debug for WindowRef<'_, P> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("WindowRef")
            .field("id", &self.id)
            .finish_non_exhaustive()
    }
}

impl<'h, P: TestProgram> WindowRef<'h, P> {
    pub(crate) fn new(harness: &'h mut Harness<P>, id: window::Id) -> Self {
        Self { harness, id }
    }

    /// The window.
    #[must_use]
    pub fn id(&self) -> window::Id {
        self.id
    }

    /// What the harness knows of it.
    pub fn info(&self) -> Result<&WindowInfo> {
        Ok(&self.harness.window_set().get(self.id)?.info)
    }

    /// Requests with no headless meaning that the app made of this window.
    pub fn requests(&self) -> Result<&[WindowRequest]> {
        Ok(&self.harness.window_set().get(self.id)?.requests)
    }

    /// Resizes as a user drag would: refused if the window is not resizable, clamped to its
    /// limits.
    pub fn resize(self, size: impl Into<Logical<Size>>) -> Result {
        self.harness.resize_window(self.id, size.into(), false)
    }

    /// Resizes as a tiling window manager would, ignoring the limits.
    pub fn force_size(self, size: impl Into<Logical<Size>>) -> Result {
        self.harness.resize_window(self.id, size.into(), true)
    }

    /// Changes the system scale factor.
    pub fn set_scale_factor(self, factor: ScaleFactor) -> Result {
        self.harness.rescale_window(self.id, factor)
    }

    /// Moves the window.
    pub fn move_to(self, position: Logical<Point>) -> Result {
        let point = IcedPoint::from(position.0);
        self.harness
            .window_action(iced_runtime::window::Action::Move(self.id, point))
    }

    /// Gives the window focus.
    pub fn focus(self) -> Result {
        self.harness
            .window_action(iced_runtime::window::Action::GainFocus(self.id))
    }

    /// Presses the close button.
    pub fn request_close(self) -> Result {
        self.harness.request_close(self.id)
    }

    /// Hovers files over the window, one `FileHovered` per path.
    pub fn hover_files(self, paths: impl IntoIterator<Item = impl Into<PathBuf>>) -> Result {
        let events = paths
            .into_iter()
            .map(|path| window::Event::FileHovered(path.into()))
            .collect();
        self.harness.window_events(self.id, events)
    }

    /// The hovered files leave the window.
    pub fn leave_files(self) -> Result {
        self.harness
            .window_events(self.id, vec![window::Event::FilesHoveredLeft])
    }

    /// Drops files on the window, one `FileDropped` per path. Refused on Wayland, where winit
    /// does not deliver drops.
    pub fn drop_files(self, paths: impl IntoIterator<Item = impl Into<PathBuf>>) -> Result {
        self.harness.check_file_drops()?;
        let events = paths
            .into_iter()
            .map(|path| window::Event::FileDropped(path.into()))
            .collect();
        self.harness.window_events(self.id, events)
    }

    /// This window's root.
    pub fn page(self) -> Handle<'h, P, role::Window> {
        Handle::new(self.harness, icedwright_locator::page(), Some(self.id))
    }

    /// A locator, scoped to this window.
    pub fn locate<R: RoleKind>(self, locator: impl IntoLocator<R>) -> Handle<'h, P, R> {
        Handle::new(self.harness, locator.into_locator(), Some(self.id))
    }

    /// `get_by_role`, scoped to this window.
    pub fn get_by_role<R: RoleType>(self, role: R) -> Handle<'h, P, R> {
        let id = self.id;
        Handle::new(
            self.harness,
            icedwright_locator::get_by_role(role),
            Some(id),
        )
    }

    /// `get_by_text`, scoped to this window.
    pub fn get_by_text(self, text: impl Into<TextMatch>) -> Handle<'h, P, AnyRole> {
        let id = self.id;
        Handle::new(
            self.harness,
            icedwright_locator::get_by_text(text),
            Some(id),
        )
    }

    /// `get_by_test_id`, scoped to this window.
    pub fn get_by_test_id<'a>(self, test_id: impl IntoTestId<'a>) -> Handle<'h, P, AnyRole> {
        let id = self.id;
        Handle::new(
            self.harness,
            icedwright_locator::get_by_test_id(test_id),
            Some(id),
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn settings() -> window::Settings {
        window::Settings {
            min_size: Some(IcedSize::new(200.0, 100.0)),
            max_size: Some(IcedSize::new(800.0, 600.0)),
            ..window::Settings::default()
        }
    }

    fn set(daemon: bool) -> WindowSet {
        WindowSet::new(daemon, Logical(Size::new(1920.0, 1080.0)))
    }

    fn open(set: &mut WindowSet) -> window::Id {
        let id = window::Id::unique();
        let _ = set.open(
            id,
            settings(),
            Logical(Size::new(400.0, 300.0)),
            ScaleFactor::ONE,
        );
        id
    }

    #[test]
    fn open_emits_opened_then_focus_and_close_emits_closed() {
        let mut windows = set(false);
        let first = open(&mut windows);
        let second = window::Id::unique();
        let effects = windows.open(
            second,
            settings(),
            Logical(Size::new(400.0, 300.0)),
            ScaleFactor::ONE,
        );
        assert!(
            matches!(effects[0], Effect::Event(id, window::Event::Opened { .. }) if id == second)
        );
        assert_eq!(effects[1], Effect::Event(first, window::Event::Unfocused));
        assert_eq!(effects[2], Effect::Event(second, window::Event::Focused));
        let closed = windows.close(second).unwrap();
        assert_eq!(closed[0], Effect::Broadcast(second, window::Event::Closed));
        assert_eq!(closed[1], Effect::Event(first, window::Event::Focused));
        assert_eq!(windows.focused, Some(first));
    }

    #[test]
    fn resize_clamps_and_refuses_a_fixed_window() {
        let mut windows = set(false);
        let id = open(&mut windows);
        let effects = windows
            .resize(id, Logical(Size::new(1000.0, 50.0)), false)
            .unwrap();
        assert_eq!(
            effects,
            vec![Effect::Event(
                id,
                window::Event::Resized(IcedSize::new(800.0, 100.0))
            )]
        );
        windows
            .windows
            .get_mut(&id)
            .unwrap()
            .info
            .settings
            .resizable = false;
        assert!(matches!(
            windows.resize(id, Logical(Size::new(300.0, 300.0)), false),
            Err(HarnessError::NotResizable(_))
        ));
        assert!(
            windows
                .resize(id, Logical(Size::new(10.0, 10.0)), true)
                .is_ok()
        );
        assert_eq!(
            windows.get(id).unwrap().info.logical_size,
            Logical(Size::new(10.0, 10.0))
        );
    }

    #[test]
    fn closing_the_last_window_exits_an_application_not_a_daemon() {
        let mut application = set(false);
        let id = open(&mut application);
        assert!(application.close(id).unwrap().contains(&Effect::Exit));
        let mut daemon = set(true);
        let id = open(&mut daemon);
        assert!(!daemon.close(id).unwrap().contains(&Effect::Exit));
    }

    #[test]
    fn focus_moves_on_gain_focus() {
        let mut windows = set(false);
        let first = open(&mut windows);
        let second = open(&mut windows);
        let effects = windows
            .apply(iced_runtime::window::Action::GainFocus(first))
            .unwrap();
        assert_eq!(
            effects,
            vec![
                Effect::Event(second, window::Event::Unfocused),
                Effect::Event(first, window::Event::Focused)
            ]
        );
        assert!(windows.get(first).unwrap().info.focused);
        assert!(!windows.get(second).unwrap().info.focused);
    }

    #[test]
    fn windows_are_visited_in_id_order() {
        let mut windows = set(false);
        let ids: Vec<window::Id> = (0..3).map(|_| open(&mut windows)).collect();
        let visited: Vec<window::Id> = windows.windows.keys().copied().collect();
        let mut sorted = ids.clone();
        sorted.sort();
        assert_eq!(visited, sorted);
    }

    #[test]
    fn a_drag_is_recorded_for_its_window() {
        let mut windows = set(false);
        let id = open(&mut windows);
        let _ = windows.apply(iced_runtime::window::Action::Drag(id));
        assert_eq!(windows.get(id).unwrap().requests, vec![WindowRequest::Drag]);
    }

    #[test]
    fn rescale_doubles_the_physical_size() {
        let mut windows = set(false);
        let id = open(&mut windows);
        let _ = windows.rescale(id, ScaleFactor::TWO, 1.0).unwrap();
        let info = &windows.get(id).unwrap().info;
        assert_eq!(info.physical_size.get(), Size::new(800, 600));
        assert_eq!(info.layout_size(), IcedSize::new(400.0, 300.0));
    }
}